authorgravatar for daniele.cocca@gmail.comDaniele Cocca <daniele.cocca@gmail.com> 2022-03-19 12:00:07+00:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-30 11:57:15+03:00
log5d5282b5f18b33489187a9a9e23a1aa2d301b4e8
treec69a668a6a63c09f3e4cc35652c02477cf501d63
parentc21f046a8b019c42aa0dbb0fb9c592b590edf977

AstGen: support local var references for outputs


1 files changed, 16 insertions(+), 34 deletions(-)

src/AstGen.zig+16-34
......@@ -6423,7 +6423,6 @@ fn identifier(
64236423
64246424 const astgen = gz.astgen;
64256425 const tree = astgen.tree;
6426 const gpa = astgen.gpa;
64276426 const main_tokens = tree.nodes.items(.main_token);
64286427
64296428 const ident_token = main_tokens[ident];
......@@ -6467,6 +6466,19 @@ fn identifier(
64676466 }
64686467
64696468 // Local variables, including function parameters.
6469 return localVarRef(gz, scope, rl, ident, ident_token);
6470}
6471
6472fn localVarRef(
6473 gz: *GenZir,
6474 scope: *Scope,
6475 rl: ResultLoc,
6476 ident: Ast.Node.Index,
6477 ident_token: Ast.Node.Index,
6478) InnerError!Zir.Inst.Ref {
6479 const astgen = gz.astgen;
6480 const gpa = astgen.gpa;
6481
64706482 const name_str_index = try astgen.identAsString(ident_token);
64716483 var s = scope;
64726484 var found_already: ?Ast.Node.Index = null; // we have found a decl with the same name already
......@@ -6808,43 +6820,13 @@ fn asmExpr(
68086820 };
68096821 } else {
68106822 const ident_token = symbolic_name + 4;
6811 const str_index = try astgen.identAsString(ident_token);
6812 // TODO this needs extra code for local variables. Have a look at #215 and related
6813 // issues and decide how to handle outputs. Do we want this to be identifiers?
6823 // TODO have a look at #215 and related issues and decide how to
6824 // handle outputs. Do we want this to be identifiers?
68146825 // Or maybe we want to force this to be expressions with a pointer type.
6815 // Until that is figured out this is only hooked up for referencing Decls.
6816 // TODO we have put this as an identifier lookup just so that we don't get
6817 // unused vars for outputs. We need to check if this is correct in the future ^^
6818 // so we just put in this simple lookup. This is a workaround.
6819 {
6820 var s = scope;
6821 while (true) switch (s.tag) {
6822 .local_val => {
6823 const local_val = s.cast(Scope.LocalVal).?;
6824 if (local_val.name == str_index) {
6825 local_val.used = true;
6826 break;
6827 }
6828 s = local_val.parent;
6829 },
6830 .local_ptr => {
6831 const local_ptr = s.cast(Scope.LocalPtr).?;
6832 if (local_ptr.name == str_index) {
6833 local_ptr.used = true;
6834 break;
6835 }
6836 s = local_ptr.parent;
6837 },
6838 .gen_zir => s = s.cast(GenZir).?.parent,
6839 .defer_normal, .defer_error => s = s.cast(Scope.Defer).?.parent,
6840 .namespace, .top => break,
6841 };
6842 }
6843 const operand = try gz.addStrTok(.decl_ref, str_index, ident_token);
68446826 outputs[i] = .{
68456827 .name = name,
68466828 .constraint = constraint,
6847 .operand = operand,
6829 .operand = try localVarRef(gz, scope, rl, node, ident_token),
68486830 };
68496831 }
68506832 }