diff --git a/core/runtime/default_allocators_general.odin b/core/runtime/default_allocators_general.odin index 8f598b7a1..2414d71d2 100644 --- a/core/runtime/default_allocators_general.odin +++ b/core/runtime/default_allocators_general.odin @@ -1,6 +1,5 @@ //+build !windows //+build !freestanding -//+build !js package runtime when ODIN_DEFAULT_TO_NIL_ALLOCATOR { diff --git a/core/runtime/default_allocators_nil.odin b/core/runtime/default_allocators_nil.odin index 4e1d7a1d3..443f41a51 100644 --- a/core/runtime/default_allocators_nil.odin +++ b/core/runtime/default_allocators_nil.odin @@ -1,4 +1,4 @@ -//+build freestanding, js +//+build freestanding package runtime // mem.nil_allocator reimplementation diff --git a/core/runtime/os_specific_any.odin b/core/runtime/os_specific_any.odin index 5a8fd2e94..9c2686661 100644 --- a/core/runtime/os_specific_any.odin +++ b/core/runtime/os_specific_any.odin @@ -1,6 +1,5 @@ //+build !freestanding //+build !windows -//+build !js package runtime import "core:os" diff --git a/src/build_settings.cpp b/src/build_settings.cpp index 0207221bc..3ddec8628 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -10,7 +10,6 @@ enum TargetOsKind { TargetOs_darwin, TargetOs_linux, TargetOs_essence, - TargetOs_js, TargetOs_freebsd, TargetOs_freestanding, @@ -44,7 +43,6 @@ String target_os_names[TargetOs_COUNT] = { str_lit("darwin"), str_lit("linux"), str_lit("essence"), - str_lit("js"), str_lit("freebsd"), str_lit("freestanding"), @@ -312,8 +310,8 @@ gb_global TargetMetrics target_essence_amd64 = { str_lit("x86_64-pc-none-elf"), }; -gb_global TargetMetrics target_js_wasm32 = { - TargetOs_js, +gb_global TargetMetrics target_freestanding_wasm32 = { + TargetOs_freestanding, TargetArch_wasm32, 4, 8, @@ -330,15 +328,15 @@ struct NamedTargetMetrics { gb_global NamedTargetMetrics named_targets[] = { { str_lit("darwin_amd64"), &target_darwin_amd64 }, - { str_lit("darwin_arm64"), &target_darwin_arm64 }, + { str_lit("darwin_arm64"), &target_darwin_arm64 }, { str_lit("essence_amd64"), &target_essence_amd64 }, - { str_lit("js_wasm32"), &target_js_wasm32 }, { str_lit("linux_386"), &target_linux_386 }, { str_lit("linux_amd64"), &target_linux_amd64 }, { str_lit("windows_386"), &target_windows_386 }, { str_lit("windows_amd64"), &target_windows_amd64 }, { str_lit("freebsd_386"), &target_freebsd_386 }, { str_lit("freebsd_amd64"), &target_freebsd_amd64 }, + { str_lit("freestanding_wasm32"), &target_freestanding_wasm32 }, }; NamedTargetMetrics *selected_target_metrics; @@ -443,6 +441,14 @@ bool find_library_collection_path(String name, String *path) { return false; } +bool is_arch_wasm(void) { + return build_context.metrics.arch == TargetArch_wasm32; +} + +bool allow_check_foreign_filepath(void) { + return build_context.metrics.arch != TargetArch_wasm32; +} + // TODO(bill): OS dependent versions for the BuildContext // join_path diff --git a/src/llvm_abi.cpp b/src/llvm_abi.cpp index 1347a1cdd..233fc2413 100644 --- a/src/llvm_abi.cpp +++ b/src/llvm_abi.cpp @@ -151,7 +151,7 @@ void lb_add_function_type_attributes(LLVMValueRef fn, lbFunctionType *ft, ProcCa lbCallingConventionKind cc_kind = lbCallingConvention_C; // TODO(bill): Clean up this logic - if (build_context.metrics.os != TargetOs_js) { + if (!is_arch_wasm()) { cc_kind = lb_calling_convention_map[calling_convention]; } LLVMSetFunctionCallConv(fn, cc_kind); diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index ef6065fcf..22fb3c498 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -2753,7 +2753,7 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool ignore_body) if (false) { lbCallingConventionKind cc_kind = lbCallingConvention_C; // TODO(bill): Clean up this logic - if (build_context.metrics.os != TargetOs_js) { + if (!is_arch_wasm()) { cc_kind = lb_calling_convention_map[pt->Proc.calling_convention]; } LLVMSetFunctionCallConv(p->value, cc_kind); @@ -2815,13 +2815,13 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool ignore_body) LLVMSetDLLStorageClass(p->value, LLVMDLLExportStorageClass); LLVMSetVisibility(p->value, LLVMDefaultVisibility); - if (build_context.metrics.os == TargetOs_js) { + if (is_arch_wasm()) { char const *export_name = alloc_cstring(permanent_allocator(), p->name); LLVMAddTargetDependentFunctionAttr(p->value, "wasm-export-name", export_name); } } if (p->is_foreign) { - if (build_context.metrics.os == TargetOs_js) { + if (is_arch_wasm()) { char const *import_name = alloc_cstring(permanent_allocator(), p->name); char const *module_name = "env"; if (entity->Procedure.foreign_library != nullptr) { @@ -2959,7 +2959,7 @@ lbProcedure *lb_create_dummy_procedure(lbModule *m, String link_name, Type *type Type *pt = p->type; lbCallingConventionKind cc_kind = lbCallingConvention_C; // TODO(bill): Clean up this logic - if (build_context.metrics.os != TargetOs_js) { + if (!is_arch_wasm()) { cc_kind = lb_calling_convention_map[pt->Proc.calling_convention]; } LLVMSetFunctionCallConv(p->value, cc_kind); @@ -14901,18 +14901,20 @@ String lb_filepath_obj_for_module(lbModule *m) { if (build_context.build_mode == BuildMode_Assembly) { ext = STR_LIT(".S"); } else { - switch (build_context.metrics.os) { - case TargetOs_windows: - ext = STR_LIT(".obj"); - break; - case TargetOs_darwin: - case TargetOs_linux: - case TargetOs_essence: - ext = STR_LIT(".o"); - break; - case TargetOs_js: - ext = STR_LIT(".wasm-obj"); - break; + if (is_arch_wasm()) { + ext = STR_LIT(".wasm.o"); + } else { + switch (build_context.metrics.os) { + case TargetOs_windows: + ext = STR_LIT(".obj"); + break; + default: + case TargetOs_darwin: + case TargetOs_linux: + case TargetOs_essence: + ext = STR_LIT(".o"); + break; + } } } @@ -15099,7 +15101,7 @@ void lb_generate_code(lbGenerator *gen) { TIME_SECTION("LLVM Create Target Machine"); LLVMCodeModel code_mode = LLVMCodeModelDefault; - if (build_context.metrics.arch == TargetArch_wasm32) { + if (is_arch_wasm()) { code_mode = LLVMCodeModelJITDefault; } diff --git a/src/main.cpp b/src/main.cpp index d16a110e3..bb7d94c9b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -152,7 +152,7 @@ i32 linker_stage(lbGenerator *gen) { String output_base = gen->output_base; - if (build_context.metrics.os == TargetOs_js) { + if (is_arch_wasm()) { timings_start_section(timings, str_lit("wasm-ld")); system_exec_command_line_app("wasm-ld", "\"%.*s\\bin\\wasm-ld\" \"%.*s.wasm-obj\" -o \"%.*s.wasm\" %.*s %.*s", diff --git a/src/parser.cpp b/src/parser.cpp index 2e8f8ff60..404f82c07 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -5121,7 +5121,7 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Slice for_array(fp_idx, fl->filepaths) { String file_str = fl->filepaths[fp_idx].string; String fullpath = file_str; - if (build_context.metrics.os != TargetOs_js) { + if (allow_check_foreign_filepath()) { String foreign_path = {}; bool ok = determine_path_from_string(&p->file_decl_mutex, node, base_dir, file_str, &foreign_path); if (!ok) {