authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-03-20 12:34:04-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-20 15:56:59-07:00
log12eeb18a263f0b1498c9bedc11e9970bc47ffa8f
treee96ea3f3952465b452814a2dc23375d4083bb9c0
parenta710368054096889385562addaed2d16f0705332

zir-memory-layout: astgen: more instructions


2 files changed, 26 insertions(+), 35 deletions(-)

src/astgen.zig+25-35
...@@ -374,12 +374,10 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In...@@ -374,12 +374,10 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
374 .bool_and => return boolBinOp(mod, scope, rl, node, true),374 .bool_and => return boolBinOp(mod, scope, rl, node, true),
375 .bool_or => return boolBinOp(mod, scope, rl, node, false),375 .bool_or => return boolBinOp(mod, scope, rl, node, false),
376376
377 .bool_not => @panic("TODO"),
378 .bit_not => @panic("TODO"),
379 .negation => @panic("TODO"),377 .negation => @panic("TODO"),
380 .negation_wrap => @panic("TODO"),378 .negation_wrap => @panic("TODO"),
381 //.bool_not => return rvalue(mod, scope, rl, try boolNot(mod, scope, node)),379 .bool_not => return rvalue(mod, scope, rl, try boolNot(mod, scope, node), node),
382 //.bit_not => return rvalue(mod, scope, rl, try bitNot(mod, scope, node)),380 .bit_not => return rvalue(mod, scope, rl, try bitNot(mod, scope, node), node),
383 //.negation => return rvalue(mod, scope, rl, try negation(mod, scope, node, .sub)),381 //.negation => return rvalue(mod, scope, rl, try negation(mod, scope, node, .sub)),
384 //.negation_wrap => return rvalue(mod, scope, rl, try negation(mod, scope, node, .subwrap)),382 //.negation_wrap => return rvalue(mod, scope, rl, try negation(mod, scope, node, .subwrap)),
385383
...@@ -419,10 +417,8 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In...@@ -419,10 +417,8 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
419 },417 },
420418
421 .unreachable_literal => {419 .unreachable_literal => {
422 if (true) @panic("TODO update for zir-memory-layout");420 const result = @enumToInt(zir.Const.unreachable_value);
423 const main_token = main_tokens[node];421 return rvalue(mod, scope, rl, result, node);
424 const src = token_starts[main_token];
425 return addZIRNoOp(mod, scope, src, .unreachable_safe);
426 },422 },
427 .@"return" => return ret(mod, scope, node),423 .@"return" => return ret(mod, scope, node),
428 .field_access => return fieldAccess(mod, scope, rl, node),424 .field_access => return fieldAccess(mod, scope, rl, node),
...@@ -470,30 +466,27 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In...@@ -470,30 +466,27 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
470 return rvalue(mod, scope, rl, result, node);466 return rvalue(mod, scope, rl, result, node);
471 },467 },
472 .optional_type => {468 .optional_type => {
473 if (true) @panic("TODO update for zir-memory-layout");469 const src_token = tree.firstToken(node);
474 const src = token_starts[main_tokens[node]];470
475 const operand = try typeExpr(mod, scope, node_datas[node].lhs);471 const operand = try typeExpr(mod, scope, node_datas[node].lhs);
476 const result = try addZIRUnOp(mod, scope, src, .optional_type, operand);472 const result = try gz.addUnTok(.optional_type, operand, src_token);
477 return rvalue(mod, scope, rl, result);473 return rvalue(mod, scope, rl, result, node);
478 },474 },
479 .unwrap_optional => {475 .unwrap_optional => {
480 if (true) @panic("TODO update for zir-memory-layout");476 const src_token = tree.firstToken(node);
477
481 const src = token_starts[main_tokens[node]];478 const src = token_starts[main_tokens[node]];
482 switch (rl) {479 switch (rl) {
483 .ref => return addZIRUnOp(480 .ref => return gz.addUnTok(
484 mod,
485 scope,
486 src,
487 .optional_payload_safe_ptr,481 .optional_payload_safe_ptr,
488 try expr(mod, scope, .ref, node_datas[node].lhs),482 try expr(mod, scope, .ref, node_datas[node].lhs),
483 src_token,
489 ),484 ),
490 else => return rvalue(mod, scope, rl, try addZIRUnOp(485 else => return rvalue(mod, scope, rl, try gz.addUnTok(
491 mod,
492 scope,
493 src,
494 .optional_payload_safe,486 .optional_payload_safe,
495 try expr(mod, scope, .none, node_datas[node].lhs),487 try expr(mod, scope, .none, node_datas[node].lhs),
496 )),488 src_token,
489 ), node),
497 }490 }
498 },491 },
499 .block_two, .block_two_semicolon => {492 .block_two, .block_two_semicolon => {
...@@ -1336,27 +1329,24 @@ fn assignOp(...@@ -1336,27 +1329,24 @@ fn assignOp(
1336fn boolNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref {1329fn boolNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref {
1337 const tree = scope.tree();1330 const tree = scope.tree();
1338 const node_datas = tree.nodes.items(.data);1331 const node_datas = tree.nodes.items(.data);
1339 const main_tokens = tree.nodes.items(.main_token);1332 const src_token = tree.firstToken(node);
1340 const token_starts = tree.tokens.items(.start);
13411333
1342 const src = token_starts[main_tokens[node]];1334 const gz = scope.getGenZir();
1343 const bool_type = try addZIRInstConst(mod, scope, src, .{1335
1344 .ty = Type.initTag(.type),1336 const operand = try expr(mod, scope, .{ .ty = @enumToInt(zir.Const.bool_type) }, node_datas[node].lhs);
1345 .val = Value.initTag(.bool_type),1337
1346 });1338 return gz.addUnTok(.bool_not, operand, src_token);
1347 const operand = try expr(mod, scope, .{ .ty = bool_type }, node_datas[node].lhs);
1348 return addZIRUnOp(mod, scope, src, .bool_not, operand);
1349}1339}
13501340
1351fn bitNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref {1341fn bitNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref {
1352 const tree = scope.tree();1342 const tree = scope.tree();
1353 const node_datas = tree.nodes.items(.data);1343 const node_datas = tree.nodes.items(.data);
1354 const main_tokens = tree.nodes.items(.main_token);1344 const src_token = tree.firstToken(node);
1355 const token_starts = tree.tokens.items(.start);1345
1346 const gz = scope.getGenZir();
13561347
1357 const src = token_starts[main_tokens[node]];
1358 const operand = try expr(mod, scope, .none, node_datas[node].lhs);1348 const operand = try expr(mod, scope, .none, node_datas[node].lhs);
1359 return addZIRUnOp(mod, scope, src, .bit_not, operand);1349 return gz.addUnTok(.bit_not, operand, src_token);
1360}1350}
13611351
1362fn negation(1352fn negation(
src/zir.zig+1
...@@ -445,6 +445,7 @@ pub const Inst = struct {...@@ -445,6 +445,7 @@ pub const Inst = struct {
445 /// The new result location pointer has an inferred type.445 /// The new result location pointer has an inferred type.
446 bitcast_result_ptr,446 bitcast_result_ptr,
447 /// Bitwise NOT. `~`447 /// Bitwise NOT. `~`
448 /// uses `un_tok`
448 bit_not,449 bit_not,
449 /// Bitwise OR. `|`450 /// Bitwise OR. `|`
450 bit_or,451 bit_or,