Skip to content

Commit d9be3aa

Browse files
committed
wamrc: Add --mllvm= option
this allows users to specify llvm command line options similarly to clang's -mllvm option. my motivations: * -debug and friends * -mtext-section-literals for xtensa
1 parent b086d58 commit d9be3aa

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

wamr-compiler/main.c

+30
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "wasm_export.h"
1010
#include "aot_export.h"
1111

12+
#include <llvm-c/Support.h>
13+
1214
#if BH_HAS_DLFCN
1315
#include <dlfcn.h>
1416

@@ -315,6 +317,8 @@ int
315317
main(int argc, char *argv[])
316318
{
317319
char *wasm_file_name = NULL, *out_file_name = NULL;
320+
char **llvm_options = NULL;
321+
size_t llvm_options_count = 0;
318322
uint8 *wasm_file = NULL;
319323
uint32 wasm_file_size;
320324
wasm_module_t wasm_module = NULL;
@@ -550,6 +554,27 @@ main(int argc, char *argv[])
550554
enable_linux_perf = true;
551555
}
552556
#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+
}
553578
else if (!strcmp(argv[0], "--version")) {
554579
uint32 major, minor, patch;
555580
wasm_runtime_get_version(&major, &minor, &patch);
@@ -625,6 +650,10 @@ main(int argc, char *argv[])
625650
native_lib_list, native_lib_count, native_handle_list);
626651
#endif
627652

653+
if (llvm_options_count > 0)
654+
LLVMParseCommandLineOptions(llvm_options_count,
655+
(const char **)llvm_options, "wamrc");
656+
628657
bh_print_time("Begin to load wasm file");
629658

630659
if (use_dummy_wasm) {
@@ -738,6 +767,7 @@ main(int argc, char *argv[])
738767
if (option.custom_sections) {
739768
free(option.custom_sections);
740769
}
770+
free(llvm_options);
741771

742772
bh_print_time("wamrc return");
743773
return exit_status;

0 commit comments

Comments
 (0)