mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Allow sysv and win64 calling conventions to be used on any platform on amd64
This commit is contained in:
@@ -33,6 +33,11 @@ Calling_Convention :: enum u8 {
|
|||||||
|
|
||||||
None = 6,
|
None = 6,
|
||||||
Naked = 7,
|
Naked = 7,
|
||||||
|
|
||||||
|
_ = 8, // reserved
|
||||||
|
|
||||||
|
Win64 = 9,
|
||||||
|
SysV = 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
Type_Info_Enum_Value :: distinct i64
|
Type_Info_Enum_Value :: distinct i64
|
||||||
|
|||||||
@@ -1910,6 +1910,25 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node,
|
|||||||
c->scope->flags &= ~ScopeFlag_ContextDefined;
|
c->scope->flags &= ~ScopeFlag_ContextDefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TargetArchKind arch = build_context.metrics.arch;
|
||||||
|
switch (cc) {
|
||||||
|
case ProcCC_StdCall:
|
||||||
|
case ProcCC_FastCall:
|
||||||
|
if (arch != TargetArch_i386 || arch != TargetArch_amd64) {
|
||||||
|
error(proc_type_node, "Invalid procedure calling convention \"%s\" for target architecture, expected either i386 or amd64, got %.*s",
|
||||||
|
proc_calling_convention_strings[cc], LIT(target_arch_names[arch]));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ProcCC_Win64:
|
||||||
|
case ProcCC_SysV:
|
||||||
|
if (arch != TargetArch_amd64) {
|
||||||
|
error(proc_type_node, "Invalid procedure calling convention \"%s\" for target architecture, expected amd64, got %.*s",
|
||||||
|
proc_calling_convention_strings[cc], LIT(target_arch_names[arch]));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool variadic = false;
|
bool variadic = false;
|
||||||
isize variadic_index = -1;
|
isize variadic_index = -1;
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|||||||
+1
-34
@@ -683,40 +683,7 @@ OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) {
|
|||||||
types[1] = odin_doc_type(w, type->Proc.results);
|
types[1] = odin_doc_type(w, type->Proc.results);
|
||||||
doc_type.types = odin_write_slice(w, types, gb_count_of(types));
|
doc_type.types = odin_write_slice(w, types, gb_count_of(types));
|
||||||
|
|
||||||
String calling_convention = {};
|
String calling_convention = make_string_c(proc_calling_convention_strings[type->Proc.calling_convention]);
|
||||||
switch (type->Proc.calling_convention) {
|
|
||||||
case ProcCC_Invalid:
|
|
||||||
// no need
|
|
||||||
break;
|
|
||||||
case ProcCC_Odin:
|
|
||||||
if (default_calling_convention() != ProcCC_Odin) {
|
|
||||||
calling_convention = str_lit("odin");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ProcCC_Contextless:
|
|
||||||
if (default_calling_convention() != ProcCC_Contextless) {
|
|
||||||
calling_convention = str_lit("contextless");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ProcCC_CDecl:
|
|
||||||
calling_convention = str_lit("cdecl");
|
|
||||||
break;
|
|
||||||
case ProcCC_StdCall:
|
|
||||||
calling_convention = str_lit("stdcall");
|
|
||||||
break;
|
|
||||||
case ProcCC_FastCall:
|
|
||||||
calling_convention = str_lit("fastcall");
|
|
||||||
break;
|
|
||||||
case ProcCC_None:
|
|
||||||
calling_convention = str_lit("none");
|
|
||||||
break;
|
|
||||||
case ProcCC_Naked:
|
|
||||||
calling_convention = str_lit("naked");
|
|
||||||
break;
|
|
||||||
case ProcCC_InlineAsm:
|
|
||||||
calling_convention = str_lit("inline-assembly");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
doc_type.calling_convention = odin_doc_write_string(w, calling_convention);
|
doc_type.calling_convention = odin_doc_write_string(w, calling_convention);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1184,6 +1184,12 @@ LB_ABI_INFO(lb_get_abi_info) {
|
|||||||
ft->calling_convention = calling_convention;
|
ft->calling_convention = calling_convention;
|
||||||
return ft;
|
return ft;
|
||||||
}
|
}
|
||||||
|
case ProcCC_Win64:
|
||||||
|
GB_ASSERT(build_context.metrics.arch == TargetArch_amd64);
|
||||||
|
return lbAbiAmd64Win64::abi_info(c, arg_types, arg_count, return_type, return_is_defined, calling_convention);
|
||||||
|
case ProcCC_SysV:
|
||||||
|
GB_ASSERT(build_context.metrics.arch == TargetArch_amd64);
|
||||||
|
return lbAbiAmd64SysV::abi_info(c, arg_types, arg_count, return_type, return_is_defined, calling_convention);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (build_context.metrics.arch) {
|
switch (build_context.metrics.arch) {
|
||||||
|
|||||||
@@ -548,6 +548,10 @@ lbCallingConventionKind const lb_calling_convention_map[ProcCC_MAX] = {
|
|||||||
lbCallingConvention_C, // ProcCC_None,
|
lbCallingConvention_C, // ProcCC_None,
|
||||||
lbCallingConvention_C, // ProcCC_Naked,
|
lbCallingConvention_C, // ProcCC_Naked,
|
||||||
lbCallingConvention_C, // ProcCC_InlineAsm,
|
lbCallingConvention_C, // ProcCC_InlineAsm,
|
||||||
|
|
||||||
|
lbCallingConvention_Win64, // ProcCC_Win64,
|
||||||
|
lbCallingConvention_X86_64_SysV, // ProcCC_SysV,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum : LLVMDWARFTypeEncoding {
|
enum : LLVMDWARFTypeEncoding {
|
||||||
|
|||||||
@@ -497,7 +497,7 @@ void lb_begin_procedure_body(lbProcedure *p) {
|
|||||||
}
|
}
|
||||||
LLVMValueRef debug_storage_value = value;
|
LLVMValueRef debug_storage_value = value;
|
||||||
if (original_value != value && LLVMIsALoadInst(value)) {
|
if (original_value != value && LLVMIsALoadInst(value)) {
|
||||||
debug_storage_value = ptr.value;
|
debug_storage_value = LLVMGetOperand(value, 0);
|
||||||
}
|
}
|
||||||
lb_add_debug_param_variable(p, debug_storage_value, e->type, e->token, param_index+1, block);
|
lb_add_debug_param_variable(p, debug_storage_value, e->type, e->token, param_index+1, block);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3412,12 +3412,18 @@ ProcCallingConvention string_to_calling_convention(String s) {
|
|||||||
if (s == "fast") return ProcCC_FastCall;
|
if (s == "fast") return ProcCC_FastCall;
|
||||||
if (s == "none") return ProcCC_None;
|
if (s == "none") return ProcCC_None;
|
||||||
if (s == "naked") return ProcCC_Naked;
|
if (s == "naked") return ProcCC_Naked;
|
||||||
|
|
||||||
|
if (s == "win64") return ProcCC_Win64;
|
||||||
|
if (s == "sysv") return ProcCC_SysV;
|
||||||
|
|
||||||
if (s == "system") {
|
if (s == "system") {
|
||||||
if (build_context.metrics.os == TargetOs_windows) {
|
if (build_context.metrics.os == TargetOs_windows) {
|
||||||
return ProcCC_StdCall;
|
return ProcCC_StdCall;
|
||||||
}
|
}
|
||||||
return ProcCC_CDecl;
|
return ProcCC_CDecl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return ProcCC_Invalid;
|
return ProcCC_Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -249,12 +249,30 @@ enum ProcCallingConvention : i32 {
|
|||||||
|
|
||||||
ProcCC_InlineAsm = 8,
|
ProcCC_InlineAsm = 8,
|
||||||
|
|
||||||
|
ProcCC_Win64 = 9,
|
||||||
|
ProcCC_SysV = 10,
|
||||||
|
|
||||||
|
|
||||||
ProcCC_MAX,
|
ProcCC_MAX,
|
||||||
|
|
||||||
|
|
||||||
ProcCC_ForeignBlockDefault = -1,
|
ProcCC_ForeignBlockDefault = -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
char const *proc_calling_convention_strings[ProcCC_MAX] = {
|
||||||
|
"",
|
||||||
|
"odin",
|
||||||
|
"contextless",
|
||||||
|
"cdecl",
|
||||||
|
"stdcall",
|
||||||
|
"fastcall",
|
||||||
|
"none",
|
||||||
|
"naked",
|
||||||
|
"inlineasm",
|
||||||
|
"win64",
|
||||||
|
"sysv",
|
||||||
|
};
|
||||||
|
|
||||||
ProcCallingConvention default_calling_convention(void) {
|
ProcCallingConvention default_calling_convention(void) {
|
||||||
return ProcCC_Odin;
|
return ProcCC_Odin;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user