diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-01-25 10:51:01 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-01-25 12:02:09 -0800 |
commit | c0c72f2fed5cd7ef4512cffa8c18152658f20e2c (patch) | |
tree | 4c13bade4227d1a6d199076c51bca79550772c26 | |
parent | 28adf7c1bdbed96e97499ca5955594790a0022b9 (diff) | |
download | binaryen-c0c72f2fed5cd7ef4512cffa8c18152658f20e2c.tar.gz binaryen-c0c72f2fed5cd7ef4512cffa8c18152658f20e2c.tar.bz2 binaryen-c0c72f2fed5cd7ef4512cffa8c18152658f20e2c.zip |
handle new alignment format from llvm
-rw-r--r-- | src/s2wasm.h | 46 | ||||
-rw-r--r-- | test/llvm_autogenerated/i32-load-store-alignment.wast | 244 | ||||
-rw-r--r-- | test/llvm_autogenerated/i64-load-store-alignment.wast | 364 | ||||
-rw-r--r-- | test/llvm_autogenerated/offset.wast | 46 |
4 files changed, 679 insertions, 21 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index 8b34d6b03..13f424f7c 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -159,6 +159,7 @@ private: return cashew::IString(str.c_str(), false); } + // get an int int32_t getInt() { const char* loc = s; uint32_t value = 0; @@ -192,6 +193,15 @@ private: return value; } + // get an int from an arbitrary string, with our full error handling + int32_t getInt(const char *from) { + const char *before = s; + s = from; + auto ret = getInt(); + s = before; + return ret; + } + // gets a constant, which may be a relocation for later. // returns whether this is a relocation bool getConst(uint32_t* target) { @@ -492,6 +502,10 @@ private: inputs[i] = curr; } if (*s == ')') s++; // tolerate 0(argument) syntax, where we started at the 'a' + if (*s == ':') { // tolerate :attribute=value syntax (see getAttributes) + s++; + skipToSep(); + } if (i < num - 1) skipComma(); } for (int i = num-1; i >= 0; i--) { @@ -515,6 +529,24 @@ private: addToBlock(set); } }; + auto getAttributes = [&](int num) { + const char *before = s; + std::vector<const char*> attributes; // TODO: optimize (if .s format doesn't change) + attributes.resize(num); + for (int i = 0; i < num; i++) { + skipToSep(); + if (*s == ')') s++; // tolerate 0(argument) syntax, where we started at the 'a' + if (*s == ':') { + attributes[i] = s + 1; + } else { + attributes[i] = nullptr; + } + if (i < num - 1) skipComma(); + } + s = before; + return attributes; + }; + // auto makeBinary = [&](BinaryOp op, WasmType type) { Name assign = getAssign(); skipComma(); @@ -559,9 +591,14 @@ private: match("_u"); Name assign = getAssign(); getConst(&curr->offset); - curr->align = curr->bytes; // XXX mustMatch("("); + auto attributes = getAttributes(1); curr->ptr = getInput(); + curr->align = curr->bytes; + if (attributes[0]) { + assert(strncmp(attributes[0], "p2align=", 8) == 0); + curr->align = pow(2, getInt(attributes[0] + 8)); + } setOutput(curr, assign); }; auto makeStore = [&](WasmType type) { @@ -570,12 +607,17 @@ private: curr->type = type; int32_t bytes = getInt(); curr->bytes = bytes > 0 ? bytes : getWasmTypeSize(type); - curr->align = curr->bytes; // XXX Name assign = getAssign(); getConst(&curr->offset); mustMatch("("); + auto attributes = getAttributes(2); auto inputs = getInputs(2); curr->ptr = inputs[0]; + curr->align = curr->bytes; + if (attributes[0]) { + assert(strncmp(attributes[0], "p2align=", 8) == 0); + curr->align = pow(2, getInt(attributes[0] + 8)); + } curr->value = inputs[1]; setOutput(curr, assign); }; diff --git a/test/llvm_autogenerated/i32-load-store-alignment.wast b/test/llvm_autogenerated/i32-load-store-alignment.wast new file mode 100644 index 000000000..b0ed4951a --- /dev/null +++ b/test/llvm_autogenerated/i32-load-store-alignment.wast @@ -0,0 +1,244 @@ +(module + (memory 0 4294967295) + (export "ldi32_a1" $ldi32_a1) + (export "ldi32_a2" $ldi32_a2) + (export "ldi32_a4" $ldi32_a4) + (export "ldi32" $ldi32) + (export "ldi32_a8" $ldi32_a8) + (export "ldi8_a1" $ldi8_a1) + (export "ldi8_a2" $ldi8_a2) + (export "ldi16_a1" $ldi16_a1) + (export "ldi16_a2" $ldi16_a2) + (export "ldi16_a4" $ldi16_a4) + (export "sti32_a1" $sti32_a1) + (export "sti32_a2" $sti32_a2) + (export "sti32_a4" $sti32_a4) + (export "sti32" $sti32) + (export "sti32_a8" $sti32_a8) + (export "sti8_a1" $sti8_a1) + (export "sti8_a2" $sti8_a2) + (export "sti16_a1" $sti16_a1) + (export "sti16_a2" $sti16_a2) + (export "sti16_a4" $sti16_a4) + (func $ldi32_a1 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.load align=1 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi32_a2 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.load align=2 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi32_a4 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.load align=4 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi32 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.load align=4 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi32_a8 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.load align=8 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi8_a1 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.load8_u align=1 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi8_a2 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.load8_u align=2 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi16_a1 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.load16_u align=1 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi16_a2 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.load16_u align=2 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi16_a4 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.load16_u align=4 + (get_local $$0) + ) + ) + ) + ) + ) + (func $sti32_a1 (param $$0 i32) (param $$1 i32) + (block $fake_return_waka123 + (block + (i32.store align=1 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti32_a2 (param $$0 i32) (param $$1 i32) + (block $fake_return_waka123 + (block + (i32.store align=2 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti32_a4 (param $$0 i32) (param $$1 i32) + (block $fake_return_waka123 + (block + (i32.store align=4 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti32 (param $$0 i32) (param $$1 i32) + (block $fake_return_waka123 + (block + (i32.store align=4 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti32_a8 (param $$0 i32) (param $$1 i32) + (block $fake_return_waka123 + (block + (i32.store align=8 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti8_a1 (param $$0 i32) (param $$1 i32) + (block $fake_return_waka123 + (block + (i32.store align=8 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti8_a2 (param $$0 i32) (param $$1 i32) + (block $fake_return_waka123 + (block + (i32.store align=2 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti16_a1 (param $$0 i32) (param $$1 i32) + (block $fake_return_waka123 + (block + (i32.store align=1 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti16_a2 (param $$0 i32) (param $$1 i32) + (block $fake_return_waka123 + (block + (i32.store align=16 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti16_a4 (param $$0 i32) (param $$1 i32) + (block $fake_return_waka123 + (block + (i32.store align=4 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) +) +;; METADATA: { "asmConsts": {},"staticBump": 4 } diff --git a/test/llvm_autogenerated/i64-load-store-alignment.wast b/test/llvm_autogenerated/i64-load-store-alignment.wast new file mode 100644 index 000000000..7f6903240 --- /dev/null +++ b/test/llvm_autogenerated/i64-load-store-alignment.wast @@ -0,0 +1,364 @@ +(module + (memory 0 4294967295) + (export "ldi64_a1" $ldi64_a1) + (export "ldi64_a2" $ldi64_a2) + (export "ldi64_a4" $ldi64_a4) + (export "ldi64_a8" $ldi64_a8) + (export "ldi64" $ldi64) + (export "ldi64_a16" $ldi64_a16) + (export "ldi8_a1" $ldi8_a1) + (export "ldi8_a2" $ldi8_a2) + (export "ldi16_a1" $ldi16_a1) + (export "ldi16_a2" $ldi16_a2) + (export "ldi16_a4" $ldi16_a4) + (export "ldi32_a1" $ldi32_a1) + (export "ldi32_a2" $ldi32_a2) + (export "ldi32_a4" $ldi32_a4) + (export "ldi32_a8" $ldi32_a8) + (export "sti64_a1" $sti64_a1) + (export "sti64_a2" $sti64_a2) + (export "sti64_a4" $sti64_a4) + (export "sti64_a8" $sti64_a8) + (export "sti64" $sti64) + (export "sti64_a16" $sti64_a16) + (export "sti8_a1" $sti8_a1) + (export "sti8_a2" $sti8_a2) + (export "sti16_a1" $sti16_a1) + (export "sti16_a2" $sti16_a2) + (export "sti16_a4" $sti16_a4) + (export "sti32_a1" $sti32_a1) + (export "sti32_a2" $sti32_a2) + (export "sti32_a4" $sti32_a4) + (export "sti32_a8" $sti32_a8) + (func $ldi64_a1 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load align=1 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi64_a2 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load align=2 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi64_a4 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load align=4 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi64_a8 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load align=8 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi64 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load align=8 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi64_a16 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load align=16 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi8_a1 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load8_u align=1 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi8_a2 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load8_u align=2 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi16_a1 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load16_u align=1 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi16_a2 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load16_u align=2 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi16_a4 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load16_u align=4 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi32_a1 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load align=1 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi32_a2 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load align=2 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi32_a4 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load align=4 + (get_local $$0) + ) + ) + ) + ) + ) + (func $ldi32_a8 (param $$0 i32) (result i64) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i64.load align=8 + (get_local $$0) + ) + ) + ) + ) + ) + (func $sti64_a1 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=1 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti64_a2 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=2 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti64_a4 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=4 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti64_a8 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=8 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti64 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=8 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti64_a16 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=16 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti8_a1 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=8 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti8_a2 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=2 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti16_a1 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=1 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti16_a2 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=16 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti16_a4 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=4 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti32_a1 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=1 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti32_a2 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=2 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti32_a4 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=32 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $sti32_a8 (param $$0 i32) (param $$1 i64) + (block $fake_return_waka123 + (block + (i64.store align=8 + (get_local $$0) + (get_local $$1) + ) + (br $fake_return_waka123) + ) + ) + ) +) +;; METADATA: { "asmConsts": {},"staticBump": 4 } diff --git a/test/llvm_autogenerated/offset.wast b/test/llvm_autogenerated/offset.wast index 5dea41ca3..759830ffd 100644 --- a/test/llvm_autogenerated/offset.wast +++ b/test/llvm_autogenerated/offset.wast @@ -32,6 +32,7 @@ (export "store_i8_with_folded_gep_offset" $store_i8_with_folded_gep_offset) (export "aggregate_load_store" $aggregate_load_store) (export "aggregate_return" $aggregate_return) + (export "aggregate_return_without_merge" $aggregate_return_without_merge) (func $load_i32_with_folded_offset (param $$0 i32) (result i32) (block $fake_return_waka123 (block @@ -311,30 +312,22 @@ ) ) (func $store_i32_to_numeric_address - (local $$0 i32) (block $fake_return_waka123 (block - (set_local $$0 - (i32.const 0) - ) (i32.store offset=42 align=4 - (get_local $$0) - (get_local $$0) + (i32.const 0) + (i32.const 0) ) (br $fake_return_waka123) ) ) ) (func $store_i32_to_global_address - (local $$0 i32) (block $fake_return_waka123 (block - (set_local $$0 - (i32.const 0) - ) (i32.store offset=8 align=4 - (get_local $$0) - (get_local $$0) + (i32.const 0) + (i32.const 0) ) (br $fake_return_waka123) ) @@ -452,19 +445,34 @@ (func $aggregate_return (param $$0 i32) (block $fake_return_waka123 (block - (i32.store align=4 + (i64.store align=4 + (get_local $$0) + (i64.store offset=8 align=4 + (get_local $$0) + (i64.const 0) + ) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $aggregate_return_without_merge (param $$0 i32) + (block $fake_return_waka123 + (block + (i32.store offset=8 align=4 (get_local $$0) - (i32.store offset=4 align=4 + (i32.store offset=12 align=16 (get_local $$0) - (i32.store offset=8 align=4 + (i32.store offset=14 align=8 (get_local $$0) - (i32.store offset=12 align=4 - (get_local $$0) - (i32.const 0) - ) + (i32.const 0) ) ) ) + (i64.store align=8 + (get_local $$0) + (i64.const 0) + ) (br $fake_return_waka123) ) ) |