aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/c.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-27 18:36:12 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-04-28 16:57:01 -0700
commitf86469bc5eea2b7bd95222d00a11bd287bfdfedf (patch)
treec34ef71820e4c7b962a631f2b9cdecdff3f5aa79 /src/codegen/c.zig
parentfa6bb4b662155e4d6a61cc551b5d02a2a7d5d144 (diff)
downloadzig-f86469bc5eea2b7bd95222d00a11bd287bfdfedf.tar.gz
zig-f86469bc5eea2b7bd95222d00a11bd287bfdfedf.zip
stage2: semaDecl properly analyzes the decl block
Also flattened out Decl TypedValue fields into ty, val, has_tv and add relevant fields to Decl for alignment and link section.
Diffstat (limited to 'src/codegen/c.zig')
-rw-r--r--src/codegen/c.zig26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 441449707a..43b851019b 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -190,8 +190,8 @@ pub const DeclGen = struct {
const decl = val.castTag(.decl_ref).?.data;
// Determine if we must pointer cast.
- const decl_tv = decl.typed_value.most_recent.typed_value;
- if (t.eql(decl_tv.ty)) {
+ assert(decl.has_tv);
+ if (t.eql(decl.ty)) {
try writer.print("&{s}", .{decl.name});
} else {
try writer.writeAll("(");
@@ -326,12 +326,11 @@ pub const DeclGen = struct {
if (!is_global) {
try w.writeAll("static ");
}
- const tv = dg.decl.typed_value.most_recent.typed_value;
- try dg.renderType(w, tv.ty.fnReturnType());
+ try dg.renderType(w, dg.decl.ty.fnReturnType());
const decl_name = mem.span(dg.decl.name);
try w.print(" {s}(", .{decl_name});
- const param_len = tv.ty.fnParamLen();
- const is_var_args = tv.ty.fnIsVarArgs();
+ const param_len = dg.decl.ty.fnParamLen();
+ const is_var_args = dg.decl.ty.fnIsVarArgs();
if (param_len == 0 and !is_var_args)
try w.writeAll("void")
else {
@@ -340,7 +339,7 @@ pub const DeclGen = struct {
if (index > 0) {
try w.writeAll(", ");
}
- try dg.renderType(w, tv.ty.fnParamType(index));
+ try dg.renderType(w, dg.decl.ty.fnParamType(index));
try w.print(" a{d}", .{index});
}
}
@@ -545,8 +544,10 @@ pub fn genDecl(o: *Object) !void {
const tracy = trace(@src());
defer tracy.end();
- const tv = o.dg.decl.typed_value.most_recent.typed_value;
-
+ const tv: TypedValue = .{
+ .ty = o.dg.decl.ty,
+ .val = o.dg.decl.val,
+ };
if (tv.val.castTag(.function)) |func_payload| {
const is_global = o.dg.functionIsGlobal(tv);
const fwd_decl_writer = o.dg.fwd_decl.writer();
@@ -589,7 +590,10 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void {
const tracy = trace(@src());
defer tracy.end();
- const tv = dg.decl.typed_value.most_recent.typed_value;
+ const tv: TypedValue = .{
+ .ty = dg.decl.ty,
+ .val = dg.decl.val,
+ };
const writer = dg.fwd_decl.writer();
switch (tv.ty.zigTypeTag()) {
@@ -842,7 +846,7 @@ fn genCall(o: *Object, inst: *Inst.Call) !CValue {
else
unreachable;
- const fn_ty = fn_decl.typed_value.most_recent.typed_value.ty;
+ const fn_ty = fn_decl.ty;
const ret_ty = fn_ty.fnReturnType();
const unused_result = inst.base.isUnused();
var result_local: CValue = .none;