aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKrzysztof Wolicki <der.teufel.mail@gmail.com>2023-09-12 17:50:40 +0200
committerLoris Cro <kappaloris@gmail.com>2023-09-16 17:35:11 +0200
commitf2026e7dd650e07defeefc9913f6fb08f9b45c21 (patch)
treedef1bb547586b07889044de3a5c5782ddeb849f0 /src
parent9a326b22d58a81a6d2b02c9f1c4be82244cfc89a (diff)
downloadzig-f2026e7dd650e07defeefc9913f6fb08f9b45c21.tar.gz
zig-f2026e7dd650e07defeefc9913f6fb08f9b45c21.zip
autodoc: Implement builtin function rendering.
Implement unary ops handling. Fix getType in main.js Minor cleanup of builtin function handling.
Diffstat (limited to 'src')
-rw-r--r--src/Autodoc.zig101
1 files changed, 67 insertions, 34 deletions
diff --git a/src/Autodoc.zig b/src/Autodoc.zig
index e4c42a1a83..c4506dc857 100644
--- a/src/Autodoc.zig
+++ b/src/Autodoc.zig
@@ -766,15 +766,12 @@ const DocData = struct {
array: []usize, // index in `exprs`
call: usize, // index in `calls`
enumLiteral: []const u8, // direct value
- alignOf: usize, // index in `exprs`
typeOf: usize, // index in `exprs`
- typeInfo: usize, // index in `exprs`
typeOf_peer: []usize,
errorUnion: usize, // index in `types`
as: As,
sizeOf: usize, // index in `exprs`
bitSizeOf: usize, // index in `exprs`
- intFromEnum: usize, // index in `exprs`
compileError: usize, // index in `exprs`
optionalPayload: usize, // index in `exprs`
elemVal: ElemVal,
@@ -794,9 +791,15 @@ const DocData = struct {
mulAdd: MulAdd,
switchIndex: usize, // index in `exprs`
switchOp: SwitchOp,
+ unOp: UnOp,
+ unOpIndex: usize,
binOp: BinOp,
binOpIndex: usize,
load: usize, // index in `exprs`
+ const UnOp = struct {
+ param: usize, // index in `exprs`
+ name: []const u8 = "", // tag name
+ };
const BinOp = struct {
lhs: usize, // index in `exprs`
rhs: usize, // index in `exprs`
@@ -1671,8 +1674,7 @@ fn walkInstruction(
.frame_type,
.frame_size,
.int_from_ptr,
- .bit_not,
- .bool_not,
+ .type_info,
// @check
.clz,
.ctz,
@@ -1695,13 +1697,49 @@ fn walkInstruction(
const param_index = self.exprs.items.len;
try self.exprs.append(self.arena, param.expr);
- self.exprs.items[bin_index] = .{ .builtin = .{ .name = @tagName(tags[inst_index]), .param = param_index } };
+ self.exprs.items[bin_index] = .{
+ .builtin = .{
+ .name = @tagName(tags[inst_index]),
+ .param = param_index,
+ },
+ };
return DocData.WalkResult{
.typeRef = param.typeRef orelse .{ .type = @intFromEnum(Ref.type_type) },
.expr = .{ .builtinIndex = bin_index },
};
},
+ .bit_not,
+ .bool_not,
+ .negate_wrap,
+ => {
+ const un_node = data[inst_index].un_node;
+ const un_index = self.exprs.items.len;
+ try self.exprs.append(self.arena, .{ .unOp = .{ .param = 0 } });
+ const param = try self.walkRef(
+ file,
+ parent_scope,
+ parent_src,
+ un_node.operand,
+ false,
+ call_ctx,
+ );
+
+ const param_index = self.exprs.items.len;
+ try self.exprs.append(self.arena, param.expr);
+
+ self.exprs.items[un_index] = .{
+ .unOp = .{
+ .name = @tagName(tags[inst_index]),
+ .param = param_index,
+ },
+ };
+
+ return DocData.WalkResult{
+ .typeRef = param.typeRef,
+ .expr = .{ .unOpIndex = un_index },
+ };
+ },
.bool_br_and, .bool_br_or => {
const bool_br = data[inst_index].bool_br;
@@ -2407,12 +2445,20 @@ fn walkInstruction(
.int => |*int| int.negated = true,
.int_big => |*int_big| int_big.negated = true,
else => {
- printWithContext(
- file,
- inst_index,
- "TODO: support negation for more types",
- .{},
- );
+ const un_index = self.exprs.items.len;
+ try self.exprs.append(self.arena, .{ .unOp = .{ .param = 0 } });
+ const param_index = self.exprs.items.len;
+ try self.exprs.append(self.arena, operand.expr);
+ self.exprs.items[un_index] = .{
+ .unOp = .{
+ .name = @tagName(tags[inst_index]),
+ .param = param_index,
+ },
+ };
+ return DocData.WalkResult{
+ .typeRef = operand.typeRef,
+ .expr = .{ .unOpIndex = un_index },
+ };
},
}
return operand;
@@ -2466,12 +2512,20 @@ fn walkInstruction(
false,
call_ctx,
);
+ const builtin_index = self.exprs.items.len;
+ try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } });
const operand_index = self.exprs.items.len;
try self.exprs.append(self.arena, operand.expr);
+ self.exprs.items[builtin_index] = .{
+ .builtin = .{
+ .name = @tagName(tags[inst_index]),
+ .param = operand_index,
+ },
+ };
return DocData.WalkResult{
.typeRef = .{ .type = @intFromEnum(Ref.comptime_int_type) },
- .expr = .{ .intFromEnum = operand_index },
+ .expr = .{ .builtinIndex = builtin_index },
};
},
.switch_block => {
@@ -2564,27 +2618,6 @@ fn walkInstruction(
.expr = .{ .typeOf = operand_index },
};
},
- .type_info => {
- // @check
- const un_node = data[inst_index].un_node;
-
- const operand = try self.walkRef(
- file,
- parent_scope,
- parent_src,
- un_node.operand,
- need_type,
- call_ctx,
- );
-
- const operand_index = self.exprs.items.len;
- try self.exprs.append(self.arena, operand.expr);
-
- return DocData.WalkResult{
- .typeRef = operand.typeRef,
- .expr = .{ .typeInfo = operand_index },
- };
- },
.as_node, .as_shift_operand => {
const pl_node = data[inst_index].pl_node;
const extra = file.zir.extraData(Zir.Inst.As, pl_node.payload_index);