|
9 | 9 | #include "wasm_export.h"
|
10 | 10 | #include "aot_export.h"
|
11 | 11 |
|
| 12 | +#include <llvm-c/Support.h> |
| 13 | + |
12 | 14 | #if BH_HAS_DLFCN
|
13 | 15 | #include <dlfcn.h>
|
14 | 16 |
|
|
315 | 317 | main(int argc, char *argv[])
|
316 | 318 | {
|
317 | 319 | char *wasm_file_name = NULL, *out_file_name = NULL;
|
| 320 | + char **llvm_options = NULL; |
| 321 | + size_t llvm_options_count = 0; |
318 | 322 | uint8 *wasm_file = NULL;
|
319 | 323 | uint32 wasm_file_size;
|
320 | 324 | wasm_module_t wasm_module = NULL;
|
@@ -550,6 +554,27 @@ main(int argc, char *argv[])
|
550 | 554 | enable_linux_perf = true;
|
551 | 555 | }
|
552 | 556 | #endif
|
| 557 | + else if (!strncmp(argv[0], "--mllvm=", 8)) { |
| 558 | + void *np; |
| 559 | + if (argv[0][8] == '\0') |
| 560 | + PRINT_HELP_AND_EXIT(); |
| 561 | + if (llvm_options_count == 0) { |
| 562 | + llvm_options_count += 2; |
| 563 | + } |
| 564 | + else { |
| 565 | + llvm_options_count++; |
| 566 | + } |
| 567 | + np = realloc(llvm_options, llvm_options_count * sizeof(char *)); |
| 568 | + if (np == NULL) { |
| 569 | + printf("Memory allocation failure\n"); |
| 570 | + goto fail0; |
| 571 | + } |
| 572 | + llvm_options = np; |
| 573 | + if (llvm_options_count == 2) { |
| 574 | + llvm_options[llvm_options_count - 2] = "wamrc"; |
| 575 | + } |
| 576 | + llvm_options[llvm_options_count - 1] = argv[0] + 8; |
| 577 | + } |
553 | 578 | else if (!strcmp(argv[0], "--version")) {
|
554 | 579 | uint32 major, minor, patch;
|
555 | 580 | wasm_runtime_get_version(&major, &minor, &patch);
|
@@ -625,6 +650,10 @@ main(int argc, char *argv[])
|
625 | 650 | native_lib_list, native_lib_count, native_handle_list);
|
626 | 651 | #endif
|
627 | 652 |
|
| 653 | + if (llvm_options_count > 0) |
| 654 | + LLVMParseCommandLineOptions(llvm_options_count, |
| 655 | + (const char **)llvm_options, "wamrc"); |
| 656 | + |
628 | 657 | bh_print_time("Begin to load wasm file");
|
629 | 658 |
|
630 | 659 | if (use_dummy_wasm) {
|
@@ -738,6 +767,7 @@ main(int argc, char *argv[])
|
738 | 767 | if (option.custom_sections) {
|
739 | 768 | free(option.custom_sections);
|
740 | 769 | }
|
| 770 | + free(llvm_options); |
741 | 771 |
|
742 | 772 | bh_print_time("wamrc return");
|
743 | 773 | return exit_status;
|
|
0 commit comments