aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2019-12-29 19:34:54 +0100
committerLemonBoy <thatlemon@gmail.com>2020-01-02 18:57:08 +0100
commit0ccac79c8ebc1ed56dbdab068076a86924a015bc (patch)
treea7dfe2ba2535f7d4c50f2f8bae07e97df1a2ef19 /src/analyze.cpp
parent08a26fea0918fba1dd315781fa96d457da5bcb50 (diff)
downloadzig-0ccac79c8ebc1ed56dbdab068076a86924a015bc.tar.gz
zig-0ccac79c8ebc1ed56dbdab068076a86924a015bc.zip
Implement Thiscall CC
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 9a4b1449b6..b71d3322a1 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -929,6 +929,7 @@ const char *calling_convention_name(CallingConvention cc) {
case CallingConventionStdcall: return "Stdcall";
case CallingConventionFastcall: return "Fastcall";
case CallingConventionVectorcall: return "Vectorcall";
+ case CallingConventionThiscall: return "Thiscall";
case CallingConventionAPCS: return "Apcs";
case CallingConventionAAPCS: return "Aapcs";
case CallingConventionAAPCSVFP: return "Aapcsvfp";
@@ -949,6 +950,7 @@ bool calling_convention_allows_zig_types(CallingConvention cc) {
case CallingConventionStdcall:
case CallingConventionFastcall:
case CallingConventionVectorcall:
+ case CallingConventionThiscall:
case CallingConventionAPCS:
case CallingConventionAAPCS:
case CallingConventionAAPCSVFP:
@@ -1706,9 +1708,7 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {
case ZigTypeIdArray:
return type_allowed_in_extern(g, type_entry->data.array.child_type, result);
case ZigTypeIdFn:
- *result = type_entry->data.fn.fn_type_id.cc == CallingConventionC ||
- type_entry->data.fn.fn_type_id.cc == CallingConventionStdcall ||
- type_entry->data.fn.fn_type_id.cc == CallingConventionAAPCS;
+ *result = !calling_convention_allows_zig_types(type_entry->data.fn.fn_type_id.cc);
return ErrorNone;
case ZigTypeIdPointer:
if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))
@@ -3445,24 +3445,21 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
fn_table_entry->cc = (CallingConvention)bigint_as_u32(&result_val->data.x_enum_tag);
}
- fn_table_entry->type_entry = analyze_fn_type(g, source_node, child_scope, fn_table_entry);
-
if (fn_proto->section_expr != nullptr) {
if (!analyze_const_string(g, child_scope, fn_proto->section_expr, &fn_table_entry->section_name)) {
fn_table_entry->type_entry = g->builtin_types.entry_invalid;
+ tld_fn->base.resolution = TldResolutionInvalid;
+ return;
}
}
- if (fn_table_entry->type_entry->id == ZigTypeIdInvalid) {
+ fn_table_entry->type_entry = analyze_fn_type(g, source_node, child_scope, fn_table_entry);
+
+ if (type_is_invalid(fn_table_entry->type_entry)) {
tld_fn->base.resolution = TldResolutionInvalid;
return;
}
- if (!fn_table_entry->type_entry->data.fn.is_generic) {
- if (fn_def_node)
- g->fn_defs.append(fn_table_entry);
- }
-
const CallingConvention fn_cc = fn_table_entry->type_entry->data.fn.fn_type_id.cc;
if (fn_proto->is_export) {
@@ -3470,6 +3467,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
case CallingConventionAsync:
add_node_error(g, fn_def_node,
buf_sprintf("exported function cannot be async"));
+ fn_table_entry->type_entry = g->builtin_types.entry_invalid;
tld_fn->base.resolution = TldResolutionInvalid;
return;
case CallingConventionC:
@@ -3480,6 +3478,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
case CallingConventionStdcall:
case CallingConventionFastcall:
case CallingConventionVectorcall:
+ case CallingConventionThiscall:
case CallingConventionAPCS:
case CallingConventionAAPCS:
case CallingConventionAAPCSVFP:
@@ -3495,6 +3494,11 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
}
}
+ if (!fn_table_entry->type_entry->data.fn.is_generic) {
+ if (fn_def_node)
+ g->fn_defs.append(fn_table_entry);
+ }
+
// if the calling convention implies that it cannot be async, we save that for later
// and leave the value to be nullptr to indicate that we have not emitted possible
// compile errors for improperly calling async functions.