Skip to content

Commit ace8a86

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 ace8a86

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

wamr-compiler/main.c

Lines changed: 27 additions & 0 deletions
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,24 @@ 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+
else
564+
llvm_options_count++;
565+
np = realloc(llvm_options, llvm_options_count * sizeof(char *));
566+
if (np == NULL) {
567+
printf("Memory allocation failure\n");
568+
goto fail0;
569+
}
570+
llvm_options = np;
571+
if (llvm_options_count == 2)
572+
llvm_options[llvm_options_count - 2] = "wamrc";
573+
llvm_options[llvm_options_count - 1] = argv[0] + 8;
574+
}
553575
else if (!strcmp(argv[0], "--version")) {
554576
uint32 major, minor, patch;
555577
wasm_runtime_get_version(&major, &minor, &patch);
@@ -625,6 +647,10 @@ main(int argc, char *argv[])
625647
native_lib_list, native_lib_count, native_handle_list);
626648
#endif
627649

650+
if (llvm_options_count > 0)
651+
LLVMParseCommandLineOptions(llvm_options_count,
652+
(const char **)llvm_options, "wamrc");
653+
628654
bh_print_time("Begin to load wasm file");
629655

630656
if (use_dummy_wasm) {
@@ -738,6 +764,7 @@ main(int argc, char *argv[])
738764
if (option.custom_sections) {
739765
free(option.custom_sections);
740766
}
767+
free(llvm_options);
741768

742769
bh_print_time("wamrc return");
743770
return exit_status;

0 commit comments

Comments
 (0)