|
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 |
|
@@ -195,6 +197,7 @@ print_help()
|
195 | 197 | #if WASM_ENABLE_LINUX_PERF != 0
|
196 | 198 | printf(" --enable-linux-perf Enable linux perf support\n");
|
197 | 199 | #endif
|
| 200 | + printf(" --mllvm=<option> Add the LLVM command line option\n"); |
198 | 201 | printf(" -v=n Set log verbose level (0 to 5, default is 2), larger with more log\n");
|
199 | 202 | printf(" --version Show version information\n");
|
200 | 203 | printf("Examples: wamrc -o test.aot test.wasm\n");
|
|
315 | 318 | main(int argc, char *argv[])
|
316 | 319 | {
|
317 | 320 | char *wasm_file_name = NULL, *out_file_name = NULL;
|
| 321 | + char **llvm_options = NULL; |
| 322 | + size_t llvm_options_count = 0; |
318 | 323 | uint8 *wasm_file = NULL;
|
319 | 324 | uint32 wasm_file_size;
|
320 | 325 | wasm_module_t wasm_module = NULL;
|
@@ -550,6 +555,24 @@ main(int argc, char *argv[])
|
550 | 555 | enable_linux_perf = true;
|
551 | 556 | }
|
552 | 557 | #endif
|
| 558 | + else if (!strncmp(argv[0], "--mllvm=", 8)) { |
| 559 | + void *np; |
| 560 | + if (argv[0][8] == '\0') |
| 561 | + PRINT_HELP_AND_EXIT(); |
| 562 | + if (llvm_options_count == 0) |
| 563 | + llvm_options_count += 2; |
| 564 | + else |
| 565 | + llvm_options_count++; |
| 566 | + np = realloc(llvm_options, llvm_options_count * sizeof(char *)); |
| 567 | + if (np == NULL) { |
| 568 | + printf("Memory allocation failure\n"); |
| 569 | + goto fail0; |
| 570 | + } |
| 571 | + llvm_options = np; |
| 572 | + if (llvm_options_count == 2) |
| 573 | + llvm_options[llvm_options_count - 2] = "wamrc"; |
| 574 | + llvm_options[llvm_options_count - 1] = argv[0] + 8; |
| 575 | + } |
553 | 576 | else if (!strcmp(argv[0], "--version")) {
|
554 | 577 | uint32 major, minor, patch;
|
555 | 578 | wasm_runtime_get_version(&major, &minor, &patch);
|
@@ -625,6 +648,10 @@ main(int argc, char *argv[])
|
625 | 648 | native_lib_list, native_lib_count, native_handle_list);
|
626 | 649 | #endif
|
627 | 650 |
|
| 651 | + if (llvm_options_count > 0) |
| 652 | + LLVMParseCommandLineOptions(llvm_options_count, |
| 653 | + (const char **)llvm_options, "wamrc"); |
| 654 | + |
628 | 655 | bh_print_time("Begin to load wasm file");
|
629 | 656 |
|
630 | 657 | if (use_dummy_wasm) {
|
@@ -738,6 +765,7 @@ main(int argc, char *argv[])
|
738 | 765 | if (option.custom_sections) {
|
739 | 766 | free(option.custom_sections);
|
740 | 767 | }
|
| 768 | + free(llvm_options); |
741 | 769 |
|
742 | 770 | bh_print_time("wamrc return");
|
743 | 771 | return exit_status;
|
|
0 commit comments