| ... | @@ -387,22 +387,24 @@ pub fn generateSymbol( | ... | @@ -387,22 +387,24 @@ pub fn generateSymbol( |
| 387 | }, | 387 | }, |
| 388 | .aggregate => |aggregate| switch (mod.intern_pool.indexToKey(typed_value.ty.toIntern())) { | 388 | .aggregate => |aggregate| switch (mod.intern_pool.indexToKey(typed_value.ty.toIntern())) { |
| 389 | .array_type => |array_type| { | 389 | .array_type => |array_type| { |
| 390 | var index: u64 = 0; | 390 | switch (aggregate.storage) { |
| 391 | while (index < array_type.len) : (index += 1) { | 391 | .bytes => |bytes| try code.appendSlice(bytes), |
| 392 | switch (aggregate.storage) { | 392 | .elems, .repeated_elem => { |
| 393 | .bytes => |bytes| try code.appendSlice(bytes), | 393 | var index: u64 = 0; |
| 394 | .elems, .repeated_elem => switch (try generateSymbol(bin_file, src_loc, .{ | 394 | while (index < array_type.len) : (index += 1) { |
| 395 | .ty = array_type.child.toType(), | 395 | switch (try generateSymbol(bin_file, src_loc, .{ |
| 396 | .val = switch (aggregate.storage) { | 396 | .ty = array_type.child.toType(), |
| 397 | .bytes => unreachable, | 397 | .val = switch (aggregate.storage) { |
| 398 | .elems => |elems| elems[@intCast(usize, index)], | 398 | .bytes => unreachable, |
| 399 | .repeated_elem => |elem| elem, | 399 | .elems => |elems| elems[@intCast(usize, index)], |
| 400 | }.toValue(), | 400 | .repeated_elem => |elem| elem, |
| 401 | }, code, debug_output, reloc_info)) { | 401 | }.toValue(), |
| 402 | .ok => {}, | 402 | }, code, debug_output, reloc_info)) { |
| 403 | .fail => |em| return .{ .fail = em }, | 403 | .ok => {}, |
| 404 | }, | 404 | .fail => |em| return .{ .fail = em }, |
| 405 | } | 405 | } |
| | 406 | } |
| | 407 | }, |
| 406 | } | 408 | } |
| 407 | | 409 | |
| 408 | if (array_type.sentinel != .none) { | 410 | if (array_type.sentinel != .none) { |
| ... | @@ -416,22 +418,24 @@ pub fn generateSymbol( | ... | @@ -416,22 +418,24 @@ pub fn generateSymbol( |
| 416 | } | 418 | } |
| 417 | }, | 419 | }, |
| 418 | .vector_type => |vector_type| { | 420 | .vector_type => |vector_type| { |
| 419 | var index: u32 = 0; | 421 | switch (aggregate.storage) { |
| 420 | while (index < vector_type.len) : (index += 1) { | 422 | .bytes => |bytes| try code.appendSlice(bytes), |
| 421 | switch (aggregate.storage) { | 423 | .elems, .repeated_elem => { |
| 422 | .bytes => |bytes| try code.appendSlice(bytes), | 424 | var index: u64 = 0; |
| 423 | .elems, .repeated_elem => switch (try generateSymbol(bin_file, src_loc, .{ | 425 | while (index < vector_type.len) : (index += 1) { |
| 424 | .ty = vector_type.child.toType(), | 426 | switch (try generateSymbol(bin_file, src_loc, .{ |
| 425 | .val = switch (aggregate.storage) { | 427 | .ty = vector_type.child.toType(), |
| 426 | .bytes => unreachable, | 428 | .val = switch (aggregate.storage) { |
| 427 | .elems => |elems| elems[@intCast(usize, index)], | 429 | .bytes => unreachable, |
| 428 | .repeated_elem => |elem| elem, | 430 | .elems => |elems| elems[@intCast(usize, index)], |
| 429 | }.toValue(), | 431 | .repeated_elem => |elem| elem, |
| 430 | }, code, debug_output, reloc_info)) { | 432 | }.toValue(), |
| 431 | .ok => {}, | 433 | }, code, debug_output, reloc_info)) { |
| 432 | .fail => |em| return .{ .fail = em }, | 434 | .ok => {}, |
| 433 | }, | 435 | .fail => |em| return .{ .fail = em }, |
| 434 | } | 436 | } |
| | 437 | } |
| | 438 | }, |
| 435 | } | 439 | } |
| 436 | | 440 | |
| 437 | const padding = math.cast(usize, typed_value.ty.abiSize(mod) - | 441 | const padding = math.cast(usize, typed_value.ty.abiSize(mod) - |
| ... | @@ -669,7 +673,7 @@ fn lowerParentPtr( | ... | @@ -669,7 +673,7 @@ fn lowerParentPtr( |
| 669 | mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).abiSize(mod))), | 673 | mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).abiSize(mod))), |
| 670 | ), | 674 | ), |
| 671 | .field => |field| { | 675 | .field => |field| { |
| 672 | const base_type = mod.intern_pool.typeOf(field.base); | 676 | const base_type = mod.intern_pool.indexToKey(mod.intern_pool.typeOf(field.base)).ptr_type.elem_type; |
| 673 | return lowerParentPtr( | 677 | return lowerParentPtr( |
| 674 | bin_file, | 678 | bin_file, |
| 675 | src_loc, | 679 | src_loc, |
| ... | @@ -688,7 +692,7 @@ fn lowerParentPtr( | ... | @@ -688,7 +692,7 @@ fn lowerParentPtr( |
| 688 | .struct_type, | 692 | .struct_type, |
| 689 | .anon_struct_type, | 693 | .anon_struct_type, |
| 690 | .union_type, | 694 | .union_type, |
| 691 | => @intCast(u32, base_type.toType().childType(mod).structFieldOffset( | 695 | => @intCast(u32, base_type.toType().structFieldOffset( |
| 692 | @intCast(u32, field.index), | 696 | @intCast(u32, field.index), |
| 693 | mod, | 697 | mod, |
| 694 | )), | 698 | )), |
| ... | @@ -989,17 +993,23 @@ pub fn genTypedValue( | ... | @@ -989,17 +993,23 @@ pub fn genTypedValue( |
| 989 | return GenResult.mcv(.{ .immediate = error_index }); | 993 | return GenResult.mcv(.{ .immediate = error_index }); |
| 990 | }, | 994 | }, |
| 991 | .ErrorUnion => { | 995 | .ErrorUnion => { |
| 992 | const error_type = typed_value.ty.errorUnionSet(mod); | 996 | const err_type = typed_value.ty.errorUnionSet(mod); |
| 993 | const payload_type = typed_value.ty.errorUnionPayload(mod); | 997 | const payload_type = typed_value.ty.errorUnionPayload(mod); |
| 994 | const is_pl = typed_value.val.errorUnionIsPayload(mod); | | |
| 995 | | | |
| 996 | if (!payload_type.hasRuntimeBitsIgnoreComptime(mod)) { | 998 | if (!payload_type.hasRuntimeBitsIgnoreComptime(mod)) { |
| 997 | // We use the error type directly as the type. | 999 | // We use the error type directly as the type. |
| 998 | const err_val = if (!is_pl) typed_value.val else try mod.intValue(error_type, 0); | 1000 | switch (mod.intern_pool.indexToKey(typed_value.val.toIntern()).error_union.val) { |
| 999 | return genTypedValue(bin_file, src_loc, .{ | 1001 | .err_name => |err_name| return genTypedValue(bin_file, src_loc, .{ |
| 1000 | .ty = error_type, | 1002 | .ty = err_type, |
| 1001 | .val = err_val, | 1003 | .val = (try mod.intern(.{ .err = .{ |
| 1002 | }, owner_decl_index); | 1004 | .ty = err_type.toIntern(), |
| | 1005 | .name = err_name, |
| | 1006 | } })).toValue(), |
| | 1007 | }, owner_decl_index), |
| | 1008 | .payload => return genTypedValue(bin_file, src_loc, .{ |
| | 1009 | .ty = Type.err_int, |
| | 1010 | .val = try mod.intValue(Type.err_int, 0), |
| | 1011 | }, owner_decl_index), |
| | 1012 | } |
| 1003 | } | 1013 | } |
| 1004 | }, | 1014 | }, |
| 1005 | | 1015 | |