From: Brendan Hansen Date: Sun, 18 Jul 2021 19:46:19 +0000 (-0500) Subject: added ability to disable #file_contents X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=7f64bcba99ea7c9584577e51504ba2c08d7cc7a6;p=onyx.git added ability to disable #file_contents --- diff --git a/bin/onyx b/bin/onyx index fd417834..9d744b08 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 5060d1ee..790b10e2 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -1155,6 +1155,7 @@ struct CompileOptions { b32 print_static_if_results : 1; b32 print_notes : 1; b32 no_colors : 1; + b32 no_file_contents : 1; b32 use_post_mvp_features : 1; diff --git a/src/onyx.c b/src/onyx.c index e5aea9c6..ec2d87fa 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -43,13 +43,14 @@ static const char* docstring = "Onyx compiler version " VERSION "\n" "\t -VV Very verbose output\n" "\t -VVV Very very verbose output (to be used by compiler developers)\n" "\t--use-post-mvp-features Enables post MVP WASM features such as memory.copy and memory.fill\n" - "\t--doc " + "\t--doc \n" "\n" "Developer flags:\n" "\t--print-function-mappings Prints a mapping from WASM function index to source location.\n" "\t--print-static-if-results Prints the conditional result of each #if statement. Useful for debugging.\n" "\t--print-notes Prints the location of notes throughout the loaded code.\n" "\t--no-colors Disables colors in the error message\n" + "\t--no-file-contents Disables '#file_contents' for security\n" "\n"; @@ -62,6 +63,7 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg .fun_output = 0, .print_function_mappings = 0, .use_post_mvp_features = 0, + .no_file_contents = 0, .runtime = Runtime_Wasi, @@ -109,6 +111,9 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg else if (!strcmp(argv[i], "--no-colors")) { options.no_colors = 1; } + else if (!strcmp(argv[i], "--no-file-contents")) { + options.no_file_contents = 1; + } else if (!strcmp(argv[i], "--use-post-mvp-features")) { options.use_post_mvp_features = 1; } diff --git a/src/onyxchecker.c b/src/onyxchecker.c index b3087ed8..d9367e79 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -2139,6 +2139,12 @@ void check_entity(Entity* ent) { case Entity_Type_Process_Directive: cs = check_process_directive((AstNode *) ent->expr); break; + case Entity_Type_File_Contents: + if (context.options->no_file_contents) { + onyx_report_error(ent->expr->token->pos, "#file_contents is disabled for this compilation."); + } + break; + default: break; }