mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-29 02:40:05 +00:00
Add wasi_wasm32
This commit is contained in:
+27
-4
@@ -16,6 +16,8 @@ enum TargetOsKind {
|
||||
TargetOs_linux,
|
||||
TargetOs_essence,
|
||||
TargetOs_freebsd,
|
||||
|
||||
TargetOs_wasi,
|
||||
|
||||
TargetOs_freestanding,
|
||||
|
||||
@@ -50,6 +52,8 @@ String target_os_names[TargetOs_COUNT] = {
|
||||
str_lit("linux"),
|
||||
str_lit("essence"),
|
||||
str_lit("freebsd"),
|
||||
|
||||
str_lit("wasi"),
|
||||
|
||||
str_lit("freestanding"),
|
||||
};
|
||||
@@ -347,6 +351,16 @@ gb_global TargetMetrics target_freestanding_wasm64 = {
|
||||
str_lit(""),
|
||||
};
|
||||
|
||||
gb_global TargetMetrics target_wasi_wasm32 = {
|
||||
TargetOs_wasi,
|
||||
TargetArch_wasm32,
|
||||
4,
|
||||
8,
|
||||
str_lit("wasm32-wasi-js"),
|
||||
str_lit(""),
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -367,6 +381,7 @@ gb_global NamedTargetMetrics named_targets[] = {
|
||||
{ str_lit("freebsd_amd64"), &target_freebsd_amd64 },
|
||||
{ str_lit("freestanding_wasm32"), &target_freestanding_wasm32 },
|
||||
{ str_lit("freestanding_wasm64"), &target_freestanding_wasm64 },
|
||||
{ str_lit("wasi_wasm32"), &target_wasi_wasm32 },
|
||||
};
|
||||
|
||||
NamedTargetMetrics *selected_target_metrics;
|
||||
@@ -893,10 +908,18 @@ void init_build_context(TargetMetrics *cross_target) {
|
||||
bc->link_flags = str_lit("-arch arm64 ");
|
||||
break;
|
||||
}
|
||||
} else if (bc->metrics.arch == TargetArch_wasm32) {
|
||||
bc->link_flags = str_lit("--no-entry --export-table --export-all --allow-undefined --features=wasm-feature-atomics ");
|
||||
} else if (bc->metrics.arch == TargetArch_wasm64) {
|
||||
bc->link_flags = str_lit("--no-entry --export-table --export-all --allow-undefined -mwasm64 --features=wasm-feature-memory64,wasm-feature-atomics --verbose ");
|
||||
} else if (is_arch_wasm()) {
|
||||
gbString link_flags = gb_string_make(heap_allocator(), "--export-all ");
|
||||
link_flags = gb_string_appendc(link_flags, "--export-table ");
|
||||
link_flags = gb_string_appendc(link_flags, "--allow-undefined ");
|
||||
if (bc->metrics.arch == TargetArch_wasm64) {
|
||||
link_flags = gb_string_appendc(link_flags, "-mwas64 ");
|
||||
}
|
||||
if (bc->metrics.os == TargetOs_freestanding) {
|
||||
link_flags = gb_string_appendc(link_flags, "--no-entry ");
|
||||
}
|
||||
|
||||
bc->link_flags = make_string_c(link_flags);
|
||||
} else {
|
||||
gb_printf_err("Compiler Error: Unsupported architecture\n");
|
||||
gb_exit(1);
|
||||
|
||||
@@ -784,6 +784,8 @@ lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime)
|
||||
params->Tuple.variables[2] = alloc_entity_param(nullptr, make_token_ident("lpReserved"), t_rawptr, false, true);
|
||||
} else if (build_context.metrics.os == TargetOs_windows && build_context.metrics.arch == TargetArch_386) {
|
||||
name = str_lit("mainCRTStartup");
|
||||
} else if (build_context.metrics.os == TargetOs_wasi) {
|
||||
name = str_lit("_start");
|
||||
} else {
|
||||
has_args = true;
|
||||
slice_init(¶ms->Tuple.variables, permanent_allocator(), 2);
|
||||
@@ -885,6 +887,14 @@ lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime)
|
||||
}
|
||||
|
||||
lb_end_procedure_body(p);
|
||||
|
||||
|
||||
if (build_context.metrics.os == TargetOs_wasi) {
|
||||
LLVMSetLinkage(p->value, LLVMDLLExportLinkage);
|
||||
} else {
|
||||
LLVMSetLinkage(p->value, LLVMExternalLinkage);
|
||||
}
|
||||
|
||||
|
||||
if (!m->debug_builder && LLVMVerifyFunction(p->value, LLVMReturnStatusAction)) {
|
||||
gb_printf_err("LLVM CODE GEN FAILED FOR PROCEDURE: %s\n", "main");
|
||||
|
||||
+4
-3
@@ -21,13 +21,14 @@ struct String {
|
||||
};
|
||||
// NOTE(bill): used for printf style arguments
|
||||
#define LIT(x) ((int)(x).len), (x).text
|
||||
#define STR_LIT(c_str) {cast(u8 *)c_str, gb_size_of(c_str)-1}
|
||||
#if defined(GB_COMPILER_MSVC) && _MSC_VER < 1700
|
||||
#define str_lit(c_str) make_string(cast(u8 *)c_str, gb_size_of(c_str)-1)
|
||||
#define STR_LIT(c_str) make_string(cast(u8 *)c_str, gb_size_of(c_str)-1)
|
||||
#else
|
||||
#define str_lit(c_str) String{cast(u8 *)c_str, gb_size_of(c_str)-1}
|
||||
#define STR_LIT(c_str) String{cast(u8 *)c_str, gb_size_of(c_str)-1}
|
||||
#endif
|
||||
|
||||
#define str_lit(c_str) STR_LIT(c_str)
|
||||
|
||||
// NOTE(bill): String16 is only used for Windows due to its file directories
|
||||
struct String16 {
|
||||
wchar_t *text;
|
||||
|
||||
Reference in New Issue
Block a user