authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-08 07:04:43+00:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-08 07:04:43+00:00
logbe0546d877e0df18201e73e803d8a966b57625c5
tree56b0cac1a3e733575c1a28f94c5ca33ca490cdad
parent5e60872060da894c38343f2afc1ddc45bce14fc6

stage2: implement compare operator AST->ZIR


2 files changed, 29 insertions(+), 0 deletions(-)

src-self-hosted/Module.zig+27
......@@ -1309,6 +1309,33 @@ fn astGenInfixOp(self: *Module, scope: *Scope, infix_node: *ast.Node.InfixOp) In
13091309
13101310 return self.addZIRInst(scope, src, zir.Inst.Add, .{ .lhs = lhs, .rhs = rhs }, .{});
13111311 },
1312 .BangEqual,
1313 .EqualEqual,
1314 .GreaterThan,
1315 .GreaterOrEqual,
1316 .LessThan,
1317 .LessOrEqual,
1318 => {
1319 const lhs = try self.astGenExpr(scope, infix_node.lhs);
1320 const rhs = try self.astGenExpr(scope, infix_node.rhs);
1321
1322 const tree = scope.tree();
1323 const src = tree.token_locs[infix_node.op_token].start;
1324
1325 return self.addZIRInst(scope, src, zir.Inst.Cmp, .{
1326 .lhs = lhs,
1327 .op = @as(std.math.CompareOperator, switch (infix_node.op) {
1328 .BangEqual => .neq,
1329 .EqualEqual => .eq,
1330 .GreaterThan => .gt,
1331 .GreaterOrEqual => .gte,
1332 .LessThan => .lt,
1333 .LessOrEqual => .lte,
1334 else => unreachable,
1335 }),
1336 .rhs = rhs,
1337 }, .{});
1338 },
13121339 else => |op| {
13131340 return self.failNode(scope, &infix_node.base, "TODO implement infix operator {}", .{op});
13141341 },
src-self-hosted/zir.zig+2
......@@ -538,6 +538,8 @@ pub const Inst = struct {
538538 kw_args: struct {},
539539 };
540540
541 /// TODO get rid of the op positional arg and make that data part of
542 /// the base Inst tag.
541543 pub const Cmp = struct {
542544 pub const base_tag = Tag.cmp;
543545 base: Inst,