Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions wamr-compiler/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "wasm_export.h"
#include "aot_export.h"

#include <llvm-c/Support.h>

#if BH_HAS_DLFCN
#include <dlfcn.h>

Expand Down Expand Up @@ -195,6 +197,7 @@ print_help()
#if WASM_ENABLE_LINUX_PERF != 0
printf(" --enable-linux-perf Enable linux perf support\n");
#endif
printf(" --mllvm=<option> Add the LLVM command line option\n");
printf(" -v=n Set log verbose level (0 to 5, default is 2), larger with more log\n");
printf(" --version Show version information\n");
printf("Examples: wamrc -o test.aot test.wasm\n");
Expand Down Expand Up @@ -315,6 +318,8 @@ int
main(int argc, char *argv[])
{
char *wasm_file_name = NULL, *out_file_name = NULL;
char **llvm_options = NULL;
size_t llvm_options_count = 0;
uint8 *wasm_file = NULL;
uint32 wasm_file_size;
wasm_module_t wasm_module = NULL;
Expand Down Expand Up @@ -550,6 +555,24 @@ main(int argc, char *argv[])
enable_linux_perf = true;
}
#endif
else if (!strncmp(argv[0], "--mllvm=", 8)) {
void *np;
if (argv[0][8] == '\0')
PRINT_HELP_AND_EXIT();
if (llvm_options_count == 0)
llvm_options_count += 2;
else
llvm_options_count++;
np = realloc(llvm_options, llvm_options_count * sizeof(char *));
if (np == NULL) {
printf("Memory allocation failure\n");
goto fail0;
}
llvm_options = np;
if (llvm_options_count == 2)
llvm_options[llvm_options_count - 2] = "wamrc";
llvm_options[llvm_options_count - 1] = argv[0] + 8;
}
else if (!strcmp(argv[0], "--version")) {
uint32 major, minor, patch;
wasm_runtime_get_version(&major, &minor, &patch);
Expand Down Expand Up @@ -625,6 +648,10 @@ main(int argc, char *argv[])
native_lib_list, native_lib_count, native_handle_list);
#endif

if (llvm_options_count > 0)
LLVMParseCommandLineOptions(llvm_options_count,
(const char **)llvm_options, "wamrc");

bh_print_time("Begin to load wasm file");

if (use_dummy_wasm) {
Expand Down Expand Up @@ -738,6 +765,7 @@ main(int argc, char *argv[])
if (option.custom_sections) {
free(option.custom_sections);
}
free(llvm_options);
Copy link
Contributor

@wenyongh wenyongh Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to check llvm_options and free it only when it is not NULL? like L765

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When --mllvm=xxx isn't specified, llvm_options is NULL, no need to free it in fact. Though the linux manual of free says no operation is performed if ptr is NULL, I am not sure whether it is a good coding style, we usually free a buffer only when it is NULL. It is good if the same behavior is ensured in other platforms.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

free(NULL) is guaranteed to be a no-op by C language.
i'm not aware of any problematic platforms wrt that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks.


bh_print_time("wamrc return");
return exit_status;
Expand Down
Loading