diff options
author | Ben Smith <binjimin@gmail.com> | 2017-05-15 10:07:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-15 10:07:21 -0700 |
commit | f1031e8ac4a4eb2ec886c03fa432d5b5b3cc56a0 (patch) | |
tree | 1c2144a7c8acadf0850ad183920d0b247ddc501c /src/common.h | |
parent | 5d10e89b5d796edc62cfb6bc3f806d8a1b1272c0 (diff) | |
download | wabt-f1031e8ac4a4eb2ec886c03fa432d5b5b3cc56a0.tar.gz wabt-f1031e8ac4a4eb2ec886c03fa432d5b5b3cc56a0.tar.bz2 wabt-f1031e8ac4a4eb2ec886c03fa432d5b5b3cc56a0.zip |
Use Index/Address/Offset instead of uint32_t (#433)
An `Index` is an index into one of the WebAssembly index spaces. It also
is used for counts for these spaces, as well as parameter counts and
result counts.
An `Address` is an index into linear memory, or the size of a data
region in linear memory.
An `Offset` is an offset into the host's file or memory buffer.
This fixes issue #322.
Diffstat (limited to 'src/common.h')
-rw-r--r-- | src/common.h | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/common.h b/src/common.h index 152800bd..3692aa45 100644 --- a/src/common.h +++ b/src/common.h @@ -40,7 +40,6 @@ #define WABT_USE(x) static_cast<void>(x) -#define WABT_UNKNOWN_OFFSET (static_cast<uint32_t>(~0)) #define WABT_PAGE_SIZE 0x10000 /* 64k */ #define WABT_MAX_PAGES 0x10000 /* # of pages that fit in 32-bit address space */ #define WABT_BYTES_TO_PAGES(x) ((x) >> 16) @@ -85,9 +84,20 @@ #define WABT_CATCH_BAD_ALLOC_AND_EXIT #endif +#define PRIindex "u" +#define PRIaddress "u" +#define PRIoffset PRIzx namespace wabt { +typedef uint32_t Index; // An index into one of the many index spaces. +typedef uint32_t Address; // An address or size in linear memory. +typedef size_t Offset; // An offset into a host's file or memory buffer. + +static const Address kInvalidAddress = ~0; +static const Index kInvalidIndex = ~0; +static const Offset kInvalidOffset = ~0; + enum class Result { Ok, Error, @@ -164,11 +174,11 @@ enum class RelocType { static const int kRelocTypeCount = WABT_ENUM_COUNT(RelocType); struct Reloc { - Reloc(RelocType, size_t offset, uint32_t index, int32_t addend = 0); + Reloc(RelocType, size_t offset, Index index, int32_t addend = 0); RelocType type; size_t offset; - uint32_t index; + Index index; int32_t addend; }; @@ -251,17 +261,6 @@ inline StringSlice string_to_string_slice(const std::string& s) { return ss; } -bool default_source_error_callback(const Location*, - const char* error, - const char* source_line, - size_t source_line_length, - size_t source_line_column_offset, - void* user_data); - -bool default_binary_error_callback(uint32_t offset, - const char* error, - void* user_data); - void init_stdio(); /* external kind */ |