mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-14 23:21:25 -07:00
Begin work on supporting wasm64; Correct wasm32 compilation behaviour
This commit is contained in:
+27
-3
@@ -29,6 +29,7 @@ enum TargetArchKind {
|
||||
TargetArch_386,
|
||||
TargetArch_arm64,
|
||||
TargetArch_wasm32,
|
||||
TargetArch_wasm64,
|
||||
|
||||
TargetArch_COUNT,
|
||||
};
|
||||
@@ -59,6 +60,7 @@ String target_arch_names[TargetArch_COUNT] = {
|
||||
str_lit("386"),
|
||||
str_lit("arm64"),
|
||||
str_lit("wasm32"),
|
||||
str_lit("wasm64"),
|
||||
};
|
||||
|
||||
String target_endian_names[TargetEndian_COUNT] = {
|
||||
@@ -72,6 +74,7 @@ TargetEndianKind target_endians[TargetArch_COUNT] = {
|
||||
TargetEndian_Little,
|
||||
TargetEndian_Little,
|
||||
TargetEndian_Little,
|
||||
TargetEndian_Little,
|
||||
};
|
||||
|
||||
#ifndef ODIN_VERSION_RAW
|
||||
@@ -335,6 +338,16 @@ gb_global TargetMetrics target_freestanding_wasm32 = {
|
||||
str_lit(""),
|
||||
};
|
||||
|
||||
gb_global TargetMetrics target_freestanding_wasm64 = {
|
||||
TargetOs_freestanding,
|
||||
TargetArch_wasm64,
|
||||
8,
|
||||
16,
|
||||
str_lit("wasm64-freestanding-js"),
|
||||
str_lit(""),
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
struct NamedTargetMetrics {
|
||||
@@ -353,6 +366,7 @@ gb_global NamedTargetMetrics named_targets[] = {
|
||||
{ str_lit("freebsd_386"), &target_freebsd_386 },
|
||||
{ str_lit("freebsd_amd64"), &target_freebsd_amd64 },
|
||||
{ str_lit("freestanding_wasm32"), &target_freestanding_wasm32 },
|
||||
{ str_lit("freestanding_wasm64"), &target_freestanding_wasm64 },
|
||||
};
|
||||
|
||||
NamedTargetMetrics *selected_target_metrics;
|
||||
@@ -458,11 +472,21 @@ bool find_library_collection_path(String name, String *path) {
|
||||
}
|
||||
|
||||
bool is_arch_wasm(void) {
|
||||
return build_context.metrics.arch == TargetArch_wasm32;
|
||||
switch (build_context.metrics.arch) {
|
||||
case TargetArch_wasm32:
|
||||
case TargetArch_wasm64:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool allow_check_foreign_filepath(void) {
|
||||
return build_context.metrics.arch != TargetArch_wasm32;
|
||||
switch (build_context.metrics.arch) {
|
||||
case TargetArch_wasm32:
|
||||
case TargetArch_wasm64:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -870,7 +894,7 @@ void init_build_context(TargetMetrics *cross_target) {
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (bc->metrics.arch == TargetArch_wasm32) {
|
||||
} else if (is_arch_wasm()) {
|
||||
bc->link_flags = str_lit("--no-entry --export-table --export-all --allow-undefined ");
|
||||
} else {
|
||||
gb_printf_err("Compiler Error: Unsupported architecture\n");;
|
||||
|
||||
+12
-4
@@ -1061,19 +1061,27 @@ LB_ABI_INFO(lb_get_abi_info) {
|
||||
}
|
||||
}
|
||||
|
||||
if (build_context.metrics.arch == TargetArch_amd64) {
|
||||
switch (build_context.metrics.arch) {
|
||||
case TargetArch_amd64:
|
||||
if (build_context.metrics.os == TargetOs_windows) {
|
||||
return lbAbiAmd64Win64::abi_info(c, arg_types, arg_count, return_type, return_is_defined, calling_convention);
|
||||
} else {
|
||||
return lbAbiAmd64SysV::abi_info(c, arg_types, arg_count, return_type, return_is_defined, calling_convention);
|
||||
}
|
||||
} else if (build_context.metrics.arch == TargetArch_386) {
|
||||
case TargetArch_386:
|
||||
return lbAbi386::abi_info(c, arg_types, arg_count, return_type, return_is_defined, calling_convention);
|
||||
} else if (build_context.metrics.arch == TargetArch_arm64) {
|
||||
case TargetArch_arm64:
|
||||
return lbAbiArm64::abi_info(c, arg_types, arg_count, return_type, return_is_defined, calling_convention);
|
||||
} else if (build_context.metrics.arch == TargetArch_wasm32) {
|
||||
case TargetArch_wasm32:
|
||||
// TODO(bill): implement wasm32's ABI correct
|
||||
// NOTE(bill): this ABI is only an issue for WASI compatibility
|
||||
return lbAbi386::abi_info(c, arg_types, arg_count, return_type, return_is_defined, calling_convention);
|
||||
case TargetArch_wasm64:
|
||||
// TODO(bill): implement wasm64's ABI correct
|
||||
// NOTE(bill): this ABI is only an issue for WASI compatibility
|
||||
return lbAbiAmd64SysV::abi_info(c, arg_types, arg_count, return_type, return_is_defined, calling_convention);
|
||||
}
|
||||
|
||||
GB_PANIC("Unsupported ABI");
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -1148,6 +1148,7 @@ void lb_generate_code(lbGenerator *gen) {
|
||||
LLVMInitializeAArch64Disassembler();
|
||||
break;
|
||||
case TargetArch_wasm32:
|
||||
case TargetArch_wasm64:
|
||||
LLVMInitializeWebAssemblyTargetInfo();
|
||||
LLVMInitializeWebAssemblyTarget();
|
||||
LLVMInitializeWebAssemblyTargetMC();
|
||||
|
||||
@@ -496,6 +496,7 @@ bool lb_is_matrix_simdable(Type *t) {
|
||||
break;
|
||||
case TargetArch_386:
|
||||
case TargetArch_wasm32:
|
||||
case TargetArch_wasm64:
|
||||
// nope
|
||||
return false;
|
||||
}
|
||||
@@ -513,6 +514,7 @@ bool lb_is_matrix_simdable(Type *t) {
|
||||
return true;
|
||||
case TargetArch_386:
|
||||
case TargetArch_wasm32:
|
||||
case TargetArch_wasm64:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1504,6 +1504,7 @@ lbValue lb_emit_mul_add(lbProcedure *p, lbValue a, lbValue b, lbValue c, Type *t
|
||||
break;
|
||||
case TargetArch_386:
|
||||
case TargetArch_wasm32:
|
||||
case TargetArch_wasm64:
|
||||
is_possible = false;
|
||||
break;
|
||||
}
|
||||
|
||||
+13
-6
@@ -135,13 +135,20 @@ i32 linker_stage(lbGenerator *gen) {
|
||||
|
||||
if (is_arch_wasm()) {
|
||||
timings_start_section(timings, str_lit("wasm-ld"));
|
||||
result = system_exec_command_line_app("wasm-ld",
|
||||
"\"%.*s\\bin\\wasm-ld\" \"%.*s.wasm-obj\" -o \"%.*s.wasm\" %.*s %.*s",
|
||||
LIT(build_context.ODIN_ROOT),
|
||||
LIT(output_base), LIT(output_base), LIT(build_context.link_flags), LIT(build_context.extra_linker_flags));
|
||||
if (result) {
|
||||
return result;
|
||||
|
||||
if (build_context.metrics.arch == TargetArch_wasm32) {
|
||||
result = system_exec_command_line_app("wasm-ld",
|
||||
"\"%.*s\\bin\\wasm-ld\" \"%.*s.wasm.o\" -o \"%.*s.wasm\" %.*s %.*s",
|
||||
LIT(build_context.ODIN_ROOT),
|
||||
LIT(output_base), LIT(output_base), LIT(build_context.link_flags), LIT(build_context.extra_linker_flags));
|
||||
} else {
|
||||
GB_ASSERT(build_context.metrics.arch == TargetArch_wasm64);
|
||||
result = system_exec_command_line_app("wasm-ld",
|
||||
"\"%.*s\\bin\\wasm-ld\" \"%.*s.wasm.o\" -o \"%.*s.wasm\" %.*s %.*s",
|
||||
LIT(build_context.ODIN_ROOT),
|
||||
LIT(output_base), LIT(output_base), LIT(build_context.link_flags), LIT(build_context.extra_linker_flags));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (build_context.cross_compiling && selected_target_metrics->metrics == &target_essence_amd64) {
|
||||
|
||||
Reference in New Issue
Block a user