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