authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-24 21:54:23-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-24 21:54:23-07:00
log449f4de3825d3448c2aa0cda79c1a567adb08b59
treeec2c79770135e854560743c489aa4b5eea7554ac
parent9b8a94265ab7313f07b300ddc349a60c85d556d1

zig fmt src/


9 files changed, 45 insertions(+), 57 deletions(-)

src/Module.zig+4-5
......@@ -1251,11 +1251,10 @@ fn astgenAndSemaFn(
12511251 .param_types = param_types,
12521252 .cc = cc,
12531253 });
1254 } else
1255 try astgen.addZirInstTag(mod, &fn_type_scope.base, fn_src, .fn_type, .{
1256 .return_type = return_type_inst,
1257 .param_types = param_types,
1258 });
1254 } else try astgen.addZirInstTag(mod, &fn_type_scope.base, fn_src, .fn_type, .{
1255 .return_type = return_type_inst,
1256 .param_types = param_types,
1257 });
12591258
12601259 if (std.builtin.mode == .Debug and mod.comp.verbose_ir) {
12611260 zir.dumpZir(mod.gpa, "fn_type", decl.name, fn_type_scope.instructions.items) catch {};
src/astgen.zig+12-15
......@@ -2143,11 +2143,10 @@ fn ifExpr(
21432143 .src = token_starts[tree.lastToken(else_node)],
21442144 .result = try expr(mod, sub_scope, block_scope.break_result_loc, else_node),
21452145 };
2146 } else
2147 .{
2148 .src = token_starts[tree.lastToken(if_full.ast.then_expr)],
2149 .result = null,
2150 };
2146 } else .{
2147 .src = token_starts[tree.lastToken(if_full.ast.then_expr)],
2148 .result = null,
2149 };
21512150
21522151 return finishThenElseBlock(
21532152 mod,
......@@ -2316,11 +2315,10 @@ fn whileExpr(
23162315 .src = token_starts[tree.lastToken(else_node)],
23172316 .result = try expr(mod, sub_scope, loop_scope.break_result_loc, else_node),
23182317 };
2319 } else
2320 .{
2321 .src = token_starts[tree.lastToken(while_full.ast.then_expr)],
2322 .result = null,
2323 };
2318 } else .{
2319 .src = token_starts[tree.lastToken(while_full.ast.then_expr)],
2320 .result = null,
2321 };
23242322
23252323 if (loop_scope.label) |some| {
23262324 if (!some.used) {
......@@ -2514,11 +2512,10 @@ fn forExpr(
25142512 .src = token_starts[tree.lastToken(else_node)],
25152513 .result = try expr(mod, sub_scope, loop_scope.break_result_loc, else_node),
25162514 };
2517 } else
2518 .{
2519 .src = token_starts[tree.lastToken(for_full.ast.then_expr)],
2520 .result = null,
2521 };
2515 } else .{
2516 .src = token_starts[tree.lastToken(for_full.ast.then_expr)],
2517 .result = null,
2518 };
25222519
25232520 if (loop_scope.label) |some| {
25242521 if (!some.used) {
src/codegen.zig+1-2
......@@ -2950,8 +2950,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
29502950 4, 8 => {
29512951 const offset = if (math.cast(i9, adj_off)) |imm|
29522952 Instruction.LoadStoreOffset.imm_post_index(-imm)
2953 else |_|
2954 Instruction.LoadStoreOffset.reg(try self.copyToTmpRegister(src, Type.initTag(.u64), MCValue{ .immediate = adj_off }));
2953 else |_| Instruction.LoadStoreOffset.reg(try self.copyToTmpRegister(src, Type.initTag(.u64), MCValue{ .immediate = adj_off }));
29552954 const rn: Register = switch (arch) {
29562955 .aarch64, .aarch64_be => .x29,
29572956 .aarch64_32 => .w29,
src/codegen/c.zig+1-2
......@@ -626,8 +626,7 @@ fn genBlock(o: *Object, inst: *Inst.Block) !CValue {
626626 const local = try o.allocLocal(inst.base.ty, .Mut);
627627 try writer.writeAll(";\n");
628628 break :blk local;
629 } else
630 CValue{ .none = {} };
629 } else CValue{ .none = {} };
631630
632631 inst.codegen.mcv = @bitCast(@import("../codegen.zig").AnyMCValue, result);
633632 try genBody(o, inst.body);
src/codegen/spirv.zig+1-3
......@@ -45,7 +45,5 @@ pub const SPIRVModule = struct {
4545 return self.next_id;
4646 }
4747
48 pub fn genDecl(self: SPIRVModule, id: u32, code: *std.ArrayList(u32), decl: *Decl) !void {
49
50 }
48 pub fn genDecl(self: SPIRVModule, id: u32, code: *std.ArrayList(u32), decl: *Decl) !void {}
5149};
src/link/SpirV.zig+16-16
......@@ -1,17 +1,3 @@
1const SpirV = @This();
2
3const std = @import("std");
4const Allocator = std.mem.Allocator;
5const assert = std.debug.assert;
6
7const Module = @import("../Module.zig");
8const Compilation = @import("../Compilation.zig");
9const link = @import("../link.zig");
10const codegen = @import("../codegen/spirv.zig");
11const trace = @import("../tracy.zig").trace;
12const build_options = @import("build_options");
13const spec = @import("../codegen/spirv/spec.zig");
14
151//! SPIR-V Spec documentation: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html
162//! According to above documentation, a SPIR-V module has the following logical layout:
173//! Header.
......@@ -30,6 +16,20 @@ const spec = @import("../codegen/spirv/spec.zig");
3016//! All function declarations without a body (extern functions presumably).
3117//! All regular functions.
3218
19const SpirV = @This();
20
21const std = @import("std");
22const Allocator = std.mem.Allocator;
23const assert = std.debug.assert;
24
25const Module = @import("../Module.zig");
26const Compilation = @import("../Compilation.zig");
27const link = @import("../link.zig");
28const codegen = @import("../codegen/spirv.zig");
29const trace = @import("../tracy.zig").trace;
30const build_options = @import("build_options");
31const spec = @import("../codegen/spirv/spec.zig");
32
3333pub const FnData = struct {
3434 id: ?u32 = null,
3535 code: std.ArrayListUnmanaged(u32) = .{},
......@@ -199,7 +199,7 @@ fn writeCapabilities(binary: *std.ArrayList(u32), target: std.Target) !void {
199199 else => unreachable, // TODO
200200 };
201201
202 try codegen.writeInstruction(binary, .OpCapability, &[_]u32{ @enumToInt(cap) });
202 try codegen.writeInstruction(binary, .OpCapability, &[_]u32{@enumToInt(cap)});
203203}
204204
205205fn writeMemoryModel(binary: *std.ArrayList(u32), target: std.Target) !void {
......@@ -221,7 +221,7 @@ fn writeMemoryModel(binary: *std.ArrayList(u32), target: std.Target) !void {
221221 };
222222
223223 try codegen.writeInstruction(binary, .OpMemoryModel, &[_]u32{
224 @enumToInt(addressing_model), @enumToInt(memory_model)
224 @enumToInt(addressing_model), @enumToInt(memory_model),
225225 });
226226}
227227
src/main.zig+1-2
......@@ -3221,8 +3221,7 @@ pub const ClangArgIterator = struct {
32213221 self.zig_equivalent = clang_arg.zig_equivalent;
32223222 break :find_clang_arg;
32233223 },
3224 }
3225 else {
3224 } else {
32263225 fatal("Unknown Clang option: '{s}'", .{arg});
32273226 }
32283227 }
src/translate_c.zig+6-9
......@@ -2313,8 +2313,7 @@ fn transCaseStmt(c: *Context, scope: *Scope, stmt: *const clang.Stmt, items: *st
23132313 const rhs_node = try transExprCoercing(c, scope, rhs, .used);
23142314
23152315 break :blk try Tag.ellipsis3.create(c.arena, .{ .lhs = lhs_node, .rhs = rhs_node });
2316 } else
2317 try transExprCoercing(c, scope, case_stmt.getLHS(), .used);
2316 } else try transExprCoercing(c, scope, case_stmt.getLHS(), .used);
23182317
23192318 try items.append(expr);
23202319 sub = case_stmt.getSubStmt();
......@@ -2551,8 +2550,7 @@ fn transArrayAccess(c: *Context, scope: *Scope, stmt: *const clang.ArraySubscrip
25512550 // check if long long first so that signed long long doesn't just become unsigned long long
25522551 var typeid_node = if (is_longlong) try Tag.identifier.create(c.arena, "usize") else try transQualTypeIntWidthOf(c, qt, false);
25532552 break :blk try Tag.int_cast.create(c.arena, .{ .lhs = typeid_node, .rhs = try transExpr(c, scope, subscr_expr, .used) });
2554 } else
2555 try transExpr(c, scope, subscr_expr, .used);
2553 } else try transExpr(c, scope, subscr_expr, .used);
25562554
25572555 const node = try Tag.array_access.create(c.arena, .{
25582556 .lhs = container_node,
......@@ -2752,8 +2750,7 @@ fn transUnaryOperator(c: *Context, scope: *Scope, stmt: *const clang.UnaryOperat
27522750 } else if (cIsUnsignedInteger(op_expr.getType())) {
27532751 // use -% x for unsigned integers
27542752 return Tag.negate_wrap.create(c.arena, try transExpr(c, scope, op_expr, .used));
2755 } else
2756 return fail(c, error.UnsupportedTranslation, stmt.getBeginLoc(), "C negation with non float non integer", .{});
2753 } else return fail(c, error.UnsupportedTranslation, stmt.getBeginLoc(), "C negation with non float non integer", .{});
27572754 },
27582755 .Not => {
27592756 return Tag.bit_not.create(c.arena, try transExpr(c, scope, op_expr, .used));
......@@ -4593,7 +4590,8 @@ fn parseCPrimaryExprInner(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!N
45934590 // (type)alignof(x)
45944591 .Keyword_alignof,
45954592 // (type)identifier
4596 .Identifier => {},
4593 .Identifier,
4594 => {},
45974595 // (type)integer
45984596 .IntegerLiteral => {
45994597 saw_integer_literal = true;
......@@ -5068,8 +5066,7 @@ fn getContainerTypeOf(c: *Context, ref: Node) ?Node {
50685066 return getContainer(c, field.type);
50695067 }
50705068 }
5071 } else
5072 return ty_node;
5069 } else return ty_node;
50735070 }
50745071 }
50755072 return null;
src/translate_c/ast.zig+3-3
......@@ -312,7 +312,7 @@ pub const Node = extern union {
312312 => Payload.Value,
313313 .@"if" => Payload.If,
314314 .@"while" => Payload.While,
315 .@"switch", .array_init,.switch_prong => Payload.Switch,
315 .@"switch", .array_init, .switch_prong => Payload.Switch,
316316 .break_val => Payload.BreakVal,
317317 .call => Payload.Call,
318318 .var_decl => Payload.VarDecl,
......@@ -394,7 +394,8 @@ pub const Node = extern union {
394394 some.data
395395 else if (case.castTag(.switch_prong)) |some|
396396 some.data.cond
397 else unreachable;
397 else
398 unreachable;
398399
399400 if (!body.isNoreturn(break_counts)) return false;
400401 }
......@@ -406,7 +407,6 @@ pub const Node = extern union {
406407 }
407408 return false;
408409 }
409
410410};
411411
412412pub const Payload = struct {