mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:47:34 +00:00
Meta: Make the wasm test generator cast numbers to i32 when needed
Otherwise the sign would be out of whack
This commit is contained in:
parent
6cd9906f60
commit
6b5d1eedcb
1 changed files with 15 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
import struct
|
||||||
from sys import argv, stderr
|
from sys import argv, stderr
|
||||||
from os import path
|
from os import path
|
||||||
from string import whitespace
|
from string import whitespace
|
||||||
|
@ -156,7 +156,7 @@ def genarg(spec):
|
||||||
return '-NaN' if math.copysign(1.0, x) < 0 else 'NaN'
|
return '-NaN' if math.copysign(1.0, x) < 0 else 'NaN'
|
||||||
if math.isinf(x):
|
if math.isinf(x):
|
||||||
return 'Infinity' if x > 0 else '-Infinity'
|
return 'Infinity' if x > 0 else '-Infinity'
|
||||||
return str(x)
|
return x
|
||||||
except ValueError:
|
except ValueError:
|
||||||
try:
|
try:
|
||||||
x = float.fromhex(x)
|
x = float.fromhex(x)
|
||||||
|
@ -165,20 +165,25 @@ def genarg(spec):
|
||||||
return '-NaN' if math.copysign(1.0, x) < 0 else 'NaN'
|
return '-NaN' if math.copysign(1.0, x) < 0 else 'NaN'
|
||||||
if math.isinf(x):
|
if math.isinf(x):
|
||||||
return 'Infinity' if x > 0 else '-Infinity'
|
return 'Infinity' if x > 0 else '-Infinity'
|
||||||
return str(x)
|
return x
|
||||||
except ValueError:
|
except ValueError:
|
||||||
try:
|
try:
|
||||||
x = int(x, 0)
|
x = int(x, 0)
|
||||||
return str(x)
|
return x
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return x
|
return x
|
||||||
|
|
||||||
x = gen()
|
x = gen()
|
||||||
if x.startswith('nan'):
|
if isinstance(x, str):
|
||||||
return 'NaN'
|
if x.startswith('nan'):
|
||||||
if x.startswith('-nan'):
|
return 'NaN'
|
||||||
return '-NaN'
|
if x.startswith('-nan'):
|
||||||
return x
|
return '-NaN'
|
||||||
|
return x
|
||||||
|
if spec['type'] == 'i32':
|
||||||
|
# cast back to i32 to get the correct sign
|
||||||
|
return str(struct.unpack('>i', struct.pack('>q', int(x))[4:])[0])
|
||||||
|
return str(x)
|
||||||
|
|
||||||
|
|
||||||
all_names_in_main = {}
|
all_names_in_main = {}
|
||||||
|
@ -249,7 +254,7 @@ def main():
|
||||||
with NamedTemporaryFile("w+") as temp:
|
with NamedTemporaryFile("w+") as temp:
|
||||||
temp.write(description["module"])
|
temp.write(description["module"])
|
||||||
temp.flush()
|
temp.flush()
|
||||||
rc = call(["wasm-as", "-n", temp.name, "-o", outpath])
|
rc = call(["wasm-as", "-n", "-all", temp.name, "-o", outpath])
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
print("Failed to compile", name, "module index", index, "skipping that test", file=stderr)
|
print("Failed to compile", name, "module index", index, "skipping that test", file=stderr)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue