summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xauto_update_tests.py2
-rwxr-xr-xcheck.py2
-rw-r--r--src/s2wasm.h24
-rw-r--r--src/shared-constants.h2
-rw-r--r--test/dot_s/cfg-stackify.wast2
-rw-r--r--test/dot_s/data-offset-folding.wast2
-rw-r--r--test/dot_s/global.wast2
-rw-r--r--test/dot_s/load-ext.wast20
-rw-r--r--test/dot_s/load-store-i1.wast8
-rw-r--r--test/dot_s/memops.wast2
-rw-r--r--test/dot_s/offset.wast10
-rw-r--r--test/dot_s/permute.wast2
-rw-r--r--test/dot_s/relocation.wast4
-rw-r--r--test/dot_s/store-results.wast4
-rw-r--r--test/dot_s/symbolic-offset.wast4
-rw-r--r--test/dot_s/vtable.wast10
16 files changed, 55 insertions, 45 deletions
diff --git a/auto_update_tests.py b/auto_update_tests.py
index 2e325ed94..c3b9742b5 100755
--- a/auto_update_tests.py
+++ b/auto_update_tests.py
@@ -29,7 +29,7 @@ for t in sorted(os.listdir('test')):
for s in sorted(os.listdir(os.path.join('test', 'dot_s'))) + sorted(os.listdir(os.path.join('test', 'experimental', 'prototype-wasmate', 'test'))):
if not s.endswith('.s'): continue
- if s in ['inline-asm.s', 'userstack.s']: continue
+ if s in ['inline-asm.s', 'userstack.s', 'offset-folding.s']: continue
print '..', s
wasm = s.replace('.s', '.wast')
full = os.path.join('test', 'dot_s', s)
diff --git a/check.py b/check.py
index ed40b1fc1..46af188bf 100755
--- a/check.py
+++ b/check.py
@@ -236,7 +236,7 @@ print '\n[ checking .s testcases... ]\n'
for s in sorted(os.listdir(os.path.join('test', 'dot_s'))) + sorted(os.listdir(os.path.join('test', 'experimental', 'prototype-wasmate', 'test'))):
if not s.endswith('.s'): continue
- if s in ['inline-asm.s', 'userstack.s']: continue
+ if s in ['inline-asm.s', 'userstack.s', 'offset-folding.s']: continue
print '..', s
wasm = s.replace('.s', '.wast')
full = os.path.join('test', 'dot_s', s)
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 02fc37cfe..45d943446 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -55,7 +55,12 @@ private:
size_t nextStatic = 1; // location of next static allocation, i.e., the data segment
std::map<Name, int32_t> staticAddresses; // name => address
- typedef std::pair<Const*, Name> Addressing;
+ struct Addressing {
+ Const* value;
+ Name name;
+ int32_t offset;
+ Addressing(Const* value, Name name, int32_t offset) : value(value), name(name), offset(offset) {}
+ };
std::vector<Addressing> addressings; // we fix these up
struct Relocation {
@@ -588,12 +593,14 @@ private:
if (match("const")) {
Name assign = getAssign();
char start = *s;
- cashew::IString str = getStr();
- if (start == '.' || (isalpha(start) && str != NAN_ && str != INFINITY_)) {
+ cashew::IString str = getStrToSep();
+ if (start == '.' || (isalpha(start) && str != NAN__ && str != INFINITY__)) {
// global address
+ int32_t offset = 0;
+ if (match("+")) offset = getInt();
auto curr = allocator.alloc<Const>();
curr->type = i32;
- addressings.emplace_back(curr, str);
+ addressings.emplace_back(curr, str, offset);
setOutput(curr, assign);
} else {
// constant
@@ -950,10 +957,11 @@ private:
}
void fix() {
- for (auto& pair : addressings) {
- Const* curr = pair.first;
- Name name = pair.second;
- curr->value = Literal(staticAddresses[name]);
+ for (auto& triple : addressings) {
+ Const* curr = triple.value;
+ Name name = triple.name;
+ size_t offset = triple.offset;
+ curr->value = Literal(staticAddresses[name] + offset);
assert(curr->value.i32 > 0);
curr->type = i32;
}
diff --git a/src/shared-constants.h b/src/shared-constants.h
index ea8980fa2..a928756da 100644
--- a/src/shared-constants.h
+++ b/src/shared-constants.h
@@ -24,6 +24,8 @@ namespace wasm {
cashew::IString GLOBAL("global"),
NAN_("NaN"),
INFINITY_("Infinity"),
+ NAN__("nan"),
+ INFINITY__("infinity"),
TOPMOST("topmost"),
INT8ARRAY("Int8Array"),
INT16ARRAY("Int16Array"),
diff --git a/test/dot_s/cfg-stackify.wast b/test/dot_s/cfg-stackify.wast
index e170415cf..639c20d29 100644
--- a/test/dot_s/cfg-stackify.wast
+++ b/test/dot_s/cfg-stackify.wast
@@ -1048,7 +1048,7 @@
(loop $BB21_8 $BB21_1
(block
(set_local $$1
- (i32.load align=8
+ (i32.load8_u align=1
(get_local $$0)
)
)
diff --git a/test/dot_s/data-offset-folding.wast b/test/dot_s/data-offset-folding.wast
index e0a60c70e..f0f2ab09e 100644
--- a/test/dot_s/data-offset-folding.wast
+++ b/test/dot_s/data-offset-folding.wast
@@ -1,4 +1,4 @@
(module
- (memory 0 4294967295 (segment 2 "\00\00\00\00") (segment 408 "X\00\00\00"))
+ (memory 0 4294967295 (segment 4 "\00\00\00\00") (segment 416 "`\00\00\00"))
)
;; METADATA: { "asmConsts": {} }
diff --git a/test/dot_s/global.wast b/test/dot_s/global.wast
index 255b35617..7e64c7b42 100644
--- a/test/dot_s/global.wast
+++ b/test/dot_s/global.wast
@@ -1,5 +1,5 @@
(module
- (memory 0 4294967295 (segment 2 "9\05\00\00"))
+ (memory 0 4294967295 (segment 4 "9\05\00\00"))
(import $memcpy "env" "memcpy")
(export "foo" $foo)
(export "call_memcpy" $call_memcpy)
diff --git a/test/dot_s/load-ext.wast b/test/dot_s/load-ext.wast
index e569cfd33..f3ae52530 100644
--- a/test/dot_s/load-ext.wast
+++ b/test/dot_s/load-ext.wast
@@ -14,7 +14,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i32.load align=8
+ (i32.load8_s align=1
(get_local $$0)
)
)
@@ -25,7 +25,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i32.load align=8
+ (i32.load8_u align=1
(get_local $$0)
)
)
@@ -36,7 +36,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i32.load align=16
+ (i32.load16_s align=2
(get_local $$0)
)
)
@@ -47,7 +47,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i32.load align=16
+ (i32.load16_u align=2
(get_local $$0)
)
)
@@ -58,7 +58,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i64.load align=8
+ (i64.load8_s align=1
(get_local $$0)
)
)
@@ -69,7 +69,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i64.load align=8
+ (i64.load8_u align=1
(get_local $$0)
)
)
@@ -80,7 +80,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i64.load align=16
+ (i64.load16_s align=2
(get_local $$0)
)
)
@@ -91,7 +91,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i64.load align=16
+ (i64.load16_u align=2
(get_local $$0)
)
)
@@ -102,7 +102,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i64.load align=32
+ (i64.load align=4
(get_local $$0)
)
)
@@ -113,7 +113,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i64.load align=32
+ (i64.load align=4
(get_local $$0)
)
)
diff --git a/test/dot_s/load-store-i1.wast b/test/dot_s/load-store-i1.wast
index 644fe798b..3f184bb0f 100644
--- a/test/dot_s/load-store-i1.wast
+++ b/test/dot_s/load-store-i1.wast
@@ -10,7 +10,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i32.load align=8
+ (i32.load8_u align=1
(get_local $$0)
)
)
@@ -27,7 +27,7 @@
(br $fake_return_waka123
(i32.shr_s
(i32.shl
- (i32.load align=8
+ (i32.load8_u align=1
(get_local $$0)
)
(get_local $$1)
@@ -42,7 +42,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i64.load align=8
+ (i64.load8_u align=1
(get_local $$0)
)
)
@@ -59,7 +59,7 @@
(br $fake_return_waka123
(i64.shr_s
(i64.shl
- (i64.load align=8
+ (i64.load8_u align=1
(get_local $$0)
)
(get_local $$1)
diff --git a/test/dot_s/memops.wast b/test/dot_s/memops.wast
index 4f23804b7..48afae938 100644
--- a/test/dot_s/memops.wast
+++ b/test/dot_s/memops.wast
@@ -132,7 +132,7 @@
(set_local $$6
(i32.add
(i32.and
- (i32.load align=8
+ (i32.load8_u align=1
(i32.add
(get_local $$11)
(get_local $$5)
diff --git a/test/dot_s/offset.wast b/test/dot_s/offset.wast
index d8a1a4a7a..481cb3cc5 100644
--- a/test/dot_s/offset.wast
+++ b/test/dot_s/offset.wast
@@ -1,5 +1,5 @@
(module
- (memory 0 4294967295 (segment 2 "\00\00\00\00"))
+ (memory 0 4294967295 (segment 4 "\00\00\00\00"))
(export "load_i32_with_folded_offset" $load_i32_with_folded_offset)
(export "load_i32_with_unfolded_offset" $load_i32_with_unfolded_offset)
(export "load_i64_with_folded_offset" $load_i64_with_folded_offset)
@@ -130,7 +130,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i32.load align=4 offset=2
+ (i32.load align=4 offset=4
(i32.const 0)
)
)
@@ -159,7 +159,7 @@
(set_local $$0
(i32.const 0)
)
- (i32.store align=4 offset=2
+ (i32.store align=4 offset=4
(get_local $$0)
(get_local $$0)
)
@@ -171,7 +171,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i32.load align=8 offset=24
+ (i32.load8_s align=1 offset=24
(get_local $$0)
)
)
@@ -182,7 +182,7 @@
(block $fake_return_waka123
(block
(br $fake_return_waka123
- (i32.load align=8 offset=24
+ (i32.load8_u align=1 offset=24
(get_local $$0)
)
)
diff --git a/test/dot_s/permute.wast b/test/dot_s/permute.wast
index e535422c9..eb659e5f3 100644
--- a/test/dot_s/permute.wast
+++ b/test/dot_s/permute.wast
@@ -1,4 +1,4 @@
(module
- (memory 0 4294967295 (segment 4 "hE?\8ds\0e7\db[g\8f\955it\c4k\0b\e2\ef\bcld\e0\fd\8c\9e\86&~\d8\94\89+\c8\a4\c2\f2\fb\12\1cej\d99\b7\b3W\c6w\af\ae\caM>\92ub\96\84\b6\b0N\ec;q\11\f7\bf\e31\e6\a7\90\fc\03\e4\aa\d7\cc- \15\83DH\80r\fa\01X\eb:_\00A\cd\e9o`n\ac(\ad\ba0\dcyS#\f4$\"\82\7f}\8e\f6\93L\'\bb\bdZ\ed4\18\f3\c0\cf\ff\a3\f8\07\05\9c\d3\0f\a0\06m%\\\f9^B<\e7\b1\17\98]\0c\dd\c5\f5p\e5\fezJ\ab,F\a5@\08R\85!\b8\1a\ce\d5\04\nI\a6\d1\9f\8a\c9\a9|\97\9aG\be8Y\8b\c1\1b\d4\ea\b9\19\14\9b\9163\d0\1d\d2\df=C\1f\0dc\e1\c7QUv\02\b5aK\b4\tV\c3x\e8\a1\1e\81\de/{\da\d6Pf\10T\f0)\88\16\ee\a8\9d\f1\cbO*\b2\99\132\87.\a2"))
+ (memory 0 4294967295 (segment 16 "hE?\8ds\0e7\db[g\8f\955it\c4k\0b\e2\ef\bcld\e0\fd\8c\9e\86&~\d8\94\89+\c8\a4\c2\f2\fb\12\1cej\d99\b7\b3W\c6w\af\ae\caM>\92ub\96\84\b6\b0N\ec;q\11\f7\bf\e31\e6\a7\90\fc\03\e4\aa\d7\cc- \15\83DH\80r\fa\01X\eb:_\00A\cd\e9o`n\ac(\ad\ba0\dcyS#\f4$\"\82\7f}\8e\f6\93L\'\bb\bdZ\ed4\18\f3\c0\cf\ff\a3\f8\07\05\9c\d3\0f\a0\06m%\\\f9^B<\e7\b1\17\98]\0c\dd\c5\f5p\e5\fezJ\ab,F\a5@\08R\85!\b8\1a\ce\d5\04\nI\a6\d1\9f\8a\c9\a9|\97\9aG\be8Y\8b\c1\1b\d4\ea\b9\19\14\9b\9163\d0\1d\d2\df=C\1f\0dc\e1\c7QUv\02\b5aK\b4\tV\c3x\e8\a1\1e\81\de/{\da\d6Pf\10T\f0)\88\16\ee\a8\9d\f1\cbO*\b2\99\132\87.\a2"))
)
;; METADATA: { "asmConsts": {} }
diff --git a/test/dot_s/relocation.wast b/test/dot_s/relocation.wast
index 2bddedb89..6a2c1dd13 100644
--- a/test/dot_s/relocation.wast
+++ b/test/dot_s/relocation.wast
@@ -1,5 +1,5 @@
(module
- (memory 0 4294967295 (segment 2 "\06\00\00\00") (segment 6 "\02\00\00\00"))
+ (memory 0 4294967295 (segment 4 "\08\00\00\00") (segment 8 "\04\00\00\00"))
(export "main" $main)
(func $main (result i32)
(local $$0 i32)
@@ -7,7 +7,7 @@
(block
(br $fake_return_waka123
(i32.load align=4
- (i32.const 0)
+ (i32.const 8)
)
)
)
diff --git a/test/dot_s/store-results.wast b/test/dot_s/store-results.wast
index 5f801cd3b..75ba772e1 100644
--- a/test/dot_s/store-results.wast
+++ b/test/dot_s/store-results.wast
@@ -34,7 +34,7 @@
(i32.const 1)
)
)
- (i32.store align=4 offset=2
+ (i32.store align=4 offset=4
(get_local $$0)
(get_local $$0)
)
@@ -70,7 +70,7 @@
(f32.const 1)
)
)
- (i32.store align=4 offset=2
+ (i32.store align=4 offset=4
(get_local $$0)
(get_local $$0)
)
diff --git a/test/dot_s/symbolic-offset.wast b/test/dot_s/symbolic-offset.wast
index 5b4904529..95df82365 100644
--- a/test/dot_s/symbolic-offset.wast
+++ b/test/dot_s/symbolic-offset.wast
@@ -1,10 +1,10 @@
(module
- (memory 0 4294967295 (segment 2 "\01\00\00\00\00\00\00\00\00\00\00\00"))
+ (memory 0 4294967295 (segment 4 "\01\00\00\00\00\00\00\00\00\00\00\00"))
(export "f" $f)
(func $f (param $$0 i32) (param $$1 i32)
(block $fake_return_waka123
(block
- (i32.store align=4 offset=6
+ (i32.store align=4 offset=8
(get_local $$0)
(get_local $$1)
)
diff --git a/test/dot_s/vtable.wast b/test/dot_s/vtable.wast
index 0ad2840c6..2080f0e51 100644
--- a/test/dot_s/vtable.wast
+++ b/test/dot_s/vtable.wast
@@ -1,5 +1,5 @@
(module
- (memory 0 4294967295 (segment 16 "1A\00") (segment 32 "1B\00") (segment 48 "1C\00") (segment 64 "1D\00") (segment 68 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 88 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 108 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 128 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 150 "\00\00\00\00\10\00\00\00") (segment 159 "\00\00\00\00\00\00\00\00\96\00\00\00") (segment 171 "\00\00\00\00\00\00\00\00\96\00\00\00") (segment 183 "\00\00\00\00\00\00\00\00\9f\00\00\00") (segment 196 "\00\00\00\00"))
+ (memory 0 4294967295 (segment 16 "1A\00") (segment 32 "1B\00") (segment 48 "1C\00") (segment 64 "1D\00") (segment 68 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 88 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 108 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 128 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 152 "\00\00\00\00\10\00\00\00") (segment 160 "\00\00\00\00\00\00\00\00\98\00\00\00") (segment 176 "\00\00\00\00\00\00\00\00\98\00\00\00") (segment 192 "\00\00\00\00\00\00\00\00\a0\00\00\00") (segment 204 "\00\00\00\00"))
(import $_ZdlPv "env" "_ZdlPv")
(export "_ZN1A3fooEv" $_ZN1A3fooEv)
(export "_ZN1B3fooEv" $_ZN1B3fooEv)
@@ -13,7 +13,7 @@
(func $_ZN1A3fooEv (param $$0 i32)
(block $fake_return_waka123
(block
- (i32.store align=4 offset=196
+ (i32.store align=4 offset=204
(i32.const 0)
(i32.const 2)
)
@@ -24,7 +24,7 @@
(func $_ZN1B3fooEv (param $$0 i32)
(block $fake_return_waka123
(block
- (i32.store align=4 offset=196
+ (i32.store align=4 offset=204
(i32.const 0)
(i32.const 4)
)
@@ -35,7 +35,7 @@
(func $_ZN1C3fooEv (param $$0 i32)
(block $fake_return_waka123
(block
- (i32.store align=4 offset=196
+ (i32.store align=4 offset=204
(i32.const 0)
(i32.const 6)
)
@@ -46,7 +46,7 @@
(func $_ZN1D3fooEv (param $$0 i32)
(block $fake_return_waka123
(block
- (i32.store align=4 offset=196
+ (i32.store align=4 offset=204
(i32.const 0)
(i32.const 8)
)