| ... | ... | @@ -19,6 +19,7 @@ |
| 19 | 19 | static int usage(const char *arg0) { |
| 20 | 20 | fprintf(stderr, "Usage: %s [command] [options]\n" |
| 21 | 21 | "Commands:\n" |
| 22 | " asm [source] create object from assembly\n" |
| 22 | 23 | " build build project from build.zig\n" |
| 23 | 24 | " build_exe [source] create executable from source\n" |
| 24 | 25 | " build_lib [source] create library from source\n" |
| ... | ... | @@ -106,6 +107,7 @@ enum Cmd { |
| 106 | 107 | CmdVersion, |
| 107 | 108 | CmdParseH, |
| 108 | 109 | CmdTargets, |
| 110 | CmdAsm, |
| 109 | 111 | }; |
| 110 | 112 | |
| 111 | 113 | int main(int argc, char **argv) { |
| ... | ... | @@ -310,6 +312,8 @@ int main(int argc, char **argv) { |
| 310 | 312 | cmd = CmdTest; |
| 311 | 313 | } else if (strcmp(arg, "targets") == 0) { |
| 312 | 314 | cmd = CmdTargets; |
| 315 | } else if (strcmp(arg, "asm") == 0) { |
| 316 | cmd = CmdAsm; |
| 313 | 317 | } else { |
| 314 | 318 | fprintf(stderr, "Unrecognized command: %s\n", arg); |
| 315 | 319 | return usage(arg0); |
| ... | ... | @@ -319,6 +323,7 @@ int main(int argc, char **argv) { |
| 319 | 323 | case CmdBuild: |
| 320 | 324 | case CmdParseH: |
| 321 | 325 | case CmdTest: |
| 326 | case CmdAsm: |
| 322 | 327 | if (!in_file) { |
| 323 | 328 | in_file = arg; |
| 324 | 329 | } else { |
| ... | ... | @@ -338,6 +343,7 @@ int main(int argc, char **argv) { |
| 338 | 343 | case CmdBuild: |
| 339 | 344 | case CmdParseH: |
| 340 | 345 | case CmdTest: |
| 346 | case CmdAsm: |
| 341 | 347 | { |
| 342 | 348 | if (!in_file) |
| 343 | 349 | return usage(arg0); |
| ... | ... | @@ -373,6 +379,7 @@ int main(int argc, char **argv) { |
| 373 | 379 | } |
| 374 | 380 | } |
| 375 | 381 | |
| 382 | bool need_name = (cmd == CmdBuild || cmd == CmdAsm); |
| 376 | 383 | |
| 377 | 384 | Buf in_file_buf = BUF_INIT; |
| 378 | 385 | buf_init_from_str(&in_file_buf, in_file); |
| ... | ... | @@ -398,14 +405,14 @@ int main(int argc, char **argv) { |
| 398 | 405 | return 1; |
| 399 | 406 | } |
| 400 | 407 | |
| 401 | | if (cmd == CmdBuild && buf_out_name == nullptr) { |
| 408 | if (need_name && buf_out_name == nullptr) { |
| 402 | 409 | buf_out_name = buf_alloc(); |
| 403 | 410 | Buf ext_name = BUF_INIT; |
| 404 | 411 | os_path_extname(&root_source_name, buf_out_name, &ext_name); |
| 405 | 412 | } |
| 406 | 413 | } |
| 407 | 414 | |
| 408 | | if (cmd == CmdBuild && buf_out_name == nullptr) { |
| 415 | if (need_name && buf_out_name == nullptr) { |
| 409 | 416 | fprintf(stderr, "--name [name] not provided and unable to infer\n\n"); |
| 410 | 417 | return usage(arg0); |
| 411 | 418 | } |
| ... | ... | @@ -420,7 +427,9 @@ int main(int argc, char **argv) { |
| 420 | 427 | codegen_set_clang_argv(g, clang_argv.items, clang_argv.length); |
| 421 | 428 | codegen_set_strip(g, strip); |
| 422 | 429 | codegen_set_is_static(g, is_static); |
| 423 | | if (out_type != OutTypeUnknown) { |
| 430 | if (cmd == CmdAsm) { |
| 431 | codegen_set_out_type(g, OutTypeObj); |
| 432 | } else if (out_type != OutTypeUnknown) { |
| 424 | 433 | codegen_set_out_type(g, out_type); |
| 425 | 434 | } else if (cmd == CmdTest) { |
| 426 | 435 | codegen_set_out_type(g, OutTypeExe); |
| ... | ... | @@ -475,6 +484,10 @@ int main(int argc, char **argv) { |
| 475 | 484 | codegen_add_root_code(g, &root_source_dir, &root_source_name, &root_source_code); |
| 476 | 485 | codegen_link(g, out_file); |
| 477 | 486 | return EXIT_SUCCESS; |
| 487 | } else if (cmd == CmdAsm) { |
| 488 | codegen_add_root_assembly(g, &root_source_dir, &root_source_name, &root_source_code); |
| 489 | codegen_link(g, out_file); |
| 490 | return EXIT_SUCCESS; |
| 478 | 491 | } else if (cmd == CmdParseH) { |
| 479 | 492 | codegen_parseh(g, &root_source_dir, &root_source_name, &root_source_code); |
| 480 | 493 | ast_render_decls(stdout, 4, g->root_import); |