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