| ... | @@ -1281,6 +1281,7 @@ pub const Value = extern union { | ... | @@ -1281,6 +1281,7 @@ pub const Value = extern union { |
| 1281 | pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{ | 1281 | pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{ |
| 1282 | ReinterpretDeclRef, | 1282 | ReinterpretDeclRef, |
| 1283 | IllDefinedMemoryLayout, | 1283 | IllDefinedMemoryLayout, |
| | 1284 | Unimplemented, |
| 1284 | }!void { | 1285 | }!void { |
| 1285 | const target = mod.getTarget(); | 1286 | const target = mod.getTarget(); |
| 1286 | const endian = target.cpu.arch.endian(); | 1287 | const endian = target.cpu.arch.endian(); |
| ... | @@ -1370,19 +1371,19 @@ pub const Value = extern union { | ... | @@ -1370,19 +1371,19 @@ pub const Value = extern union { |
| 1370 | }, | 1371 | }, |
| 1371 | .Union => switch (ty.containerLayout()) { | 1372 | .Union => switch (ty.containerLayout()) { |
| 1372 | .Auto => return error.IllDefinedMemoryLayout, | 1373 | .Auto => return error.IllDefinedMemoryLayout, |
| 1373 | .Extern => @panic("TODO implement writeToMemory for extern unions"), | 1374 | .Extern => return error.Unimplemented, |
| 1374 | .Packed => { | 1375 | .Packed => { |
| 1375 | const byte_count = (@intCast(usize, ty.bitSize(target)) + 7) / 8; | 1376 | const byte_count = (@intCast(usize, ty.bitSize(target)) + 7) / 8; |
| 1376 | return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0); | 1377 | return writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0); |
| 1377 | }, | 1378 | }, |
| 1378 | }, | 1379 | }, |
| 1379 | .Pointer => { | 1380 | .Pointer => { |
| 1380 | assert(!ty.isSlice()); // No well defined layout. | 1381 | if (ty.isSlice()) return error.IllDefinedMemoryLayout; |
| 1381 | if (val.isDeclRef()) return error.ReinterpretDeclRef; | 1382 | if (val.isDeclRef()) return error.ReinterpretDeclRef; |
| 1382 | return val.writeToMemory(Type.usize, mod, buffer); | 1383 | return val.writeToMemory(Type.usize, mod, buffer); |
| 1383 | }, | 1384 | }, |
| 1384 | .Optional => { | 1385 | .Optional => { |
| 1385 | assert(ty.isPtrLikeOptional()); | 1386 | if (!ty.isPtrLikeOptional()) return error.IllDefinedMemoryLayout; |
| 1386 | var buf: Type.Payload.ElemType = undefined; | 1387 | var buf: Type.Payload.ElemType = undefined; |
| 1387 | const child = ty.optionalChild(&buf); | 1388 | const child = ty.optionalChild(&buf); |
| 1388 | const opt_val = val.optionalValue(); | 1389 | const opt_val = val.optionalValue(); |
| ... | @@ -1392,7 +1393,7 @@ pub const Value = extern union { | ... | @@ -1392,7 +1393,7 @@ pub const Value = extern union { |
| 1392 | return writeToMemory(Value.zero, Type.usize, mod, buffer); | 1393 | return writeToMemory(Value.zero, Type.usize, mod, buffer); |
| 1393 | } | 1394 | } |
| 1394 | }, | 1395 | }, |
| 1395 | else => @panic("TODO implement writeToMemory for more types"), | 1396 | else => return error.Unimplemented, |
| 1396 | } | 1397 | } |
| 1397 | } | 1398 | } |
| 1398 | | 1399 | |
| ... | @@ -5401,6 +5402,7 @@ pub const Value = extern union { | ... | @@ -5401,6 +5402,7 @@ pub const Value = extern union { |
| 5401 | // code late in compilation. So, this error handling is too aggressive and | 5402 | // code late in compilation. So, this error handling is too aggressive and |
| 5402 | // causes some false negatives, causing less-than-ideal code generation. | 5403 | // causes some false negatives, causing less-than-ideal code generation. |
| 5403 | error.IllDefinedMemoryLayout => return null, | 5404 | error.IllDefinedMemoryLayout => return null, |
| | 5405 | error.Unimplemented => return null, |
| 5404 | }; | 5406 | }; |
| 5405 | const first_byte = byte_buffer[0]; | 5407 | const first_byte = byte_buffer[0]; |
| 5406 | for (byte_buffer[1..]) |byte| { | 5408 | for (byte_buffer[1..]) |byte| { |