Skip to content

Commit 0768854

Browse files
authored
Remove legacy/broken makeCopyValues from parseTools_legacy.mjs. NFC (emscripten-core#23354)
This function was calling functions that are not imported by this module (at least isNumber and getFastValue). Rather than fix this by importing them I think we can safely simple remove this. Also, move isNumber in to parseTools.mjs which is its only user. Also remove `stripCorrections` which was not exported via `addToCompileTimeContext` is was not visible at all.
1 parent d6aabb2 commit 0768854

File tree

3 files changed

+5
-72
lines changed

3 files changed

+5
-72
lines changed

src/parseTools.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
addToCompileTimeContext,
1313
assert,
1414
error,
15-
isNumber,
1615
printErr,
1716
read,
1817
runInMacroContext,
@@ -337,6 +336,11 @@ function ensureDot(value) {
337336
return value.substr(0, e) + '.0' + value.substr(e);
338337
}
339338

339+
export function isNumber(x) {
340+
// XXX this does not handle 0xabc123 etc. We should likely also do x == parseInt(x) (which handles that), and remove hack |// handle 0x... as well|
341+
return x == parseFloat(x) || (typeof x == 'string' && x.match(/^-?\d+$/)) || x == 'NaN';
342+
}
343+
340344
// ensures that a float type has either 5.5 (clearly a float) or +5 (float due to asm coercion)
341345
function asmEnsureFloat(value, type) {
342346
if (!isNumber(value)) return value;

src/parseTools_legacy.mjs

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -37,71 +37,6 @@ function receiveI64ParamAsI32s(name) {
3737
return '';
3838
}
3939

40-
function stripCorrections(param) {
41-
warn('use of legacy parseTools function: stripCorrections');
42-
let m;
43-
while (true) {
44-
if ((m = /^\((.*)\)$/.exec(param))) {
45-
param = m[1];
46-
continue;
47-
}
48-
if ((m = /^\(([$_\w]+)\)&\d+$/.exec(param))) {
49-
param = m[1];
50-
continue;
51-
}
52-
if ((m = /^\(([$_\w()]+)\)\|0$/.exec(param))) {
53-
param = m[1];
54-
continue;
55-
}
56-
if ((m = /^\(([$_\w()]+)\)\>>>0$/.exec(param))) {
57-
param = m[1];
58-
continue;
59-
}
60-
if ((m = /CHECK_OVERFLOW\(([^,)]*),.*/.exec(param))) {
61-
param = m[1];
62-
continue;
63-
}
64-
break;
65-
}
66-
return param;
67-
}
68-
69-
const UNROLL_LOOP_MAX = 8;
70-
71-
function makeCopyValues(dest, src, num, type, modifier, align, sep = ';') {
72-
warn('use of legacy parseTools function: makeCopyValues');
73-
assert(typeof align === 'undefined');
74-
function unroll(type, num, jump = 1) {
75-
const setValues = range(num).map((i) =>
76-
makeSetValue(dest, i * jump, makeGetValue(src, i * jump, type), type),
77-
);
78-
return setValues.join(sep);
79-
}
80-
// If we don't know how to handle this at compile-time, or handling it is best
81-
// done in a large amount of code, call memcpy
82-
if (!isNumber(num)) num = stripCorrections(num);
83-
if (!isNumber(align)) align = stripCorrections(align);
84-
if (!isNumber(num) || parseInt(num) / align >= UNROLL_LOOP_MAX) {
85-
return '(_memcpy(' + dest + ', ' + src + ', ' + num + ')|0)';
86-
}
87-
num = parseInt(num);
88-
// remove corrections, since we will be correcting after we add anyhow,
89-
dest = stripCorrections(dest);
90-
src = stripCorrections(src);
91-
// and in the heap assignment expression
92-
const ret = [];
93-
[4, 2, 1].forEach((possibleAlign) => {
94-
if (num == 0) return;
95-
if (align >= possibleAlign) {
96-
ret.push(unroll('i' + possibleAlign * 8, Math.floor(num / possibleAlign), possibleAlign));
97-
src = getFastValue(src, '+', Math.floor(num / possibleAlign) * possibleAlign);
98-
dest = getFastValue(dest, '+', Math.floor(num / possibleAlign) * possibleAlign);
99-
num %= possibleAlign;
100-
}
101-
});
102-
return ret.join(sep);
103-
}
104-
10540
function makeMalloc(source, param) {
10641
warn('use of legacy parseTools function: makeMalloc');
10742
return `_malloc(${param})`;
@@ -143,7 +78,6 @@ addToCompileTimeContext({
14378
Runtime,
14479
addAtMain,
14580
asmFFICoercion,
146-
makeCopyValues,
14781
makeMalloc,
14882
makeStructuralReturn,
14983
receiveI64ParamAsDouble,

src/utility.mjs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,6 @@ export function mergeInto(obj, other, options = null) {
200200
return Object.assign(obj, other);
201201
}
202202

203-
export function isNumber(x) {
204-
// XXX this does not handle 0xabc123 etc. We should likely also do x == parseInt(x) (which handles that), and remove hack |// handle 0x... as well|
205-
return x == parseFloat(x) || (typeof x == 'string' && x.match(/^-?\d+$/)) || x == 'NaN';
206-
}
207-
208203
// Symbols that start with '$' are not exported to the wasm module.
209204
// They are intended to be called exclusively by JS code.
210205
export function isJsOnlySymbol(symbol) {

0 commit comments

Comments
 (0)