| author | |
| committer | |
| log | a61def10c66abc871f92c84d9cef85b6b7752cbf |
| tree | 6d8dfdbad1cbaf827d52ec61c33fff0d6ddae86d |
| parent | b8d114a29e341a0cbd4c22cf02cb1588b0154446 |
| signature |
24 files changed, 307 insertions(+), 487 deletions(-)
src/Module.zig+16-15| ... | ... | @@ -3678,20 +3678,21 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 3678 | 3678 | const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 }; |
| 3679 | 3679 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 }; |
| 3680 | 3680 | const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 }; |
| 3681 | const decl_tv = try sema.resolveFinalDeclValue(&block_scope, init_src, result_ref); | |
| 3681 | const decl_val = try sema.resolveFinalDeclValue(&block_scope, init_src, result_ref); | |
| 3682 | const decl_ty = decl_val.typeOf(mod); | |
| 3682 | 3683 | |
| 3683 | 3684 | // Note this resolves the type of the Decl, not the value; if this Decl |
| 3684 | 3685 | // is a struct, for example, this resolves `type` (which needs no resolution), |
| 3685 | 3686 | // not the struct itself. |
| 3686 | try sema.resolveTypeLayout(decl_tv.ty); | |
| 3687 | try sema.resolveTypeLayout(decl_ty); | |
| 3687 | 3688 | |
| 3688 | 3689 | if (decl.kind == .@"usingnamespace") { |
| 3689 | if (!decl_tv.ty.eql(Type.type, mod)) { | |
| 3690 | if (!decl_ty.eql(Type.type, mod)) { | |
| 3690 | 3691 | return sema.fail(&block_scope, ty_src, "expected type, found {}", .{ |
| 3691 | decl_tv.ty.fmt(mod), | |
| 3692 | decl_ty.fmt(mod), | |
| 3692 | 3693 | }); |
| 3693 | 3694 | } |
| 3694 | const ty = decl_tv.val.toType(); | |
| 3695 | const ty = decl_val.toType(); | |
| 3695 | 3696 | if (ty.getNamespace(mod) == null) { |
| 3696 | 3697 | return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)}); |
| 3697 | 3698 | } |
| ... | ... | @@ -3713,10 +3714,10 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 3713 | 3714 | var queue_linker_work = true; |
| 3714 | 3715 | var is_func = false; |
| 3715 | 3716 | var is_inline = false; |
| 3716 | switch (decl_tv.val.toIntern()) { | |
| 3717 | switch (decl_val.toIntern()) { | |
| 3717 | 3718 | .generic_poison => unreachable, |
| 3718 | 3719 | .unreachable_value => unreachable, |
| 3719 | else => switch (ip.indexToKey(decl_tv.val.toIntern())) { | |
| 3720 | else => switch (ip.indexToKey(decl_val.toIntern())) { | |
| 3720 | 3721 | .variable => |variable| { |
| 3721 | 3722 | decl.owns_tv = variable.decl == decl_index; |
| 3722 | 3723 | queue_linker_work = decl.owns_tv; |
| ... | ... | @@ -3731,7 +3732,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 3731 | 3732 | .func => |func| { |
| 3732 | 3733 | decl.owns_tv = func.owner_decl == decl_index; |
| 3733 | 3734 | queue_linker_work = false; |
| 3734 | is_inline = decl.owns_tv and decl_tv.ty.fnCallingConvention(mod) == .Inline; | |
| 3735 | is_inline = decl.owns_tv and decl_ty.fnCallingConvention(mod) == .Inline; | |
| 3735 | 3736 | is_func = decl.owns_tv; |
| 3736 | 3737 | }, |
| 3737 | 3738 | |
| ... | ... | @@ -3739,7 +3740,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 3739 | 3740 | }, |
| 3740 | 3741 | } |
| 3741 | 3742 | |
| 3742 | decl.val = decl_tv.val; | |
| 3743 | decl.val = decl_val; | |
| 3743 | 3744 | // Function linksection, align, and addrspace were already set by Sema |
| 3744 | 3745 | if (!is_func) { |
| 3745 | 3746 | decl.alignment = blk: { |
| ... | ... | @@ -3762,7 +3763,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 3762 | 3763 | break :blk section.toOptional(); |
| 3763 | 3764 | }; |
| 3764 | 3765 | decl.@"addrspace" = blk: { |
| 3765 | const addrspace_ctx: Sema.AddressSpaceContext = switch (ip.indexToKey(decl_tv.val.toIntern())) { | |
| 3766 | const addrspace_ctx: Sema.AddressSpaceContext = switch (ip.indexToKey(decl_val.toIntern())) { | |
| 3766 | 3767 | .variable => .variable, |
| 3767 | 3768 | .extern_func, .func => .function, |
| 3768 | 3769 | else => .constant, |
| ... | ... | @@ -3784,10 +3785,10 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 3784 | 3785 | decl.analysis = .complete; |
| 3785 | 3786 | |
| 3786 | 3787 | const result: SemaDeclResult = if (old_has_tv) .{ |
| 3787 | .invalidate_decl_val = !decl_tv.ty.eql(old_ty, mod) or | |
| 3788 | !decl.val.eql(old_val, decl_tv.ty, mod) or | |
| 3788 | .invalidate_decl_val = !decl_ty.eql(old_ty, mod) or | |
| 3789 | !decl.val.eql(old_val, decl_ty, mod) or | |
| 3789 | 3790 | is_inline != old_is_inline, |
| 3790 | .invalidate_decl_ref = !decl_tv.ty.eql(old_ty, mod) or | |
| 3791 | .invalidate_decl_ref = !decl_ty.eql(old_ty, mod) or | |
| 3791 | 3792 | decl.alignment != old_align or |
| 3792 | 3793 | decl.@"linksection" != old_linksection or |
| 3793 | 3794 | decl.@"addrspace" != old_addrspace or |
| ... | ... | @@ -3797,11 +3798,11 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 3797 | 3798 | .invalidate_decl_ref = true, |
| 3798 | 3799 | }; |
| 3799 | 3800 | |
| 3800 | const has_runtime_bits = queue_linker_work and (is_func or try sema.typeHasRuntimeBits(decl_tv.ty)); | |
| 3801 | const has_runtime_bits = queue_linker_work and (is_func or try sema.typeHasRuntimeBits(decl_ty)); | |
| 3801 | 3802 | if (has_runtime_bits) { |
| 3802 | 3803 | // Needed for codegen_decl which will call updateDecl and then the |
| 3803 | 3804 | // codegen backend wants full access to the Decl Type. |
| 3804 | try sema.resolveTypeFully(decl_tv.ty); | |
| 3805 | try sema.resolveTypeFully(decl_ty); | |
| 3805 | 3806 | |
| 3806 | 3807 | try mod.comp.work_queue.writeItem(.{ .codegen_decl = decl_index }); |
| 3807 | 3808 |
src/Sema.zig+10-19| ... | ... | @@ -175,7 +175,6 @@ const Sema = @This(); |
| 175 | 175 | const Value = @import("Value.zig"); |
| 176 | 176 | const MutableValue = @import("mutable_value.zig").MutableValue; |
| 177 | 177 | const Type = @import("type.zig").Type; |
| 178 | const TypedValue = @import("TypedValue.zig"); | |
| 179 | 178 | const Air = @import("Air.zig"); |
| 180 | 179 | const Zir = std.zig.Zir; |
| 181 | 180 | const Module = @import("Module.zig"); |
| ... | ... | @@ -1708,7 +1707,7 @@ fn analyzeBodyInner( |
| 1708 | 1707 | .needed_comptime_reason = "condition in comptime branch must be comptime-known", |
| 1709 | 1708 | .block_comptime_reason = block.comptime_reason, |
| 1710 | 1709 | }); |
| 1711 | const inline_body = if (cond.val.toBool()) then_body else else_body; | |
| 1710 | const inline_body = if (cond.toBool()) then_body else else_body; | |
| 1712 | 1711 | |
| 1713 | 1712 | try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src); |
| 1714 | 1713 | |
| ... | ... | @@ -1728,7 +1727,7 @@ fn analyzeBodyInner( |
| 1728 | 1727 | .needed_comptime_reason = "condition in comptime branch must be comptime-known", |
| 1729 | 1728 | .block_comptime_reason = block.comptime_reason, |
| 1730 | 1729 | }); |
| 1731 | const inline_body = if (cond.val.toBool()) then_body else else_body; | |
| 1730 | const inline_body = if (cond.toBool()) then_body else else_body; | |
| 1732 | 1731 | |
| 1733 | 1732 | try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src); |
| 1734 | 1733 | const old_runtime_index = block.runtime_index; |
| ... | ... | @@ -2179,13 +2178,9 @@ fn resolveInstConst( |
| 2179 | 2178 | src: LazySrcLoc, |
| 2180 | 2179 | zir_ref: Zir.Inst.Ref, |
| 2181 | 2180 | reason: NeededComptimeReason, |
| 2182 | ) CompileError!TypedValue { | |
| 2181 | ) CompileError!Value { | |
| 2183 | 2182 | const air_ref = try sema.resolveInst(zir_ref); |
| 2184 | const val = try sema.resolveConstDefinedValue(block, src, air_ref, reason); | |
| 2185 | return .{ | |
| 2186 | .ty = sema.typeOf(air_ref), | |
| 2187 | .val = val, | |
| 2188 | }; | |
| 2183 | return sema.resolveConstDefinedValue(block, src, air_ref, reason); | |
| 2189 | 2184 | } |
| 2190 | 2185 | |
| 2191 | 2186 | /// Value Tag may be `undef` or `variable`. |
| ... | ... | @@ -2194,7 +2189,7 @@ pub fn resolveFinalDeclValue( |
| 2194 | 2189 | block: *Block, |
| 2195 | 2190 | src: LazySrcLoc, |
| 2196 | 2191 | air_ref: Air.Inst.Ref, |
| 2197 | ) CompileError!TypedValue { | |
| 2192 | ) CompileError!Value { | |
| 2198 | 2193 | const val = try sema.resolveValueAllowVariables(air_ref) orelse { |
| 2199 | 2194 | return sema.failWithNeededComptime(block, src, .{ |
| 2200 | 2195 | .needed_comptime_reason = "global variable initializer must be comptime-known", |
| ... | ... | @@ -2204,10 +2199,7 @@ pub fn resolveFinalDeclValue( |
| 2204 | 2199 | if (val.canMutateComptimeVarState(sema.mod)) { |
| 2205 | 2200 | return sema.fail(block, src, "global variable contains reference to comptime var", .{}); |
| 2206 | 2201 | } |
| 2207 | return .{ | |
| 2208 | .ty = sema.typeOf(air_ref), | |
| 2209 | .val = val, | |
| 2210 | }; | |
| 2202 | return val; | |
| 2211 | 2203 | } |
| 2212 | 2204 | |
| 2213 | 2205 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError { |
| ... | ... | @@ -6414,7 +6406,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 6414 | 6406 | const options = try sema.resolveExportOptions(block, options_src, extra.options); |
| 6415 | 6407 | if (options.linkage == .internal) |
| 6416 | 6408 | return; |
| 6417 | if (operand.val.getFunction(mod)) |function| { | |
| 6409 | if (operand.getFunction(mod)) |function| { | |
| 6418 | 6410 | const decl_index = function.owner_decl; |
| 6419 | 6411 | return sema.analyzeExport(block, src, options, decl_index); |
| 6420 | 6412 | } |
| ... | ... | @@ -6424,7 +6416,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 6424 | 6416 | .src = src, |
| 6425 | 6417 | .owner_decl = sema.owner_decl_index, |
| 6426 | 6418 | .src_decl = block.src_decl, |
| 6427 | .exported = .{ .value = operand.val.toIntern() }, | |
| 6419 | .exported = .{ .value = operand.toIntern() }, | |
| 6428 | 6420 | .status = .in_progress, |
| 6429 | 6421 | }); |
| 6430 | 6422 | } |
| ... | ... | @@ -25831,7 +25823,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 25831 | 25823 | } else if (extra.data.bits.has_ret_ty_ref) blk: { |
| 25832 | 25824 | const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 25833 | 25825 | extra_index += 1; |
| 25834 | const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref, .{ | |
| 25826 | const ret_ty_val = sema.resolveInstConst(block, ret_src, ret_ty_ref, .{ | |
| 25835 | 25827 | .needed_comptime_reason = "return type must be comptime-known", |
| 25836 | 25828 | }) catch |err| switch (err) { |
| 25837 | 25829 | error.GenericPoison => { |
| ... | ... | @@ -25839,8 +25831,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 25839 | 25831 | }, |
| 25840 | 25832 | else => |e| return e, |
| 25841 | 25833 | }; |
| 25842 | const ty = ret_ty_tv.val.toType(); | |
| 25843 | break :blk ty; | |
| 25834 | break :blk ret_ty_val.toType(); | |
| 25844 | 25835 | } else Type.void; |
| 25845 | 25836 | |
| 25846 | 25837 | const noalias_bits: u32 = if (extra.data.bits.has_any_noalias) blk: { |
src/TypedValue.zig+3-37| ... | ... | @@ -1,3 +1,6 @@ |
| 1 | //! This type exists only for legacy purposes, and will be removed in the future. | |
| 2 | //! It is a thin wrapper around a `Value` which also, redundantly, stores its `Type`. | |
| 3 | ||
| 1 | 4 | const std = @import("std"); |
| 2 | 5 | const Type = @import("type.zig").Type; |
| 3 | 6 | const Value = @import("Value.zig"); |
| ... | ... | @@ -12,42 +15,6 @@ const Target = std.Target; |
| 12 | 15 | ty: Type, |
| 13 | 16 | val: Value, |
| 14 | 17 | |
| 15 | /// Memory management for TypedValue. The main purpose of this type | |
| 16 | /// is to be small and have a deinit() function to free associated resources. | |
| 17 | pub const Managed = struct { | |
| 18 | /// If the tag value is less than Tag.no_payload_count, then no pointer | |
| 19 | /// dereference is needed. | |
| 20 | typed_value: TypedValue, | |
| 21 | /// If this is `null` then there is no memory management needed. | |
| 22 | arena: ?*std.heap.ArenaAllocator.State = null, | |
| 23 | ||
| 24 | pub fn deinit(self: *Managed, allocator: Allocator) void { | |
| 25 | if (self.arena) |a| a.promote(allocator).deinit(); | |
| 26 | self.* = undefined; | |
| 27 | } | |
| 28 | }; | |
| 29 | ||
| 30 | /// Assumes arena allocation. Does a recursive copy. | |
| 31 | pub fn copy(self: TypedValue, arena: Allocator) error{OutOfMemory}!TypedValue { | |
| 32 | return TypedValue{ | |
| 33 | .ty = self.ty, | |
| 34 | .val = try self.val.copy(arena), | |
| 35 | }; | |
| 36 | } | |
| 37 | ||
| 38 | pub fn eql(a: TypedValue, b: TypedValue, mod: *Module) bool { | |
| 39 | if (a.ty.toIntern() != b.ty.toIntern()) return false; | |
| 40 | return a.val.eql(b.val, a.ty, mod); | |
| 41 | } | |
| 42 | ||
| 43 | pub fn hash(tv: TypedValue, hasher: *std.hash.Wyhash, mod: *Module) void { | |
| 44 | return tv.val.hash(tv.ty, hasher, mod); | |
| 45 | } | |
| 46 | ||
| 47 | pub fn intFromEnum(tv: TypedValue, mod: *Module) Allocator.Error!Value { | |
| 48 | return tv.val.intFromEnum(tv.ty, mod); | |
| 49 | } | |
| 50 | ||
| 51 | 18 | const max_aggregate_items = 100; |
| 52 | 19 | const max_string_len = 256; |
| 53 | 20 | |
| ... | ... | @@ -72,7 +39,6 @@ pub fn format( |
| 72 | 39 | }; |
| 73 | 40 | } |
| 74 | 41 | |
| 75 | /// Prints the Value according to the Type, not according to the Value Tag. | |
| 76 | 42 | pub fn print( |
| 77 | 43 | tv: TypedValue, |
| 78 | 44 | writer: anytype, |
src/Value.zig+3-3| ... | ... | @@ -249,12 +249,12 @@ pub fn getUnsignedIntAdvanced(val: Value, mod: *Module, opt_sema: ?*Sema) !?u64 |
| 249 | 249 | .int => |int| Value.fromInterned(int).getUnsignedIntAdvanced(mod, opt_sema), |
| 250 | 250 | .elem => |elem| { |
| 251 | 251 | const base_addr = (try Value.fromInterned(elem.base).getUnsignedIntAdvanced(mod, opt_sema)) orelse return null; |
| 252 | const elem_ty = Type.fromInterned(mod.intern_pool.typeOf(elem.base)).elemType2(mod); | |
| 252 | const elem_ty = Value.fromInterned(elem.base).typeOf(mod).elemType2(mod); | |
| 253 | 253 | return base_addr + elem.index * elem_ty.abiSize(mod); |
| 254 | 254 | }, |
| 255 | 255 | .field => |field| { |
| 256 | 256 | const base_addr = (try Value.fromInterned(field.base).getUnsignedIntAdvanced(mod, opt_sema)) orelse return null; |
| 257 | const struct_ty = Type.fromInterned(mod.intern_pool.typeOf(field.base)).childType(mod); | |
| 257 | const struct_ty = Value.fromInterned(field.base).typeOf(mod).childType(mod); | |
| 258 | 258 | if (opt_sema) |sema| try sema.resolveTypeLayout(struct_ty); |
| 259 | 259 | return base_addr + struct_ty.structFieldOffset(@as(usize, @intCast(field.index)), mod); |
| 260 | 260 | }, |
| ... | ... | @@ -1390,7 +1390,7 @@ pub fn elemPtr( |
| 1390 | 1390 | }; |
| 1391 | 1391 | switch (mod.intern_pool.indexToKey(ptr_val.toIntern())) { |
| 1392 | 1392 | .ptr => |ptr| switch (ptr.addr) { |
| 1393 | .elem => |elem| if (Type.fromInterned(mod.intern_pool.typeOf(elem.base)).elemType2(mod).eql(elem_ty, mod)) | |
| 1393 | .elem => |elem| if (Value.fromInterned(elem.base).typeOf(mod).elemType2(mod).eql(elem_ty, mod)) | |
| 1394 | 1394 | return Value.fromInterned((try mod.intern(.{ .ptr = .{ |
| 1395 | 1395 | .ty = elem_ptr_ty.toIntern(), |
| 1396 | 1396 | .addr = .{ .elem = .{ |
src/arch/aarch64/CodeGen.zig+3-7| ... | ... | @@ -10,7 +10,6 @@ const Emit = @import("Emit.zig"); |
| 10 | 10 | const Liveness = @import("../../Liveness.zig"); |
| 11 | 11 | const Type = @import("../../type.zig").Type; |
| 12 | 12 | const Value = @import("../../Value.zig"); |
| 13 | const TypedValue = @import("../../TypedValue.zig"); | |
| 14 | 13 | const link = @import("../../link.zig"); |
| 15 | 14 | const Module = @import("../../Module.zig"); |
| 16 | 15 | const InternPool = @import("../../InternPool.zig"); |
| ... | ... | @@ -6143,10 +6142,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue { |
| 6143 | 6142 | if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod) and !inst_ty.isError(mod)) |
| 6144 | 6143 | return MCValue{ .none = {} }; |
| 6145 | 6144 | |
| 6146 | const inst_index = inst.toIndex() orelse return self.genTypedValue(.{ | |
| 6147 | .ty = inst_ty, | |
| 6148 | .val = (try self.air.value(inst, mod)).?, | |
| 6149 | }); | |
| 6145 | const inst_index = inst.toIndex() orelse return self.genTypedValue((try self.air.value(inst, mod)).?); | |
| 6150 | 6146 | |
| 6151 | 6147 | return self.getResolvedInstValue(inst_index); |
| 6152 | 6148 | } |
| ... | ... | @@ -6163,11 +6159,11 @@ fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) MCValue { |
| 6163 | 6159 | } |
| 6164 | 6160 | } |
| 6165 | 6161 | |
| 6166 | fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue { | |
| 6162 | fn genTypedValue(self: *Self, val: Value) InnerError!MCValue { | |
| 6167 | 6163 | const mcv: MCValue = switch (try codegen.genTypedValue( |
| 6168 | 6164 | self.bin_file, |
| 6169 | 6165 | self.src_loc, |
| 6170 | arg_tv, | |
| 6166 | val, | |
| 6171 | 6167 | self.owner_decl, |
| 6172 | 6168 | )) { |
| 6173 | 6169 | .mcv => |mcv| switch (mcv) { |
src/arch/arm/CodeGen.zig+3-7| ... | ... | @@ -10,7 +10,6 @@ const Emit = @import("Emit.zig"); |
| 10 | 10 | const Liveness = @import("../../Liveness.zig"); |
| 11 | 11 | const Type = @import("../../type.zig").Type; |
| 12 | 12 | const Value = @import("../../Value.zig"); |
| 13 | const TypedValue = @import("../../TypedValue.zig"); | |
| 14 | 13 | const link = @import("../../link.zig"); |
| 15 | 14 | const Module = @import("../../Module.zig"); |
| 16 | 15 | const InternPool = @import("../../InternPool.zig"); |
| ... | ... | @@ -6097,10 +6096,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue { |
| 6097 | 6096 | if (!inst_ty.hasRuntimeBitsIgnoreComptime(mod) and !inst_ty.isError(mod)) |
| 6098 | 6097 | return MCValue{ .none = {} }; |
| 6099 | 6098 | |
| 6100 | const inst_index = inst.toIndex() orelse return self.genTypedValue(.{ | |
| 6101 | .ty = inst_ty, | |
| 6102 | .val = (try self.air.value(inst, mod)).?, | |
| 6103 | }); | |
| 6099 | const inst_index = inst.toIndex() orelse return self.genTypedValue((try self.air.value(inst, mod)).?); | |
| 6104 | 6100 | |
| 6105 | 6101 | return self.getResolvedInstValue(inst_index); |
| 6106 | 6102 | } |
| ... | ... | @@ -6117,12 +6113,12 @@ fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) MCValue { |
| 6117 | 6113 | } |
| 6118 | 6114 | } |
| 6119 | 6115 | |
| 6120 | fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue { | |
| 6116 | fn genTypedValue(self: *Self, val: Value) InnerError!MCValue { | |
| 6121 | 6117 | const mod = self.bin_file.comp.module.?; |
| 6122 | 6118 | const mcv: MCValue = switch (try codegen.genTypedValue( |
| 6123 | 6119 | self.bin_file, |
| 6124 | 6120 | self.src_loc, |
| 6125 | arg_tv, | |
| 6121 | val, | |
| 6126 | 6122 | mod.funcOwnerDeclIndex(self.func_index), |
| 6127 | 6123 | )) { |
| 6128 | 6124 | .mcv => |mcv| switch (mcv) { |
src/arch/riscv64/CodeGen.zig+3-7| ... | ... | @@ -9,7 +9,6 @@ const Emit = @import("Emit.zig"); |
| 9 | 9 | const Liveness = @import("../../Liveness.zig"); |
| 10 | 10 | const Type = @import("../../type.zig").Type; |
| 11 | 11 | const Value = @import("../../Value.zig"); |
| 12 | const TypedValue = @import("../../TypedValue.zig"); | |
| 13 | 12 | const link = @import("../../link.zig"); |
| 14 | 13 | const Module = @import("../../Module.zig"); |
| 15 | 14 | const InternPool = @import("../../InternPool.zig"); |
| ... | ... | @@ -2552,10 +2551,7 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue { |
| 2552 | 2551 | if (!inst_ty.hasRuntimeBits(mod)) |
| 2553 | 2552 | return MCValue{ .none = {} }; |
| 2554 | 2553 | |
| 2555 | const inst_index = inst.toIndex() orelse return self.genTypedValue(.{ | |
| 2556 | .ty = inst_ty, | |
| 2557 | .val = (try self.air.value(inst, mod)).?, | |
| 2558 | }); | |
| 2554 | const inst_index = inst.toIndex() orelse return self.genTypedValue((try self.air.value(inst, mod)).?); | |
| 2559 | 2555 | |
| 2560 | 2556 | return self.getResolvedInstValue(inst_index); |
| 2561 | 2557 | } |
| ... | ... | @@ -2572,12 +2568,12 @@ fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) MCValue { |
| 2572 | 2568 | } |
| 2573 | 2569 | } |
| 2574 | 2570 | |
| 2575 | fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue { | |
| 2571 | fn genTypedValue(self: *Self, val: Value) InnerError!MCValue { | |
| 2576 | 2572 | const mod = self.bin_file.comp.module.?; |
| 2577 | 2573 | const mcv: MCValue = switch (try codegen.genTypedValue( |
| 2578 | 2574 | self.bin_file, |
| 2579 | 2575 | self.src_loc, |
| 2580 | typed_value, | |
| 2576 | val, | |
| 2581 | 2577 | mod.funcOwnerDeclIndex(self.func_index), |
| 2582 | 2578 | )) { |
| 2583 | 2579 | .mcv => |mcv| switch (mcv) { |
src/arch/sparc64/CodeGen.zig+4-7| ... | ... | @@ -12,7 +12,7 @@ const builtin = @import("builtin"); |
| 12 | 12 | const link = @import("../../link.zig"); |
| 13 | 13 | const Module = @import("../../Module.zig"); |
| 14 | 14 | const InternPool = @import("../../InternPool.zig"); |
| 15 | const TypedValue = @import("../../TypedValue.zig"); | |
| 15 | const Value = @import("../../Value.zig"); | |
| 16 | 16 | const ErrorMsg = Module.ErrorMsg; |
| 17 | 17 | const codegen = @import("../../codegen.zig"); |
| 18 | 18 | const Air = @import("../../Air.zig"); |
| ... | ... | @@ -4118,12 +4118,12 @@ fn genStoreASI(self: *Self, value_reg: Register, addr_reg: Register, off_reg: Re |
| 4118 | 4118 | } |
| 4119 | 4119 | } |
| 4120 | 4120 | |
| 4121 | fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue { | |
| 4121 | fn genTypedValue(self: *Self, val: Value) InnerError!MCValue { | |
| 4122 | 4122 | const mod = self.bin_file.comp.module.?; |
| 4123 | 4123 | const mcv: MCValue = switch (try codegen.genTypedValue( |
| 4124 | 4124 | self.bin_file, |
| 4125 | 4125 | self.src_loc, |
| 4126 | typed_value, | |
| 4126 | val, | |
| 4127 | 4127 | mod.funcOwnerDeclIndex(self.func_index), |
| 4128 | 4128 | )) { |
| 4129 | 4129 | .mcv => |mcv| switch (mcv) { |
| ... | ... | @@ -4546,10 +4546,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue { |
| 4546 | 4546 | return self.getResolvedInstValue(inst); |
| 4547 | 4547 | } |
| 4548 | 4548 | |
| 4549 | return self.genTypedValue(.{ | |
| 4550 | .ty = ty, | |
| 4551 | .val = (try self.air.value(ref, mod)).?, | |
| 4552 | }); | |
| 4549 | return self.genTypedValue((try self.air.value(ref, mod)).?); | |
| 4553 | 4550 | } |
| 4554 | 4551 | |
| 4555 | 4552 | fn ret(self: *Self, mcv: MCValue) !void { |
src/arch/wasm/CodeGen.zig+14-18| ... | ... | @@ -18,7 +18,6 @@ const Value = @import("../../Value.zig"); |
| 18 | 18 | const Compilation = @import("../../Compilation.zig"); |
| 19 | 19 | const LazySrcLoc = std.zig.LazySrcLoc; |
| 20 | 20 | const link = @import("../../link.zig"); |
| 21 | const TypedValue = @import("../../TypedValue.zig"); | |
| 22 | 21 | const Air = @import("../../Air.zig"); |
| 23 | 22 | const Liveness = @import("../../Liveness.zig"); |
| 24 | 23 | const target_util = @import("../../target.zig"); |
| ... | ... | @@ -805,7 +804,7 @@ fn resolveInst(func: *CodeGen, ref: Air.Inst.Ref) InnerError!WValue { |
| 805 | 804 | // In the other cases, we will simply lower the constant to a value that fits |
| 806 | 805 | // into a single local (such as a pointer, integer, bool, etc). |
| 807 | 806 | const result = if (isByRef(ty, mod)) blk: { |
| 808 | const sym_index = try func.bin_file.lowerUnnamedConst(.{ .ty = ty, .val = val }, func.decl_index); | |
| 807 | const sym_index = try func.bin_file.lowerUnnamedConst(val, func.decl_index); | |
| 809 | 808 | break :blk WValue{ .memory = sym_index }; |
| 810 | 809 | } else try func.lowerConstant(val, ty); |
| 811 | 810 | |
| ... | ... | @@ -3119,10 +3118,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue |
| 3119 | 3118 | } |
| 3120 | 3119 | |
| 3121 | 3120 | fn lowerParentPtrDecl(func: *CodeGen, ptr_val: Value, decl_index: InternPool.DeclIndex, offset: u32) InnerError!WValue { |
| 3122 | const mod = func.bin_file.base.comp.module.?; | |
| 3123 | const decl = mod.declPtr(decl_index); | |
| 3124 | const ptr_ty = try mod.singleMutPtrType(decl.typeOf(mod)); | |
| 3125 | return func.lowerDeclRefValue(.{ .ty = ptr_ty, .val = ptr_val }, decl_index, offset); | |
| 3121 | return func.lowerDeclRefValue(ptr_val, decl_index, offset); | |
| 3126 | 3122 | } |
| 3127 | 3123 | |
| 3128 | 3124 | fn lowerAnonDeclRef( |
| ... | ... | @@ -3157,7 +3153,7 @@ fn lowerAnonDeclRef( |
| 3157 | 3153 | } else return WValue{ .memory_offset = .{ .pointer = target_sym_index, .offset = offset } }; |
| 3158 | 3154 | } |
| 3159 | 3155 | |
| 3160 | fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: InternPool.DeclIndex, offset: u32) InnerError!WValue { | |
| 3156 | fn lowerDeclRefValue(func: *CodeGen, val: Value, decl_index: InternPool.DeclIndex, offset: u32) InnerError!WValue { | |
| 3161 | 3157 | const mod = func.bin_file.base.comp.module.?; |
| 3162 | 3158 | |
| 3163 | 3159 | const decl = mod.declPtr(decl_index); |
| ... | ... | @@ -3165,11 +3161,11 @@ fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: InternPool.Decl |
| 3165 | 3161 | // want to lower the actual decl, rather than the alias itself. |
| 3166 | 3162 | if (decl.val.getFunction(mod)) |func_val| { |
| 3167 | 3163 | if (func_val.owner_decl != decl_index) { |
| 3168 | return func.lowerDeclRefValue(tv, func_val.owner_decl, offset); | |
| 3164 | return func.lowerDeclRefValue(val, func_val.owner_decl, offset); | |
| 3169 | 3165 | } |
| 3170 | 3166 | } else if (decl.val.getExternFunc(mod)) |func_val| { |
| 3171 | 3167 | if (func_val.decl != decl_index) { |
| 3172 | return func.lowerDeclRefValue(tv, func_val.decl, offset); | |
| 3168 | return func.lowerDeclRefValue(val, func_val.decl, offset); | |
| 3173 | 3169 | } |
| 3174 | 3170 | } |
| 3175 | 3171 | const decl_ty = decl.typeOf(mod); |
| ... | ... | @@ -3280,23 +3276,23 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue { |
| 3280 | 3276 | }, |
| 3281 | 3277 | .error_union => |error_union| { |
| 3282 | 3278 | const err_int_ty = try mod.errorIntType(); |
| 3283 | const err_tv: TypedValue = switch (error_union.val) { | |
| 3279 | const err_ty, const err_val = switch (error_union.val) { | |
| 3284 | 3280 | .err_name => |err_name| .{ |
| 3285 | .ty = ty.errorUnionSet(mod), | |
| 3286 | .val = Value.fromInterned((try mod.intern(.{ .err = .{ | |
| 3281 | ty.errorUnionSet(mod), | |
| 3282 | Value.fromInterned((try mod.intern(.{ .err = .{ | |
| 3287 | 3283 | .ty = ty.errorUnionSet(mod).toIntern(), |
| 3288 | 3284 | .name = err_name, |
| 3289 | 3285 | } }))), |
| 3290 | 3286 | }, |
| 3291 | 3287 | .payload => .{ |
| 3292 | .ty = err_int_ty, | |
| 3293 | .val = try mod.intValue(err_int_ty, 0), | |
| 3288 | err_int_ty, | |
| 3289 | try mod.intValue(err_int_ty, 0), | |
| 3294 | 3290 | }, |
| 3295 | 3291 | }; |
| 3296 | 3292 | const payload_type = ty.errorUnionPayload(mod); |
| 3297 | 3293 | if (!payload_type.hasRuntimeBitsIgnoreComptime(mod)) { |
| 3298 | 3294 | // We use the error type directly as the type. |
| 3299 | return func.lowerConstant(err_tv.val, err_tv.ty); | |
| 3295 | return func.lowerConstant(err_val, err_ty); | |
| 3300 | 3296 | } |
| 3301 | 3297 | |
| 3302 | 3298 | return func.fail("Wasm TODO: lowerConstant error union with non-zero-bit payload type", .{}); |
| ... | ... | @@ -3320,10 +3316,10 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue { |
| 3320 | 3316 | .elem, .field => |base_index| ptr = ip.indexToKey(base_index.base).ptr, |
| 3321 | 3317 | .comptime_field, .comptime_alloc => unreachable, |
| 3322 | 3318 | }; |
| 3323 | return .{ .memory = try func.bin_file.lowerUnnamedConst(.{ .ty = ty, .val = val }, owner_decl) }; | |
| 3319 | return .{ .memory = try func.bin_file.lowerUnnamedConst(val, owner_decl) }; | |
| 3324 | 3320 | }, |
| 3325 | 3321 | .ptr => |ptr| switch (ptr.addr) { |
| 3326 | .decl => |decl| return func.lowerDeclRefValue(.{ .ty = ty, .val = val }, decl, 0), | |
| 3322 | .decl => |decl| return func.lowerDeclRefValue(val, decl, 0), | |
| 3327 | 3323 | .int => |int| return func.lowerConstant(Value.fromInterned(int), Type.fromInterned(ip.typeOf(int))), |
| 3328 | 3324 | .opt_payload, .elem, .field => return func.lowerParentPtr(val, 0), |
| 3329 | 3325 | .anon_decl => |ad| return func.lowerAnonDeclRef(ad, 0), |
| ... | ... | @@ -7285,7 +7281,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { |
| 7285 | 7281 | .storage = .{ .bytes = tag_name }, |
| 7286 | 7282 | } }); |
| 7287 | 7283 | const tag_sym_index = try func.bin_file.lowerUnnamedConst( |
| 7288 | .{ .ty = name_ty, .val = Value.fromInterned(name_val) }, | |
| 7284 | Value.fromInterned(name_val), | |
| 7289 | 7285 | enum_decl_index, |
| 7290 | 7286 | ); |
| 7291 | 7287 |
src/arch/x86_64/CodeGen.zig+38-63| ... | ... | @@ -32,7 +32,6 @@ const InternPool = @import("../../InternPool.zig"); |
| 32 | 32 | const Alignment = InternPool.Alignment; |
| 33 | 33 | const Target = std.Target; |
| 34 | 34 | const Type = @import("../../type.zig").Type; |
| 35 | const TypedValue = @import("../../TypedValue.zig"); | |
| 36 | 35 | const Value = @import("../../Value.zig"); |
| 37 | 36 | const Instruction = @import("encoder.zig").Instruction; |
| 38 | 37 | |
| ... | ... | @@ -2250,7 +2249,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void { |
| 2250 | 2249 | for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, tag_index| { |
| 2251 | 2250 | const tag_name_len = ip.stringToSlice(tag_names.get(ip)[tag_index]).len; |
| 2252 | 2251 | const tag_val = try mod.enumValueFieldIndex(enum_ty, @intCast(tag_index)); |
| 2253 | const tag_mcv = try self.genTypedValue(.{ .ty = enum_ty, .val = tag_val }); | |
| 2252 | const tag_mcv = try self.genTypedValue(tag_val); | |
| 2254 | 2253 | try self.genBinOpMir(.{ ._, .cmp }, enum_ty, enum_mcv, tag_mcv); |
| 2255 | 2254 | const skip_reloc = try self.asmJccReloc(.ne, undefined); |
| 2256 | 2255 | |
| ... | ... | @@ -3323,7 +3322,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void { |
| 3323 | 3322 | .storage = .{ .repeated_elem = mask_val.ip_index }, |
| 3324 | 3323 | } }); |
| 3325 | 3324 | |
| 3326 | const splat_mcv = try self.genTypedValue(.{ .ty = splat_ty, .val = Value.fromInterned(splat_val) }); | |
| 3325 | const splat_mcv = try self.genTypedValue(Value.fromInterned(splat_val)); | |
| 3327 | 3326 | const splat_addr_mcv: MCValue = switch (splat_mcv) { |
| 3328 | 3327 | .memory, .indirect, .load_frame => splat_mcv.address(), |
| 3329 | 3328 | else => .{ .register = try self.copyToTmpRegister(Type.usize, splat_mcv.address()) }, |
| ... | ... | @@ -4992,17 +4991,14 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void { |
| 4992 | 4991 | defer self.register_manager.unlockReg(shift_lock); |
| 4993 | 4992 | |
| 4994 | 4993 | const mask_ty = try mod.vectorType(.{ .len = 16, .child = .u8_type }); |
| 4995 | const mask_mcv = try self.genTypedValue(.{ | |
| 4996 | .ty = mask_ty, | |
| 4997 | .val = Value.fromInterned((try mod.intern(.{ .aggregate = .{ | |
| 4998 | .ty = mask_ty.toIntern(), | |
| 4999 | .storage = .{ .elems = &([1]InternPool.Index{ | |
| 5000 | (try rhs_ty.childType(mod).maxIntScalar(mod, Type.u8)).toIntern(), | |
| 5001 | } ++ [1]InternPool.Index{ | |
| 5002 | (try mod.intValue(Type.u8, 0)).toIntern(), | |
| 5003 | } ** 15) }, | |
| 5004 | } }))), | |
| 5005 | }); | |
| 4994 | const mask_mcv = try self.genTypedValue(Value.fromInterned(try mod.intern(.{ .aggregate = .{ | |
| 4995 | .ty = mask_ty.toIntern(), | |
| 4996 | .storage = .{ .elems = &([1]InternPool.Index{ | |
| 4997 | (try rhs_ty.childType(mod).maxIntScalar(mod, Type.u8)).toIntern(), | |
| 4998 | } ++ [1]InternPool.Index{ | |
| 4999 | (try mod.intValue(Type.u8, 0)).toIntern(), | |
| 5000 | } ** 15) }, | |
| 5001 | } }))); | |
| 5006 | 5002 | const mask_addr_reg = |
| 5007 | 5003 | try self.copyToTmpRegister(Type.usize, mask_mcv.address()); |
| 5008 | 5004 | const mask_addr_lock = self.register_manager.lockRegAssumeUnused(mask_addr_reg); |
| ... | ... | @@ -6860,11 +6856,11 @@ fn floatSign(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type) |
| 6860 | 6856 | .child = (try mod.intType(.signed, scalar_bits)).ip_index, |
| 6861 | 6857 | }); |
| 6862 | 6858 | |
| 6863 | const sign_mcv = try self.genTypedValue(.{ .ty = vec_ty, .val = switch (tag) { | |
| 6859 | const sign_mcv = try self.genTypedValue(switch (tag) { | |
| 6864 | 6860 | .neg => try vec_ty.minInt(mod, vec_ty), |
| 6865 | 6861 | .abs => try vec_ty.maxInt(mod, vec_ty), |
| 6866 | 6862 | else => unreachable, |
| 6867 | } }); | |
| 6863 | }); | |
| 6868 | 6864 | const sign_mem: Memory = if (sign_mcv.isMemory()) |
| 6869 | 6865 | try sign_mcv.mem(self, Memory.Size.fromSize(abi_size)) |
| 6870 | 6866 | else |
| ... | ... | @@ -11130,10 +11126,7 @@ fn genBinOp( |
| 11130 | 11126 | .cmp_neq, |
| 11131 | 11127 | => { |
| 11132 | 11128 | const unsigned_ty = try lhs_ty.toUnsigned(mod); |
| 11133 | const not_mcv = try self.genTypedValue(.{ | |
| 11134 | .ty = lhs_ty, | |
| 11135 | .val = try unsigned_ty.maxInt(mod, unsigned_ty), | |
| 11136 | }); | |
| 11129 | const not_mcv = try self.genTypedValue(try unsigned_ty.maxInt(mod, unsigned_ty)); | |
| 11137 | 11130 | const not_mem: Memory = if (not_mcv.isMemory()) |
| 11138 | 11131 | try not_mcv.mem(self, Memory.Size.fromSize(abi_size)) |
| 11139 | 11132 | else |
| ... | ... | @@ -14692,10 +14685,7 @@ fn genSetReg( |
| 14692 | 14685 | ), |
| 14693 | 14686 | else => unreachable, |
| 14694 | 14687 | }, |
| 14695 | .segment, .x87, .mmx, .sse => try self.genSetReg(dst_reg, ty, try self.genTypedValue(.{ | |
| 14696 | .ty = ty, | |
| 14697 | .val = try mod.undefValue(ty), | |
| 14698 | }), opts), | |
| 14688 | .segment, .x87, .mmx, .sse => try self.genSetReg(dst_reg, ty, try self.genTypedValue(try mod.undefValue(ty)), opts), | |
| 14699 | 14689 | }, |
| 14700 | 14690 | .eflags => |cc| try self.asmSetccRegister(cc, dst_reg.to8()), |
| 14701 | 14691 | .immediate => |imm| { |
| ... | ... | @@ -16893,13 +16883,10 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void { |
| 16893 | 16883 | .ty = mask_elem_ty.toIntern(), |
| 16894 | 16884 | .storage = .{ .u64 = bit / elem_bits }, |
| 16895 | 16885 | } }); |
| 16896 | const mask_mcv = try self.genTypedValue(.{ | |
| 16897 | .ty = mask_ty, | |
| 16898 | .val = Value.fromInterned(try mod.intern(.{ .aggregate = .{ | |
| 16899 | .ty = mask_ty.toIntern(), | |
| 16900 | .storage = .{ .elems = mask_elems[0..vec_len] }, | |
| 16901 | } })), | |
| 16902 | }); | |
| 16886 | const mask_mcv = try self.genTypedValue(Value.fromInterned(try mod.intern(.{ .aggregate = .{ | |
| 16887 | .ty = mask_ty.toIntern(), | |
| 16888 | .storage = .{ .elems = mask_elems[0..vec_len] }, | |
| 16889 | } }))); | |
| 16903 | 16890 | const mask_mem: Memory = .{ |
| 16904 | 16891 | .base = .{ .reg = try self.copyToTmpRegister(Type.usize, mask_mcv.address()) }, |
| 16905 | 16892 | .mod = .{ .rm = .{ .size = self.memSize(ty) } }, |
| ... | ... | @@ -16921,13 +16908,10 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void { |
| 16921 | 16908 | .ty = mask_elem_ty.toIntern(), |
| 16922 | 16909 | .storage = .{ .u64 = @as(u32, 1) << @intCast(bit & (elem_bits - 1)) }, |
| 16923 | 16910 | } }); |
| 16924 | const mask_mcv = try self.genTypedValue(.{ | |
| 16925 | .ty = mask_ty, | |
| 16926 | .val = Value.fromInterned(try mod.intern(.{ .aggregate = .{ | |
| 16927 | .ty = mask_ty.toIntern(), | |
| 16928 | .storage = .{ .elems = mask_elems[0..vec_len] }, | |
| 16929 | } })), | |
| 16930 | }); | |
| 16911 | const mask_mcv = try self.genTypedValue(Value.fromInterned(try mod.intern(.{ .aggregate = .{ | |
| 16912 | .ty = mask_ty.toIntern(), | |
| 16913 | .storage = .{ .elems = mask_elems[0..vec_len] }, | |
| 16914 | } }))); | |
| 16931 | 16915 | const mask_mem: Memory = .{ |
| 16932 | 16916 | .base = .{ .reg = try self.copyToTmpRegister(Type.usize, mask_mcv.address()) }, |
| 16933 | 16917 | .mod = .{ .rm = .{ .size = self.memSize(ty) } }, |
| ... | ... | @@ -17658,13 +17642,10 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void { |
| 17658 | 17642 | else |
| 17659 | 17643 | try select_mask_elem_ty.minIntScalar(mod, select_mask_elem_ty)).toIntern(); |
| 17660 | 17644 | } |
| 17661 | const select_mask_mcv = try self.genTypedValue(.{ | |
| 17662 | .ty = select_mask_ty, | |
| 17663 | .val = Value.fromInterned(try mod.intern(.{ .aggregate = .{ | |
| 17664 | .ty = select_mask_ty.toIntern(), | |
| 17665 | .storage = .{ .elems = select_mask_elems[0..mask_elems.len] }, | |
| 17666 | } })), | |
| 17667 | }); | |
| 17645 | const select_mask_mcv = try self.genTypedValue(Value.fromInterned(try mod.intern(.{ .aggregate = .{ | |
| 17646 | .ty = select_mask_ty.toIntern(), | |
| 17647 | .storage = .{ .elems = select_mask_elems[0..mask_elems.len] }, | |
| 17648 | } }))); | |
| 17668 | 17649 | |
| 17669 | 17650 | if (self.hasFeature(.sse4_1)) { |
| 17670 | 17651 | const mir_tag: Mir.Inst.FixedTag = .{ |
| ... | ... | @@ -17809,13 +17790,10 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void { |
| 17809 | 17790 | } }); |
| 17810 | 17791 | } |
| 17811 | 17792 | const lhs_mask_ty = try mod.vectorType(.{ .len = max_abi_size, .child = .u8_type }); |
| 17812 | const lhs_mask_mcv = try self.genTypedValue(.{ | |
| 17813 | .ty = lhs_mask_ty, | |
| 17814 | .val = Value.fromInterned(try mod.intern(.{ .aggregate = .{ | |
| 17815 | .ty = lhs_mask_ty.toIntern(), | |
| 17816 | .storage = .{ .elems = lhs_mask_elems[0..max_abi_size] }, | |
| 17817 | } })), | |
| 17818 | }); | |
| 17793 | const lhs_mask_mcv = try self.genTypedValue(Value.fromInterned(try mod.intern(.{ .aggregate = .{ | |
| 17794 | .ty = lhs_mask_ty.toIntern(), | |
| 17795 | .storage = .{ .elems = lhs_mask_elems[0..max_abi_size] }, | |
| 17796 | } }))); | |
| 17819 | 17797 | const lhs_mask_mem: Memory = .{ |
| 17820 | 17798 | .base = .{ .reg = try self.copyToTmpRegister(Type.usize, lhs_mask_mcv.address()) }, |
| 17821 | 17799 | .mod = .{ .rm = .{ .size = Memory.Size.fromSize(@max(max_abi_size, 16)) } }, |
| ... | ... | @@ -17846,13 +17824,10 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void { |
| 17846 | 17824 | } }); |
| 17847 | 17825 | } |
| 17848 | 17826 | const rhs_mask_ty = try mod.vectorType(.{ .len = max_abi_size, .child = .u8_type }); |
| 17849 | const rhs_mask_mcv = try self.genTypedValue(.{ | |
| 17850 | .ty = rhs_mask_ty, | |
| 17851 | .val = Value.fromInterned(try mod.intern(.{ .aggregate = .{ | |
| 17852 | .ty = rhs_mask_ty.toIntern(), | |
| 17853 | .storage = .{ .elems = rhs_mask_elems[0..max_abi_size] }, | |
| 17854 | } })), | |
| 17855 | }); | |
| 17827 | const rhs_mask_mcv = try self.genTypedValue(Value.fromInterned(try mod.intern(.{ .aggregate = .{ | |
| 17828 | .ty = rhs_mask_ty.toIntern(), | |
| 17829 | .storage = .{ .elems = rhs_mask_elems[0..max_abi_size] }, | |
| 17830 | } }))); | |
| 17856 | 17831 | const rhs_mask_mem: Memory = .{ |
| 17857 | 17832 | .base = .{ .reg = try self.copyToTmpRegister(Type.usize, rhs_mask_mcv.address()) }, |
| 17858 | 17833 | .mod = .{ .rm = .{ .size = Memory.Size.fromSize(@max(max_abi_size, 16)) } }, |
| ... | ... | @@ -18138,7 +18113,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { |
| 18138 | 18113 | .{ .frame = frame_index }, |
| 18139 | 18114 | @intCast(elem_size * elements.len), |
| 18140 | 18115 | elem_ty, |
| 18141 | try self.genTypedValue(.{ .ty = elem_ty, .val = sentinel }), | |
| 18116 | try self.genTypedValue(sentinel), | |
| 18142 | 18117 | .{}, |
| 18143 | 18118 | ); |
| 18144 | 18119 | break :result .{ .load_frame = .{ .index = frame_index } }; |
| ... | ... | @@ -18662,7 +18637,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue { |
| 18662 | 18637 | const ip_index = ref.toInterned().?; |
| 18663 | 18638 | const gop = try self.const_tracking.getOrPut(self.gpa, ip_index); |
| 18664 | 18639 | if (!gop.found_existing) gop.value_ptr.* = InstTracking.init(init: { |
| 18665 | const const_mcv = try self.genTypedValue(.{ .ty = ty, .val = Value.fromInterned(ip_index) }); | |
| 18640 | const const_mcv = try self.genTypedValue(Value.fromInterned(ip_index)); | |
| 18666 | 18641 | switch (const_mcv) { |
| 18667 | 18642 | .lea_tlv => |tlv_sym| switch (self.bin_file.tag) { |
| 18668 | 18643 | .elf, .macho => { |
| ... | ... | @@ -18727,9 +18702,9 @@ fn limitImmediateType(self: *Self, operand: Air.Inst.Ref, comptime T: type) !MCV |
| 18727 | 18702 | return mcv; |
| 18728 | 18703 | } |
| 18729 | 18704 | |
| 18730 | fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue { | |
| 18705 | fn genTypedValue(self: *Self, val: Value) InnerError!MCValue { | |
| 18731 | 18706 | const mod = self.bin_file.comp.module.?; |
| 18732 | return switch (try codegen.genTypedValue(self.bin_file, self.src_loc, arg_tv, self.owner.getDecl(mod))) { | |
| 18707 | return switch (try codegen.genTypedValue(self.bin_file, self.src_loc, val, self.owner.getDecl(mod))) { | |
| 18733 | 18708 | .mcv => |mcv| switch (mcv) { |
| 18734 | 18709 | .none => .none, |
| 18735 | 18710 | .undef => .undef, |
src/codegen.zig+120-168| ... | ... | @@ -19,7 +19,6 @@ const Liveness = @import("Liveness.zig"); |
| 19 | 19 | const Module = @import("Module.zig"); |
| 20 | 20 | const Target = std.Target; |
| 21 | 21 | const Type = @import("type.zig").Type; |
| 22 | const TypedValue = @import("TypedValue.zig"); | |
| 23 | 22 | const Value = @import("Value.zig"); |
| 24 | 23 | const Zir = std.zig.Zir; |
| 25 | 24 | const Alignment = InternPool.Alignment; |
| ... | ... | @@ -171,7 +170,7 @@ pub fn generateLazySymbol( |
| 171 | 170 | pub fn generateSymbol( |
| 172 | 171 | bin_file: *link.File, |
| 173 | 172 | src_loc: Module.SrcLoc, |
| 174 | arg_tv: TypedValue, | |
| 173 | val: Value, | |
| 175 | 174 | code: *std.ArrayList(u8), |
| 176 | 175 | debug_output: DebugInfoOutput, |
| 177 | 176 | reloc_info: RelocInfo, |
| ... | ... | @@ -181,23 +180,22 @@ pub fn generateSymbol( |
| 181 | 180 | |
| 182 | 181 | const mod = bin_file.comp.module.?; |
| 183 | 182 | const ip = &mod.intern_pool; |
| 184 | const typed_value = arg_tv; | |
| 183 | const ty = val.typeOf(mod); | |
| 185 | 184 | |
| 186 | 185 | const target = mod.getTarget(); |
| 187 | 186 | const endian = target.cpu.arch.endian(); |
| 188 | 187 | |
| 189 | log.debug("generateSymbol: ty = {}, val = {}", .{ | |
| 190 | typed_value.ty.fmt(mod), | |
| 191 | typed_value.val.fmtValue(typed_value.ty, mod), | |
| 188 | log.debug("generateSymbol: val = {}", .{ | |
| 189 | val.fmtValue(ty, mod), | |
| 192 | 190 | }); |
| 193 | 191 | |
| 194 | if (typed_value.val.isUndefDeep(mod)) { | |
| 195 | const abi_size = math.cast(usize, typed_value.ty.abiSize(mod)) orelse return error.Overflow; | |
| 192 | if (val.isUndefDeep(mod)) { | |
| 193 | const abi_size = math.cast(usize, ty.abiSize(mod)) orelse return error.Overflow; | |
| 196 | 194 | try code.appendNTimes(0xaa, abi_size); |
| 197 | 195 | return .ok; |
| 198 | 196 | } |
| 199 | 197 | |
| 200 | switch (ip.indexToKey(typed_value.val.toIntern())) { | |
| 198 | switch (ip.indexToKey(val.toIntern())) { | |
| 201 | 199 | .int_type, |
| 202 | 200 | .ptr_type, |
| 203 | 201 | .array_type, |
| ... | ... | @@ -238,17 +236,17 @@ pub fn generateSymbol( |
| 238 | 236 | .empty_enum_value, |
| 239 | 237 | => unreachable, // non-runtime values |
| 240 | 238 | .int => { |
| 241 | const abi_size = math.cast(usize, typed_value.ty.abiSize(mod)) orelse return error.Overflow; | |
| 239 | const abi_size = math.cast(usize, ty.abiSize(mod)) orelse return error.Overflow; | |
| 242 | 240 | var space: Value.BigIntSpace = undefined; |
| 243 | const val = typed_value.val.toBigInt(&space, mod); | |
| 244 | val.writeTwosComplement(try code.addManyAsSlice(abi_size), endian); | |
| 241 | const int_val = val.toBigInt(&space, mod); | |
| 242 | int_val.writeTwosComplement(try code.addManyAsSlice(abi_size), endian); | |
| 245 | 243 | }, |
| 246 | 244 | .err => |err| { |
| 247 | 245 | const int = try mod.getErrorValue(err.name); |
| 248 | 246 | try code.writer().writeInt(u16, @as(u16, @intCast(int)), endian); |
| 249 | 247 | }, |
| 250 | 248 | .error_union => |error_union| { |
| 251 | const payload_ty = typed_value.ty.errorUnionPayload(mod); | |
| 249 | const payload_ty = ty.errorUnionPayload(mod); | |
| 252 | 250 | const err_val = switch (error_union.val) { |
| 253 | 251 | .err_name => |err_name| @as(u16, @intCast(try mod.getErrorValue(err_name))), |
| 254 | 252 | .payload => @as(u16, 0), |
| ... | ... | @@ -261,7 +259,7 @@ pub fn generateSymbol( |
| 261 | 259 | |
| 262 | 260 | const payload_align = payload_ty.abiAlignment(mod); |
| 263 | 261 | const error_align = Type.anyerror.abiAlignment(mod); |
| 264 | const abi_align = typed_value.ty.abiAlignment(mod); | |
| 262 | const abi_align = ty.abiAlignment(mod); | |
| 265 | 263 | |
| 266 | 264 | // error value first when its type is larger than the error union's payload |
| 267 | 265 | if (error_align.order(payload_align) == .gt) { |
| ... | ... | @@ -271,13 +269,10 @@ pub fn generateSymbol( |
| 271 | 269 | // emit payload part of the error union |
| 272 | 270 | { |
| 273 | 271 | const begin = code.items.len; |
| 274 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 275 | .ty = payload_ty, | |
| 276 | .val = Value.fromInterned(switch (error_union.val) { | |
| 277 | .err_name => try mod.intern(.{ .undef = payload_ty.toIntern() }), | |
| 278 | .payload => |payload| payload, | |
| 279 | }), | |
| 280 | }, code, debug_output, reloc_info)) { | |
| 272 | switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(switch (error_union.val) { | |
| 273 | .err_name => try mod.intern(.{ .undef = payload_ty.toIntern() }), | |
| 274 | .payload => |payload| payload, | |
| 275 | }), code, debug_output, reloc_info)) { | |
| 281 | 276 | .ok => {}, |
| 282 | 277 | .fail => |em| return .{ .fail = em }, |
| 283 | 278 | } |
| ... | ... | @@ -304,11 +299,8 @@ pub fn generateSymbol( |
| 304 | 299 | } |
| 305 | 300 | }, |
| 306 | 301 | .enum_tag => |enum_tag| { |
| 307 | const int_tag_ty = typed_value.ty.intTagType(mod); | |
| 308 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 309 | .ty = int_tag_ty, | |
| 310 | .val = try mod.getCoerced(Value.fromInterned(enum_tag.int), int_tag_ty), | |
| 311 | }, code, debug_output, reloc_info)) { | |
| 302 | const int_tag_ty = ty.intTagType(mod); | |
| 303 | switch (try generateSymbol(bin_file, src_loc, try mod.getCoerced(Value.fromInterned(enum_tag.int), int_tag_ty), code, debug_output, reloc_info)) { | |
| 312 | 304 | .ok => {}, |
| 313 | 305 | .fail => |em| return .{ .fail = em }, |
| 314 | 306 | } |
| ... | ... | @@ -319,42 +311,33 @@ pub fn generateSymbol( |
| 319 | 311 | .f64 => |f64_val| writeFloat(f64, f64_val, target, endian, try code.addManyAsArray(8)), |
| 320 | 312 | .f80 => |f80_val| { |
| 321 | 313 | writeFloat(f80, f80_val, target, endian, try code.addManyAsArray(10)); |
| 322 | const abi_size = math.cast(usize, typed_value.ty.abiSize(mod)) orelse return error.Overflow; | |
| 314 | const abi_size = math.cast(usize, ty.abiSize(mod)) orelse return error.Overflow; | |
| 323 | 315 | try code.appendNTimes(0, abi_size - 10); |
| 324 | 316 | }, |
| 325 | 317 | .f128 => |f128_val| writeFloat(f128, f128_val, target, endian, try code.addManyAsArray(16)), |
| 326 | 318 | }, |
| 327 | .ptr => switch (try lowerParentPtr(bin_file, src_loc, typed_value.val.toIntern(), code, debug_output, reloc_info)) { | |
| 319 | .ptr => switch (try lowerParentPtr(bin_file, src_loc, val.toIntern(), code, debug_output, reloc_info)) { | |
| 328 | 320 | .ok => {}, |
| 329 | 321 | .fail => |em| return .{ .fail = em }, |
| 330 | 322 | }, |
| 331 | 323 | .slice => |slice| { |
| 332 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 333 | .ty = typed_value.ty.slicePtrFieldType(mod), | |
| 334 | .val = Value.fromInterned(slice.ptr), | |
| 335 | }, code, debug_output, reloc_info)) { | |
| 324 | switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(slice.ptr), code, debug_output, reloc_info)) { | |
| 336 | 325 | .ok => {}, |
| 337 | 326 | .fail => |em| return .{ .fail = em }, |
| 338 | 327 | } |
| 339 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 340 | .ty = Type.usize, | |
| 341 | .val = Value.fromInterned(slice.len), | |
| 342 | }, code, debug_output, reloc_info)) { | |
| 328 | switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(slice.len), code, debug_output, reloc_info)) { | |
| 343 | 329 | .ok => {}, |
| 344 | 330 | .fail => |em| return .{ .fail = em }, |
| 345 | 331 | } |
| 346 | 332 | }, |
| 347 | 333 | .opt => { |
| 348 | const payload_type = typed_value.ty.optionalChild(mod); | |
| 349 | const payload_val = typed_value.val.optionalValue(mod); | |
| 350 | const abi_size = math.cast(usize, typed_value.ty.abiSize(mod)) orelse return error.Overflow; | |
| 334 | const payload_type = ty.optionalChild(mod); | |
| 335 | const payload_val = val.optionalValue(mod); | |
| 336 | const abi_size = math.cast(usize, ty.abiSize(mod)) orelse return error.Overflow; | |
| 351 | 337 | |
| 352 | if (typed_value.ty.optionalReprIsPayload(mod)) { | |
| 338 | if (ty.optionalReprIsPayload(mod)) { | |
| 353 | 339 | if (payload_val) |value| { |
| 354 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 355 | .ty = payload_type, | |
| 356 | .val = value, | |
| 357 | }, code, debug_output, reloc_info)) { | |
| 340 | switch (try generateSymbol(bin_file, src_loc, value, code, debug_output, reloc_info)) { | |
| 358 | 341 | .ok => {}, |
| 359 | 342 | .fail => |em| return Result{ .fail = em }, |
| 360 | 343 | } |
| ... | ... | @@ -365,10 +348,7 @@ pub fn generateSymbol( |
| 365 | 348 | const padding = abi_size - (math.cast(usize, payload_type.abiSize(mod)) orelse return error.Overflow) - 1; |
| 366 | 349 | if (payload_type.hasRuntimeBits(mod)) { |
| 367 | 350 | const value = payload_val orelse Value.fromInterned((try mod.intern(.{ .undef = payload_type.toIntern() }))); |
| 368 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 369 | .ty = payload_type, | |
| 370 | .val = value, | |
| 371 | }, code, debug_output, reloc_info)) { | |
| 351 | switch (try generateSymbol(bin_file, src_loc, value, code, debug_output, reloc_info)) { | |
| 372 | 352 | .ok => {}, |
| 373 | 353 | .fail => |em| return Result{ .fail = em }, |
| 374 | 354 | } |
| ... | ... | @@ -377,7 +357,7 @@ pub fn generateSymbol( |
| 377 | 357 | try code.appendNTimes(0, padding); |
| 378 | 358 | } |
| 379 | 359 | }, |
| 380 | .aggregate => |aggregate| switch (ip.indexToKey(typed_value.ty.toIntern())) { | |
| 360 | .aggregate => |aggregate| switch (ip.indexToKey(ty.toIntern())) { | |
| 381 | 361 | .array_type => |array_type| switch (aggregate.storage) { |
| 382 | 362 | .bytes => |bytes| try code.appendSlice(bytes), |
| 383 | 363 | .elems, .repeated_elem => { |
| ... | ... | @@ -385,17 +365,14 @@ pub fn generateSymbol( |
| 385 | 365 | const len_including_sentinel = |
| 386 | 366 | array_type.len + @intFromBool(array_type.sentinel != .none); |
| 387 | 367 | while (index < len_including_sentinel) : (index += 1) { |
| 388 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 389 | .ty = Type.fromInterned(array_type.child), | |
| 390 | .val = Value.fromInterned(switch (aggregate.storage) { | |
| 391 | .bytes => unreachable, | |
| 392 | .elems => |elems| elems[@as(usize, @intCast(index))], | |
| 393 | .repeated_elem => |elem| if (index < array_type.len) | |
| 394 | elem | |
| 395 | else | |
| 396 | array_type.sentinel, | |
| 397 | }), | |
| 398 | }, code, debug_output, reloc_info)) { | |
| 368 | switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(switch (aggregate.storage) { | |
| 369 | .bytes => unreachable, | |
| 370 | .elems => |elems| elems[@as(usize, @intCast(index))], | |
| 371 | .repeated_elem => |elem| if (index < array_type.len) | |
| 372 | elem | |
| 373 | else | |
| 374 | array_type.sentinel, | |
| 375 | }), code, debug_output, reloc_info)) { | |
| 399 | 376 | .ok => {}, |
| 400 | 377 | .fail => |em| return .{ .fail = em }, |
| 401 | 378 | } |
| ... | ... | @@ -403,7 +380,7 @@ pub fn generateSymbol( |
| 403 | 380 | }, |
| 404 | 381 | }, |
| 405 | 382 | .vector_type => |vector_type| { |
| 406 | const abi_size = math.cast(usize, typed_value.ty.abiSize(mod)) orelse | |
| 383 | const abi_size = math.cast(usize, ty.abiSize(mod)) orelse | |
| 407 | 384 | return error.Overflow; |
| 408 | 385 | if (vector_type.child == .bool_type) { |
| 409 | 386 | const bytes = try code.addManyAsSlice(abi_size); |
| ... | ... | @@ -449,16 +426,13 @@ pub fn generateSymbol( |
| 449 | 426 | .elems, .repeated_elem => { |
| 450 | 427 | var index: u64 = 0; |
| 451 | 428 | while (index < vector_type.len) : (index += 1) { |
| 452 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 453 | .ty = Type.fromInterned(vector_type.child), | |
| 454 | .val = Value.fromInterned(switch (aggregate.storage) { | |
| 455 | .bytes => unreachable, | |
| 456 | .elems => |elems| elems[ | |
| 457 | math.cast(usize, index) orelse return error.Overflow | |
| 458 | ], | |
| 459 | .repeated_elem => |elem| elem, | |
| 460 | }), | |
| 461 | }, code, debug_output, reloc_info)) { | |
| 429 | switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(switch (aggregate.storage) { | |
| 430 | .bytes => unreachable, | |
| 431 | .elems => |elems| elems[ | |
| 432 | math.cast(usize, index) orelse return error.Overflow | |
| 433 | ], | |
| 434 | .repeated_elem => |elem| elem, | |
| 435 | }), code, debug_output, reloc_info)) { | |
| 462 | 436 | .ok => {}, |
| 463 | 437 | .fail => |em| return .{ .fail = em }, |
| 464 | 438 | } |
| ... | ... | @@ -491,17 +465,14 @@ pub fn generateSymbol( |
| 491 | 465 | .repeated_elem => |elem| elem, |
| 492 | 466 | }; |
| 493 | 467 | |
| 494 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 495 | .ty = Type.fromInterned(field_ty), | |
| 496 | .val = Value.fromInterned(field_val), | |
| 497 | }, code, debug_output, reloc_info)) { | |
| 468 | switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(field_val), code, debug_output, reloc_info)) { | |
| 498 | 469 | .ok => {}, |
| 499 | 470 | .fail => |em| return Result{ .fail = em }, |
| 500 | 471 | } |
| 501 | 472 | const unpadded_field_end = code.items.len - struct_begin; |
| 502 | 473 | |
| 503 | 474 | // Pad struct members if required |
| 504 | const padded_field_end = typed_value.ty.structFieldOffset(index + 1, mod); | |
| 475 | const padded_field_end = ty.structFieldOffset(index + 1, mod); | |
| 505 | 476 | const padding = math.cast(usize, padded_field_end - unpadded_field_end) orelse |
| 506 | 477 | return error.Overflow; |
| 507 | 478 | |
| ... | ... | @@ -511,10 +482,10 @@ pub fn generateSymbol( |
| 511 | 482 | } |
| 512 | 483 | }, |
| 513 | 484 | .struct_type => { |
| 514 | const struct_type = ip.loadStructType(typed_value.ty.toIntern()); | |
| 485 | const struct_type = ip.loadStructType(ty.toIntern()); | |
| 515 | 486 | switch (struct_type.layout) { |
| 516 | 487 | .@"packed" => { |
| 517 | const abi_size = math.cast(usize, typed_value.ty.abiSize(mod)) orelse | |
| 488 | const abi_size = math.cast(usize, ty.abiSize(mod)) orelse | |
| 518 | 489 | return error.Overflow; |
| 519 | 490 | const current_pos = code.items.len; |
| 520 | 491 | try code.resize(current_pos + abi_size); |
| ... | ... | @@ -537,10 +508,7 @@ pub fn generateSymbol( |
| 537 | 508 | return error.Overflow; |
| 538 | 509 | var tmp_list = try std.ArrayList(u8).initCapacity(code.allocator, field_size); |
| 539 | 510 | defer tmp_list.deinit(); |
| 540 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 541 | .ty = Type.fromInterned(field_ty), | |
| 542 | .val = Value.fromInterned(field_val), | |
| 543 | }, &tmp_list, debug_output, reloc_info)) { | |
| 511 | switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(field_val), &tmp_list, debug_output, reloc_info)) { | |
| 544 | 512 | .ok => @memcpy(code.items[current_pos..][0..tmp_list.items.len], tmp_list.items), |
| 545 | 513 | .fail => |em| return Result{ .fail = em }, |
| 546 | 514 | } |
| ... | ... | @@ -560,7 +528,7 @@ pub fn generateSymbol( |
| 560 | 528 | const field_ty = field_types[field_index]; |
| 561 | 529 | if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue; |
| 562 | 530 | |
| 563 | const field_val = switch (ip.indexToKey(typed_value.val.toIntern()).aggregate.storage) { | |
| 531 | const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) { | |
| 564 | 532 | .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{ |
| 565 | 533 | .ty = field_ty, |
| 566 | 534 | .storage = .{ .u64 = bytes[field_index] }, |
| ... | ... | @@ -575,10 +543,7 @@ pub fn generateSymbol( |
| 575 | 543 | ) orelse return error.Overflow; |
| 576 | 544 | if (padding > 0) try code.appendNTimes(0, padding); |
| 577 | 545 | |
| 578 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 579 | .ty = Type.fromInterned(field_ty), | |
| 580 | .val = Value.fromInterned(field_val), | |
| 581 | }, code, debug_output, reloc_info)) { | |
| 546 | switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(field_val), code, debug_output, reloc_info)) { | |
| 582 | 547 | .ok => {}, |
| 583 | 548 | .fail => |em| return Result{ .fail = em }, |
| 584 | 549 | } |
| ... | ... | @@ -599,37 +564,28 @@ pub fn generateSymbol( |
| 599 | 564 | else => unreachable, |
| 600 | 565 | }, |
| 601 | 566 | .un => |un| { |
| 602 | const layout = typed_value.ty.unionGetLayout(mod); | |
| 567 | const layout = ty.unionGetLayout(mod); | |
| 603 | 568 | |
| 604 | 569 | if (layout.payload_size == 0) { |
| 605 | return generateSymbol(bin_file, src_loc, .{ | |
| 606 | .ty = typed_value.ty.unionTagTypeSafety(mod).?, | |
| 607 | .val = Value.fromInterned(un.tag), | |
| 608 | }, code, debug_output, reloc_info); | |
| 570 | return generateSymbol(bin_file, src_loc, Value.fromInterned(un.tag), code, debug_output, reloc_info); | |
| 609 | 571 | } |
| 610 | 572 | |
| 611 | 573 | // Check if we should store the tag first. |
| 612 | 574 | if (layout.tag_size > 0 and layout.tag_align.compare(.gte, layout.payload_align)) { |
| 613 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 614 | .ty = typed_value.ty.unionTagTypeSafety(mod).?, | |
| 615 | .val = Value.fromInterned(un.tag), | |
| 616 | }, code, debug_output, reloc_info)) { | |
| 575 | switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(un.tag), code, debug_output, reloc_info)) { | |
| 617 | 576 | .ok => {}, |
| 618 | 577 | .fail => |em| return Result{ .fail = em }, |
| 619 | 578 | } |
| 620 | 579 | } |
| 621 | 580 | |
| 622 | const union_obj = mod.typeToUnion(typed_value.ty).?; | |
| 581 | const union_obj = mod.typeToUnion(ty).?; | |
| 623 | 582 | if (un.tag != .none) { |
| 624 | const field_index = typed_value.ty.unionTagFieldIndex(Value.fromInterned(un.tag), mod).?; | |
| 583 | const field_index = ty.unionTagFieldIndex(Value.fromInterned(un.tag), mod).?; | |
| 625 | 584 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]); |
| 626 | 585 | if (!field_ty.hasRuntimeBits(mod)) { |
| 627 | 586 | try code.appendNTimes(0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow); |
| 628 | 587 | } else { |
| 629 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 630 | .ty = field_ty, | |
| 631 | .val = Value.fromInterned(un.val), | |
| 632 | }, code, debug_output, reloc_info)) { | |
| 588 | switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(un.val), code, debug_output, reloc_info)) { | |
| 633 | 589 | .ok => {}, |
| 634 | 590 | .fail => |em| return Result{ .fail = em }, |
| 635 | 591 | } |
| ... | ... | @@ -640,20 +596,14 @@ pub fn generateSymbol( |
| 640 | 596 | } |
| 641 | 597 | } |
| 642 | 598 | } else { |
| 643 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 644 | .ty = Type.fromInterned(ip.typeOf(un.val)), | |
| 645 | .val = Value.fromInterned(un.val), | |
| 646 | }, code, debug_output, reloc_info)) { | |
| 599 | switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(un.val), code, debug_output, reloc_info)) { | |
| 647 | 600 | .ok => {}, |
| 648 | 601 | .fail => |em| return Result{ .fail = em }, |
| 649 | 602 | } |
| 650 | 603 | } |
| 651 | 604 | |
| 652 | 605 | if (layout.tag_size > 0 and layout.tag_align.compare(.lt, layout.payload_align)) { |
| 653 | switch (try generateSymbol(bin_file, src_loc, .{ | |
| 654 | .ty = Type.fromInterned(union_obj.enum_tag_ty), | |
| 655 | .val = Value.fromInterned(un.tag), | |
| 656 | }, code, debug_output, reloc_info)) { | |
| 606 | switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(un.tag), code, debug_output, reloc_info)) { | |
| 657 | 607 | .ok => {}, |
| 658 | 608 | .fail => |em| return Result{ .fail = em }, |
| 659 | 609 | } |
| ... | ... | @@ -681,10 +631,7 @@ fn lowerParentPtr( |
| 681 | 631 | return switch (ptr.addr) { |
| 682 | 632 | .decl => |decl| try lowerDeclRef(bin_file, src_loc, decl, code, debug_output, reloc_info), |
| 683 | 633 | .anon_decl => |ad| try lowerAnonDeclRef(bin_file, src_loc, ad, code, debug_output, reloc_info), |
| 684 | .int => |int| try generateSymbol(bin_file, src_loc, .{ | |
| 685 | .ty = Type.usize, | |
| 686 | .val = Value.fromInterned(int), | |
| 687 | }, code, debug_output, reloc_info), | |
| 634 | .int => |int| try generateSymbol(bin_file, src_loc, Value.fromInterned(int), code, debug_output, reloc_info), | |
| 688 | 635 | .eu_payload => |eu_payload| try lowerParentPtr( |
| 689 | 636 | bin_file, |
| 690 | 637 | src_loc, |
| ... | ... | @@ -910,11 +857,12 @@ pub const GenResult = union(enum) { |
| 910 | 857 | fn genDeclRef( |
| 911 | 858 | lf: *link.File, |
| 912 | 859 | src_loc: Module.SrcLoc, |
| 913 | tv: TypedValue, | |
| 860 | val: Value, | |
| 914 | 861 | ptr_decl_index: InternPool.DeclIndex, |
| 915 | 862 | ) CodeGenError!GenResult { |
| 916 | 863 | const zcu = lf.comp.module.?; |
| 917 | log.debug("genDeclRef: ty = {}, val = {}", .{ tv.ty.fmt(zcu), tv.val.fmtValue(tv.ty, zcu) }); | |
| 864 | const ty = val.typeOf(zcu); | |
| 865 | log.debug("genDeclRef: val = {}", .{val.fmtValue(ty, zcu)}); | |
| 918 | 866 | |
| 919 | 867 | const ptr_decl = zcu.declPtr(ptr_decl_index); |
| 920 | 868 | const namespace = zcu.namespacePtr(ptr_decl.src_namespace); |
| ... | ... | @@ -945,12 +893,12 @@ fn genDeclRef( |
| 945 | 893 | const gpa = comp.gpa; |
| 946 | 894 | |
| 947 | 895 | // TODO this feels clunky. Perhaps we should check for it in `genTypedValue`? |
| 948 | if (tv.ty.castPtrToFn(zcu)) |fn_ty| { | |
| 896 | if (ty.castPtrToFn(zcu)) |fn_ty| { | |
| 949 | 897 | if (zcu.typeToFunc(fn_ty).?.is_generic) { |
| 950 | 898 | return GenResult.mcv(.{ .immediate = fn_ty.abiAlignment(zcu).toByteUnitsOptional().? }); |
| 951 | 899 | } |
| 952 | } else if (tv.ty.zigTypeTag(zcu) == .Pointer) { | |
| 953 | const elem_ty = tv.ty.elemType2(zcu); | |
| 900 | } else if (ty.zigTypeTag(zcu) == .Pointer) { | |
| 901 | const elem_ty = ty.elemType2(zcu); | |
| 954 | 902 | if (!elem_ty.hasRuntimeBits(zcu)) { |
| 955 | 903 | return GenResult.mcv(.{ .immediate = elem_ty.abiAlignment(zcu).toByteUnitsOptional().? }); |
| 956 | 904 | } |
| ... | ... | @@ -958,7 +906,7 @@ fn genDeclRef( |
| 958 | 906 | |
| 959 | 907 | const decl_namespace = zcu.namespacePtr(decl.src_namespace); |
| 960 | 908 | const single_threaded = decl_namespace.file_scope.mod.single_threaded; |
| 961 | const is_threadlocal = tv.val.isPtrToThreadLocal(zcu) and !single_threaded; | |
| 909 | const is_threadlocal = val.isPtrToThreadLocal(zcu) and !single_threaded; | |
| 962 | 910 | const is_extern = decl.isExtern(zcu); |
| 963 | 911 | |
| 964 | 912 | if (lf.cast(link.File.Elf)) |elf_file| { |
| ... | ... | @@ -1023,14 +971,14 @@ fn genDeclRef( |
| 1023 | 971 | fn genUnnamedConst( |
| 1024 | 972 | lf: *link.File, |
| 1025 | 973 | src_loc: Module.SrcLoc, |
| 1026 | tv: TypedValue, | |
| 974 | val: Value, | |
| 1027 | 975 | owner_decl_index: InternPool.DeclIndex, |
| 1028 | 976 | ) CodeGenError!GenResult { |
| 1029 | 977 | const zcu = lf.comp.module.?; |
| 1030 | 978 | const gpa = lf.comp.gpa; |
| 1031 | log.debug("genUnnamedConst: ty = {}, val = {}", .{ tv.ty.fmt(zcu), tv.val.fmtValue(tv.ty, zcu) }); | |
| 979 | log.debug("genUnnamedConst: val = {}", .{val.fmtValue(val.typeOf(zcu), zcu)}); | |
| 1032 | 980 | |
| 1033 | const local_sym_index = lf.lowerUnnamedConst(tv, owner_decl_index) catch |err| { | |
| 981 | const local_sym_index = lf.lowerUnnamedConst(val, owner_decl_index) catch |err| { | |
| 1034 | 982 | return GenResult.fail(gpa, src_loc, "lowering unnamed constant failed: {s}", .{@errorName(err)}); |
| 1035 | 983 | }; |
| 1036 | 984 | switch (lf.tag) { |
| ... | ... | @@ -1062,18 +1010,15 @@ fn genUnnamedConst( |
| 1062 | 1010 | pub fn genTypedValue( |
| 1063 | 1011 | lf: *link.File, |
| 1064 | 1012 | src_loc: Module.SrcLoc, |
| 1065 | arg_tv: TypedValue, | |
| 1013 | val: Value, | |
| 1066 | 1014 | owner_decl_index: InternPool.DeclIndex, |
| 1067 | 1015 | ) CodeGenError!GenResult { |
| 1068 | 1016 | const zcu = lf.comp.module.?; |
| 1069 | const typed_value = arg_tv; | |
| 1017 | const ty = val.typeOf(zcu); | |
| 1070 | 1018 | |
| 1071 | log.debug("genTypedValue: ty = {}, val = {}", .{ | |
| 1072 | typed_value.ty.fmt(zcu), | |
| 1073 | typed_value.val.fmtValue(typed_value.ty, zcu), | |
| 1074 | }); | |
| 1019 | log.debug("genTypedValue: val = {}", .{val.fmtValue(ty, zcu)}); | |
| 1075 | 1020 | |
| 1076 | if (typed_value.val.isUndef(zcu)) | |
| 1021 | if (val.isUndef(zcu)) | |
| 1077 | 1022 | return GenResult.mcv(.undef); |
| 1078 | 1023 | |
| 1079 | 1024 | const owner_decl = zcu.declPtr(owner_decl_index); |
| ... | ... | @@ -1081,85 +1026,92 @@ pub fn genTypedValue( |
| 1081 | 1026 | const target = namespace.file_scope.mod.resolved_target.result; |
| 1082 | 1027 | const ptr_bits = target.ptrBitWidth(); |
| 1083 | 1028 | |
| 1084 | if (!typed_value.ty.isSlice(zcu)) switch (zcu.intern_pool.indexToKey(typed_value.val.toIntern())) { | |
| 1029 | if (!ty.isSlice(zcu)) switch (zcu.intern_pool.indexToKey(val.toIntern())) { | |
| 1085 | 1030 | .ptr => |ptr| switch (ptr.addr) { |
| 1086 | .decl => |decl| return genDeclRef(lf, src_loc, typed_value, decl), | |
| 1031 | .decl => |decl| return genDeclRef(lf, src_loc, val, decl), | |
| 1087 | 1032 | else => {}, |
| 1088 | 1033 | }, |
| 1089 | 1034 | else => {}, |
| 1090 | 1035 | }; |
| 1091 | 1036 | |
| 1092 | switch (typed_value.ty.zigTypeTag(zcu)) { | |
| 1037 | switch (ty.zigTypeTag(zcu)) { | |
| 1093 | 1038 | .Void => return GenResult.mcv(.none), |
| 1094 | .Pointer => switch (typed_value.ty.ptrSize(zcu)) { | |
| 1039 | .Pointer => switch (ty.ptrSize(zcu)) { | |
| 1095 | 1040 | .Slice => {}, |
| 1096 | else => switch (typed_value.val.toIntern()) { | |
| 1041 | else => switch (val.toIntern()) { | |
| 1097 | 1042 | .null_value => { |
| 1098 | 1043 | return GenResult.mcv(.{ .immediate = 0 }); |
| 1099 | 1044 | }, |
| 1100 | 1045 | .none => {}, |
| 1101 | else => switch (zcu.intern_pool.indexToKey(typed_value.val.toIntern())) { | |
| 1046 | else => switch (zcu.intern_pool.indexToKey(val.toIntern())) { | |
| 1102 | 1047 | .int => { |
| 1103 | return GenResult.mcv(.{ .immediate = typed_value.val.toUnsignedInt(zcu) }); | |
| 1048 | return GenResult.mcv(.{ .immediate = val.toUnsignedInt(zcu) }); | |
| 1104 | 1049 | }, |
| 1105 | 1050 | else => {}, |
| 1106 | 1051 | }, |
| 1107 | 1052 | }, |
| 1108 | 1053 | }, |
| 1109 | 1054 | .Int => { |
| 1110 | const info = typed_value.ty.intInfo(zcu); | |
| 1055 | const info = ty.intInfo(zcu); | |
| 1111 | 1056 | if (info.bits <= ptr_bits) { |
| 1112 | 1057 | const unsigned = switch (info.signedness) { |
| 1113 | .signed => @as(u64, @bitCast(typed_value.val.toSignedInt(zcu))), | |
| 1114 | .unsigned => typed_value.val.toUnsignedInt(zcu), | |
| 1058 | .signed => @as(u64, @bitCast(val.toSignedInt(zcu))), | |
| 1059 | .unsigned => val.toUnsignedInt(zcu), | |
| 1115 | 1060 | }; |
| 1116 | 1061 | return GenResult.mcv(.{ .immediate = unsigned }); |
| 1117 | 1062 | } |
| 1118 | 1063 | }, |
| 1119 | 1064 | .Bool => { |
| 1120 | return GenResult.mcv(.{ .immediate = @intFromBool(typed_value.val.toBool()) }); | |
| 1065 | return GenResult.mcv(.{ .immediate = @intFromBool(val.toBool()) }); | |
| 1121 | 1066 | }, |
| 1122 | 1067 | .Optional => { |
| 1123 | if (typed_value.ty.isPtrLikeOptional(zcu)) { | |
| 1124 | return genTypedValue(lf, src_loc, .{ | |
| 1125 | .ty = typed_value.ty.optionalChild(zcu), | |
| 1126 | .val = typed_value.val.optionalValue(zcu) orelse return GenResult.mcv(.{ .immediate = 0 }), | |
| 1127 | }, owner_decl_index); | |
| 1128 | } else if (typed_value.ty.abiSize(zcu) == 1) { | |
| 1129 | return GenResult.mcv(.{ .immediate = @intFromBool(!typed_value.val.isNull(zcu)) }); | |
| 1068 | if (ty.isPtrLikeOptional(zcu)) { | |
| 1069 | return genTypedValue( | |
| 1070 | lf, | |
| 1071 | src_loc, | |
| 1072 | val.optionalValue(zcu) orelse return GenResult.mcv(.{ .immediate = 0 }), | |
| 1073 | owner_decl_index, | |
| 1074 | ); | |
| 1075 | } else if (ty.abiSize(zcu) == 1) { | |
| 1076 | return GenResult.mcv(.{ .immediate = @intFromBool(!val.isNull(zcu)) }); | |
| 1130 | 1077 | } |
| 1131 | 1078 | }, |
| 1132 | 1079 | .Enum => { |
| 1133 | const enum_tag = zcu.intern_pool.indexToKey(typed_value.val.toIntern()).enum_tag; | |
| 1134 | const int_tag_ty = zcu.intern_pool.typeOf(enum_tag.int); | |
| 1135 | return genTypedValue(lf, src_loc, .{ | |
| 1136 | .ty = Type.fromInterned(int_tag_ty), | |
| 1137 | .val = Value.fromInterned(enum_tag.int), | |
| 1138 | }, owner_decl_index); | |
| 1080 | const enum_tag = zcu.intern_pool.indexToKey(val.toIntern()).enum_tag; | |
| 1081 | return genTypedValue( | |
| 1082 | lf, | |
| 1083 | src_loc, | |
| 1084 | Value.fromInterned(enum_tag.int), | |
| 1085 | owner_decl_index, | |
| 1086 | ); | |
| 1139 | 1087 | }, |
| 1140 | 1088 | .ErrorSet => { |
| 1141 | const err_name = zcu.intern_pool.indexToKey(typed_value.val.toIntern()).err.name; | |
| 1089 | const err_name = zcu.intern_pool.indexToKey(val.toIntern()).err.name; | |
| 1142 | 1090 | const error_index = zcu.global_error_set.getIndex(err_name).?; |
| 1143 | 1091 | return GenResult.mcv(.{ .immediate = error_index }); |
| 1144 | 1092 | }, |
| 1145 | 1093 | .ErrorUnion => { |
| 1146 | const err_type = typed_value.ty.errorUnionSet(zcu); | |
| 1147 | const payload_type = typed_value.ty.errorUnionPayload(zcu); | |
| 1094 | const err_type = ty.errorUnionSet(zcu); | |
| 1095 | const payload_type = ty.errorUnionPayload(zcu); | |
| 1148 | 1096 | if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 1149 | 1097 | // We use the error type directly as the type. |
| 1150 | 1098 | const err_int_ty = try zcu.errorIntType(); |
| 1151 | switch (zcu.intern_pool.indexToKey(typed_value.val.toIntern()).error_union.val) { | |
| 1152 | .err_name => |err_name| return genTypedValue(lf, src_loc, .{ | |
| 1153 | .ty = err_type, | |
| 1154 | .val = Value.fromInterned((try zcu.intern(.{ .err = .{ | |
| 1099 | switch (zcu.intern_pool.indexToKey(val.toIntern()).error_union.val) { | |
| 1100 | .err_name => |err_name| return genTypedValue( | |
| 1101 | lf, | |
| 1102 | src_loc, | |
| 1103 | Value.fromInterned(try zcu.intern(.{ .err = .{ | |
| 1155 | 1104 | .ty = err_type.toIntern(), |
| 1156 | 1105 | .name = err_name, |
| 1157 | } }))), | |
| 1158 | }, owner_decl_index), | |
| 1159 | .payload => return genTypedValue(lf, src_loc, .{ | |
| 1160 | .ty = err_int_ty, | |
| 1161 | .val = try zcu.intValue(err_int_ty, 0), | |
| 1162 | }, owner_decl_index), | |
| 1106 | } })), | |
| 1107 | owner_decl_index, | |
| 1108 | ), | |
| 1109 | .payload => return genTypedValue( | |
| 1110 | lf, | |
| 1111 | src_loc, | |
| 1112 | try zcu.intValue(err_int_ty, 0), | |
| 1113 | owner_decl_index, | |
| 1114 | ), | |
| 1163 | 1115 | } |
| 1164 | 1116 | } |
| 1165 | 1117 | }, |
| ... | ... | @@ -1176,7 +1128,7 @@ pub fn genTypedValue( |
| 1176 | 1128 | else => {}, |
| 1177 | 1129 | } |
| 1178 | 1130 | |
| 1179 | return genUnnamedConst(lf, src_loc, typed_value, owner_decl_index); | |
| 1131 | return genUnnamedConst(lf, src_loc, val, owner_decl_index); | |
| 1180 | 1132 | } |
| 1181 | 1133 | |
| 1182 | 1134 | pub fn errUnionPayloadOffset(payload_ty: Type, mod: *Module) u64 { |
src/codegen/c.zig+28-35| ... | ... | @@ -9,7 +9,6 @@ const Module = @import("../Module.zig"); |
| 9 | 9 | const Compilation = @import("../Compilation.zig"); |
| 10 | 10 | const Value = @import("../Value.zig"); |
| 11 | 11 | const Type = @import("../type.zig").Type; |
| 12 | const TypedValue = @import("../TypedValue.zig"); | |
| 13 | 12 | const C = link.File.C; |
| 14 | 13 | const Decl = Module.Decl; |
| 15 | 14 | const trace = @import("../tracy.zig").trace; |
| ... | ... | @@ -1877,9 +1876,9 @@ pub const DeclGen = struct { |
| 1877 | 1876 | try renderTypeSuffix(dg.pass, store.*, mod, w, cty_idx, .suffix, .{}); |
| 1878 | 1877 | } |
| 1879 | 1878 | |
| 1880 | fn declIsGlobal(dg: *DeclGen, tv: TypedValue) bool { | |
| 1879 | fn declIsGlobal(dg: *DeclGen, val: Value) bool { | |
| 1881 | 1880 | const mod = dg.module; |
| 1882 | return switch (mod.intern_pool.indexToKey(tv.val.ip_index)) { | |
| 1881 | return switch (mod.intern_pool.indexToKey(val.ip_index)) { | |
| 1883 | 1882 | .variable => |variable| mod.decl_exports.contains(variable.decl), |
| 1884 | 1883 | .extern_func => true, |
| 1885 | 1884 | .func => |func| mod.decl_exports.contains(func.owner_decl), |
| ... | ... | @@ -1972,7 +1971,7 @@ pub const DeclGen = struct { |
| 1972 | 1971 | ) !void { |
| 1973 | 1972 | const decl = dg.module.declPtr(decl_index); |
| 1974 | 1973 | const fwd = dg.fwdDeclWriter(); |
| 1975 | const is_global = variable.is_extern or dg.declIsGlobal(.{ .ty = decl.typeOf(dg.module), .val = decl.val }); | |
| 1974 | const is_global = variable.is_extern or dg.declIsGlobal(decl.val); | |
| 1976 | 1975 | try fwd.writeAll(if (is_global) "zig_extern " else "static "); |
| 1977 | 1976 | const maybe_exports = dg.module.decl_exports.get(decl_index); |
| 1978 | 1977 | const export_weak_linkage = if (maybe_exports) |exports| |
| ... | ... | @@ -2656,13 +2655,12 @@ fn genExports(o: *Object) !void { |
| 2656 | 2655 | .anon, .flush => return, |
| 2657 | 2656 | }; |
| 2658 | 2657 | const decl = mod.declPtr(decl_index); |
| 2659 | const tv: TypedValue = .{ .ty = decl.typeOf(mod), .val = decl.val }; | |
| 2660 | 2658 | const fwd = o.dg.fwdDeclWriter(); |
| 2661 | 2659 | |
| 2662 | 2660 | const exports = mod.decl_exports.get(decl_index) orelse return; |
| 2663 | 2661 | if (exports.items.len < 2) return; |
| 2664 | 2662 | |
| 2665 | const is_variable_const = switch (ip.indexToKey(tv.val.toIntern())) { | |
| 2663 | const is_variable_const = switch (ip.indexToKey(decl.val.toIntern())) { | |
| 2666 | 2664 | .func => return for (exports.items[1..], 1..) |@"export", i| { |
| 2667 | 2665 | try fwd.writeAll("zig_extern "); |
| 2668 | 2666 | if (@"export".opts.linkage == .weak) try fwd.writeAll("zig_weak_linkage_fn "); |
| ... | ... | @@ -2805,15 +2803,11 @@ pub fn genFunc(f: *Function) !void { |
| 2805 | 2803 | const gpa = o.dg.gpa; |
| 2806 | 2804 | const decl_index = o.dg.pass.decl; |
| 2807 | 2805 | const decl = mod.declPtr(decl_index); |
| 2808 | const tv: TypedValue = .{ | |
| 2809 | .ty = decl.typeOf(mod), | |
| 2810 | .val = decl.val, | |
| 2811 | }; | |
| 2812 | 2806 | |
| 2813 | 2807 | o.code_header = std.ArrayList(u8).init(gpa); |
| 2814 | 2808 | defer o.code_header.deinit(); |
| 2815 | 2809 | |
| 2816 | const is_global = o.dg.declIsGlobal(tv); | |
| 2810 | const is_global = o.dg.declIsGlobal(decl.val); | |
| 2817 | 2811 | const fwd_decl_writer = o.dg.fwdDeclWriter(); |
| 2818 | 2812 | try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static "); |
| 2819 | 2813 | |
| ... | ... | @@ -2893,22 +2887,23 @@ pub fn genDecl(o: *Object) !void { |
| 2893 | 2887 | const mod = o.dg.module; |
| 2894 | 2888 | const decl_index = o.dg.pass.decl; |
| 2895 | 2889 | const decl = mod.declPtr(decl_index); |
| 2896 | const tv: TypedValue = .{ .ty = decl.typeOf(mod), .val = decl.val }; | |
| 2890 | const decl_val = decl.val; | |
| 2891 | const decl_ty = decl_val.typeOf(mod); | |
| 2897 | 2892 | |
| 2898 | if (!tv.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return; | |
| 2899 | if (tv.val.getExternFunc(mod)) |_| { | |
| 2893 | if (!decl_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return; | |
| 2894 | if (decl_val.getExternFunc(mod)) |_| { | |
| 2900 | 2895 | const fwd_decl_writer = o.dg.fwdDeclWriter(); |
| 2901 | 2896 | try fwd_decl_writer.writeAll("zig_extern "); |
| 2902 | 2897 | try o.dg.renderFunctionSignature(fwd_decl_writer, decl_index, .forward, .{ .export_index = 0 }); |
| 2903 | 2898 | try fwd_decl_writer.writeAll(";\n"); |
| 2904 | 2899 | try genExports(o); |
| 2905 | } else if (tv.val.getVariable(mod)) |variable| { | |
| 2900 | } else if (decl_val.getVariable(mod)) |variable| { | |
| 2906 | 2901 | try o.dg.renderFwdDecl(decl_index, variable, .final); |
| 2907 | 2902 | try genExports(o); |
| 2908 | 2903 | |
| 2909 | 2904 | if (variable.is_extern) return; |
| 2910 | 2905 | |
| 2911 | const is_global = variable.is_extern or o.dg.declIsGlobal(tv); | |
| 2906 | const is_global = variable.is_extern or o.dg.declIsGlobal(decl_val); | |
| 2912 | 2907 | const w = o.writer(); |
| 2913 | 2908 | if (!is_global) try w.writeAll("static "); |
| 2914 | 2909 | if (variable.is_weak_linkage) try w.writeAll("zig_weak_linkage "); |
| ... | ... | @@ -2916,22 +2911,22 @@ pub fn genDecl(o: *Object) !void { |
| 2916 | 2911 | if (mod.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |s| |
| 2917 | 2912 | try w.print("zig_linksection(\"{s}\", ", .{s}); |
| 2918 | 2913 | const decl_c_value = .{ .decl = decl_index }; |
| 2919 | try o.dg.renderTypeAndName(w, tv.ty, decl_c_value, .{}, decl.alignment, .complete); | |
| 2914 | try o.dg.renderTypeAndName(w, decl_ty, decl_c_value, .{}, decl.alignment, .complete); | |
| 2920 | 2915 | if (decl.@"linksection" != .none) try w.writeAll(", read, write)"); |
| 2921 | 2916 | try w.writeAll(" = "); |
| 2922 | try o.dg.renderValue(w, tv.ty, Value.fromInterned(variable.init), .StaticInitializer); | |
| 2917 | try o.dg.renderValue(w, decl_ty, Value.fromInterned(variable.init), .StaticInitializer); | |
| 2923 | 2918 | try w.writeByte(';'); |
| 2924 | 2919 | try o.indent_writer.insertNewline(); |
| 2925 | 2920 | } else { |
| 2926 | 2921 | const is_global = o.dg.module.decl_exports.contains(decl_index); |
| 2927 | 2922 | const decl_c_value = .{ .decl = decl_index }; |
| 2928 | try genDeclValue(o, tv, is_global, decl_c_value, decl.alignment, decl.@"linksection"); | |
| 2923 | try genDeclValue(o, decl_val, is_global, decl_c_value, decl.alignment, decl.@"linksection"); | |
| 2929 | 2924 | } |
| 2930 | 2925 | } |
| 2931 | 2926 | |
| 2932 | 2927 | pub fn genDeclValue( |
| 2933 | 2928 | o: *Object, |
| 2934 | tv: TypedValue, | |
| 2929 | val: Value, | |
| 2935 | 2930 | is_global: bool, |
| 2936 | 2931 | decl_c_value: CValue, |
| 2937 | 2932 | alignment: Alignment, |
| ... | ... | @@ -2940,8 +2935,10 @@ pub fn genDeclValue( |
| 2940 | 2935 | const mod = o.dg.module; |
| 2941 | 2936 | const fwd_decl_writer = o.dg.fwdDeclWriter(); |
| 2942 | 2937 | |
| 2938 | const ty = val.typeOf(mod); | |
| 2939 | ||
| 2943 | 2940 | try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static "); |
| 2944 | try o.dg.renderTypeAndName(fwd_decl_writer, tv.ty, decl_c_value, Const, alignment, .complete); | |
| 2941 | try o.dg.renderTypeAndName(fwd_decl_writer, ty, decl_c_value, Const, alignment, .complete); | |
| 2945 | 2942 | switch (o.dg.pass) { |
| 2946 | 2943 | .decl => |decl_index| { |
| 2947 | 2944 | if (mod.decl_exports.get(decl_index)) |exports| { |
| ... | ... | @@ -2964,10 +2961,10 @@ pub fn genDeclValue( |
| 2964 | 2961 | |
| 2965 | 2962 | if (mod.intern_pool.stringToSliceUnwrap(link_section)) |s| |
| 2966 | 2963 | try w.print("zig_linksection(\"{s}\", ", .{s}); |
| 2967 | try o.dg.renderTypeAndName(w, tv.ty, decl_c_value, Const, alignment, .complete); | |
| 2964 | try o.dg.renderTypeAndName(w, ty, decl_c_value, Const, alignment, .complete); | |
| 2968 | 2965 | if (link_section != .none) try w.writeAll(", read)"); |
| 2969 | 2966 | try w.writeAll(" = "); |
| 2970 | try o.dg.renderValue(w, tv.ty, tv.val, .StaticInitializer); | |
| 2967 | try o.dg.renderValue(w, ty, val, .StaticInitializer); | |
| 2971 | 2968 | try w.writeAll(";\n"); |
| 2972 | 2969 | } |
| 2973 | 2970 | |
| ... | ... | @@ -2978,14 +2975,10 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void { |
| 2978 | 2975 | const mod = dg.module; |
| 2979 | 2976 | const decl_index = dg.pass.decl; |
| 2980 | 2977 | const decl = mod.declPtr(decl_index); |
| 2981 | const tv: TypedValue = .{ | |
| 2982 | .ty = decl.typeOf(mod), | |
| 2983 | .val = decl.val, | |
| 2984 | }; | |
| 2985 | 2978 | const writer = dg.fwdDeclWriter(); |
| 2986 | 2979 | |
| 2987 | switch (tv.ty.zigTypeTag(mod)) { | |
| 2988 | .Fn => if (dg.declIsGlobal(tv)) { | |
| 2980 | switch (decl.val.typeOf(mod).zigTypeTag(mod)) { | |
| 2981 | .Fn => if (dg.declIsGlobal(decl.val)) { | |
| 2989 | 2982 | try writer.writeAll("zig_extern "); |
| 2990 | 2983 | try dg.renderFunctionSignature(writer, dg.pass.decl, .complete, .{ .export_index = 0 }); |
| 2991 | 2984 | try dg.fwd_decl.appendSlice(";\n"); |
| ... | ... | @@ -5304,25 +5297,25 @@ fn airIsNull( |
| 5304 | 5297 | const err_int_ty = try mod.errorIntType(); |
| 5305 | 5298 | |
| 5306 | 5299 | const rhs = if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) |
| 5307 | TypedValue{ .ty = Type.bool, .val = Value.true } | |
| 5300 | Value.true | |
| 5308 | 5301 | else if (optional_ty.isPtrLikeOptional(mod)) |
| 5309 | 5302 | // operand is a regular pointer, test `operand !=/== NULL` |
| 5310 | TypedValue{ .ty = optional_ty, .val = try mod.getCoerced(Value.null, optional_ty) } | |
| 5303 | try mod.getCoerced(Value.null, optional_ty) | |
| 5311 | 5304 | else if (payload_ty.zigTypeTag(mod) == .ErrorSet) |
| 5312 | TypedValue{ .ty = err_int_ty, .val = try mod.intValue(err_int_ty, 0) } | |
| 5305 | try mod.intValue(err_int_ty, 0) | |
| 5313 | 5306 | else if (payload_ty.isSlice(mod) and optional_ty.optionalReprIsPayload(mod)) rhs: { |
| 5314 | 5307 | try writer.writeAll(".ptr"); |
| 5315 | 5308 | const slice_ptr_ty = payload_ty.slicePtrFieldType(mod); |
| 5316 | 5309 | const opt_slice_ptr_ty = try mod.optionalType(slice_ptr_ty.toIntern()); |
| 5317 | break :rhs TypedValue{ .ty = opt_slice_ptr_ty, .val = try mod.nullValue(opt_slice_ptr_ty) }; | |
| 5310 | break :rhs try mod.nullValue(opt_slice_ptr_ty); | |
| 5318 | 5311 | } else rhs: { |
| 5319 | 5312 | try writer.writeAll(".is_null"); |
| 5320 | break :rhs TypedValue{ .ty = Type.bool, .val = Value.true }; | |
| 5313 | break :rhs Value.true; | |
| 5321 | 5314 | }; |
| 5322 | 5315 | try writer.writeByte(' '); |
| 5323 | 5316 | try writer.writeAll(operator); |
| 5324 | 5317 | try writer.writeByte(' '); |
| 5325 | try f.object.dg.renderValue(writer, rhs.ty, rhs.val, .Other); | |
| 5318 | try f.object.dg.renderValue(writer, rhs.typeOf(mod), rhs, .Other); | |
| 5326 | 5319 | try writer.writeAll(";\n"); |
| 5327 | 5320 | return local; |
| 5328 | 5321 | } |
src/codegen/llvm.zig+11-18| ... | ... | @@ -18,7 +18,6 @@ const Module = @import("../Module.zig"); |
| 18 | 18 | const Zcu = Module; |
| 19 | 19 | const InternPool = @import("../InternPool.zig"); |
| 20 | 20 | const Package = @import("../Package.zig"); |
| 21 | const TypedValue = @import("../TypedValue.zig"); | |
| 22 | 21 | const Air = @import("../Air.zig"); |
| 23 | 22 | const Liveness = @import("../Liveness.zig"); |
| 24 | 23 | const Value = @import("../Value.zig"); |
| ... | ... | @@ -4823,19 +4822,17 @@ pub const FuncGen = struct { |
| 4823 | 4822 | |
| 4824 | 4823 | const o = self.dg.object; |
| 4825 | 4824 | const mod = o.module; |
| 4826 | const llvm_val = try self.resolveValue(.{ | |
| 4827 | .ty = self.typeOf(inst), | |
| 4828 | .val = (try self.air.value(inst, mod)).?, | |
| 4829 | }); | |
| 4825 | const llvm_val = try self.resolveValue((try self.air.value(inst, mod)).?); | |
| 4830 | 4826 | gop.value_ptr.* = llvm_val.toValue(); |
| 4831 | 4827 | return llvm_val.toValue(); |
| 4832 | 4828 | } |
| 4833 | 4829 | |
| 4834 | fn resolveValue(self: *FuncGen, tv: TypedValue) Error!Builder.Constant { | |
| 4830 | fn resolveValue(self: *FuncGen, val: Value) Error!Builder.Constant { | |
| 4835 | 4831 | const o = self.dg.object; |
| 4836 | 4832 | const mod = o.module; |
| 4837 | const llvm_val = try o.lowerValue(tv.val.toIntern()); | |
| 4838 | if (!isByRef(tv.ty, mod)) return llvm_val; | |
| 4833 | const ty = val.typeOf(mod); | |
| 4834 | const llvm_val = try o.lowerValue(val.toIntern()); | |
| 4835 | if (!isByRef(ty, mod)) return llvm_val; | |
| 4839 | 4836 | |
| 4840 | 4837 | // We have an LLVM value but we need to create a global constant and |
| 4841 | 4838 | // set the value as its initializer, and then return a pointer to the global. |
| ... | ... | @@ -4849,7 +4846,7 @@ pub const FuncGen = struct { |
| 4849 | 4846 | variable_index.setLinkage(.private, &o.builder); |
| 4850 | 4847 | variable_index.setMutability(.constant, &o.builder); |
| 4851 | 4848 | variable_index.setUnnamedAddr(.unnamed_addr, &o.builder); |
| 4852 | variable_index.setAlignment(tv.ty.abiAlignment(mod).toLlvm(), &o.builder); | |
| 4849 | variable_index.setAlignment(ty.abiAlignment(mod).toLlvm(), &o.builder); | |
| 4853 | 4850 | return o.builder.convConst( |
| 4854 | 4851 | .unneeded, |
| 4855 | 4852 | variable_index.toConst(&o.builder), |
| ... | ... | @@ -4861,11 +4858,10 @@ pub const FuncGen = struct { |
| 4861 | 4858 | const o = self.dg.object; |
| 4862 | 4859 | const mod = o.module; |
| 4863 | 4860 | if (o.null_opt_usize == .no_init) { |
| 4864 | const ty = try mod.intern(.{ .opt_type = .usize_type }); | |
| 4865 | o.null_opt_usize = try self.resolveValue(.{ | |
| 4866 | .ty = Type.fromInterned(ty), | |
| 4867 | .val = Value.fromInterned((try mod.intern(.{ .opt = .{ .ty = ty, .val = .none } }))), | |
| 4868 | }); | |
| 4861 | o.null_opt_usize = try self.resolveValue(Value.fromInterned(try mod.intern(.{ .opt = .{ | |
| 4862 | .ty = try mod.intern(.{ .opt_type = .usize_type }), | |
| 4863 | .val = .none, | |
| 4864 | } }))); | |
| 4869 | 4865 | } |
| 4870 | 4866 | return o.null_opt_usize; |
| 4871 | 4867 | } |
| ... | ... | @@ -10061,10 +10057,7 @@ pub const FuncGen = struct { |
| 10061 | 10057 | const elem_ptr = try self.wip.gep(.inbounds, llvm_result_ty, alloca_inst, &.{ |
| 10062 | 10058 | usize_zero, try o.builder.intValue(llvm_usize, array_info.len), |
| 10063 | 10059 | }, ""); |
| 10064 | const llvm_elem = try self.resolveValue(.{ | |
| 10065 | .ty = array_info.elem_type, | |
| 10066 | .val = sent_val, | |
| 10067 | }); | |
| 10060 | const llvm_elem = try self.resolveValue(sent_val); | |
| 10068 | 10061 | try self.store(elem_ptr, elem_ptr_ty, llvm_elem.toValue(), .none); |
| 10069 | 10062 | } |
| 10070 | 10063 |
src/link.zig+3-3| ... | ... | @@ -17,7 +17,7 @@ const Liveness = @import("Liveness.zig"); |
| 17 | 17 | const Module = @import("Module.zig"); |
| 18 | 18 | const InternPool = @import("InternPool.zig"); |
| 19 | 19 | const Type = @import("type.zig").Type; |
| 20 | const TypedValue = @import("TypedValue.zig"); | |
| 20 | const Value = @import("Value.zig"); | |
| 21 | 21 | const LlvmObject = @import("codegen/llvm.zig").Object; |
| 22 | 22 | |
| 23 | 23 | /// When adding a new field, remember to update `hashAddSystemLibs`. |
| ... | ... | @@ -376,14 +376,14 @@ pub const File = struct { |
| 376 | 376 | /// Called from within the CodeGen to lower a local variable instantion as an unnamed |
| 377 | 377 | /// constant. Returns the symbol index of the lowered constant in the read-only section |
| 378 | 378 | /// of the final binary. |
| 379 | pub fn lowerUnnamedConst(base: *File, tv: TypedValue, decl_index: InternPool.DeclIndex) UpdateDeclError!u32 { | |
| 379 | pub fn lowerUnnamedConst(base: *File, val: Value, decl_index: InternPool.DeclIndex) UpdateDeclError!u32 { | |
| 380 | 380 | if (build_options.only_c) @compileError("unreachable"); |
| 381 | 381 | switch (base.tag) { |
| 382 | 382 | .spirv => unreachable, |
| 383 | 383 | .c => unreachable, |
| 384 | 384 | .nvptx => unreachable, |
| 385 | 385 | inline else => |t| { |
| 386 | return @fieldParentPtr(t.Type(), "base", base).lowerUnnamedConst(tv, decl_index); | |
| 386 | return @fieldParentPtr(t.Type(), "base", base).lowerUnnamedConst(val, decl_index); | |
| 387 | 387 | }, |
| 388 | 388 | } |
| 389 | 389 | } |
src/link/C.zig+1-5| ... | ... | @@ -283,13 +283,9 @@ fn updateAnonDecl(self: *C, module: *Module, i: usize) !void { |
| 283 | 283 | code.* = object.code.moveToUnmanaged(); |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | const tv: @import("../TypedValue.zig") = .{ | |
| 287 | .ty = Type.fromInterned(module.intern_pool.typeOf(anon_decl)), | |
| 288 | .val = Value.fromInterned(anon_decl), | |
| 289 | }; | |
| 290 | 286 | const c_value: codegen.CValue = .{ .constant = anon_decl }; |
| 291 | 287 | const alignment: Alignment = self.aligned_anon_decls.get(anon_decl) orelse .none; |
| 292 | codegen.genDeclValue(&object, tv, false, c_value, alignment, .none) catch |err| switch (err) { | |
| 288 | codegen.genDeclValue(&object, Value.fromInterned(anon_decl), false, c_value, alignment, .none) catch |err| switch (err) { | |
| 293 | 289 | error.AnalysisFail => { |
| 294 | 290 | @panic("TODO: C backend AnalysisFail on anonymous decl"); |
| 295 | 291 | //try module.failed_decls.put(gpa, decl_index, object.dg.error_msg.?); |
src/link/Coff.zig+7-11| ... | ... | @@ -1167,7 +1167,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air: |
| 1167 | 1167 | return self.updateExports(mod, .{ .decl_index = decl_index }, mod.getDeclExports(decl_index)); |
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: InternPool.DeclIndex) !u32 { | |
| 1170 | pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclIndex) !u32 { | |
| 1171 | 1171 | const gpa = self.base.comp.gpa; |
| 1172 | 1172 | const mod = self.base.comp.module.?; |
| 1173 | 1173 | const decl = mod.declPtr(decl_index); |
| ... | ... | @@ -1180,7 +1180,8 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: InternPool.Dec |
| 1180 | 1180 | const index = unnamed_consts.items.len; |
| 1181 | 1181 | const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{s}_{d}", .{ decl_name, index }); |
| 1182 | 1182 | defer gpa.free(sym_name); |
| 1183 | const atom_index = switch (try self.lowerConst(sym_name, tv, tv.ty.abiAlignment(mod), self.rdata_section_index.?, decl.srcLoc(mod))) { | |
| 1183 | const ty = val.typeOf(mod); | |
| 1184 | const atom_index = switch (try self.lowerConst(sym_name, val, ty.abiAlignment(mod), self.rdata_section_index.?, decl.srcLoc(mod))) { | |
| 1184 | 1185 | .ok => |atom_index| atom_index, |
| 1185 | 1186 | .fail => |em| { |
| 1186 | 1187 | decl.analysis = .codegen_failure; |
| ... | ... | @@ -1198,7 +1199,7 @@ const LowerConstResult = union(enum) { |
| 1198 | 1199 | fail: *Module.ErrorMsg, |
| 1199 | 1200 | }; |
| 1200 | 1201 | |
| 1201 | fn lowerConst(self: *Coff, name: []const u8, tv: TypedValue, required_alignment: InternPool.Alignment, sect_id: u16, src_loc: Module.SrcLoc) !LowerConstResult { | |
| 1202 | fn lowerConst(self: *Coff, name: []const u8, val: Value, required_alignment: InternPool.Alignment, sect_id: u16, src_loc: Module.SrcLoc) !LowerConstResult { | |
| 1202 | 1203 | const gpa = self.base.comp.gpa; |
| 1203 | 1204 | |
| 1204 | 1205 | var code_buffer = std.ArrayList(u8).init(gpa); |
| ... | ... | @@ -1209,7 +1210,7 @@ fn lowerConst(self: *Coff, name: []const u8, tv: TypedValue, required_alignment: |
| 1209 | 1210 | try self.setSymbolName(sym, name); |
| 1210 | 1211 | sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_id + 1)); |
| 1211 | 1212 | |
| 1212 | const res = try codegen.generateSymbol(&self.base, src_loc, tv, &code_buffer, .none, .{ | |
| 1213 | const res = try codegen.generateSymbol(&self.base, src_loc, val, &code_buffer, .none, .{ | |
| 1213 | 1214 | .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, |
| 1214 | 1215 | }); |
| 1215 | 1216 | const code = switch (res) { |
| ... | ... | @@ -1271,10 +1272,7 @@ pub fn updateDecl( |
| 1271 | 1272 | defer code_buffer.deinit(); |
| 1272 | 1273 | |
| 1273 | 1274 | const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; |
| 1274 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ | |
| 1275 | .ty = decl.typeOf(mod), | |
| 1276 | .val = decl_val, | |
| 1277 | }, &code_buffer, .none, .{ | |
| 1275 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), decl_val, &code_buffer, .none, .{ | |
| 1278 | 1276 | .parent_atom_index = atom.getSymbolIndex().?, |
| 1279 | 1277 | }); |
| 1280 | 1278 | const code = switch (res) { |
| ... | ... | @@ -1887,14 +1885,13 @@ pub fn lowerAnonDecl( |
| 1887 | 1885 | } |
| 1888 | 1886 | |
| 1889 | 1887 | const val = Value.fromInterned(decl_val); |
| 1890 | const tv = TypedValue{ .ty = ty, .val = val }; | |
| 1891 | 1888 | var name_buf: [32]u8 = undefined; |
| 1892 | 1889 | const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{ |
| 1893 | 1890 | @intFromEnum(decl_val), |
| 1894 | 1891 | }) catch unreachable; |
| 1895 | 1892 | const res = self.lowerConst( |
| 1896 | 1893 | name, |
| 1897 | tv, | |
| 1894 | val, | |
| 1898 | 1895 | decl_alignment, |
| 1899 | 1896 | self.rdata_section_index.?, |
| 1900 | 1897 | src_loc, |
| ... | ... | @@ -2754,7 +2751,6 @@ const TableSection = @import("table_section.zig").TableSection; |
| 2754 | 2751 | const StringTable = @import("StringTable.zig"); |
| 2755 | 2752 | const Type = @import("../type.zig").Type; |
| 2756 | 2753 | const Value = @import("../Value.zig"); |
| 2757 | const TypedValue = @import("../TypedValue.zig"); | |
| 2758 | 2754 | |
| 2759 | 2755 | pub const base_tag: link.File.Tag = .coff; |
| 2760 | 2756 |
src/link/Elf.zig+3-3| ... | ... | @@ -3039,8 +3039,8 @@ pub fn updateDecl( |
| 3039 | 3039 | return self.zigObjectPtr().?.updateDecl(self, mod, decl_index); |
| 3040 | 3040 | } |
| 3041 | 3041 | |
| 3042 | pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: InternPool.DeclIndex) !u32 { | |
| 3043 | return self.zigObjectPtr().?.lowerUnnamedConst(self, typed_value, decl_index); | |
| 3042 | pub fn lowerUnnamedConst(self: *Elf, val: Value, decl_index: InternPool.DeclIndex) !u32 { | |
| 3043 | return self.zigObjectPtr().?.lowerUnnamedConst(self, val, decl_index); | |
| 3044 | 3044 | } |
| 3045 | 3045 | |
| 3046 | 3046 | pub fn updateExports( |
| ... | ... | @@ -6260,7 +6260,7 @@ const SharedObject = @import("Elf/SharedObject.zig"); |
| 6260 | 6260 | const Symbol = @import("Elf/Symbol.zig"); |
| 6261 | 6261 | const StringTable = @import("StringTable.zig"); |
| 6262 | 6262 | const Thunk = thunks.Thunk; |
| 6263 | const TypedValue = @import("../TypedValue.zig"); | |
| 6263 | const Value = @import("../Value.zig"); | |
| 6264 | 6264 | const VerneedSection = synthetic_sections.VerneedSection; |
| 6265 | 6265 | const ZigGotSection = synthetic_sections.ZigGotSection; |
| 6266 | 6266 | const ZigObject = @import("Elf/ZigObject.zig"); |
src/link/Elf/ZigObject.zig+9-16| ... | ... | @@ -702,7 +702,6 @@ pub fn lowerAnonDecl( |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | const val = Value.fromInterned(decl_val); |
| 705 | const tv = TypedValue{ .ty = ty, .val = val }; | |
| 706 | 705 | var name_buf: [32]u8 = undefined; |
| 707 | 706 | const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{ |
| 708 | 707 | @intFromEnum(decl_val), |
| ... | ... | @@ -710,7 +709,7 @@ pub fn lowerAnonDecl( |
| 710 | 709 | const res = self.lowerConst( |
| 711 | 710 | elf_file, |
| 712 | 711 | name, |
| 713 | tv, | |
| 712 | val, | |
| 714 | 713 | decl_alignment, |
| 715 | 714 | elf_file.zig_data_rel_ro_section_index.?, |
| 716 | 715 | src_loc, |
| ... | ... | @@ -1157,19 +1156,13 @@ pub fn updateDecl( |
| 1157 | 1156 | // TODO implement .debug_info for global variables |
| 1158 | 1157 | const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; |
| 1159 | 1158 | const res = if (decl_state) |*ds| |
| 1160 | try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), .{ | |
| 1161 | .ty = decl.typeOf(mod), | |
| 1162 | .val = decl_val, | |
| 1163 | }, &code_buffer, .{ | |
| 1159 | try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), decl_val, &code_buffer, .{ | |
| 1164 | 1160 | .dwarf = ds, |
| 1165 | 1161 | }, .{ |
| 1166 | 1162 | .parent_atom_index = sym_index, |
| 1167 | 1163 | }) |
| 1168 | 1164 | else |
| 1169 | try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), .{ | |
| 1170 | .ty = decl.typeOf(mod), | |
| 1171 | .val = decl_val, | |
| 1172 | }, &code_buffer, .none, .{ | |
| 1165 | try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), decl_val, &code_buffer, .none, .{ | |
| 1173 | 1166 | .parent_atom_index = sym_index, |
| 1174 | 1167 | }); |
| 1175 | 1168 | |
| ... | ... | @@ -1289,7 +1282,7 @@ fn updateLazySymbol( |
| 1289 | 1282 | pub fn lowerUnnamedConst( |
| 1290 | 1283 | self: *ZigObject, |
| 1291 | 1284 | elf_file: *Elf, |
| 1292 | typed_value: TypedValue, | |
| 1285 | val: Value, | |
| 1293 | 1286 | decl_index: InternPool.DeclIndex, |
| 1294 | 1287 | ) !u32 { |
| 1295 | 1288 | const gpa = elf_file.base.comp.gpa; |
| ... | ... | @@ -1304,11 +1297,12 @@ pub fn lowerUnnamedConst( |
| 1304 | 1297 | const index = unnamed_consts.items.len; |
| 1305 | 1298 | const name = try std.fmt.allocPrint(gpa, "__unnamed_{s}_{d}", .{ decl_name, index }); |
| 1306 | 1299 | defer gpa.free(name); |
| 1300 | const ty = val.typeOf(mod); | |
| 1307 | 1301 | const sym_index = switch (try self.lowerConst( |
| 1308 | 1302 | elf_file, |
| 1309 | 1303 | name, |
| 1310 | typed_value, | |
| 1311 | typed_value.ty.abiAlignment(mod), | |
| 1304 | val, | |
| 1305 | ty.abiAlignment(mod), | |
| 1312 | 1306 | elf_file.zig_data_rel_ro_section_index.?, |
| 1313 | 1307 | decl.srcLoc(mod), |
| 1314 | 1308 | )) { |
| ... | ... | @@ -1334,7 +1328,7 @@ fn lowerConst( |
| 1334 | 1328 | self: *ZigObject, |
| 1335 | 1329 | elf_file: *Elf, |
| 1336 | 1330 | name: []const u8, |
| 1337 | tv: TypedValue, | |
| 1331 | val: Value, | |
| 1338 | 1332 | required_alignment: InternPool.Alignment, |
| 1339 | 1333 | output_section_index: u32, |
| 1340 | 1334 | src_loc: Module.SrcLoc, |
| ... | ... | @@ -1346,7 +1340,7 @@ fn lowerConst( |
| 1346 | 1340 | |
| 1347 | 1341 | const sym_index = try self.addAtom(elf_file); |
| 1348 | 1342 | |
| 1349 | const res = try codegen.generateSymbol(&elf_file.base, src_loc, tv, &code_buffer, .{ | |
| 1343 | const res = try codegen.generateSymbol(&elf_file.base, src_loc, val, &code_buffer, .{ | |
| 1350 | 1344 | .none = {}, |
| 1351 | 1345 | }, .{ |
| 1352 | 1346 | .parent_atom_index = sym_index, |
| ... | ... | @@ -1657,5 +1651,4 @@ const Symbol = @import("Symbol.zig"); |
| 1657 | 1651 | const StringTable = @import("../StringTable.zig"); |
| 1658 | 1652 | const Type = @import("../../type.zig").Type; |
| 1659 | 1653 | const Value = @import("../../Value.zig"); |
| 1660 | const TypedValue = @import("../../TypedValue.zig"); | |
| 1661 | 1654 | const ZigObject = @This(); |
src/link/MachO.zig+3-3| ... | ... | @@ -3127,8 +3127,8 @@ pub fn updateFunc(self: *MachO, mod: *Module, func_index: InternPool.Index, air: |
| 3127 | 3127 | return self.getZigObject().?.updateFunc(self, mod, func_index, air, liveness); |
| 3128 | 3128 | } |
| 3129 | 3129 | |
| 3130 | pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: InternPool.DeclIndex) !u32 { | |
| 3131 | return self.getZigObject().?.lowerUnnamedConst(self, typed_value, decl_index); | |
| 3130 | pub fn lowerUnnamedConst(self: *MachO, val: Value, decl_index: InternPool.DeclIndex) !u32 { | |
| 3131 | return self.getZigObject().?.lowerUnnamedConst(self, val, decl_index); | |
| 3132 | 3132 | } |
| 3133 | 3133 | |
| 3134 | 3134 | pub fn updateDecl(self: *MachO, mod: *Module, decl_index: InternPool.DeclIndex) !void { |
| ... | ... | @@ -4689,7 +4689,7 @@ const StubsHelperSection = synthetic.StubsHelperSection; |
| 4689 | 4689 | const Symbol = @import("MachO/Symbol.zig"); |
| 4690 | 4690 | const Thunk = thunks.Thunk; |
| 4691 | 4691 | const TlvPtrSection = synthetic.TlvPtrSection; |
| 4692 | const TypedValue = @import("../TypedValue.zig"); | |
| 4692 | const Value = @import("../Value.zig"); | |
| 4693 | 4693 | const UnwindInfo = @import("MachO/UnwindInfo.zig"); |
| 4694 | 4694 | const WeakBindSection = synthetic.WeakBindSection; |
| 4695 | 4695 | const ZigGotSection = synthetic.ZigGotSection; |
src/link/MachO/ZigObject.zig+7-14| ... | ... | @@ -567,8 +567,6 @@ pub fn lowerAnonDecl( |
| 567 | 567 | return .ok; |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | const val = Value.fromInterned(decl_val); | |
| 571 | const tv = TypedValue{ .ty = ty, .val = val }; | |
| 572 | 570 | var name_buf: [32]u8 = undefined; |
| 573 | 571 | const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{ |
| 574 | 572 | @intFromEnum(decl_val), |
| ... | ... | @@ -576,7 +574,7 @@ pub fn lowerAnonDecl( |
| 576 | 574 | const res = self.lowerConst( |
| 577 | 575 | macho_file, |
| 578 | 576 | name, |
| 579 | tv, | |
| 577 | Value.fromInterned(decl_val), | |
| 580 | 578 | decl_alignment, |
| 581 | 579 | macho_file.zig_const_sect_index.?, |
| 582 | 580 | src_loc, |
| ... | ... | @@ -738,11 +736,7 @@ pub fn updateDecl( |
| 738 | 736 | |
| 739 | 737 | const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; |
| 740 | 738 | const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none; |
| 741 | const res = | |
| 742 | try codegen.generateSymbol(&macho_file.base, decl.srcLoc(mod), .{ | |
| 743 | .ty = decl.typeOf(mod), | |
| 744 | .val = decl_val, | |
| 745 | }, &code_buffer, dio, .{ | |
| 739 | const res = try codegen.generateSymbol(&macho_file.base, decl.srcLoc(mod), decl_val, &code_buffer, dio, .{ | |
| 746 | 740 | .parent_atom_index = sym_index, |
| 747 | 741 | }); |
| 748 | 742 | |
| ... | ... | @@ -1068,7 +1062,7 @@ fn getDeclOutputSection( |
| 1068 | 1062 | pub fn lowerUnnamedConst( |
| 1069 | 1063 | self: *ZigObject, |
| 1070 | 1064 | macho_file: *MachO, |
| 1071 | typed_value: TypedValue, | |
| 1065 | val: Value, | |
| 1072 | 1066 | decl_index: InternPool.DeclIndex, |
| 1073 | 1067 | ) !u32 { |
| 1074 | 1068 | const gpa = macho_file.base.comp.gpa; |
| ... | ... | @@ -1086,8 +1080,8 @@ pub fn lowerUnnamedConst( |
| 1086 | 1080 | const sym_index = switch (try self.lowerConst( |
| 1087 | 1081 | macho_file, |
| 1088 | 1082 | name, |
| 1089 | typed_value, | |
| 1090 | typed_value.ty.abiAlignment(mod), | |
| 1083 | val, | |
| 1084 | val.typeOf(mod).abiAlignment(mod), | |
| 1091 | 1085 | macho_file.zig_const_sect_index.?, |
| 1092 | 1086 | decl.srcLoc(mod), |
| 1093 | 1087 | )) { |
| ... | ... | @@ -1113,7 +1107,7 @@ fn lowerConst( |
| 1113 | 1107 | self: *ZigObject, |
| 1114 | 1108 | macho_file: *MachO, |
| 1115 | 1109 | name: []const u8, |
| 1116 | tv: TypedValue, | |
| 1110 | val: Value, | |
| 1117 | 1111 | required_alignment: Atom.Alignment, |
| 1118 | 1112 | output_section_index: u8, |
| 1119 | 1113 | src_loc: Module.SrcLoc, |
| ... | ... | @@ -1125,7 +1119,7 @@ fn lowerConst( |
| 1125 | 1119 | |
| 1126 | 1120 | const sym_index = try self.addAtom(macho_file); |
| 1127 | 1121 | |
| 1128 | const res = try codegen.generateSymbol(&macho_file.base, src_loc, tv, &code_buffer, .{ | |
| 1122 | const res = try codegen.generateSymbol(&macho_file.base, src_loc, val, &code_buffer, .{ | |
| 1129 | 1123 | .none = {}, |
| 1130 | 1124 | }, .{ |
| 1131 | 1125 | .parent_atom_index = sym_index, |
| ... | ... | @@ -1580,5 +1574,4 @@ const Symbol = @import("Symbol.zig"); |
| 1580 | 1574 | const StringTable = @import("../StringTable.zig"); |
| 1581 | 1575 | const Type = @import("../../type.zig").Type; |
| 1582 | 1576 | const Value = @import("../../Value.zig"); |
| 1583 | const TypedValue = @import("../../TypedValue.zig"); | |
| 1584 | 1577 | const ZigObject = @This(); |
src/link/Plan9.zig+4-11| ... | ... | @@ -15,7 +15,6 @@ const Air = @import("../Air.zig"); |
| 15 | 15 | const Liveness = @import("../Liveness.zig"); |
| 16 | 16 | const Type = @import("../type.zig").Type; |
| 17 | 17 | const Value = @import("../Value.zig"); |
| 18 | const TypedValue = @import("../TypedValue.zig"); | |
| 19 | 18 | |
| 20 | 19 | const std = @import("std"); |
| 21 | 20 | const builtin = @import("builtin"); |
| ... | ... | @@ -463,7 +462,7 @@ pub fn updateFunc(self: *Plan9, mod: *Module, func_index: InternPool.Index, air: |
| 463 | 462 | return self.updateFinish(decl_index); |
| 464 | 463 | } |
| 465 | 464 | |
| 466 | pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: InternPool.DeclIndex) !u32 { | |
| 465 | pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIndex) !u32 { | |
| 467 | 466 | const gpa = self.base.comp.gpa; |
| 468 | 467 | _ = try self.seeDecl(decl_index); |
| 469 | 468 | var code_buffer = std.ArrayList(u8).init(gpa); |
| ... | ... | @@ -500,7 +499,7 @@ pub fn lowerUnnamedConst(self: *Plan9, tv: TypedValue, decl_index: InternPool.De |
| 500 | 499 | }; |
| 501 | 500 | self.syms.items[info.sym_index.?] = sym; |
| 502 | 501 | |
| 503 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), tv, &code_buffer, .{ | |
| 502 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), val, &code_buffer, .{ | |
| 504 | 503 | .none = {}, |
| 505 | 504 | }, .{ |
| 506 | 505 | .parent_atom_index = new_atom_idx, |
| ... | ... | @@ -539,10 +538,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex) |
| 539 | 538 | defer code_buffer.deinit(); |
| 540 | 539 | const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; |
| 541 | 540 | // TODO we need the symbol index for symbol in the table of locals for the containing atom |
| 542 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ | |
| 543 | .ty = decl.typeOf(mod), | |
| 544 | .val = decl_val, | |
| 545 | }, &code_buffer, .{ .none = {} }, .{ | |
| 541 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), decl_val, &code_buffer, .{ .none = {} }, .{ | |
| 546 | 542 | .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)), |
| 547 | 543 | }); |
| 548 | 544 | const code = switch (res) { |
| ... | ... | @@ -1545,11 +1541,8 @@ pub fn lowerAnonDecl( |
| 1545 | 1541 | // ... |
| 1546 | 1542 | const gpa = self.base.comp.gpa; |
| 1547 | 1543 | const gop = try self.anon_decls.getOrPut(gpa, decl_val); |
| 1548 | const mod = self.base.comp.module.?; | |
| 1549 | 1544 | if (!gop.found_existing) { |
| 1550 | const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val)); | |
| 1551 | 1545 | const val = Value.fromInterned(decl_val); |
| 1552 | const tv = TypedValue{ .ty = ty, .val = val }; | |
| 1553 | 1546 | const name = try std.fmt.allocPrint(gpa, "__anon_{d}", .{@intFromEnum(decl_val)}); |
| 1554 | 1547 | |
| 1555 | 1548 | const index = try self.createAtom(); |
| ... | ... | @@ -1557,7 +1550,7 @@ pub fn lowerAnonDecl( |
| 1557 | 1550 | gop.value_ptr.* = index; |
| 1558 | 1551 | // we need to free name latex |
| 1559 | 1552 | var code_buffer = std.ArrayList(u8).init(gpa); |
| 1560 | const res = try codegen.generateSymbol(&self.base, src_loc, tv, &code_buffer, .{ .none = {} }, .{ .parent_atom_index = index }); | |
| 1553 | const res = try codegen.generateSymbol(&self.base, src_loc, val, &code_buffer, .{ .none = {} }, .{ .parent_atom_index = index }); | |
| 1561 | 1554 | const code = switch (res) { |
| 1562 | 1555 | .ok => code_buffer.items, |
| 1563 | 1556 | .fail => |em| return .{ .fail = em }, |
src/link/Wasm.zig+3-3| ... | ... | @@ -32,7 +32,7 @@ const Module = @import("../Module.zig"); |
| 32 | 32 | const Object = @import("Wasm/Object.zig"); |
| 33 | 33 | const Symbol = @import("Wasm/Symbol.zig"); |
| 34 | 34 | const Type = @import("../type.zig").Type; |
| 35 | const TypedValue = @import("../TypedValue.zig"); | |
| 35 | const Value = @import("../Value.zig"); | |
| 36 | 36 | const ZigObject = @import("Wasm/ZigObject.zig"); |
| 37 | 37 | |
| 38 | 38 | pub const Atom = @import("Wasm/Atom.zig"); |
| ... | ... | @@ -1504,8 +1504,8 @@ fn getFunctionSignature(wasm: *const Wasm, loc: SymbolLoc) std.wasm.Type { |
| 1504 | 1504 | /// Lowers a constant typed value to a local symbol and atom. |
| 1505 | 1505 | /// Returns the symbol index of the local |
| 1506 | 1506 | /// The given `decl` is the parent decl whom owns the constant. |
| 1507 | pub fn lowerUnnamedConst(wasm: *Wasm, tv: TypedValue, decl_index: InternPool.DeclIndex) !u32 { | |
| 1508 | return wasm.zigObjectPtr().?.lowerUnnamedConst(wasm, tv, decl_index); | |
| 1507 | pub fn lowerUnnamedConst(wasm: *Wasm, val: Value, decl_index: InternPool.DeclIndex) !u32 { | |
| 1508 | return wasm.zigObjectPtr().?.lowerUnnamedConst(wasm, val, decl_index); | |
| 1509 | 1509 | } |
| 1510 | 1510 | |
| 1511 | 1511 | /// Returns the symbol index from a symbol of which its flag is set global, |
src/link/Wasm/ZigObject.zig+11-13| ... | ... | @@ -270,7 +270,7 @@ pub fn updateDecl( |
| 270 | 270 | const res = try codegen.generateSymbol( |
| 271 | 271 | &wasm_file.base, |
| 272 | 272 | decl.srcLoc(mod), |
| 273 | .{ .ty = decl.typeOf(mod), .val = val }, | |
| 273 | val, | |
| 274 | 274 | &code_writer, |
| 275 | 275 | .none, |
| 276 | 276 | .{ .parent_atom_index = @intFromEnum(atom.sym_index) }, |
| ... | ... | @@ -444,15 +444,12 @@ pub fn lowerAnonDecl( |
| 444 | 444 | const gpa = wasm_file.base.comp.gpa; |
| 445 | 445 | const gop = try zig_object.anon_decls.getOrPut(gpa, decl_val); |
| 446 | 446 | if (!gop.found_existing) { |
| 447 | const mod = wasm_file.base.comp.module.?; | |
| 448 | const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val)); | |
| 449 | const tv: TypedValue = .{ .ty = ty, .val = Value.fromInterned(decl_val) }; | |
| 450 | 447 | var name_buf: [32]u8 = undefined; |
| 451 | 448 | const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{ |
| 452 | 449 | @intFromEnum(decl_val), |
| 453 | 450 | }) catch unreachable; |
| 454 | 451 | |
| 455 | switch (try zig_object.lowerConst(wasm_file, name, tv, src_loc)) { | |
| 452 | switch (try zig_object.lowerConst(wasm_file, name, Value.fromInterned(decl_val), src_loc)) { | |
| 456 | 453 | .ok => |atom_index| zig_object.anon_decls.values()[gop.index] = atom_index, |
| 457 | 454 | .fail => |em| return .{ .fail = em }, |
| 458 | 455 | } |
| ... | ... | @@ -472,10 +469,10 @@ pub fn lowerAnonDecl( |
| 472 | 469 | /// Lowers a constant typed value to a local symbol and atom. |
| 473 | 470 | /// Returns the symbol index of the local |
| 474 | 471 | /// The given `decl` is the parent decl whom owns the constant. |
| 475 | pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, tv: TypedValue, decl_index: InternPool.DeclIndex) !u32 { | |
| 472 | pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, decl_index: InternPool.DeclIndex) !u32 { | |
| 476 | 473 | const gpa = wasm_file.base.comp.gpa; |
| 477 | 474 | const mod = wasm_file.base.comp.module.?; |
| 478 | std.debug.assert(tv.ty.zigTypeTag(mod) != .Fn); // cannot create local symbols for functions | |
| 475 | std.debug.assert(val.typeOf(mod).zigTypeTag(mod) != .Fn); // cannot create local symbols for functions | |
| 479 | 476 | const decl = mod.declPtr(decl_index); |
| 480 | 477 | |
| 481 | 478 | const parent_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index); |
| ... | ... | @@ -487,7 +484,7 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, tv: TypedValu |
| 487 | 484 | }); |
| 488 | 485 | defer gpa.free(name); |
| 489 | 486 | |
| 490 | switch (try zig_object.lowerConst(wasm_file, name, tv, decl.srcLoc(mod))) { | |
| 487 | switch (try zig_object.lowerConst(wasm_file, name, val, decl.srcLoc(mod))) { | |
| 491 | 488 | .ok => |atom_index| { |
| 492 | 489 | try wasm_file.getAtomPtr(parent_atom_index).locals.append(gpa, atom_index); |
| 493 | 490 | return @intFromEnum(wasm_file.getAtom(atom_index).sym_index); |
| ... | ... | @@ -505,10 +502,12 @@ const LowerConstResult = union(enum) { |
| 505 | 502 | fail: *Module.ErrorMsg, |
| 506 | 503 | }; |
| 507 | 504 | |
| 508 | fn lowerConst(zig_object: *ZigObject, wasm_file: *Wasm, name: []const u8, tv: TypedValue, src_loc: Module.SrcLoc) !LowerConstResult { | |
| 505 | fn lowerConst(zig_object: *ZigObject, wasm_file: *Wasm, name: []const u8, val: Value, src_loc: Module.SrcLoc) !LowerConstResult { | |
| 509 | 506 | const gpa = wasm_file.base.comp.gpa; |
| 510 | 507 | const mod = wasm_file.base.comp.module.?; |
| 511 | 508 | |
| 509 | const ty = val.typeOf(mod); | |
| 510 | ||
| 512 | 511 | // Create and initialize a new local symbol and atom |
| 513 | 512 | const sym_index = try zig_object.allocateSymbol(gpa); |
| 514 | 513 | const atom_index = try wasm_file.createAtom(sym_index, zig_object.index); |
| ... | ... | @@ -517,7 +516,7 @@ fn lowerConst(zig_object: *ZigObject, wasm_file: *Wasm, name: []const u8, tv: Ty |
| 517 | 516 | |
| 518 | 517 | const code = code: { |
| 519 | 518 | const atom = wasm_file.getAtomPtr(atom_index); |
| 520 | atom.alignment = tv.ty.abiAlignment(mod); | |
| 519 | atom.alignment = ty.abiAlignment(mod); | |
| 521 | 520 | const segment_name = try std.mem.concat(gpa, u8, &.{ ".rodata.", name }); |
| 522 | 521 | errdefer gpa.free(segment_name); |
| 523 | 522 | zig_object.symbol(sym_index).* = .{ |
| ... | ... | @@ -527,7 +526,7 @@ fn lowerConst(zig_object: *ZigObject, wasm_file: *Wasm, name: []const u8, tv: Ty |
| 527 | 526 | .index = try zig_object.createDataSegment( |
| 528 | 527 | gpa, |
| 529 | 528 | segment_name, |
| 530 | tv.ty.abiAlignment(mod), | |
| 529 | ty.abiAlignment(mod), | |
| 531 | 530 | ), |
| 532 | 531 | .virtual_address = undefined, |
| 533 | 532 | }; |
| ... | ... | @@ -535,7 +534,7 @@ fn lowerConst(zig_object: *ZigObject, wasm_file: *Wasm, name: []const u8, tv: Ty |
| 535 | 534 | const result = try codegen.generateSymbol( |
| 536 | 535 | &wasm_file.base, |
| 537 | 536 | src_loc, |
| 538 | tv, | |
| 537 | val, | |
| 539 | 538 | &value_bytes, |
| 540 | 539 | .none, |
| 541 | 540 | .{ |
| ... | ... | @@ -1242,7 +1241,6 @@ const Module = @import("../../Module.zig"); |
| 1242 | 1241 | const StringTable = @import("../StringTable.zig"); |
| 1243 | 1242 | const Symbol = @import("Symbol.zig"); |
| 1244 | 1243 | const Type = @import("../../type.zig").Type; |
| 1245 | const TypedValue = @import("../../TypedValue.zig"); | |
| 1246 | 1244 | const Value = @import("../../Value.zig"); |
| 1247 | 1245 | const Wasm = @import("../Wasm.zig"); |
| 1248 | 1246 | const ZigObject = @This(); |
src/type.zig-1| ... | ... | @@ -7,7 +7,6 @@ const Module = @import("Module.zig"); |
| 7 | 7 | const Zcu = Module; |
| 8 | 8 | const log = std.log.scoped(.Type); |
| 9 | 9 | const target_util = @import("target.zig"); |
| 10 | const TypedValue = @import("TypedValue.zig"); | |
| 11 | 10 | const Sema = @import("Sema.zig"); |
| 12 | 11 | const InternPool = @import("InternPool.zig"); |
| 13 | 12 | const Alignment = InternPool.Alignment; |