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
374374 .bool_and => return boolBinOp(mod, scope, rl, node, true),
375375 .bool_or => return boolBinOp(mod, scope, rl, node, false),
376376
377 .bool_not => @panic("TODO"),
378 .bit_not => @panic("TODO"),
379377 .negation => @panic("TODO"),
380378 .negation_wrap => @panic("TODO"),
381 //.bool_not => return rvalue(mod, scope, rl, try boolNot(mod, scope, node)),
382 //.bit_not => return rvalue(mod, scope, rl, try bitNot(mod, scope, node)),
379 .bool_not => return rvalue(mod, scope, rl, try boolNot(mod, scope, node), node),
380 .bit_not => return rvalue(mod, scope, rl, try bitNot(mod, scope, node), node),
383381 //.negation => return rvalue(mod, scope, rl, try negation(mod, scope, node, .sub)),
384382 //.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
419417 },
420418
421419 .unreachable_literal => {
422 if (true) @panic("TODO update for zir-memory-layout");
423 const main_token = main_tokens[node];
424 const src = token_starts[main_token];
425 return addZIRNoOp(mod, scope, src, .unreachable_safe);
420 const result = @enumToInt(zir.Const.unreachable_value);
421 return rvalue(mod, scope, rl, result, node);
426422 },
427423 .@"return" => return ret(mod, scope, node),
428424 .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
470466 return rvalue(mod, scope, rl, result, node);
471467 },
472468 .optional_type => {
473 if (true) @panic("TODO update for zir-memory-layout");
474 const src = token_starts[main_tokens[node]];
469 const src_token = tree.firstToken(node);
470
475471 const operand = try typeExpr(mod, scope, node_datas[node].lhs);
476 const result = try addZIRUnOp(mod, scope, src, .optional_type, operand);
477 return rvalue(mod, scope, rl, result);
472 const result = try gz.addUnTok(.optional_type, operand, src_token);
473 return rvalue(mod, scope, rl, result, node);
478474 },
479475 .unwrap_optional => {
480 if (true) @panic("TODO update for zir-memory-layout");
476 const src_token = tree.firstToken(node);
477
481478 const src = token_starts[main_tokens[node]];
482479 switch (rl) {
483 .ref => return addZIRUnOp(
484 mod,
485 scope,
486 src,
480 .ref => return gz.addUnTok(
487481 .optional_payload_safe_ptr,
488482 try expr(mod, scope, .ref, node_datas[node].lhs),
483 src_token,
489484 ),
490 else => return rvalue(mod, scope, rl, try addZIRUnOp(
491 mod,
492 scope,
493 src,
485 else => return rvalue(mod, scope, rl, try gz.addUnTok(
494486 .optional_payload_safe,
495487 try expr(mod, scope, .none, node_datas[node].lhs),
496 )),
488 src_token,
489 ), node),
497490 }
498491 },
499492 .block_two, .block_two_semicolon => {
......@@ -1336,27 +1329,24 @@ fn assignOp(
13361329fn boolNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref {
13371330 const tree = scope.tree();
13381331 const node_datas = tree.nodes.items(.data);
1339 const main_tokens = tree.nodes.items(.main_token);
1340 const token_starts = tree.tokens.items(.start);
1332 const src_token = tree.firstToken(node);
13411333
1342 const src = token_starts[main_tokens[node]];
1343 const bool_type = try addZIRInstConst(mod, scope, src, .{
1344 .ty = Type.initTag(.type),
1345 .val = Value.initTag(.bool_type),
1346 });
1347 const operand = try expr(mod, scope, .{ .ty = bool_type }, node_datas[node].lhs);
1348 return addZIRUnOp(mod, scope, src, .bool_not, operand);
1334 const gz = scope.getGenZir();
1335
1336 const operand = try expr(mod, scope, .{ .ty = @enumToInt(zir.Const.bool_type) }, node_datas[node].lhs);
1337
1338 return gz.addUnTok(.bool_not, operand, src_token);
13491339}
13501340
13511341fn bitNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref {
13521342 const tree = scope.tree();
13531343 const node_datas = tree.nodes.items(.data);
1354 const main_tokens = tree.nodes.items(.main_token);
1355 const token_starts = tree.tokens.items(.start);
1344 const src_token = tree.firstToken(node);
1345
1346 const gz = scope.getGenZir();
13561347
1357 const src = token_starts[main_tokens[node]];
13581348 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);
13601350}
13611351
13621352fn negation(
src/zir.zig+1
......@@ -445,6 +445,7 @@ pub const Inst = struct {
445445 /// The new result location pointer has an inferred type.
446446 bitcast_result_ptr,
447447 /// Bitwise NOT. `~`
448 /// uses `un_tok`
448449 bit_not,
449450 /// Bitwise OR. `|`
450451 bit_or,