aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-16 14:44:02 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-04-16 14:48:10 -0700
commit01b4bf34ea4f37d8b778bb2413ac1fc445f8bead (patch)
tree6075a5f6e35448ab1899b34a559d5c1ce9e27bd2 /src/Sema.zig
parentcf57e8223f06f6b305e7274445cf935b1ed312d2 (diff)
downloadzig-01b4bf34ea4f37d8b778bb2413ac1fc445f8bead.tar.gz
zig-01b4bf34ea4f37d8b778bb2413ac1fc445f8bead.zip
stage2: AstGen improvements
* AstGen: represent compile errors in ZIR rather than returning `error.AnalysisFail`. * ZIR: remove decl_ref and decl_val instructions. These are replaced by `decl_ref_named` and `decl_val_named`, respectively, which will probably get renamed in the future to the instructions that were just deleted. * AstGen: implement `@This()`, `@fence()`, `@returnAddress()`, and `@src()`. * AstGen: struct_decl improved to support fields_len=0 but have decls. * AstGen: fix missing null bytes after compile error messages. * SrcLoc: no longer depend on `Decl`. Instead have an explicit field `parent_decl_node` which is an absolute AST Node index. * Module: `failed_files` table can have null value, in which case the key, which is a `*Scope.File`, will have ZIR errors in it. * ZIR: implement text rendering of struct decls. * CLI: introduce debug_usage and `zig astgen` command which is enabled when the compiler is built in debug mode.
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig41
1 files changed, 25 insertions, 16 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index e0cc9fe750..eaea6961e8 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -170,9 +170,7 @@ pub fn analyzeBody(
.cmp_lte => try sema.zirCmp(block, inst, .lte),
.cmp_neq => try sema.zirCmp(block, inst, .neq),
.coerce_result_ptr => try sema.zirCoerceResultPtr(block, inst),
- .decl_ref => try sema.zirDeclRef(block, inst),
.decl_ref_named => try sema.zirDeclRefNamed(block, inst),
- .decl_val => try sema.zirDeclVal(block, inst),
.decl_val_named => try sema.zirDeclValNamed(block, inst),
.load => try sema.zirLoad(block, inst),
.div => try sema.zirArithmetic(block, inst),
@@ -266,6 +264,10 @@ pub fn analyzeBody(
.type_info => try sema.zirTypeInfo(block, inst),
.size_of => try sema.zirSizeOf(block, inst),
.bit_size_of => try sema.zirBitSizeOf(block, inst),
+ .this => try sema.zirThis(block, inst),
+ .fence => try sema.zirFence(block, inst),
+ .ret_addr => try sema.zirRetAddr(block, inst),
+ .builtin_src => try sema.zirBuiltinSrc(block, inst),
.typeof => try sema.zirTypeof(block, inst),
.typeof_elem => try sema.zirTypeofElem(block, inst),
.typeof_peer => try sema.zirTypeofPeer(block, inst),
@@ -1656,20 +1658,6 @@ fn zirDbgStmtNode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerE
_ = try block.addDbgStmt(src, abs_byte_off);
}
-fn zirDeclRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
- const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
- const src = inst_data.src();
- const decl = sema.owner_decl.dependencies.entries.items[inst_data.payload_index].key;
- return sema.analyzeDeclRef(block, src, decl);
-}
-
-fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
- const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
- const src = inst_data.src();
- const decl = sema.owner_decl.dependencies.entries.items[inst_data.payload_index].key;
- return sema.analyzeDeclVal(block, src, decl);
-}
-
fn zirDeclRefNamed(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
const src = inst_data.src();
@@ -4373,6 +4361,27 @@ fn zirBitSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErr
return sema.mod.constIntUnsigned(sema.arena, src, Type.initTag(.comptime_int), bit_size);
}
+fn zirThis(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
+ const src_node = sema.code.instructions.items(.data)[inst].node;
+ const src: LazySrcLoc = .{ .node_offset = src_node };
+ return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirThis", .{});
+}
+fn zirFence(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
+ const src_node = sema.code.instructions.items(.data)[inst].node;
+ const src: LazySrcLoc = .{ .node_offset = src_node };
+ return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirFence", .{});
+}
+fn zirRetAddr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
+ const src_node = sema.code.instructions.items(.data)[inst].node;
+ const src: LazySrcLoc = .{ .node_offset = src_node };
+ return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirRetAddr", .{});
+}
+fn zirBuiltinSrc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
+ const src_node = sema.code.instructions.items(.data)[inst].node;
+ const src: LazySrcLoc = .{ .node_offset = src_node };
+ return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinSrc", .{});
+}
+
fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
const inst_data = sema.code.instructions.items(.data)[inst].un_node;
const src = inst_data.src();