authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-07-30 19:24:51+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-07-30 19:24:51+02:00
log9be16fe65fc15a74abf32c6b198a28bc5e86cd27
tree4d53df0b7ade302706a6a566ffc5b32a19de5ad2
parentd58883cd535f1623c6e0e9b025f1da1fb6672955
parentd632f2a5b43e2e7adba1b742d16ce15d74a0accb

Merge pull request 'wasm2c: Debloating and cleanups' (#36336) from ennui/zig:misc/wasm2c into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36336 Reviewed-by: Andrew Kelley <andrew@ziglang.org>

3 files changed, 14 insertions(+), 14 deletions(-)

build.zig+2-2
......@@ -763,9 +763,8 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
763763 .optimize = .ReleaseSmall,
764764 .target = b.resolveTargetQuery(std.Target.Query.parse(.{
765765 .arch_os_abi = "wasm32-wasi",
766 // * `extended_const` is not supported by the `wasm-opt` version in CI.
767766 // * `nontrapping_bulk_memory_len0` is supported by `wasm2c`.
768 .cpu_features = "baseline-extended_const+nontrapping_bulk_memory_len0",
767 .cpu_features = "baseline+nontrapping_bulk_memory_len0",
769768 }) catch unreachable),
770769 });
771770
......@@ -809,6 +808,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
809808 "-Oz",
810809 "--enable-bulk-memory",
811810 "--enable-mutable-globals",
811 "--enable-extended-const",
812812 "--enable-nontrapping-float-to-int",
813813 "--enable-sign-ext",
814814 });
stage1/FuncGen.h+3-3
......@@ -52,17 +52,17 @@ static void FuncGen_free(struct FuncGen *self) {
5252}
5353
5454static void FuncGen_outdent(struct FuncGen *self, FILE *out) {
55 for (uint32_t i = 0; i < self->block_i; i += 1) fputs(" ", out);
55 for (uint32_t i = 0; i < self->block_i; i += 1) fputs(" ", out);
5656}
5757
5858static void FuncGen_indent(struct FuncGen *self, FILE *out) {
5959 FuncGen_outdent(self, out);
60 fputs(" ", out);
60 fputs(" ", out);
6161}
6262
6363static void FuncGen_cont(struct FuncGen *self, FILE *out) {
6464 FuncGen_indent(self, out);
65 fputs(" ", out);
65 fputs(" ", out);
6666}
6767
6868static uint32_t FuncGen_localAlloc(struct FuncGen *self, int8_t type) {
stage1/wasm2c.c+9-9
......@@ -518,8 +518,8 @@ int main(int argc, char **argv) {
518518 }
519519 fprintf(out,
520520 ") {\n"
521 " init();\n"
522 " %sf%" PRIu32 "(",
521 " init();\n"
522 " %sf%" PRIu32 "(",
523523 func_type->result->len > 0 ? "return " : "", idx - imports_len);
524524 for (uint32_t param_i = 0; param_i < func_type->param->len; param_i += 1) {
525525 if (param_i > 0) fputs(", ", out);
......@@ -552,7 +552,7 @@ int main(int argc, char **argv) {
552552 uint32_t segment_len = InputStream_readLeb128_u32(&in);
553553 for (uint32_t i = 0; i < segment_len; i += 1) {
554554 uint32_t func_id = InputStream_readLeb128_u32(&in);
555 fprintf(out, " t%" PRIu32 "[UINT32_C(%" PRIu32 ")] = (void (*)(void))&",
555 fprintf(out, " t%" PRIu32 "[UINT32_C(%" PRIu32 ")] = (void (*)(void))&",
556556 table_idx, offset + i);
557557 if (func_id < imports_len)
558558 fprintf(out, "%s_%s", imports[func_id].mod, imports[func_id].name);
......@@ -2260,9 +2260,9 @@ int main(int argc, char **argv) {
22602260 uint32_t len = InputStream_readLeb128_u32(&in);
22612261 fputs("static void init_data(void) {\n", out);
22622262 for (uint32_t i = 0; i < mems_len; i += 1)
2263 fprintf(out, " p%" PRIu32 " = UINT32_C(%" PRIu32 ");\n"
2264 " c%" PRIu32 " = p%" PRIu32 ";\n"
2265 " m%" PRIu32 " = calloc(c%" PRIu32 ", UINT32_C(1) << 16);\n",
2263 fprintf(out, " p%" PRIu32 " = UINT32_C(%" PRIu32 ");\n"
2264 " c%" PRIu32 " = p%" PRIu32 ";\n"
2265 " m%" PRIu32 " = calloc(c%" PRIu32 ", UINT32_C(1) << 16);\n",
22662266 i, mems[i].limits.min, i, i, i, i);
22672267 for (uint32_t segment_i = 0; segment_i < len; segment_i += 1) {
22682268 uint32_t mem_idx;
......@@ -2280,15 +2280,15 @@ int main(int argc, char **argv) {
22802280 uint32_t offset = evalExpr(&in);
22812281 uint32_t segment_len = InputStream_readLeb128_u32(&in);
22822282 fputc('\n', out);
2283 fprintf(out, " static const uint8_t s%" PRIu32 "[UINT32_C(%" PRIu32 ")] = {",
2283 fprintf(out, " static const uint8_t s%" PRIu32 "[UINT32_C(%" PRIu32 ")] = {",
22842284 segment_i, segment_len);
22852285 for (uint32_t i = 0; i < segment_len; i += 1) {
22862286 if (i % 32 == 0) fputs("\n ", out);
22872287 fprintf(out, " 0x%02hhX,", InputStream_readByte(&in));
22882288 }
22892289 fprintf(out, "\n"
2290 " };\n"
2291 " memcpy(&m%" PRIu32 "[UINT32_C(0x%" PRIX32 ")], s%" PRIu32 ", UINT32_C(%" PRIu32 "));\n",
2290 " };\n"
2291 " memcpy(&m%" PRIu32 "[UINT32_C(0x%" PRIX32 ")], s%" PRIu32 ", UINT32_C(%" PRIu32 "));\n",
22922292 mem_idx, offset, segment_i, segment_len);
22932293 }
22942294 fputs("}\n", out);