authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-15 22:52:46+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-26 22:00:09+02:00
logc2e6be97ffc23f2fa6c28175766b8bb565e9c970
treef8ac14960e2096ea503d6e7a6c86a167897f3bb2
parent5cb45b68557e32724cb6a10ead8123a588c5000f
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

wasm2c: Add an optional endianness command line argument.

If not given, endianness is inferred from the target that wasm2c is built for.

1 files changed, 17 insertions(+), 3 deletions(-)

stage1/wasm2c.c+17-3
...@@ -76,13 +76,27 @@ static void renderExpr(FILE *out, struct InputStream *in) {...@@ -76,13 +76,27 @@ static void renderExpr(FILE *out, struct InputStream *in) {
76static const uint32_t big_endian = 0xff000000;76static const uint32_t big_endian = 0xff000000;
7777
78int main(int argc, char **argv) {78int main(int argc, char **argv) {
79 if (argc != 3) {79 if (argc != 3 && argc != 4) {
80 fprintf(stderr, "usage: %s in.wasm.zst out.c\n", argv[0]);80 fprintf(stderr, "usage: %s <in.wasm.zst> <out.c> [endian]\n", argv[0]);
81 return 1;81 return 1;
82 }82 }
8383
84 bool is_big_endian;
85
86 if (argc >= 4) {
87 if (!strcmp(argv[3], "big")) {
88 is_big_endian = true;
89 } else if (!strcmp(argv[3], "little")) {
90 is_big_endian = false;
91 } else {
92 fprintf(stderr, "endianness must be 'big' or 'little'\n");
93 return 1;
94 }
95 } else {
96 is_big_endian = *(uint8_t *)&big_endian; // Infer from host endianness.
97 }
98
84 const char *mod = "wasm";99 const char *mod = "wasm";
85 bool is_big_endian = *(uint8_t *)&big_endian;
86100
87 struct InputStream in;101 struct InputStream in;
88 InputStream_open(&in, argv[1]);102 InputStream_open(&in, argv[1]);