aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/c.zig
diff options
context:
space:
mode:
authorjoachimschmidt557 <joachim.schmidt557@outlook.com>2021-05-09 15:20:08 +0800
committerAndrew Kelley <andrew@ziglang.org>2021-05-22 21:15:25 -0400
commite8236551abdb7bb74811e5e9dc9890cb2abbd269 (patch)
treea7cdaddfb3e7b5cd3f760b682e6ded775a68bfc5 /src/codegen/c.zig
parent1c636e2564e2fc2e8e4b6b1edbc782592ee3d2d7 (diff)
downloadzig-e8236551abdb7bb74811e5e9dc9890cb2abbd269.tar.gz
zig-e8236551abdb7bb74811e5e9dc9890cb2abbd269.zip
stage2: Move BlockData out of ir.Inst.Block
Diffstat (limited to 'src/codegen/c.zig')
-rw-r--r--src/codegen/c.zig18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index cc73b6cad9..55c9c5b641 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -33,6 +33,11 @@ pub const CValue = union(enum) {
decl_ref: *Decl,
};
+const BlockData = struct {
+ block_id: usize,
+ result: CValue,
+};
+
pub const CValueMap = std.AutoHashMap(*Inst, CValue);
pub const TypedefMap = std.HashMap(Type, struct { name: []const u8, rendered: []u8 }, Type.hash, Type.eql, std.hash_map.default_max_load_percentage);
@@ -83,6 +88,7 @@ pub const Object = struct {
gpa: *mem.Allocator,
code: std.ArrayList(u8),
value_map: CValueMap,
+ blocks: std.AutoHashMapUnmanaged(*ir.Inst.Block, BlockData) = .{},
next_arg_index: usize = 0,
next_local_index: usize = 0,
next_block_index: usize = 0,
@@ -939,8 +945,6 @@ fn genBlock(o: *Object, inst: *Inst.Block) !CValue {
o.next_block_index += 1;
const writer = o.writer();
- // store the block id in relocs.capacity as it is not used for anything else in the C backend.
- inst.codegen.relocs.capacity = block_id;
const result = if (inst.base.ty.tag() != .void and !inst.base.isUnused()) blk: {
// allocate a location for the result
const local = try o.allocLocal(inst.base.ty, .Mut);
@@ -948,7 +952,11 @@ fn genBlock(o: *Object, inst: *Inst.Block) !CValue {
break :blk local;
} else CValue{ .none = {} };
- inst.codegen.mcv = @bitCast(@import("../codegen.zig").AnyMCValue, result);
+ try o.blocks.putNoClobber(o.gpa, inst, .{
+ .block_id = block_id,
+ .result = result,
+ });
+
try genBody(o, inst.body);
try o.indent_writer.insertNewline();
// label must be followed by an expression, add an empty one.
@@ -957,7 +965,7 @@ fn genBlock(o: *Object, inst: *Inst.Block) !CValue {
}
fn genBr(o: *Object, inst: *Inst.Br) !CValue {
- const result = @bitCast(CValue, inst.block.codegen.mcv);
+ const result = o.blocks.get(inst.block).?.result;
const writer = o.writer();
// If result is .none then the value of the block is unused.
@@ -973,7 +981,7 @@ fn genBr(o: *Object, inst: *Inst.Br) !CValue {
}
fn genBrVoid(o: *Object, block: *Inst.Block) !CValue {
- try o.writer().print("goto zig_block_{d};\n", .{block.codegen.relocs.capacity});
+ try o.writer().print("goto zig_block_{d};\n", .{o.blocks.get(block).?.block_id});
return CValue.none;
}