| author | |
| committer | |
| log | 9f4ef4de23927f724413efa6ef54c2cd08a05976 |
| tree | 8463c0e7dbbb4d1c4410a8a568b620e46cb0800b |
| parent | fdb98c5ce121e80582aee9854bbe2543af725a74 |
This avoids the need to pass `-fbracket-depth=512` to clang.3 files changed, 29 insertions(+), 14 deletions(-)
CMakeLists.txt-3| ... | ... | @@ -731,9 +731,6 @@ else() |
| 731 | 731 | set(ZIG_WASM2C_COMPILE_FLAGS "-std=c99 -O2") |
| 732 | 732 | set(ZIG1_COMPILE_FLAGS "-std=c99 -Os") |
| 733 | 733 | set(ZIG2_COMPILE_FLAGS "-std=c99 -O0") |
| 734 | if(CMAKE_C_COMPILER_ID MATCHES "Clang") | |
| 735 | set(ZIG1_COMPILE_FLAGS "${ZIG1_COMPILE_FLAGS} -fbracket-depth=512") | |
| 736 | endif() | |
| 737 | 734 | if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang") |
| 738 | 735 | set(ZIG2_LINK_FLAGS "-Wl,-stack_size,0x10000000") |
| 739 | 736 | else() |
stage1/FuncGen.h+15-5| ... | ... | @@ -119,9 +119,15 @@ static void FuncGen_blockBegin(struct FuncGen *self, FILE *out, enum WasmOpcode |
| 119 | 119 | if (self->block == NULL) panic("out of memory"); |
| 120 | 120 | } |
| 121 | 121 | uint32_t label = FuncGen_localAlloc(self, type < 0 ? ~(int8_t)kind : (int8_t)kind); |
| 122 | FuncGen_indent(self, out); | |
| 123 | if (kind == WasmOpcode_if) fprintf(out, "if (l%" PRIu32 ") ", FuncGen_stackPop(self)); | |
| 124 | fputs("{\n", out); | |
| 122 | ||
| 123 | if (kind == WasmOpcode_if) { | |
| 124 | FuncGen_indent(self, out); | |
| 125 | fprintf(out, "if (l%" PRIu32 ") {\n", FuncGen_stackPop(self)); | |
| 126 | } else if (EXTRA_BRACES) { | |
| 127 | FuncGen_indent(self, out); | |
| 128 | fputs("{\n", out); | |
| 129 | } | |
| 130 | ||
| 125 | 131 | self->block[self->block_i].type = type < 0 ? ~type : type; |
| 126 | 132 | self->block[self->block_i].label = label; |
| 127 | 133 | self->block[self->block_i].stack_i = self->stack_i; |
| ... | ... | @@ -148,8 +154,12 @@ static void FuncGen_blockEnd(struct FuncGen *self, FILE *out) { |
| 148 | 154 | uint32_t label = FuncGen_blockLabel(self, 0); |
| 149 | 155 | if (kind != WasmOpcode_loop) FuncGen_label(self, out, label); |
| 150 | 156 | self->block_i -= 1; |
| 151 | FuncGen_indent(self, out); | |
| 152 | fputs("}\n", out); | |
| 157 | ||
| 158 | if (EXTRA_BRACES || kind == WasmOpcode_if) { | |
| 159 | FuncGen_indent(self, out); | |
| 160 | fputs("}\n", out); | |
| 161 | } | |
| 162 | ||
| 153 | 163 | if (self->stack_i != self->block[self->block_i].stack_i) { |
| 154 | 164 | FuncGen_indent(self, out); |
| 155 | 165 | fprintf(out, "// stack mismatch %u != %u\n", self->stack_i, self->block[self->block_i].stack_i); |
stage1/wasm2c.c+14-6| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | #define EXTRA_BRACES 0 | |
| 2 | ||
| 1 | 3 | #include "FuncGen.h" |
| 2 | 4 | #include "InputStream.h" |
| 3 | 5 | #include "panic.h" |
| ... | ... | @@ -800,10 +802,14 @@ int main(int argc, char **argv) { |
| 800 | 802 | FuncType_blockType(types, FuncGen_blockType(&fg, label_idx)); |
| 801 | 803 | uint32_t label = FuncGen_blockLabel(&fg, label_idx); |
| 802 | 804 | |
| 803 | FuncGen_indent(&fg, out); | |
| 804 | if (opcode == WasmOpcode_br_if) | |
| 805 | fprintf(out, "if (l%" PRIu32 ") ", FuncGen_stackPop(&fg)); | |
| 806 | fputs("{\n", out); | |
| 805 | if (opcode == WasmOpcode_br_if) { | |
| 806 | FuncGen_indent(&fg, out); | |
| 807 | fprintf(out, "if (l%" PRIu32 ") {\n", FuncGen_stackPop(&fg)); | |
| 808 | } else if (EXTRA_BRACES) { | |
| 809 | FuncGen_indent(&fg, out); | |
| 810 | fputs("{\n", out); | |
| 811 | } | |
| 812 | ||
| 807 | 813 | const struct ResultType *label_type; |
| 808 | 814 | uint32_t lhs; |
| 809 | 815 | switch (kind) { |
| ... | ... | @@ -833,8 +839,10 @@ int main(int argc, char **argv) { |
| 833 | 839 | } |
| 834 | 840 | FuncGen_cont(&fg, out); |
| 835 | 841 | fprintf(out, "goto l%" PRIu32 ";\n", label); |
| 836 | FuncGen_indent(&fg, out); | |
| 837 | fprintf(out, "}\n"); | |
| 842 | if (EXTRA_BRACES || opcode == WasmOpcode_br_if) { | |
| 843 | FuncGen_indent(&fg, out); | |
| 844 | fputs("}\n", out); | |
| 845 | } | |
| 838 | 846 | if (opcode == WasmOpcode_br) unreachable_depth += 1; |
| 839 | 847 | } |
| 840 | 848 | break; |