summaryrefslogtreecommitdiff
path: root/src/wasm.h
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2016-05-11 15:34:49 -0700
committerDerek Schuff <dschuff@chromium.org>2016-05-11 15:34:49 -0700
commitac827e35fec84074d9d8141ca2c94ad01ca9c5c3 (patch)
tree38f1c4b00de8af9f0545974847e4ab04f13b45fd /src/wasm.h
parent9c79f86a3f518c60840b416287a5d26502911ad6 (diff)
downloadbinaryen-ac827e35fec84074d9d8141ca2c94ad01ca9c5c3.tar.gz
binaryen-ac827e35fec84074d9d8141ca2c94ad01ca9c5c3.tar.bz2
binaryen-ac827e35fec84074d9d8141ca2c94ad01ca9c5c3.zip
Introduce a separate type for linear memory addresses (#477)
We've been using size_t (and other things) for addresses, which is generally wrong because it depends on the host, when it should in fact depend on the target. This is a partial fix for #278 (i.e. it's the right fix, I don't think it's applied quite everywhere yet).
Diffstat (limited to 'src/wasm.h')
-rw-r--r--src/wasm.h30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/wasm.h b/src/wasm.h
index 2e3a63105..9f5f6820c 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -89,9 +89,11 @@ struct Name : public cashew::IString {
};
// An index in a wasm module
-
typedef uint32_t Index;
+// An address in linear memory. For now only wasm32
+typedef uint32_t Address;
+
// Types
enum WasmType {
@@ -1054,10 +1056,10 @@ public:
Load() {}
Load(MixedArena& allocator) {}
- uint32_t bytes;
+ uint8_t bytes;
bool signed_;
- uint32_t offset;
- uint32_t align;
+ Address offset;
+ Address align;
Expression *ptr;
// type must be set during creation, cannot be inferred
@@ -1068,9 +1070,9 @@ public:
Store() {}
Store(MixedArena& allocator) {}
- unsigned bytes;
- uint32_t offset;
- unsigned align;
+ uint8_t bytes;
+ Address offset;
+ Address align;
Expression *ptr, *value;
void finalize() {
@@ -1264,26 +1266,26 @@ public:
class Memory {
public:
- static const size_t kPageSize = 64 * 1024;
- static const size_t kPageMask = ~(kPageSize - 1);
+ static const Address kPageSize = 64 * 1024;
+ static const Address kPageMask = ~(kPageSize - 1);
struct Segment {
- size_t offset;
+ Address offset;
std::vector<char> data; // TODO: optimize
Segment() {}
- Segment(size_t offset, const char *init, size_t size) : offset(offset) {
+ Segment(Address offset, const char *init, Address size) : offset(offset) {
data.resize(size);
std::copy_n(init, size, data.begin());
}
- Segment(size_t offset, std::vector<char>& init) : offset(offset) {
+ Segment(Address offset, std::vector<char>& init) : offset(offset) {
data.swap(init);
}
};
- size_t initial, max; // sizes are in pages
+ Address initial, max; // sizes are in pages
std::vector<Segment> segments;
Name exportName;
- Memory() : initial(0), max((uint32_t)-1) {}
+ Memory() : initial(0), max((Address)-1) {}
};
class Module {