aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-09-07 12:23:50 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-09-07 12:23:50 -0400
commit04d7b565f78895d96e5a43e8b1f4873ea5f529cf (patch)
tree95ae4c50915c84dfb059784f27d84658def0c1db /src/codegen.cpp
parentbe6cccb3a51512dea011326d9ad30ad495e7c716 (diff)
downloadzig-04d7b565f78895d96e5a43e8b1f4873ea5f529cf.tar.gz
zig-04d7b565f78895d96e5a43e8b1f4873ea5f529cf.zip
stage1: refactor fn type analysis to use C ABI walk fn
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 469d62f3a2..e96445ebe3 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -1893,6 +1893,17 @@ static void give_up_with_c_abi_error(CodeGen *g, AstNode *source_node) {
report_errors_and_exit(g);
}
+static bool type_is_c_abi_int(CodeGen *g, ZigType *ty) {
+ size_t ty_size = type_size(g, ty);
+ if (ty_size > g->pointer_size_bytes)
+ return false;
+ return (ty->id == ZigTypeIdInt ||
+ ty->id == ZigTypeIdFloat ||
+ ty->id == ZigTypeIdBool ||
+ ty->id == ZigTypeIdEnum ||
+ get_codegen_ptr_type(ty) != nullptr);
+}
+
static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk, size_t src_i) {
// Initialized from the type for some walks, but because of C var args,
// initialized based on callsite instructions for that one.
@@ -1919,7 +1930,14 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
val = ir_llvm_value(g, arg);
break;
}
+ case FnWalkIdTypes:
+ if (src_i >= fn_type->data.fn.fn_type_id.param_count)
+ return false;
+ param_info = &fn_type->data.fn.fn_type_id.param_info[src_i];
+ ty = param_info->type;
+ break;
}
+
if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat ||
ty->id == ZigTypeIdInt // TODO investigate if we need to change this
) {
@@ -1943,6 +1961,10 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
case FnWalkIdCall:
fn_walk->data.call.gen_param_values->append(val);
break;
+ case FnWalkIdTypes:
+ fn_walk->data.types.gen_param_types->append(ty->type_ref);
+ fn_walk->data.types.param_di_types->append(ty->di_type);
+ break;
}
return true;
}
@@ -1958,6 +1980,12 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
case FnWalkIdCall:
fn_walk->data.call.gen_param_values->append(val);
break;
+ case FnWalkIdTypes: {
+ ZigType *gen_type = get_pointer_to_type(g, ty, true);
+ fn_walk->data.types.gen_param_types->append(gen_type->type_ref);
+ fn_walk->data.types.param_di_types->append(gen_type->di_type);
+ break;
+ }
}
return true;
}
@@ -1979,6 +2007,12 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
case FnWalkIdCall:
fn_walk->data.call.gen_param_values->append(val);
break;
+ case FnWalkIdTypes: {
+ ZigType *gen_type = get_pointer_to_type(g, ty, true);
+ fn_walk->data.types.gen_param_types->append(gen_type->type_ref);
+ fn_walk->data.types.param_di_types->append(gen_type->di_type);
+ break;
+ }
}
return true;
}
@@ -2007,6 +2041,12 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
fn_walk->data.call.gen_param_values->append(loaded);
break;
}
+ case FnWalkIdTypes: {
+ ZigType *gen_type = get_int_type(g, false, ty_size * 8);
+ fn_walk->data.types.gen_param_types->append(gen_type->type_ref);
+ fn_walk->data.types.param_di_types->append(gen_type->di_type);
+ break;
+ }
}
return true;
}
@@ -2074,6 +2114,9 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
case FnWalkIdCall:
// handled before for loop
zig_unreachable();
+ case FnWalkIdTypes:
+ // Not called for non-c-abi
+ zig_unreachable();
}
}
}