mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
Begin work on supporting wasm64; Correct wasm32 compilation behaviour
This commit is contained in:
@@ -17,6 +17,19 @@ Default_Temp_Allocator :: struct {
|
|||||||
leaked_allocations: [dynamic][]byte,
|
leaked_allocations: [dynamic][]byte,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
when ODIN_OS == "freestanding" {
|
||||||
|
default_temp_allocator_init :: proc(s: ^Default_Temp_Allocator, size: int, backup_allocator := context.allocator) {
|
||||||
|
}
|
||||||
|
|
||||||
|
default_temp_allocator_destroy :: proc(s: ^Default_Temp_Allocator) {
|
||||||
|
}
|
||||||
|
|
||||||
|
default_temp_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||||
|
size, alignment: int,
|
||||||
|
old_memory: rawptr, old_size: int, loc := #caller_location) -> (data: []byte, err: Allocator_Error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
default_temp_allocator_init :: proc(s: ^Default_Temp_Allocator, size: int, backup_allocator := context.allocator) {
|
default_temp_allocator_init :: proc(s: ^Default_Temp_Allocator, size: int, backup_allocator := context.allocator) {
|
||||||
s.data = make_aligned([]byte, size, 2*align_of(rawptr), backup_allocator)
|
s.data = make_aligned([]byte, size, 2*align_of(rawptr), backup_allocator)
|
||||||
s.curr_offset = 0
|
s.curr_offset = 0
|
||||||
@@ -187,6 +200,7 @@ default_temp_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
default_temp_allocator :: proc(allocator: ^Default_Temp_Allocator) -> Allocator {
|
default_temp_allocator :: proc(allocator: ^Default_Temp_Allocator) -> Allocator {
|
||||||
return Allocator{
|
return Allocator{
|
||||||
|
|||||||
+27
-3
@@ -29,6 +29,7 @@ enum TargetArchKind {
|
|||||||
TargetArch_386,
|
TargetArch_386,
|
||||||
TargetArch_arm64,
|
TargetArch_arm64,
|
||||||
TargetArch_wasm32,
|
TargetArch_wasm32,
|
||||||
|
TargetArch_wasm64,
|
||||||
|
|
||||||
TargetArch_COUNT,
|
TargetArch_COUNT,
|
||||||
};
|
};
|
||||||
@@ -59,6 +60,7 @@ String target_arch_names[TargetArch_COUNT] = {
|
|||||||
str_lit("386"),
|
str_lit("386"),
|
||||||
str_lit("arm64"),
|
str_lit("arm64"),
|
||||||
str_lit("wasm32"),
|
str_lit("wasm32"),
|
||||||
|
str_lit("wasm64"),
|
||||||
};
|
};
|
||||||
|
|
||||||
String target_endian_names[TargetEndian_COUNT] = {
|
String target_endian_names[TargetEndian_COUNT] = {
|
||||||
@@ -72,6 +74,7 @@ TargetEndianKind target_endians[TargetArch_COUNT] = {
|
|||||||
TargetEndian_Little,
|
TargetEndian_Little,
|
||||||
TargetEndian_Little,
|
TargetEndian_Little,
|
||||||
TargetEndian_Little,
|
TargetEndian_Little,
|
||||||
|
TargetEndian_Little,
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef ODIN_VERSION_RAW
|
#ifndef ODIN_VERSION_RAW
|
||||||
@@ -335,6 +338,16 @@ gb_global TargetMetrics target_freestanding_wasm32 = {
|
|||||||
str_lit(""),
|
str_lit(""),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
gb_global TargetMetrics target_freestanding_wasm64 = {
|
||||||
|
TargetOs_freestanding,
|
||||||
|
TargetArch_wasm64,
|
||||||
|
8,
|
||||||
|
16,
|
||||||
|
str_lit("wasm64-freestanding-js"),
|
||||||
|
str_lit(""),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct NamedTargetMetrics {
|
struct NamedTargetMetrics {
|
||||||
@@ -353,6 +366,7 @@ gb_global NamedTargetMetrics named_targets[] = {
|
|||||||
{ str_lit("freebsd_386"), &target_freebsd_386 },
|
{ str_lit("freebsd_386"), &target_freebsd_386 },
|
||||||
{ str_lit("freebsd_amd64"), &target_freebsd_amd64 },
|
{ str_lit("freebsd_amd64"), &target_freebsd_amd64 },
|
||||||
{ str_lit("freestanding_wasm32"), &target_freestanding_wasm32 },
|
{ str_lit("freestanding_wasm32"), &target_freestanding_wasm32 },
|
||||||
|
{ str_lit("freestanding_wasm64"), &target_freestanding_wasm64 },
|
||||||
};
|
};
|
||||||
|
|
||||||
NamedTargetMetrics *selected_target_metrics;
|
NamedTargetMetrics *selected_target_metrics;
|
||||||
@@ -458,11 +472,21 @@ bool find_library_collection_path(String name, String *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool is_arch_wasm(void) {
|
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) {
|
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;
|
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 ");
|
bc->link_flags = str_lit("--no-entry --export-table --export-all --allow-undefined ");
|
||||||
} else {
|
} else {
|
||||||
gb_printf_err("Compiler Error: Unsupported architecture\n");;
|
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) {
|
if (build_context.metrics.os == TargetOs_windows) {
|
||||||
return lbAbiAmd64Win64::abi_info(c, arg_types, arg_count, return_type, return_is_defined, calling_convention);
|
return lbAbiAmd64Win64::abi_info(c, arg_types, arg_count, return_type, return_is_defined, calling_convention);
|
||||||
} else {
|
} else {
|
||||||
return lbAbiAmd64SysV::abi_info(c, arg_types, arg_count, return_type, return_is_defined, calling_convention);
|
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);
|
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);
|
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);
|
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");
|
GB_PANIC("Unsupported ABI");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1148,6 +1148,7 @@ void lb_generate_code(lbGenerator *gen) {
|
|||||||
LLVMInitializeAArch64Disassembler();
|
LLVMInitializeAArch64Disassembler();
|
||||||
break;
|
break;
|
||||||
case TargetArch_wasm32:
|
case TargetArch_wasm32:
|
||||||
|
case TargetArch_wasm64:
|
||||||
LLVMInitializeWebAssemblyTargetInfo();
|
LLVMInitializeWebAssemblyTargetInfo();
|
||||||
LLVMInitializeWebAssemblyTarget();
|
LLVMInitializeWebAssemblyTarget();
|
||||||
LLVMInitializeWebAssemblyTargetMC();
|
LLVMInitializeWebAssemblyTargetMC();
|
||||||
|
|||||||
@@ -496,6 +496,7 @@ bool lb_is_matrix_simdable(Type *t) {
|
|||||||
break;
|
break;
|
||||||
case TargetArch_386:
|
case TargetArch_386:
|
||||||
case TargetArch_wasm32:
|
case TargetArch_wasm32:
|
||||||
|
case TargetArch_wasm64:
|
||||||
// nope
|
// nope
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -513,6 +514,7 @@ bool lb_is_matrix_simdable(Type *t) {
|
|||||||
return true;
|
return true;
|
||||||
case TargetArch_386:
|
case TargetArch_386:
|
||||||
case TargetArch_wasm32:
|
case TargetArch_wasm32:
|
||||||
|
case TargetArch_wasm64:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1504,6 +1504,7 @@ lbValue lb_emit_mul_add(lbProcedure *p, lbValue a, lbValue b, lbValue c, Type *t
|
|||||||
break;
|
break;
|
||||||
case TargetArch_386:
|
case TargetArch_386:
|
||||||
case TargetArch_wasm32:
|
case TargetArch_wasm32:
|
||||||
|
case TargetArch_wasm64:
|
||||||
is_possible = false;
|
is_possible = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-3
@@ -135,13 +135,20 @@ i32 linker_stage(lbGenerator *gen) {
|
|||||||
|
|
||||||
if (is_arch_wasm()) {
|
if (is_arch_wasm()) {
|
||||||
timings_start_section(timings, str_lit("wasm-ld"));
|
timings_start_section(timings, str_lit("wasm-ld"));
|
||||||
|
|
||||||
|
if (build_context.metrics.arch == TargetArch_wasm32) {
|
||||||
result = system_exec_command_line_app("wasm-ld",
|
result = system_exec_command_line_app("wasm-ld",
|
||||||
"\"%.*s\\bin\\wasm-ld\" \"%.*s.wasm-obj\" -o \"%.*s.wasm\" %.*s %.*s",
|
"\"%.*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(build_context.ODIN_ROOT),
|
||||||
LIT(output_base), LIT(output_base), LIT(build_context.link_flags), LIT(build_context.extra_linker_flags));
|
LIT(output_base), LIT(output_base), LIT(build_context.link_flags), LIT(build_context.extra_linker_flags));
|
||||||
if (result) {
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (build_context.cross_compiling && selected_target_metrics->metrics == &target_essence_amd64) {
|
if (build_context.cross_compiling && selected_target_metrics->metrics == &target_essence_amd64) {
|
||||||
|
|||||||
Reference in New Issue
Block a user