aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIsaac Freund <ifreund@ifreund.xyz>2021-03-21 19:02:27 +0100
committerIsaac Freund <ifreund@ifreund.xyz>2021-03-21 20:32:39 +0100
commit4cfd5f6a300a97778ec515319656c6f1c0ca6ec5 (patch)
tree5d772d83baed4449be0c780d493ef0846b74dfb6 /src
parent310a44d5be051a339b5739d59416a70604375541 (diff)
downloadzig-4cfd5f6a300a97778ec515319656c6f1c0ca6ec5.tar.gz
zig-4cfd5f6a300a97778ec515319656c6f1c0ca6ec5.zip
astgen: implement simple binary operators
Diffstat (limited to 'src')
-rw-r--r--src/astgen.zig12
-rw-r--r--src/zir.zig23
2 files changed, 27 insertions, 8 deletions
diff --git a/src/astgen.zig b/src/astgen.zig
index 6a6d7997a1..80137f221c 100644
--- a/src/astgen.zig
+++ b/src/astgen.zig
@@ -1789,15 +1789,15 @@ fn simpleBinOp(
infix_node: ast.Node.Index,
op_inst_tag: zir.Inst.Tag,
) InnerError!zir.Inst.Ref {
- if (true) @panic("TODO update for zir-memory-layout");
const tree = scope.tree();
const node_datas = tree.nodes.items(.data);
- const main_tokens = tree.nodes.items(.main_token);
- const lhs = try expr(mod, scope, .none, node_datas[infix_node].lhs);
- const rhs = try expr(mod, scope, .none, node_datas[infix_node].rhs);
- const result = try addZIRBinOp(mod, scope, src, op_inst_tag, lhs, rhs);
- return rvalue(mod, scope, rl, result);
+ const gz = scope.getGenZir();
+ const result = try gz.addPlNode(op_inst_tag, infix_node, zir.Inst.Bin{
+ .lhs = try expr(mod, scope, .none, node_datas[infix_node].lhs),
+ .rhs = try expr(mod, scope, .none, node_datas[infix_node].rhs),
+ });
+ return rvalue(mod, scope, rl, result, infix_node);
}
fn boolBinOp(
diff --git a/src/zir.zig b/src/zir.zig
index 58abd7e8d8..08750207cc 100644
--- a/src/zir.zig
+++ b/src/zir.zig
@@ -392,8 +392,10 @@ pub const Inst = struct {
/// These names are used directly as the instruction names in the text format.
pub const Tag = enum {
/// Arithmetic addition, asserts no integer overflow.
+ /// Uses the `pl_node` union field. Payload is `Bin`.
add,
/// Twos complement wrapping integer addition.
+ /// Uses the `pl_node` union field. Payload is `Bin`.
addwrap,
/// Allocates stack local memory.
/// Uses the `un_node` union field. The operand is the type of the allocated object.
@@ -411,8 +413,10 @@ pub const Inst = struct {
/// Uses the `un_node` field. AST node is the `anyframe->T` syntax. Operand is the type.
anyframe_type,
/// Array concatenation. `a ++ b`
+ /// Uses the `pl_node` union field. Payload is `Bin`.
array_cat,
/// Array multiplication `a ** b`
+ /// Uses the `pl_node` union field. Payload is `Bin`.
array_mul,
/// `[N]T` syntax. No source location provided.
/// Uses the `bin` union field. lhs is length, rhs is element type.
@@ -468,13 +472,13 @@ pub const Inst = struct {
/// Same as `block_flat` but additionally makes the inner instructions execute at comptime.
block_comptime_flat,
/// Boolean AND. See also `bit_and`.
- /// Uses the `bin` field.
+ /// Uses the `pl_node` union field. Payload is `Bin`.
bool_and,
/// Boolean NOT. See also `bit_not`.
/// Uses the `un_node` field.
bool_not,
/// Boolean OR. See also `bit_or`.
- /// Uses the `bin` field.
+ /// Uses the `pl_node` union field. Payload is `Bin`.
bool_or,
/// Return a value from a block.
/// Uses the `bin` union field: `lhs` is `Index` to the block (*not* `Ref`!),
@@ -501,16 +505,22 @@ pub const Inst = struct {
/// Uses the `un_node` field. Operand is callee. AST node is the function call.
call_none,
/// `<`
+ /// Uses the `pl_node` union field. Payload is `Bin`.
cmp_lt,
/// `<=`
+ /// Uses the `pl_node` union field. Payload is `Bin`.
cmp_lte,
/// `==`
+ /// Uses the `pl_node` union field. Payload is `Bin`.
cmp_eq,
/// `>=`
+ /// Uses the `pl_node` union field. Payload is `Bin`.
cmp_gte,
/// `>`
+ /// Uses the `pl_node` union field. Payload is `Bin`.
cmp_gt,
/// `!=`
+ /// Uses the `pl_node` union field. Payload is `Bin`.
cmp_neq,
/// Coerces a result location pointer to a new element type. It is evaluated "backwards"-
/// as type coercion from the new element type to the old element type.
@@ -543,6 +553,7 @@ pub const Inst = struct {
/// Uses `un_node` field. AST node is the `x.*` syntax.
deref_node,
/// Arithmetic division. Asserts no integer overflow.
+ /// Uses the `pl_node` union field. Payload is `Bin`.
div,
/// Given a pointer to an array, slice, or pointer, returns a pointer to the element at
/// the provided index. Uses the `bin` union field. Source location is implied
@@ -646,10 +657,13 @@ pub const Inst = struct {
/// Ambiguously remainder division or modulus. If the computation would possibly have
/// a different value depending on whether the operation is remainder division or modulus,
/// a compile error is emitted. Otherwise the computation is performed.
+ /// Uses the `pl_node` union field. Payload is `Bin`.
mod_rem,
/// Arithmetic multiplication. Asserts no integer overflow.
+ /// Uses the `pl_node` union field. Payload is `Bin`.
mul,
/// Twos complement wrapping integer multiplication.
+ /// Uses the `pl_node` union field. Payload is `Bin`.
mulwrap,
/// An await inside a nosuspend scope.
nosuspend_await,
@@ -697,8 +711,10 @@ pub const Inst = struct {
/// Uses the `un_node` union field.
set_eval_branch_quota,
/// Integer shift-left. Zeroes are shifted in from the right hand side.
+ /// Uses the `pl_node` union field. Payload is `Bin`.
shl,
/// Integer shift-right. Arithmetic or logical depending on the signedness of the integer type.
+ /// Uses the `pl_node` union field. Payload is `Bin`.
shr,
/// Create a pointer type that does not have a sentinel, alignment, or bit range specified.
/// Uses the `ptr_type_simple` union field.
@@ -734,8 +750,10 @@ pub const Inst = struct {
/// Uses the `str` union field.
str,
/// Arithmetic subtraction. Asserts no integer overflow.
+ /// Uses the `pl_node` union field. Payload is `Bin`.
sub,
/// Twos complement wrapping integer subtraction.
+ /// Uses the `pl_node` union field. Payload is `Bin`.
subwrap,
/// Arithmetic negation. Asserts no integer overflow.
/// Same as sub with a lhs of 0, split into a separate instruction to save memory.
@@ -756,6 +774,7 @@ pub const Inst = struct {
/// Uses the `unreachable` union field.
@"unreachable",
/// Bitwise XOR. `^`
+ /// Uses the `pl_node` union field. Payload is `Bin`.
xor,
/// Create an optional type '?T'
/// Uses the `un_node` field.