Skip to content

Commit 2ceaaf0

Browse files
committed
fix up static addresses in s2wasm; basics test is complete
1 parent 15f1677 commit 2ceaaf0

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/s2wasm.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ class S2WasmBuilder {
2222
public:
2323
S2WasmBuilder(AllocatingModule& wasm, char *s) : wasm(wasm), allocator(wasm.allocator), s(s) {
2424
process();
25+
fix();
2526
}
2627

2728
private:
2829
// state
2930

3031
size_t nextStatic = 0; // location of next static allocation, i.e., the data segment
31-
std::map<Name, size_t> staticAddresses; // name => address
32+
std::map<Name, int32_t> staticAddresses; // name => address
3233
typedef std::pair<Const*, Name> Addressing;
3334
std::vector<Addressing> addressings; // we fix these up
3435

@@ -461,6 +462,17 @@ class S2WasmBuilder {
461462
nextStatic += size;
462463
nextStatic = (nextStatic + ALIGN - 1) & -ALIGN;
463464
}
465+
466+
void fix() {
467+
for (auto& pair : addressings) {
468+
Const* curr = pair.first;
469+
Name name = pair.second;
470+
curr->value = Literal(staticAddresses[name]);
471+
assert(curr->value.i32 > 0);
472+
curr->type = i32;
473+
}
474+
}
475+
464476
};
465477

466478
} // namespace wasm

test/dot_s/basics.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
(block $fake_return_waka123
55
(block
66
(call $puts
7-
(none.const ?)
7+
(i32.const 16)
88
)
99
(block $BB0_5
1010
(block $BB0_4

0 commit comments

Comments
 (0)