summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/s2wasm.h24
-rw-r--r--src/shared-constants.h2
2 files changed, 18 insertions, 8 deletions
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"),