| ... | @@ -76,13 +76,27 @@ static void renderExpr(FILE *out, struct InputStream *in) { | ... | @@ -76,13 +76,27 @@ static void renderExpr(FILE *out, struct InputStream *in) { |
| 76 | static const uint32_t big_endian = 0xff000000; | 76 | static const uint32_t big_endian = 0xff000000; |
| 77 | | 77 | |
| 78 | int main(int argc, char **argv) { | 78 | int 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 | } |
| 83 | | 83 | |
| | 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; | | |
| 86 | | 100 | |
| 87 | struct InputStream in; | 101 | struct InputStream in; |
| 88 | InputStream_open(&in, argv[1]); | 102 | InputStream_open(&in, argv[1]); |