add: handling @bitCast as binOp

This commit is contained in:
Vallahor 2022-05-29 12:59:54 -03:00 committed by Andrew Kelley
parent 8e835fd3a2
commit f59bb65ff5
2 changed files with 35 additions and 1 deletions

View File

@ -1152,6 +1152,9 @@ var zigAnalysis;
operator += ">>";
break;
}
case 9 : {
return "@bitCast(" + print_lhs + ", " + print_rhs + ")";
}
default: console.log("operator not handled yet or doesn't exist!");
};
if (expr.binOp.wrap) {

View File

@ -669,7 +669,7 @@ const DocData = struct {
rhs: usize, // index in `exprs`
// opKind
// Identify the operator in js
// 0: add, 1: sub, 2: mul, 3: div, 4: mod, 5: rem, 6: rem_mod, 7: shl, 8: shr
// 0: add, 1: sub, 2: mul, 3: div, 4: mod, 5: rem, 6: rem_mod, 7: shl, 8: shr, 9: bitcast
// Others binOp are not handled yet
opKind: usize = 0,
// flags to operations
@ -969,6 +969,37 @@ fn walkInstruction(
.expr = .{ .int = .{ .value = int } },
};
},
.bitcast => {
const pl_node = data[inst_index].pl_node;
const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);
const binop_index = self.exprs.items.len;
try self.exprs.append(self.arena, .{ .binOp = .{ .lhs = 0, .rhs = 0 } });
var lhs: DocData.WalkResult = try self.walkRef(
file,
parent_scope,
extra.data.lhs,
false,
);
var rhs: DocData.WalkResult = try self.walkRef(
file,
parent_scope,
extra.data.rhs,
false,
);
const lhs_index = self.exprs.items.len;
try self.exprs.append(self.arena, lhs.expr);
const rhs_index = self.exprs.items.len;
try self.exprs.append(self.arena, rhs.expr);
self.exprs.items[binop_index] = .{ .binOp = .{ .lhs = lhs_index, .rhs = rhs_index, .opKind = 9 } };
return DocData.WalkResult{
.typeRef = .{ .type = @enumToInt(Ref.type_type) },
.expr = .{ .binOpIndex = binop_index },
};
},
.add => {
const pl_node = data[inst_index].pl_node;
const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index);