| author | |
| committer | |
| log | 449f4de3825d3448c2aa0cda79c1a567adb08b59 |
| tree | ec2c79770135e854560743c489aa4b5eea7554ac |
| parent | 9b8a94265ab7313f07b300ddc349a60c85d556d1 |
9 files changed, 45 insertions(+), 57 deletions(-)
src/Module.zig+4-5| ... | @@ -1251,11 +1251,10 @@ fn astgenAndSemaFn( | ... | @@ -1251,11 +1251,10 @@ fn astgenAndSemaFn( |
| 1251 | .param_types = param_types, | 1251 | .param_types = param_types, |
| 1252 | .cc = cc, | 1252 | .cc = cc, |
| 1253 | }); | 1253 | }); |
| 1254 | } else | 1254 | } else try astgen.addZirInstTag(mod, &fn_type_scope.base, fn_src, .fn_type, .{ |
| 1255 | try astgen.addZirInstTag(mod, &fn_type_scope.base, fn_src, .fn_type, .{ | 1255 | .return_type = return_type_inst, |
| 1256 | .return_type = return_type_inst, | 1256 | .param_types = param_types, |
| 1257 | .param_types = param_types, | 1257 | }); |
| 1258 | }); | ||
| 1259 | 1258 | ||
| 1260 | if (std.builtin.mode == .Debug and mod.comp.verbose_ir) { | 1259 | if (std.builtin.mode == .Debug and mod.comp.verbose_ir) { |
| 1261 | zir.dumpZir(mod.gpa, "fn_type", decl.name, fn_type_scope.instructions.items) catch {}; | 1260 | 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( | ... | @@ -2143,11 +2143,10 @@ fn ifExpr( |
| 2143 | .src = token_starts[tree.lastToken(else_node)], | 2143 | .src = token_starts[tree.lastToken(else_node)], |
| 2144 | .result = try expr(mod, sub_scope, block_scope.break_result_loc, else_node), | 2144 | .result = try expr(mod, sub_scope, block_scope.break_result_loc, else_node), |
| 2145 | }; | 2145 | }; |
| 2146 | } else | 2146 | } else .{ |
| 2147 | .{ | 2147 | .src = token_starts[tree.lastToken(if_full.ast.then_expr)], |
| 2148 | .src = token_starts[tree.lastToken(if_full.ast.then_expr)], | 2148 | .result = null, |
| 2149 | .result = null, | 2149 | }; |
| 2150 | }; | ||
| 2151 | 2150 | ||
| 2152 | return finishThenElseBlock( | 2151 | return finishThenElseBlock( |
| 2153 | mod, | 2152 | mod, |
| ... | @@ -2316,11 +2315,10 @@ fn whileExpr( | ... | @@ -2316,11 +2315,10 @@ fn whileExpr( |
| 2316 | .src = token_starts[tree.lastToken(else_node)], | 2315 | .src = token_starts[tree.lastToken(else_node)], |
| 2317 | .result = try expr(mod, sub_scope, loop_scope.break_result_loc, else_node), | 2316 | .result = try expr(mod, sub_scope, loop_scope.break_result_loc, else_node), |
| 2318 | }; | 2317 | }; |
| 2319 | } else | 2318 | } else .{ |
| 2320 | .{ | 2319 | .src = token_starts[tree.lastToken(while_full.ast.then_expr)], |
| 2321 | .src = token_starts[tree.lastToken(while_full.ast.then_expr)], | 2320 | .result = null, |
| 2322 | .result = null, | 2321 | }; |
| 2323 | }; | ||
| 2324 | 2322 | ||
| 2325 | if (loop_scope.label) |some| { | 2323 | if (loop_scope.label) |some| { |
| 2326 | if (!some.used) { | 2324 | if (!some.used) { |
| ... | @@ -2514,11 +2512,10 @@ fn forExpr( | ... | @@ -2514,11 +2512,10 @@ fn forExpr( |
| 2514 | .src = token_starts[tree.lastToken(else_node)], | 2512 | .src = token_starts[tree.lastToken(else_node)], |
| 2515 | .result = try expr(mod, sub_scope, loop_scope.break_result_loc, else_node), | 2513 | .result = try expr(mod, sub_scope, loop_scope.break_result_loc, else_node), |
| 2516 | }; | 2514 | }; |
| 2517 | } else | 2515 | } else .{ |
| 2518 | .{ | 2516 | .src = token_starts[tree.lastToken(for_full.ast.then_expr)], |
| 2519 | .src = token_starts[tree.lastToken(for_full.ast.then_expr)], | 2517 | .result = null, |
| 2520 | .result = null, | 2518 | }; |
| 2521 | }; | ||
| 2522 | 2519 | ||
| 2523 | if (loop_scope.label) |some| { | 2520 | if (loop_scope.label) |some| { |
| 2524 | if (!some.used) { | 2521 | if (!some.used) { |
src/codegen.zig+1-2| ... | @@ -2950,8 +2950,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2950,8 +2950,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2950 | 4, 8 => { | 2950 | 4, 8 => { |
| 2951 | const offset = if (math.cast(i9, adj_off)) |imm| | 2951 | const offset = if (math.cast(i9, adj_off)) |imm| |
| 2952 | Instruction.LoadStoreOffset.imm_post_index(-imm) | 2952 | Instruction.LoadStoreOffset.imm_post_index(-imm) |
| 2953 | else |_| | 2953 | else |_| Instruction.LoadStoreOffset.reg(try self.copyToTmpRegister(src, Type.initTag(.u64), MCValue{ .immediate = adj_off })); |
| 2954 | Instruction.LoadStoreOffset.reg(try self.copyToTmpRegister(src, Type.initTag(.u64), MCValue{ .immediate = adj_off })); | ||
| 2955 | const rn: Register = switch (arch) { | 2954 | const rn: Register = switch (arch) { |
| 2956 | .aarch64, .aarch64_be => .x29, | 2955 | .aarch64, .aarch64_be => .x29, |
| 2957 | .aarch64_32 => .w29, | 2956 | .aarch64_32 => .w29, |
src/codegen/c.zig+1-2| ... | @@ -626,8 +626,7 @@ fn genBlock(o: *Object, inst: *Inst.Block) !CValue { | ... | @@ -626,8 +626,7 @@ fn genBlock(o: *Object, inst: *Inst.Block) !CValue { |
| 626 | const local = try o.allocLocal(inst.base.ty, .Mut); | 626 | const local = try o.allocLocal(inst.base.ty, .Mut); |
| 627 | try writer.writeAll(";\n"); | 627 | try writer.writeAll(";\n"); |
| 628 | break :blk local; | 628 | break :blk local; |
| 629 | } else | 629 | } else CValue{ .none = {} }; |
| 630 | CValue{ .none = {} }; | ||
| 631 | 630 | ||
| 632 | inst.codegen.mcv = @bitCast(@import("../codegen.zig").AnyMCValue, result); | 631 | inst.codegen.mcv = @bitCast(@import("../codegen.zig").AnyMCValue, result); |
| 633 | try genBody(o, inst.body); | 632 | try genBody(o, inst.body); |
src/codegen/spirv.zig+1-3| ... | @@ -45,7 +45,5 @@ pub const SPIRVModule = struct { | ... | @@ -45,7 +45,5 @@ pub const SPIRVModule = struct { |
| 45 | return self.next_id; | 45 | return self.next_id; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | pub fn genDecl(self: SPIRVModule, id: u32, code: *std.ArrayList(u32), decl: *Decl) !void { | 48 | pub fn genDecl(self: SPIRVModule, id: u32, code: *std.ArrayList(u32), decl: *Decl) !void {} |
| 49 | |||
| 50 | } | ||
| 51 | }; | 49 | }; |
src/link/SpirV.zig+16-16| ... | @@ -1,17 +1,3 @@ | ... | @@ -1,17 +1,3 @@ |
| 1 | const SpirV = @This(); | ||
| 2 | |||
| 3 | const std = @import("std"); | ||
| 4 | const Allocator = std.mem.Allocator; | ||
| 5 | const assert = std.debug.assert; | ||
| 6 | |||
| 7 | const Module = @import("../Module.zig"); | ||
| 8 | const Compilation = @import("../Compilation.zig"); | ||
| 9 | const link = @import("../link.zig"); | ||
| 10 | const codegen = @import("../codegen/spirv.zig"); | ||
| 11 | const trace = @import("../tracy.zig").trace; | ||
| 12 | const build_options = @import("build_options"); | ||
| 13 | const spec = @import("../codegen/spirv/spec.zig"); | ||
| 14 | |||
| 15 | //! SPIR-V Spec documentation: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html | 1 | //! SPIR-V Spec documentation: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html |
| 16 | //! According to above documentation, a SPIR-V module has the following logical layout: | 2 | //! According to above documentation, a SPIR-V module has the following logical layout: |
| 17 | //! Header. | 3 | //! Header. |
| ... | @@ -30,6 +16,20 @@ const spec = @import("../codegen/spirv/spec.zig"); | ... | @@ -30,6 +16,20 @@ const spec = @import("../codegen/spirv/spec.zig"); |
| 30 | //! All function declarations without a body (extern functions presumably). | 16 | //! All function declarations without a body (extern functions presumably). |
| 31 | //! All regular functions. | 17 | //! All regular functions. |
| 32 | 18 | ||
| 19 | const SpirV = @This(); | ||
| 20 | |||
| 21 | const std = @import("std"); | ||
| 22 | const Allocator = std.mem.Allocator; | ||
| 23 | const assert = std.debug.assert; | ||
| 24 | |||
| 25 | const Module = @import("../Module.zig"); | ||
| 26 | const Compilation = @import("../Compilation.zig"); | ||
| 27 | const link = @import("../link.zig"); | ||
| 28 | const codegen = @import("../codegen/spirv.zig"); | ||
| 29 | const trace = @import("../tracy.zig").trace; | ||
| 30 | const build_options = @import("build_options"); | ||
| 31 | const spec = @import("../codegen/spirv/spec.zig"); | ||
| 32 | |||
| 33 | pub const FnData = struct { | 33 | pub const FnData = struct { |
| 34 | id: ?u32 = null, | 34 | id: ?u32 = null, |
| 35 | code: std.ArrayListUnmanaged(u32) = .{}, | 35 | code: std.ArrayListUnmanaged(u32) = .{}, |
| ... | @@ -199,7 +199,7 @@ fn writeCapabilities(binary: *std.ArrayList(u32), target: std.Target) !void { | ... | @@ -199,7 +199,7 @@ fn writeCapabilities(binary: *std.ArrayList(u32), target: std.Target) !void { |
| 199 | else => unreachable, // TODO | 199 | else => unreachable, // TODO |
| 200 | }; | 200 | }; |
| 201 | 201 | ||
| 202 | try codegen.writeInstruction(binary, .OpCapability, &[_]u32{ @enumToInt(cap) }); | 202 | try codegen.writeInstruction(binary, .OpCapability, &[_]u32{@enumToInt(cap)}); |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | fn writeMemoryModel(binary: *std.ArrayList(u32), target: std.Target) !void { | 205 | fn writeMemoryModel(binary: *std.ArrayList(u32), target: std.Target) !void { |
| ... | @@ -221,7 +221,7 @@ fn writeMemoryModel(binary: *std.ArrayList(u32), target: std.Target) !void { | ... | @@ -221,7 +221,7 @@ fn writeMemoryModel(binary: *std.ArrayList(u32), target: std.Target) !void { |
| 221 | }; | 221 | }; |
| 222 | 222 | ||
| 223 | try codegen.writeInstruction(binary, .OpMemoryModel, &[_]u32{ | 223 | try codegen.writeInstruction(binary, .OpMemoryModel, &[_]u32{ |
| 224 | @enumToInt(addressing_model), @enumToInt(memory_model) | 224 | @enumToInt(addressing_model), @enumToInt(memory_model), |
| 225 | }); | 225 | }); |
| 226 | } | 226 | } |
| 227 | 227 |
src/main.zig+1-2| ... | @@ -3221,8 +3221,7 @@ pub const ClangArgIterator = struct { | ... | @@ -3221,8 +3221,7 @@ pub const ClangArgIterator = struct { |
| 3221 | self.zig_equivalent = clang_arg.zig_equivalent; | 3221 | self.zig_equivalent = clang_arg.zig_equivalent; |
| 3222 | break :find_clang_arg; | 3222 | break :find_clang_arg; |
| 3223 | }, | 3223 | }, |
| 3224 | } | 3224 | } else { |
| 3225 | else { | ||
| 3226 | fatal("Unknown Clang option: '{s}'", .{arg}); | 3225 | fatal("Unknown Clang option: '{s}'", .{arg}); |
| 3227 | } | 3226 | } |
| 3228 | } | 3227 | } |
src/translate_c.zig+6-9| ... | @@ -2313,8 +2313,7 @@ fn transCaseStmt(c: *Context, scope: *Scope, stmt: *const clang.Stmt, items: *st | ... | @@ -2313,8 +2313,7 @@ fn transCaseStmt(c: *Context, scope: *Scope, stmt: *const clang.Stmt, items: *st |
| 2313 | const rhs_node = try transExprCoercing(c, scope, rhs, .used); | 2313 | const rhs_node = try transExprCoercing(c, scope, rhs, .used); |
| 2314 | 2314 | ||
| 2315 | break :blk try Tag.ellipsis3.create(c.arena, .{ .lhs = lhs_node, .rhs = rhs_node }); | 2315 | break :blk try Tag.ellipsis3.create(c.arena, .{ .lhs = lhs_node, .rhs = rhs_node }); |
| 2316 | } else | 2316 | } else try transExprCoercing(c, scope, case_stmt.getLHS(), .used); |
| 2317 | try transExprCoercing(c, scope, case_stmt.getLHS(), .used); | ||
| 2318 | 2317 | ||
| 2319 | try items.append(expr); | 2318 | try items.append(expr); |
| 2320 | sub = case_stmt.getSubStmt(); | 2319 | sub = case_stmt.getSubStmt(); |
| ... | @@ -2551,8 +2550,7 @@ fn transArrayAccess(c: *Context, scope: *Scope, stmt: *const clang.ArraySubscrip | ... | @@ -2551,8 +2550,7 @@ fn transArrayAccess(c: *Context, scope: *Scope, stmt: *const clang.ArraySubscrip |
| 2551 | // check if long long first so that signed long long doesn't just become unsigned long long | 2550 | // check if long long first so that signed long long doesn't just become unsigned long long |
| 2552 | var typeid_node = if (is_longlong) try Tag.identifier.create(c.arena, "usize") else try transQualTypeIntWidthOf(c, qt, false); | 2551 | var typeid_node = if (is_longlong) try Tag.identifier.create(c.arena, "usize") else try transQualTypeIntWidthOf(c, qt, false); |
| 2553 | break :blk try Tag.int_cast.create(c.arena, .{ .lhs = typeid_node, .rhs = try transExpr(c, scope, subscr_expr, .used) }); | 2552 | break :blk try Tag.int_cast.create(c.arena, .{ .lhs = typeid_node, .rhs = try transExpr(c, scope, subscr_expr, .used) }); |
| 2554 | } else | 2553 | } else try transExpr(c, scope, subscr_expr, .used); |
| 2555 | try transExpr(c, scope, subscr_expr, .used); | ||
| 2556 | 2554 | ||
| 2557 | const node = try Tag.array_access.create(c.arena, .{ | 2555 | const node = try Tag.array_access.create(c.arena, .{ |
| 2558 | .lhs = container_node, | 2556 | .lhs = container_node, |
| ... | @@ -2752,8 +2750,7 @@ fn transUnaryOperator(c: *Context, scope: *Scope, stmt: *const clang.UnaryOperat | ... | @@ -2752,8 +2750,7 @@ fn transUnaryOperator(c: *Context, scope: *Scope, stmt: *const clang.UnaryOperat |
| 2752 | } else if (cIsUnsignedInteger(op_expr.getType())) { | 2750 | } else if (cIsUnsignedInteger(op_expr.getType())) { |
| 2753 | // use -% x for unsigned integers | 2751 | // use -% x for unsigned integers |
| 2754 | return Tag.negate_wrap.create(c.arena, try transExpr(c, scope, op_expr, .used)); | 2752 | return Tag.negate_wrap.create(c.arena, try transExpr(c, scope, op_expr, .used)); |
| 2755 | } else | 2753 | } else return fail(c, error.UnsupportedTranslation, stmt.getBeginLoc(), "C negation with non float non integer", .{}); |
| 2756 | return fail(c, error.UnsupportedTranslation, stmt.getBeginLoc(), "C negation with non float non integer", .{}); | ||
| 2757 | }, | 2754 | }, |
| 2758 | .Not => { | 2755 | .Not => { |
| 2759 | return Tag.bit_not.create(c.arena, try transExpr(c, scope, op_expr, .used)); | 2756 | 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 | ... | @@ -4593,7 +4590,8 @@ fn parseCPrimaryExprInner(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!N |
| 4593 | // (type)alignof(x) | 4590 | // (type)alignof(x) |
| 4594 | .Keyword_alignof, | 4591 | .Keyword_alignof, |
| 4595 | // (type)identifier | 4592 | // (type)identifier |
| 4596 | .Identifier => {}, | 4593 | .Identifier, |
| 4594 | => {}, | ||
| 4597 | // (type)integer | 4595 | // (type)integer |
| 4598 | .IntegerLiteral => { | 4596 | .IntegerLiteral => { |
| 4599 | saw_integer_literal = true; | 4597 | saw_integer_literal = true; |
| ... | @@ -5068,8 +5066,7 @@ fn getContainerTypeOf(c: *Context, ref: Node) ?Node { | ... | @@ -5068,8 +5066,7 @@ fn getContainerTypeOf(c: *Context, ref: Node) ?Node { |
| 5068 | return getContainer(c, field.type); | 5066 | return getContainer(c, field.type); |
| 5069 | } | 5067 | } |
| 5070 | } | 5068 | } |
| 5071 | } else | 5069 | } else return ty_node; |
| 5072 | return ty_node; | ||
| 5073 | } | 5070 | } |
| 5074 | } | 5071 | } |
| 5075 | return null; | 5072 | return null; |
src/translate_c/ast.zig+3-3| ... | @@ -312,7 +312,7 @@ pub const Node = extern union { | ... | @@ -312,7 +312,7 @@ pub const Node = extern union { |
| 312 | => Payload.Value, | 312 | => Payload.Value, |
| 313 | .@"if" => Payload.If, | 313 | .@"if" => Payload.If, |
| 314 | .@"while" => Payload.While, | 314 | .@"while" => Payload.While, |
| 315 | .@"switch", .array_init,.switch_prong => Payload.Switch, | 315 | .@"switch", .array_init, .switch_prong => Payload.Switch, |
| 316 | .break_val => Payload.BreakVal, | 316 | .break_val => Payload.BreakVal, |
| 317 | .call => Payload.Call, | 317 | .call => Payload.Call, |
| 318 | .var_decl => Payload.VarDecl, | 318 | .var_decl => Payload.VarDecl, |
| ... | @@ -394,7 +394,8 @@ pub const Node = extern union { | ... | @@ -394,7 +394,8 @@ pub const Node = extern union { |
| 394 | some.data | 394 | some.data |
| 395 | else if (case.castTag(.switch_prong)) |some| | 395 | else if (case.castTag(.switch_prong)) |some| |
| 396 | some.data.cond | 396 | some.data.cond |
| 397 | else unreachable; | 397 | else |
| 398 | unreachable; | ||
| 398 | 399 | ||
| 399 | if (!body.isNoreturn(break_counts)) return false; | 400 | if (!body.isNoreturn(break_counts)) return false; |
| 400 | } | 401 | } |
| ... | @@ -406,7 +407,6 @@ pub const Node = extern union { | ... | @@ -406,7 +407,6 @@ pub const Node = extern union { |
| 406 | } | 407 | } |
| 407 | return false; | 408 | return false; |
| 408 | } | 409 | } |
| 409 | |||
| 410 | }; | 410 | }; |
| 411 | 411 | ||
| 412 | pub const Payload = struct { | 412 | pub const Payload = struct { |