mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-26 17:30:02 +00:00
Merge remote-tracking branch 'offical/master'
This commit is contained in:
+13
-1
@@ -23,6 +23,7 @@ enum TargetOsKind : u16 {
|
||||
|
||||
TargetOs_wasi,
|
||||
TargetOs_js,
|
||||
TargetOs_orca,
|
||||
|
||||
TargetOs_freestanding,
|
||||
|
||||
@@ -90,6 +91,7 @@ gb_global String target_os_names[TargetOs_COUNT] = {
|
||||
|
||||
str_lit("wasi"),
|
||||
str_lit("js"),
|
||||
str_lit("orca"),
|
||||
|
||||
str_lit("freestanding"),
|
||||
};
|
||||
@@ -1067,6 +1069,15 @@ gb_global TargetMetrics target_wasi_wasm32 = {
|
||||
};
|
||||
|
||||
|
||||
gb_global TargetMetrics target_orca_wasm32 = {
|
||||
TargetOs_orca,
|
||||
TargetArch_wasm32,
|
||||
4, 4, 8, 16,
|
||||
str_lit("wasm32-wasi-js"),
|
||||
// str_lit("e-m:e-p:32:32-i64:64-n32:64-S128"),
|
||||
};
|
||||
|
||||
|
||||
gb_global TargetMetrics target_freestanding_wasm64p32 = {
|
||||
TargetOs_freestanding,
|
||||
TargetArch_wasm64p32,
|
||||
@@ -2012,8 +2023,9 @@ gb_internal void init_build_context(TargetMetrics *cross_target, Subtarget subta
|
||||
// if (bc->metrics.arch == TargetArch_wasm64) {
|
||||
// link_flags = gb_string_appendc(link_flags, "-mwasm64 ");
|
||||
// }
|
||||
if (bc->no_entry_point) {
|
||||
if (bc->no_entry_point || bc->metrics.os == TargetOs_orca) {
|
||||
link_flags = gb_string_appendc(link_flags, "--no-entry ");
|
||||
bc->no_entry_point = true; // just in case for the "orca" target
|
||||
}
|
||||
|
||||
bc->link_flags = make_string_c(link_flags);
|
||||
|
||||
+26
-6
@@ -724,9 +724,10 @@ gb_internal Entity *init_entity_foreign_library(CheckerContext *ctx, Entity *e)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
gb_internal String handle_link_name(CheckerContext *ctx, Token token, String link_name, String link_prefix) {
|
||||
gb_internal String handle_link_name(CheckerContext *ctx, Token token, String link_name, String link_prefix, String link_suffix) {
|
||||
String original_link_name = link_name;
|
||||
if (link_prefix.len > 0) {
|
||||
if (link_name.len > 0) {
|
||||
if (original_link_name.len > 0) {
|
||||
error(token, "'link_name' and 'link_prefix' cannot be used together");
|
||||
} else {
|
||||
isize len = link_prefix.len + token.string.len;
|
||||
@@ -738,9 +739,28 @@ gb_internal String handle_link_name(CheckerContext *ctx, Token token, String lin
|
||||
link_name = make_string(name, len);
|
||||
}
|
||||
}
|
||||
|
||||
if (link_suffix.len > 0) {
|
||||
if (original_link_name.len > 0) {
|
||||
error(token, "'link_name' and 'link_suffix' cannot be used together");
|
||||
} else {
|
||||
String new_name = token.string;
|
||||
if (link_name != original_link_name) {
|
||||
new_name = link_name;
|
||||
}
|
||||
|
||||
isize len = new_name.len + link_suffix.len;
|
||||
u8 *name = gb_alloc_array(permanent_allocator(), u8, len+1);
|
||||
gb_memmove(name, &new_name[0], new_name.len);
|
||||
gb_memmove(name+new_name.len, &link_suffix[0], link_suffix.len);
|
||||
name[len] = 0;
|
||||
link_name = make_string(name, len);
|
||||
}
|
||||
}
|
||||
return link_name;
|
||||
}
|
||||
|
||||
|
||||
gb_internal void check_objc_methods(CheckerContext *ctx, Entity *e, AttributeContext const &ac) {
|
||||
if (!(ac.objc_name.len || ac.objc_is_class_method || ac.objc_type)) {
|
||||
return;
|
||||
@@ -862,7 +882,7 @@ gb_internal void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
|
||||
}
|
||||
|
||||
TypeProc *pt = &proc_type->Proc;
|
||||
AttributeContext ac = make_attribute_context(e->Procedure.link_prefix);
|
||||
AttributeContext ac = make_attribute_context(e->Procedure.link_prefix, e->Procedure.link_suffix);
|
||||
|
||||
if (d != nullptr) {
|
||||
check_decl_attributes(ctx, d->attributes, proc_decl_attribute, &ac);
|
||||
@@ -1015,7 +1035,7 @@ gb_internal void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
|
||||
|
||||
e->deprecated_message = ac.deprecated_message;
|
||||
e->warning_message = ac.warning_message;
|
||||
ac.link_name = handle_link_name(ctx, e->token, ac.link_name, ac.link_prefix);
|
||||
ac.link_name = handle_link_name(ctx, e->token, ac.link_name, ac.link_prefix,ac.link_suffix);
|
||||
if (ac.has_disabled_proc) {
|
||||
if (ac.disabled_proc) {
|
||||
e->flags |= EntityFlag_Disabled;
|
||||
@@ -1223,7 +1243,7 @@ gb_internal void check_global_variable_decl(CheckerContext *ctx, Entity *&e, Ast
|
||||
}
|
||||
e->flags |= EntityFlag_Visited;
|
||||
|
||||
AttributeContext ac = make_attribute_context(e->Variable.link_prefix);
|
||||
AttributeContext ac = make_attribute_context(e->Variable.link_prefix, e->Variable.link_suffix);
|
||||
ac.init_expr_list_count = init_expr != nullptr ? 1 : 0;
|
||||
|
||||
DeclInfo *decl = decl_info_of_entity(e);
|
||||
@@ -1244,7 +1264,7 @@ gb_internal void check_global_variable_decl(CheckerContext *ctx, Entity *&e, Ast
|
||||
if (ac.is_static) {
|
||||
error(e->token, "@(static) is not supported for global variables, nor required");
|
||||
}
|
||||
ac.link_name = handle_link_name(ctx, e->token, ac.link_name, ac.link_prefix);
|
||||
ac.link_name = handle_link_name(ctx, e->token, ac.link_name, ac.link_prefix, ac.link_suffix);
|
||||
|
||||
if (is_arch_wasm() && e->Variable.thread_local_model.len != 0) {
|
||||
e->Variable.thread_local_model.len = 0;
|
||||
|
||||
+2
-2
@@ -2020,7 +2020,7 @@ gb_internal void check_value_decl_stmt(CheckerContext *ctx, Ast *node, u32 mod_f
|
||||
|
||||
|
||||
// TODO NOTE(bill): This technically checks things multple times
|
||||
AttributeContext ac = make_attribute_context(ctx->foreign_context.link_prefix);
|
||||
AttributeContext ac = make_attribute_context(ctx->foreign_context.link_prefix, ctx->foreign_context.link_suffix);
|
||||
check_decl_attributes(ctx, vd->attributes, var_decl_attribute, &ac);
|
||||
|
||||
for (isize i = 0; i < entity_count; i++) {
|
||||
@@ -2037,7 +2037,7 @@ gb_internal void check_value_decl_stmt(CheckerContext *ctx, Ast *node, u32 mod_f
|
||||
e->type = init_type;
|
||||
e->state = EntityState_Resolved;
|
||||
}
|
||||
ac.link_name = handle_link_name(ctx, e->token, ac.link_name, ac.link_prefix);
|
||||
ac.link_name = handle_link_name(ctx, e->token, ac.link_name, ac.link_prefix, ac.link_suffix);
|
||||
|
||||
if (ac.link_name.len > 0) {
|
||||
e->Variable.link_name = ac.link_name;
|
||||
|
||||
@@ -1016,6 +1016,7 @@ gb_internal void init_universal(void) {
|
||||
{"NetBSD", TargetOs_netbsd},
|
||||
{"WASI", TargetOs_wasi},
|
||||
{"JS", TargetOs_js},
|
||||
{"Orca", TargetOs_orca},
|
||||
{"Freestanding", TargetOs_freestanding},
|
||||
};
|
||||
|
||||
@@ -3127,6 +3128,18 @@ gb_internal DECL_ATTRIBUTE_PROC(foreign_block_decl_attribute) {
|
||||
error(elem, "Expected a string value for '%.*s'", LIT(name));
|
||||
}
|
||||
return true;
|
||||
} else if (name == "link_suffix") {
|
||||
if (ev.kind == ExactValue_String) {
|
||||
String link_suffix = ev.value_string;
|
||||
if (!is_foreign_name_valid(link_suffix)) {
|
||||
error(elem, "Invalid link suffix: '%.*s'", LIT(link_suffix));
|
||||
} else {
|
||||
c->foreign_context.link_suffix = link_suffix;
|
||||
}
|
||||
} else {
|
||||
error(elem, "Expected a string value for '%.*s'", LIT(name));
|
||||
}
|
||||
return true;
|
||||
} else if (name == "private") {
|
||||
EntityVisiblityKind kind = EntityVisiblity_PrivateToPackage;
|
||||
if (ev.kind == ExactValue_Invalid) {
|
||||
@@ -3421,6 +3434,18 @@ gb_internal DECL_ATTRIBUTE_PROC(proc_decl_attribute) {
|
||||
error(elem, "Expected a string value for '%.*s'", LIT(name));
|
||||
}
|
||||
return true;
|
||||
} else if (name == "link_suffix") {
|
||||
ExactValue ev = check_decl_attribute_value(c, value);
|
||||
|
||||
if (ev.kind == ExactValue_String) {
|
||||
ac->link_suffix = ev.value_string;
|
||||
if (!is_foreign_name_valid(ac->link_suffix)) {
|
||||
error(elem, "Invalid link suffix: %.*s", LIT(ac->link_suffix));
|
||||
}
|
||||
} else {
|
||||
error(elem, "Expected a string value for '%.*s'", LIT(name));
|
||||
}
|
||||
return true;
|
||||
} else if (name == "deprecated") {
|
||||
ExactValue ev = check_decl_attribute_value(c, value);
|
||||
|
||||
@@ -3702,6 +3727,17 @@ gb_internal DECL_ATTRIBUTE_PROC(var_decl_attribute) {
|
||||
error(elem, "Expected a string value for '%.*s'", LIT(name));
|
||||
}
|
||||
return true;
|
||||
} else if (name == "link_suffix") {
|
||||
ExactValue ev = check_decl_attribute_value(c, value);
|
||||
if (ev.kind == ExactValue_String) {
|
||||
ac->link_suffix = ev.value_string;
|
||||
if (!is_foreign_name_valid(ac->link_suffix)) {
|
||||
error(elem, "Invalid link suffix: %.*s", LIT(ac->link_suffix));
|
||||
}
|
||||
} else {
|
||||
error(elem, "Expected a string value for '%.*s'", LIT(name));
|
||||
}
|
||||
return true;
|
||||
} else if (name == "link_section") {
|
||||
ExactValue ev = check_decl_attribute_value(c, value);
|
||||
if (ev.kind == ExactValue_String) {
|
||||
@@ -3733,6 +3769,7 @@ gb_internal DECL_ATTRIBUTE_PROC(const_decl_attribute) {
|
||||
name == "linkage" ||
|
||||
name == "link_name" ||
|
||||
name == "link_prefix" ||
|
||||
name == "link_suffix" ||
|
||||
false) {
|
||||
error(elem, "@(%.*s) is not supported for compile time constant value declarations", LIT(name));
|
||||
return true;
|
||||
@@ -3775,8 +3812,10 @@ gb_internal void check_decl_attributes(CheckerContext *c, Array<Ast *> const &at
|
||||
if (attributes.count == 0) return;
|
||||
|
||||
String original_link_prefix = {};
|
||||
String original_link_suffix = {};
|
||||
if (ac) {
|
||||
original_link_prefix = ac->link_prefix;
|
||||
original_link_suffix = ac->link_suffix;
|
||||
}
|
||||
|
||||
StringSet set = {};
|
||||
@@ -3851,6 +3890,12 @@ gb_internal void check_decl_attributes(CheckerContext *c, Array<Ast *> const &at
|
||||
ac->link_prefix.len = 0;
|
||||
}
|
||||
}
|
||||
if (ac->link_suffix.text == original_link_suffix.text) {
|
||||
if (ac->link_name.len > 0) {
|
||||
ac->link_suffix.text = nullptr;
|
||||
ac->link_suffix.len = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4145,6 +4190,7 @@ gb_internal void check_collect_value_decl(CheckerContext *c, Ast *decl) {
|
||||
e->Variable.foreign_library_ident = fl;
|
||||
|
||||
e->Variable.link_prefix = c->foreign_context.link_prefix;
|
||||
e->Variable.link_suffix = c->foreign_context.link_suffix;
|
||||
}
|
||||
|
||||
Ast *init_expr = value;
|
||||
@@ -4219,6 +4265,7 @@ gb_internal void check_collect_value_decl(CheckerContext *c, Ast *decl) {
|
||||
}
|
||||
}
|
||||
e->Procedure.link_prefix = c->foreign_context.link_prefix;
|
||||
e->Procedure.link_suffix = c->foreign_context.link_suffix;
|
||||
|
||||
GB_ASSERT(cc != ProcCC_Invalid);
|
||||
pl->type->ProcType.calling_convention = cc;
|
||||
|
||||
+4
-1
@@ -112,6 +112,7 @@ enum InstrumentationFlag : i32 {
|
||||
struct AttributeContext {
|
||||
String link_name;
|
||||
String link_prefix;
|
||||
String link_suffix;
|
||||
String link_section;
|
||||
String linkage;
|
||||
isize init_expr_list_count;
|
||||
@@ -146,9 +147,10 @@ struct AttributeContext {
|
||||
String enable_target_feature; // will be enabled for the procedure only
|
||||
};
|
||||
|
||||
gb_internal gb_inline AttributeContext make_attribute_context(String link_prefix) {
|
||||
gb_internal gb_inline AttributeContext make_attribute_context(String link_prefix, String link_suffix) {
|
||||
AttributeContext ac = {};
|
||||
ac.link_prefix = link_prefix;
|
||||
ac.link_suffix = link_suffix;
|
||||
return ac;
|
||||
}
|
||||
|
||||
@@ -302,6 +304,7 @@ struct ForeignContext {
|
||||
Ast * curr_library;
|
||||
ProcCallingConvention default_cc;
|
||||
String link_prefix;
|
||||
String link_suffix;
|
||||
EntityVisiblityKind visibility_kind;
|
||||
};
|
||||
|
||||
|
||||
@@ -223,6 +223,7 @@ struct Entity {
|
||||
Ast * foreign_library_ident;
|
||||
String link_name;
|
||||
String link_prefix;
|
||||
String link_suffix;
|
||||
String link_section;
|
||||
CommentGroup *docs;
|
||||
CommentGroup *comment;
|
||||
@@ -243,6 +244,7 @@ struct Entity {
|
||||
Ast * foreign_library_ident;
|
||||
String link_name;
|
||||
String link_prefix;
|
||||
String link_suffix;
|
||||
DeferredProcedure deferred_procedure;
|
||||
|
||||
struct GenProcsData *gen_procs;
|
||||
|
||||
+16
-4
@@ -69,15 +69,27 @@ gb_internal i32 linker_stage(LinkerData *gen) {
|
||||
if (is_arch_wasm()) {
|
||||
timings_start_section(timings, str_lit("wasm-ld"));
|
||||
|
||||
String extra_orca_flags = {};
|
||||
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
if (build_context.metrics.os == TargetOs_orca) {
|
||||
extra_orca_flags = str_lit(" W:/orca/installation/dev-afb9591/bin/liborca_wasm.a --export-dynamic");
|
||||
}
|
||||
|
||||
result = system_exec_command_line_app("wasm-ld",
|
||||
"\"%.*s\\bin\\wasm-ld\" \"%.*s.o\" -o \"%.*s\" %.*s %.*s",
|
||||
"\"%.*s\\bin\\wasm-ld\" \"%.*s.o\" -o \"%.*s\" %.*s %.*s %.*s",
|
||||
LIT(build_context.ODIN_ROOT),
|
||||
LIT(output_filename), LIT(output_filename), LIT(build_context.link_flags), LIT(build_context.extra_linker_flags));
|
||||
LIT(output_filename), LIT(output_filename), LIT(build_context.link_flags), LIT(build_context.extra_linker_flags),
|
||||
LIT(extra_orca_flags));
|
||||
#else
|
||||
if (build_context.metrics.os == TargetOs_orca) {
|
||||
extra_orca_flags = str_lit(" -L . -lorca --export-dynamic");
|
||||
}
|
||||
|
||||
result = system_exec_command_line_app("wasm-ld",
|
||||
"wasm-ld \"%.*s.o\" -o \"%.*s\" %.*s %.*s",
|
||||
LIT(output_filename), LIT(output_filename), LIT(build_context.link_flags), LIT(build_context.extra_linker_flags));
|
||||
"wasm-ld \"%.*s.o\" -o \"%.*s\" %.*s %.*s %.*s",
|
||||
LIT(output_filename), LIT(output_filename), LIT(build_context.link_flags), LIT(build_context.extra_linker_flags),
|
||||
LIT(extra_orca_flags));
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1365,6 +1365,8 @@ gb_internal lbValue lb_emit_deep_field_gep(lbProcedure *p, lbValue e, Selection
|
||||
} else {
|
||||
e = lb_emit_ptr_offset(p, lb_emit_load(p, arr), index);
|
||||
}
|
||||
e.type = alloc_type_multi_pointer_to_pointer(e.type);
|
||||
|
||||
} else if (is_type_quaternion(type)) {
|
||||
e = lb_emit_struct_ep(p, e, index);
|
||||
} else if (is_type_raw_union(type)) {
|
||||
|
||||
Reference in New Issue
Block a user