| ... | @@ -22,8 +22,10 @@ const Value = @import("value.zig").Value; | ... | @@ -22,8 +22,10 @@ const Value = @import("value.zig").Value; |
| 22 | const Zir = @import("Zir.zig"); | 22 | const Zir = @import("Zir.zig"); |
| 23 | | 23 | |
| 24 | pub const Result = union(enum) { | 24 | pub const Result = union(enum) { |
| 25 | /// The `code` parameter passed to `generateSymbol` has the value appended. | 25 | /// The `code` parameter passed to `generateSymbol` has the value ok. |
| 26 | appended: void, | 26 | ok: void, |
| | 27 | |
| | 28 | /// There was a codegen error. |
| 27 | fail: *ErrorMsg, | 29 | fail: *ErrorMsg, |
| 28 | }; | 30 | }; |
| 29 | | 31 | |
| ... | @@ -138,7 +140,7 @@ pub fn generateSymbol( | ... | @@ -138,7 +140,7 @@ pub fn generateSymbol( |
| 138 | if (typed_value.val.isUndefDeep()) { | 140 | if (typed_value.val.isUndefDeep()) { |
| 139 | const abi_size = math.cast(usize, typed_value.ty.abiSize(target)) orelse return error.Overflow; | 141 | const abi_size = math.cast(usize, typed_value.ty.abiSize(target)) orelse return error.Overflow; |
| 140 | try code.appendNTimes(0xaa, abi_size); | 142 | try code.appendNTimes(0xaa, abi_size); |
| 141 | return Result{ .appended = {} }; | 143 | return Result.ok; |
| 142 | } | 144 | } |
| 143 | | 145 | |
| 144 | switch (typed_value.ty.zigTypeTag()) { | 146 | switch (typed_value.ty.zigTypeTag()) { |
| ... | @@ -169,7 +171,7 @@ pub fn generateSymbol( | ... | @@ -169,7 +171,7 @@ pub fn generateSymbol( |
| 169 | 128 => writeFloat(f128, typed_value.val.toFloat(f128), target, endian, try code.addManyAsArray(16)), | 171 | 128 => writeFloat(f128, typed_value.val.toFloat(f128), target, endian, try code.addManyAsArray(16)), |
| 170 | else => unreachable, | 172 | else => unreachable, |
| 171 | } | 173 | } |
| 172 | return Result{ .appended = {} }; | 174 | return Result.ok; |
| 173 | }, | 175 | }, |
| 174 | .Array => switch (typed_value.val.tag()) { | 176 | .Array => switch (typed_value.val.tag()) { |
| 175 | .bytes => { | 177 | .bytes => { |
| ... | @@ -178,7 +180,7 @@ pub fn generateSymbol( | ... | @@ -178,7 +180,7 @@ pub fn generateSymbol( |
| 178 | // The bytes payload already includes the sentinel, if any | 180 | // The bytes payload already includes the sentinel, if any |
| 179 | try code.ensureUnusedCapacity(len); | 181 | try code.ensureUnusedCapacity(len); |
| 180 | code.appendSliceAssumeCapacity(bytes[0..len]); | 182 | code.appendSliceAssumeCapacity(bytes[0..len]); |
| 181 | return Result{ .appended = {} }; | 183 | return Result.ok; |
| 182 | }, | 184 | }, |
| 183 | .str_lit => { | 185 | .str_lit => { |
| 184 | const str_lit = typed_value.val.castTag(.str_lit).?.data; | 186 | const str_lit = typed_value.val.castTag(.str_lit).?.data; |
| ... | @@ -190,7 +192,7 @@ pub fn generateSymbol( | ... | @@ -190,7 +192,7 @@ pub fn generateSymbol( |
| 190 | const byte = @intCast(u8, sent_val.toUnsignedInt(target)); | 192 | const byte = @intCast(u8, sent_val.toUnsignedInt(target)); |
| 191 | code.appendAssumeCapacity(byte); | 193 | code.appendAssumeCapacity(byte); |
| 192 | } | 194 | } |
| 193 | return Result{ .appended = {} }; | 195 | return Result.ok; |
| 194 | }, | 196 | }, |
| 195 | .aggregate => { | 197 | .aggregate => { |
| 196 | const elem_vals = typed_value.val.castTag(.aggregate).?.data; | 198 | const elem_vals = typed_value.val.castTag(.aggregate).?.data; |
| ... | @@ -201,11 +203,11 @@ pub fn generateSymbol( | ... | @@ -201,11 +203,11 @@ pub fn generateSymbol( |
| 201 | .ty = elem_ty, | 203 | .ty = elem_ty, |
| 202 | .val = elem_val, | 204 | .val = elem_val, |
| 203 | }, code, debug_output, reloc_info)) { | 205 | }, code, debug_output, reloc_info)) { |
| 204 | .appended => {}, | 206 | .ok => {}, |
| 205 | .fail => |em| return Result{ .fail = em }, | 207 | .fail => |em| return Result{ .fail = em }, |
| 206 | } | 208 | } |
| 207 | } | 209 | } |
| 208 | return Result{ .appended = {} }; | 210 | return Result.ok; |
| 209 | }, | 211 | }, |
| 210 | .repeated => { | 212 | .repeated => { |
| 211 | const array = typed_value.val.castTag(.repeated).?.data; | 213 | const array = typed_value.val.castTag(.repeated).?.data; |
| ... | @@ -219,7 +221,7 @@ pub fn generateSymbol( | ... | @@ -219,7 +221,7 @@ pub fn generateSymbol( |
| 219 | .ty = elem_ty, | 221 | .ty = elem_ty, |
| 220 | .val = array, | 222 | .val = array, |
| 221 | }, code, debug_output, reloc_info)) { | 223 | }, code, debug_output, reloc_info)) { |
| 222 | .appended => {}, | 224 | .ok => {}, |
| 223 | .fail => |em| return Result{ .fail = em }, | 225 | .fail => |em| return Result{ .fail = em }, |
| 224 | } | 226 | } |
| 225 | } | 227 | } |
| ... | @@ -229,12 +231,12 @@ pub fn generateSymbol( | ... | @@ -229,12 +231,12 @@ pub fn generateSymbol( |
| 229 | .ty = elem_ty, | 231 | .ty = elem_ty, |
| 230 | .val = sentinel_val, | 232 | .val = sentinel_val, |
| 231 | }, code, debug_output, reloc_info)) { | 233 | }, code, debug_output, reloc_info)) { |
| 232 | .appended => {}, | 234 | .ok => {}, |
| 233 | .fail => |em| return Result{ .fail = em }, | 235 | .fail => |em| return Result{ .fail = em }, |
| 234 | } | 236 | } |
| 235 | } | 237 | } |
| 236 | | 238 | |
| 237 | return Result{ .appended = {} }; | 239 | return Result.ok; |
| 238 | }, | 240 | }, |
| 239 | .empty_array_sentinel => { | 241 | .empty_array_sentinel => { |
| 240 | const elem_ty = typed_value.ty.childType(); | 242 | const elem_ty = typed_value.ty.childType(); |
| ... | @@ -243,10 +245,10 @@ pub fn generateSymbol( | ... | @@ -243,10 +245,10 @@ pub fn generateSymbol( |
| 243 | .ty = elem_ty, | 245 | .ty = elem_ty, |
| 244 | .val = sentinel_val, | 246 | .val = sentinel_val, |
| 245 | }, code, debug_output, reloc_info)) { | 247 | }, code, debug_output, reloc_info)) { |
| 246 | .appended => {}, | 248 | .ok => {}, |
| 247 | .fail => |em| return Result{ .fail = em }, | 249 | .fail => |em| return Result{ .fail = em }, |
| 248 | } | 250 | } |
| 249 | return Result{ .appended = {} }; | 251 | return Result.ok; |
| 250 | }, | 252 | }, |
| 251 | else => return Result{ | 253 | else => return Result{ |
| 252 | .fail = try ErrorMsg.create( | 254 | .fail = try ErrorMsg.create( |
| ... | @@ -270,7 +272,7 @@ pub fn generateSymbol( | ... | @@ -270,7 +272,7 @@ pub fn generateSymbol( |
| 270 | }, | 272 | }, |
| 271 | else => unreachable, | 273 | else => unreachable, |
| 272 | } | 274 | } |
| 273 | return Result{ .appended = {} }; | 275 | return Result.ok; |
| 274 | }, | 276 | }, |
| 275 | .variable => { | 277 | .variable => { |
| 276 | const decl = typed_value.val.castTag(.variable).?.data.owner_decl; | 278 | const decl = typed_value.val.castTag(.variable).?.data.owner_decl; |
| ... | @@ -290,7 +292,7 @@ pub fn generateSymbol( | ... | @@ -290,7 +292,7 @@ pub fn generateSymbol( |
| 290 | .ty = slice_ptr_field_type, | 292 | .ty = slice_ptr_field_type, |
| 291 | .val = slice.ptr, | 293 | .val = slice.ptr, |
| 292 | }, code, debug_output, reloc_info)) { | 294 | }, code, debug_output, reloc_info)) { |
| 293 | .appended => {}, | 295 | .ok => {}, |
| 294 | .fail => |em| return Result{ .fail = em }, | 296 | .fail => |em| return Result{ .fail = em }, |
| 295 | } | 297 | } |
| 296 | | 298 | |
| ... | @@ -299,11 +301,11 @@ pub fn generateSymbol( | ... | @@ -299,11 +301,11 @@ pub fn generateSymbol( |
| 299 | .ty = Type.initTag(.usize), | 301 | .ty = Type.initTag(.usize), |
| 300 | .val = slice.len, | 302 | .val = slice.len, |
| 301 | }, code, debug_output, reloc_info)) { | 303 | }, code, debug_output, reloc_info)) { |
| 302 | .appended => {}, | 304 | .ok => {}, |
| 303 | .fail => |em| return Result{ .fail = em }, | 305 | .fail => |em| return Result{ .fail = em }, |
| 304 | } | 306 | } |
| 305 | | 307 | |
| 306 | return Result{ .appended = {} }; | 308 | return Result.ok; |
| 307 | }, | 309 | }, |
| 308 | .field_ptr => { | 310 | .field_ptr => { |
| 309 | const field_ptr = typed_value.val.castTag(.field_ptr).?.data; | 311 | const field_ptr = typed_value.val.castTag(.field_ptr).?.data; |
| ... | @@ -350,10 +352,10 @@ pub fn generateSymbol( | ... | @@ -350,10 +352,10 @@ pub fn generateSymbol( |
| 350 | .ty = typed_value.ty, | 352 | .ty = typed_value.ty, |
| 351 | .val = container_ptr, | 353 | .val = container_ptr, |
| 352 | }, code, debug_output, reloc_info)) { | 354 | }, code, debug_output, reloc_info)) { |
| 353 | .appended => {}, | 355 | .ok => {}, |
| 354 | .fail => |em| return Result{ .fail = em }, | 356 | .fail => |em| return Result{ .fail = em }, |
| 355 | } | 357 | } |
| 356 | return Result{ .appended = {} }; | 358 | return Result.ok; |
| 357 | }, | 359 | }, |
| 358 | else => return Result{ | 360 | else => return Result{ |
| 359 | .fail = try ErrorMsg.create( | 361 | .fail = try ErrorMsg.create( |
| ... | @@ -406,7 +408,7 @@ pub fn generateSymbol( | ... | @@ -406,7 +408,7 @@ pub fn generateSymbol( |
| 406 | .signed => @bitCast(u8, @intCast(i8, typed_value.val.toSignedInt(target))), | 408 | .signed => @bitCast(u8, @intCast(i8, typed_value.val.toSignedInt(target))), |
| 407 | }; | 409 | }; |
| 408 | try code.append(x); | 410 | try code.append(x); |
| 409 | return Result{ .appended = {} }; | 411 | return Result.ok; |
| 410 | } | 412 | } |
| 411 | if (info.bits > 64) { | 413 | if (info.bits > 64) { |
| 412 | var bigint_buffer: Value.BigIntSpace = undefined; | 414 | var bigint_buffer: Value.BigIntSpace = undefined; |
| ... | @@ -415,7 +417,7 @@ pub fn generateSymbol( | ... | @@ -415,7 +417,7 @@ pub fn generateSymbol( |
| 415 | const start = code.items.len; | 417 | const start = code.items.len; |
| 416 | try code.resize(start + abi_size); | 418 | try code.resize(start + abi_size); |
| 417 | bigint.writeTwosComplement(code.items[start..][0..abi_size], endian); | 419 | bigint.writeTwosComplement(code.items[start..][0..abi_size], endian); |
| 418 | return Result{ .appended = {} }; | 420 | return Result.ok; |
| 419 | } | 421 | } |
| 420 | switch (info.signedness) { | 422 | switch (info.signedness) { |
| 421 | .unsigned => { | 423 | .unsigned => { |
| ... | @@ -443,7 +445,7 @@ pub fn generateSymbol( | ... | @@ -443,7 +445,7 @@ pub fn generateSymbol( |
| 443 | } | 445 | } |
| 444 | }, | 446 | }, |
| 445 | } | 447 | } |
| 446 | return Result{ .appended = {} }; | 448 | return Result.ok; |
| 447 | }, | 449 | }, |
| 448 | .Enum => { | 450 | .Enum => { |
| 449 | var int_buffer: Value.Payload.U64 = undefined; | 451 | var int_buffer: Value.Payload.U64 = undefined; |
| ... | @@ -453,7 +455,7 @@ pub fn generateSymbol( | ... | @@ -453,7 +455,7 @@ pub fn generateSymbol( |
| 453 | if (info.bits <= 8) { | 455 | if (info.bits <= 8) { |
| 454 | const x = @intCast(u8, int_val.toUnsignedInt(target)); | 456 | const x = @intCast(u8, int_val.toUnsignedInt(target)); |
| 455 | try code.append(x); | 457 | try code.append(x); |
| 456 | return Result{ .appended = {} }; | 458 | return Result.ok; |
| 457 | } | 459 | } |
| 458 | if (info.bits > 64) { | 460 | if (info.bits > 64) { |
| 459 | return Result{ | 461 | return Result{ |
| ... | @@ -491,12 +493,12 @@ pub fn generateSymbol( | ... | @@ -491,12 +493,12 @@ pub fn generateSymbol( |
| 491 | } | 493 | } |
| 492 | }, | 494 | }, |
| 493 | } | 495 | } |
| 494 | return Result{ .appended = {} }; | 496 | return Result.ok; |
| 495 | }, | 497 | }, |
| 496 | .Bool => { | 498 | .Bool => { |
| 497 | const x: u8 = @boolToInt(typed_value.val.toBool()); | 499 | const x: u8 = @boolToInt(typed_value.val.toBool()); |
| 498 | try code.append(x); | 500 | try code.append(x); |
| 499 | return Result{ .appended = {} }; | 501 | return Result.ok; |
| 500 | }, | 502 | }, |
| 501 | .Struct => { | 503 | .Struct => { |
| 502 | if (typed_value.ty.containerLayout() == .Packed) { | 504 | if (typed_value.ty.containerLayout() == .Packed) { |
| ... | @@ -521,9 +523,7 @@ pub fn generateSymbol( | ... | @@ -521,9 +523,7 @@ pub fn generateSymbol( |
| 521 | .ty = field_ty, | 523 | .ty = field_ty, |
| 522 | .val = field_val, | 524 | .val = field_val, |
| 523 | }, &tmp_list, debug_output, reloc_info)) { | 525 | }, &tmp_list, debug_output, reloc_info)) { |
| 524 | .appended => { | 526 | .ok => mem.copy(u8, code.items[current_pos..], tmp_list.items), |
| 525 | mem.copy(u8, code.items[current_pos..], tmp_list.items); | | |
| 526 | }, | | |
| 527 | .fail => |em| return Result{ .fail = em }, | 527 | .fail => |em| return Result{ .fail = em }, |
| 528 | } | 528 | } |
| 529 | } else { | 529 | } else { |
| ... | @@ -532,7 +532,7 @@ pub fn generateSymbol( | ... | @@ -532,7 +532,7 @@ pub fn generateSymbol( |
| 532 | bits += @intCast(u16, field_ty.bitSize(target)); | 532 | bits += @intCast(u16, field_ty.bitSize(target)); |
| 533 | } | 533 | } |
| 534 | | 534 | |
| 535 | return Result{ .appended = {} }; | 535 | return Result.ok; |
| 536 | } | 536 | } |
| 537 | | 537 | |
| 538 | const struct_begin = code.items.len; | 538 | const struct_begin = code.items.len; |
| ... | @@ -545,7 +545,7 @@ pub fn generateSymbol( | ... | @@ -545,7 +545,7 @@ pub fn generateSymbol( |
| 545 | .ty = field_ty, | 545 | .ty = field_ty, |
| 546 | .val = field_val, | 546 | .val = field_val, |
| 547 | }, code, debug_output, reloc_info)) { | 547 | }, code, debug_output, reloc_info)) { |
| 548 | .appended => {}, | 548 | .ok => {}, |
| 549 | .fail => |em| return Result{ .fail = em }, | 549 | .fail => |em| return Result{ .fail = em }, |
| 550 | } | 550 | } |
| 551 | const unpadded_field_end = code.items.len - struct_begin; | 551 | const unpadded_field_end = code.items.len - struct_begin; |
| ... | @@ -559,7 +559,7 @@ pub fn generateSymbol( | ... | @@ -559,7 +559,7 @@ pub fn generateSymbol( |
| 559 | } | 559 | } |
| 560 | } | 560 | } |
| 561 | | 561 | |
| 562 | return Result{ .appended = {} }; | 562 | return Result.ok; |
| 563 | }, | 563 | }, |
| 564 | .Union => { | 564 | .Union => { |
| 565 | const union_obj = typed_value.val.castTag(.@"union").?.data; | 565 | const union_obj = typed_value.val.castTag(.@"union").?.data; |
| ... | @@ -578,7 +578,7 @@ pub fn generateSymbol( | ... | @@ -578,7 +578,7 @@ pub fn generateSymbol( |
| 578 | .ty = typed_value.ty.unionTagType().?, | 578 | .ty = typed_value.ty.unionTagType().?, |
| 579 | .val = union_obj.tag, | 579 | .val = union_obj.tag, |
| 580 | }, code, debug_output, reloc_info)) { | 580 | }, code, debug_output, reloc_info)) { |
| 581 | .appended => {}, | 581 | .ok => {}, |
| 582 | .fail => |em| return Result{ .fail = em }, | 582 | .fail => |em| return Result{ .fail = em }, |
| 583 | } | 583 | } |
| 584 | } | 584 | } |
| ... | @@ -595,7 +595,7 @@ pub fn generateSymbol( | ... | @@ -595,7 +595,7 @@ pub fn generateSymbol( |
| 595 | .ty = field_ty, | 595 | .ty = field_ty, |
| 596 | .val = union_obj.val, | 596 | .val = union_obj.val, |
| 597 | }, code, debug_output, reloc_info)) { | 597 | }, code, debug_output, reloc_info)) { |
| 598 | .appended => {}, | 598 | .ok => {}, |
| 599 | .fail => |em| return Result{ .fail = em }, | 599 | .fail => |em| return Result{ .fail = em }, |
| 600 | } | 600 | } |
| 601 | | 601 | |
| ... | @@ -610,12 +610,12 @@ pub fn generateSymbol( | ... | @@ -610,12 +610,12 @@ pub fn generateSymbol( |
| 610 | .ty = union_ty.tag_ty, | 610 | .ty = union_ty.tag_ty, |
| 611 | .val = union_obj.tag, | 611 | .val = union_obj.tag, |
| 612 | }, code, debug_output, reloc_info)) { | 612 | }, code, debug_output, reloc_info)) { |
| 613 | .appended => {}, | 613 | .ok => {}, |
| 614 | .fail => |em| return Result{ .fail = em }, | 614 | .fail => |em| return Result{ .fail = em }, |
| 615 | } | 615 | } |
| 616 | } | 616 | } |
| 617 | | 617 | |
| 618 | return Result{ .appended = {} }; | 618 | return Result.ok; |
| 619 | }, | 619 | }, |
| 620 | .Optional => { | 620 | .Optional => { |
| 621 | var opt_buf: Type.Payload.ElemType = undefined; | 621 | var opt_buf: Type.Payload.ElemType = undefined; |
| ... | @@ -626,7 +626,7 @@ pub fn generateSymbol( | ... | @@ -626,7 +626,7 @@ pub fn generateSymbol( |
| 626 | | 626 | |
| 627 | if (!payload_type.hasRuntimeBits()) { | 627 | if (!payload_type.hasRuntimeBits()) { |
| 628 | try code.writer().writeByteNTimes(@boolToInt(is_pl), abi_size); | 628 | try code.writer().writeByteNTimes(@boolToInt(is_pl), abi_size); |
| 629 | return Result{ .appended = {} }; | 629 | return Result.ok; |
| 630 | } | 630 | } |
| 631 | | 631 | |
| 632 | if (typed_value.ty.optionalReprIsPayload()) { | 632 | if (typed_value.ty.optionalReprIsPayload()) { |
| ... | @@ -635,7 +635,7 @@ pub fn generateSymbol( | ... | @@ -635,7 +635,7 @@ pub fn generateSymbol( |
| 635 | .ty = payload_type, | 635 | .ty = payload_type, |
| 636 | .val = payload.data, | 636 | .val = payload.data, |
| 637 | }, code, debug_output, reloc_info)) { | 637 | }, code, debug_output, reloc_info)) { |
| 638 | .appended => {}, | 638 | .ok => {}, |
| 639 | .fail => |em| return Result{ .fail = em }, | 639 | .fail => |em| return Result{ .fail = em }, |
| 640 | } | 640 | } |
| 641 | } else if (!typed_value.val.isNull()) { | 641 | } else if (!typed_value.val.isNull()) { |
| ... | @@ -643,14 +643,14 @@ pub fn generateSymbol( | ... | @@ -643,14 +643,14 @@ pub fn generateSymbol( |
| 643 | .ty = payload_type, | 643 | .ty = payload_type, |
| 644 | .val = typed_value.val, | 644 | .val = typed_value.val, |
| 645 | }, code, debug_output, reloc_info)) { | 645 | }, code, debug_output, reloc_info)) { |
| 646 | .appended => {}, | 646 | .ok => {}, |
| 647 | .fail => |em| return Result{ .fail = em }, | 647 | .fail => |em| return Result{ .fail = em }, |
| 648 | } | 648 | } |
| 649 | } else { | 649 | } else { |
| 650 | try code.writer().writeByteNTimes(0, abi_size); | 650 | try code.writer().writeByteNTimes(0, abi_size); |
| 651 | } | 651 | } |
| 652 | | 652 | |
| 653 | return Result{ .appended = {} }; | 653 | return Result.ok; |
| 654 | } | 654 | } |
| 655 | | 655 | |
| 656 | const value = if (typed_value.val.castTag(.opt_payload)) |payload| payload.data else Value.initTag(.undef); | 656 | const value = if (typed_value.val.castTag(.opt_payload)) |payload| payload.data else Value.initTag(.undef); |
| ... | @@ -659,11 +659,11 @@ pub fn generateSymbol( | ... | @@ -659,11 +659,11 @@ pub fn generateSymbol( |
| 659 | .ty = payload_type, | 659 | .ty = payload_type, |
| 660 | .val = value, | 660 | .val = value, |
| 661 | }, code, debug_output, reloc_info)) { | 661 | }, code, debug_output, reloc_info)) { |
| 662 | .appended => {}, | 662 | .ok => {}, |
| 663 | .fail => |em| return Result{ .fail = em }, | 663 | .fail => |em| return Result{ .fail = em }, |
| 664 | } | 664 | } |
| 665 | | 665 | |
| 666 | return Result{ .appended = {} }; | 666 | return Result.ok; |
| 667 | }, | 667 | }, |
| 668 | .ErrorUnion => { | 668 | .ErrorUnion => { |
| 669 | const error_ty = typed_value.ty.errorUnionSet(); | 669 | const error_ty = typed_value.ty.errorUnionSet(); |
| ... | @@ -688,7 +688,7 @@ pub fn generateSymbol( | ... | @@ -688,7 +688,7 @@ pub fn generateSymbol( |
| 688 | .ty = error_ty, | 688 | .ty = error_ty, |
| 689 | .val = if (is_payload) Value.initTag(.zero) else typed_value.val, | 689 | .val = if (is_payload) Value.initTag(.zero) else typed_value.val, |
| 690 | }, code, debug_output, reloc_info)) { | 690 | }, code, debug_output, reloc_info)) { |
| 691 | .appended => {}, | 691 | .ok => {}, |
| 692 | .fail => |em| return Result{ .fail = em }, | 692 | .fail => |em| return Result{ .fail = em }, |
| 693 | } | 693 | } |
| 694 | } | 694 | } |
| ... | @@ -701,7 +701,7 @@ pub fn generateSymbol( | ... | @@ -701,7 +701,7 @@ pub fn generateSymbol( |
| 701 | .ty = payload_ty, | 701 | .ty = payload_ty, |
| 702 | .val = payload_val, | 702 | .val = payload_val, |
| 703 | }, code, debug_output, reloc_info)) { | 703 | }, code, debug_output, reloc_info)) { |
| 704 | .appended => {}, | 704 | .ok => {}, |
| 705 | .fail => |em| return Result{ .fail = em }, | 705 | .fail => |em| return Result{ .fail = em }, |
| 706 | } | 706 | } |
| 707 | const unpadded_end = code.items.len - begin; | 707 | const unpadded_end = code.items.len - begin; |
| ... | @@ -720,7 +720,7 @@ pub fn generateSymbol( | ... | @@ -720,7 +720,7 @@ pub fn generateSymbol( |
| 720 | .ty = error_ty, | 720 | .ty = error_ty, |
| 721 | .val = if (is_payload) Value.initTag(.zero) else typed_value.val, | 721 | .val = if (is_payload) Value.initTag(.zero) else typed_value.val, |
| 722 | }, code, debug_output, reloc_info)) { | 722 | }, code, debug_output, reloc_info)) { |
| 723 | .appended => {}, | 723 | .ok => {}, |
| 724 | .fail => |em| return Result{ .fail = em }, | 724 | .fail => |em| return Result{ .fail = em }, |
| 725 | } | 725 | } |
| 726 | const unpadded_end = code.items.len - begin; | 726 | const unpadded_end = code.items.len - begin; |
| ... | @@ -732,7 +732,7 @@ pub fn generateSymbol( | ... | @@ -732,7 +732,7 @@ pub fn generateSymbol( |
| 732 | } | 732 | } |
| 733 | } | 733 | } |
| 734 | | 734 | |
| 735 | return Result{ .appended = {} }; | 735 | return Result.ok; |
| 736 | }, | 736 | }, |
| 737 | .ErrorSet => { | 737 | .ErrorSet => { |
| 738 | switch (typed_value.val.tag()) { | 738 | switch (typed_value.val.tag()) { |
| ... | @@ -745,7 +745,7 @@ pub fn generateSymbol( | ... | @@ -745,7 +745,7 @@ pub fn generateSymbol( |
| 745 | try code.writer().writeByteNTimes(0, @intCast(usize, Type.anyerror.abiSize(target))); | 745 | try code.writer().writeByteNTimes(0, @intCast(usize, Type.anyerror.abiSize(target))); |
| 746 | }, | 746 | }, |
| 747 | } | 747 | } |
| 748 | return Result{ .appended = {} }; | 748 | return Result.ok; |
| 749 | }, | 749 | }, |
| 750 | .Vector => switch (typed_value.val.tag()) { | 750 | .Vector => switch (typed_value.val.tag()) { |
| 751 | .bytes => { | 751 | .bytes => { |
| ... | @@ -753,7 +753,7 @@ pub fn generateSymbol( | ... | @@ -753,7 +753,7 @@ pub fn generateSymbol( |
| 753 | const len = @intCast(usize, typed_value.ty.arrayLen()); | 753 | const len = @intCast(usize, typed_value.ty.arrayLen()); |
| 754 | try code.ensureUnusedCapacity(len); | 754 | try code.ensureUnusedCapacity(len); |
| 755 | code.appendSliceAssumeCapacity(bytes[0..len]); | 755 | code.appendSliceAssumeCapacity(bytes[0..len]); |
| 756 | return Result{ .appended = {} }; | 756 | return Result.ok; |
| 757 | }, | 757 | }, |
| 758 | .aggregate => { | 758 | .aggregate => { |
| 759 | const elem_vals = typed_value.val.castTag(.aggregate).?.data; | 759 | const elem_vals = typed_value.val.castTag(.aggregate).?.data; |
| ... | @@ -764,11 +764,11 @@ pub fn generateSymbol( | ... | @@ -764,11 +764,11 @@ pub fn generateSymbol( |
| 764 | .ty = elem_ty, | 764 | .ty = elem_ty, |
| 765 | .val = elem_val, | 765 | .val = elem_val, |
| 766 | }, code, debug_output, reloc_info)) { | 766 | }, code, debug_output, reloc_info)) { |
| 767 | .appended => {}, | 767 | .ok => {}, |
| 768 | .fail => |em| return Result{ .fail = em }, | 768 | .fail => |em| return Result{ .fail = em }, |
| 769 | } | 769 | } |
| 770 | } | 770 | } |
| 771 | return Result{ .appended = {} }; | 771 | return Result.ok; |
| 772 | }, | 772 | }, |
| 773 | .repeated => { | 773 | .repeated => { |
| 774 | const array = typed_value.val.castTag(.repeated).?.data; | 774 | const array = typed_value.val.castTag(.repeated).?.data; |
| ... | @@ -781,11 +781,11 @@ pub fn generateSymbol( | ... | @@ -781,11 +781,11 @@ pub fn generateSymbol( |
| 781 | .ty = elem_ty, | 781 | .ty = elem_ty, |
| 782 | .val = array, | 782 | .val = array, |
| 783 | }, code, debug_output, reloc_info)) { | 783 | }, code, debug_output, reloc_info)) { |
| 784 | .appended => {}, | 784 | .ok => {}, |
| 785 | .fail => |em| return Result{ .fail = em }, | 785 | .fail => |em| return Result{ .fail = em }, |
| 786 | } | 786 | } |
| 787 | } | 787 | } |
| 788 | return Result{ .appended = {} }; | 788 | return Result.ok; |
| 789 | }, | 789 | }, |
| 790 | .str_lit => { | 790 | .str_lit => { |
| 791 | const str_lit = typed_value.val.castTag(.str_lit).?.data; | 791 | const str_lit = typed_value.val.castTag(.str_lit).?.data; |
| ... | @@ -793,7 +793,7 @@ pub fn generateSymbol( | ... | @@ -793,7 +793,7 @@ pub fn generateSymbol( |
| 793 | const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len]; | 793 | const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len]; |
| 794 | try code.ensureUnusedCapacity(str_lit.len); | 794 | try code.ensureUnusedCapacity(str_lit.len); |
| 795 | code.appendSliceAssumeCapacity(bytes); | 795 | code.appendSliceAssumeCapacity(bytes); |
| 796 | return Result{ .appended = {} }; | 796 | return Result.ok; |
| 797 | }, | 797 | }, |
| 798 | else => unreachable, | 798 | else => unreachable, |
| 799 | }, | 799 | }, |
| ... | @@ -834,7 +834,7 @@ fn lowerDeclRef( | ... | @@ -834,7 +834,7 @@ fn lowerDeclRef( |
| 834 | .ty = slice_ptr_field_type, | 834 | .ty = slice_ptr_field_type, |
| 835 | .val = typed_value.val, | 835 | .val = typed_value.val, |
| 836 | }, code, debug_output, reloc_info)) { | 836 | }, code, debug_output, reloc_info)) { |
| 837 | .appended => {}, | 837 | .ok => {}, |
| 838 | .fail => |em| return Result{ .fail = em }, | 838 | .fail => |em| return Result{ .fail = em }, |
| 839 | } | 839 | } |
| 840 | | 840 | |
| ... | @@ -847,11 +847,11 @@ fn lowerDeclRef( | ... | @@ -847,11 +847,11 @@ fn lowerDeclRef( |
| 847 | .ty = Type.usize, | 847 | .ty = Type.usize, |
| 848 | .val = Value.initPayload(&slice_len.base), | 848 | .val = Value.initPayload(&slice_len.base), |
| 849 | }, code, debug_output, reloc_info)) { | 849 | }, code, debug_output, reloc_info)) { |
| 850 | .appended => {}, | 850 | .ok => {}, |
| 851 | .fail => |em| return Result{ .fail = em }, | 851 | .fail => |em| return Result{ .fail = em }, |
| 852 | } | 852 | } |
| 853 | | 853 | |
| 854 | return Result{ .appended = {} }; | 854 | return Result.ok; |
| 855 | } | 855 | } |
| 856 | | 856 | |
| 857 | const ptr_width = target.cpu.arch.ptrBitWidth(); | 857 | const ptr_width = target.cpu.arch.ptrBitWidth(); |
| ... | @@ -859,7 +859,7 @@ fn lowerDeclRef( | ... | @@ -859,7 +859,7 @@ fn lowerDeclRef( |
| 859 | const is_fn_body = decl.ty.zigTypeTag() == .Fn; | 859 | const is_fn_body = decl.ty.zigTypeTag() == .Fn; |
| 860 | if (!is_fn_body and !decl.ty.hasRuntimeBits()) { | 860 | if (!is_fn_body and !decl.ty.hasRuntimeBits()) { |
| 861 | try code.writer().writeByteNTimes(0xaa, @divExact(ptr_width, 8)); | 861 | try code.writer().writeByteNTimes(0xaa, @divExact(ptr_width, 8)); |
| 862 | return Result{ .appended = {} }; | 862 | return Result.ok; |
| 863 | } | 863 | } |
| 864 | | 864 | |
| 865 | module.markDeclAlive(decl); | 865 | module.markDeclAlive(decl); |
| ... | @@ -877,7 +877,7 @@ fn lowerDeclRef( | ... | @@ -877,7 +877,7 @@ fn lowerDeclRef( |
| 877 | else => unreachable, | 877 | else => unreachable, |
| 878 | } | 878 | } |
| 879 | | 879 | |
| 880 | return Result{ .appended = {} }; | 880 | return Result.ok; |
| 881 | } | 881 | } |
| 882 | | 882 | |
| 883 | pub fn errUnionPayloadOffset(payload_ty: Type, target: std.Target) u64 { | 883 | pub fn errUnionPayloadOffset(payload_ty: Type, target: std.Target) u64 { |