| ... | ... | @@ -4502,6 +4502,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, |
| 4502 | 4502 | case IrInstructionIdDeclRef: |
| 4503 | 4503 | case IrInstructionIdSwitchVar: |
| 4504 | 4504 | case IrInstructionIdOffsetOf: |
| 4505 | case IrInstructionIdTypeInfo: |
| 4505 | 4506 | case IrInstructionIdTypeId: |
| 4506 | 4507 | case IrInstructionIdSetEvalBranchQuota: |
| 4507 | 4508 | case IrInstructionIdPtrTypeOf: |
| ... | ... | @@ -6125,6 +6126,7 @@ static void define_builtin_fns(CodeGen *g) { |
| 6125 | 6126 | create_builtin_fn(g, BuiltinFnIdMemberType, "memberType", 2); |
| 6126 | 6127 | create_builtin_fn(g, BuiltinFnIdMemberName, "memberName", 2); |
| 6127 | 6128 | create_builtin_fn(g, BuiltinFnIdField, "field", 2); |
| 6129 | create_builtin_fn(g, BuiltinFnIdTypeInfo, "typeInfo", 1); |
| 6128 | 6130 | create_builtin_fn(g, BuiltinFnIdTypeof, "typeOf", 1); // TODO rename to TypeOf |
| 6129 | 6131 | create_builtin_fn(g, BuiltinFnIdAddWithOverflow, "addWithOverflow", 4); |
| 6130 | 6132 | create_builtin_fn(g, BuiltinFnIdSubWithOverflow, "subWithOverflow", 4); |
| ... | ... | @@ -6344,6 +6346,157 @@ static void define_builtin_compile_vars(CodeGen *g) { |
| 6344 | 6346 | } |
| 6345 | 6347 | buf_appendf(contents, "};\n\n"); |
| 6346 | 6348 | } |
| 6349 | { |
| 6350 | buf_appendf(contents, |
| 6351 | "pub const IntInfo = struct {\n" |
| 6352 | " is_signed: bool,\n" |
| 6353 | " bits: u8,\n" |
| 6354 | "};\n" |
| 6355 | "\n" |
| 6356 | "pub const FloatInfo = struct {\n" |
| 6357 | " bits: u8,\n" |
| 6358 | "};\n" |
| 6359 | "\n" |
| 6360 | "pub const PointerInfo = struct {\n" |
| 6361 | " is_const: bool,\n" |
| 6362 | " is_volatile: bool,\n" |
| 6363 | " alignment: u32,\n" |
| 6364 | " child: &TypeInfo,\n" |
| 6365 | "};\n" |
| 6366 | "\n" |
| 6367 | "pub const ArrayInfo = struct {\n" |
| 6368 | " len: u64,\n" |
| 6369 | " child: &TypeInfo,\n" |
| 6370 | "};\n" |
| 6371 | "\n" |
| 6372 | "pub const ContainerLayout = enum {\n" |
| 6373 | " Auto,\n" |
| 6374 | " Extern,\n" |
| 6375 | " Packed,\n" |
| 6376 | "};\n" |
| 6377 | "\n" |
| 6378 | "pub const StructFieldInfo = struct {\n" |
| 6379 | " name: []const u8,\n" |
| 6380 | " offset: usize,\n" |
| 6381 | " type_info: TypeInfo,\n" |
| 6382 | "};\n" |
| 6383 | "\n" |
| 6384 | "pub const StructInfo = struct {\n" |
| 6385 | " layout: ContainerLayout,\n" |
| 6386 | " fields: []StructFieldInfo,\n" |
| 6387 | "};\n" |
| 6388 | "\n" |
| 6389 | "pub const NullableInfo = struct {\n" |
| 6390 | " child: &TypeInfo,\n" |
| 6391 | "};\n" |
| 6392 | "\n" |
| 6393 | "pub const ErrorUnionInfo = struct {\n" |
| 6394 | " error_set: ErrorSetInfo,\n" |
| 6395 | " payload: &TypeInfo,\n" |
| 6396 | "};\n" |
| 6397 | "\n" |
| 6398 | "pub const ErrorInfo = struct {\n" |
| 6399 | " name: []const u8,\n" |
| 6400 | " value: usize,\n" |
| 6401 | "};\n" |
| 6402 | "\n" |
| 6403 | "pub const ErrorSetInfo = struct {\n" |
| 6404 | " errors: []ErrorInfo,\n" |
| 6405 | "};\n" |
| 6406 | "\n" |
| 6407 | "pub const EnumFieldInfo = struct {\n" |
| 6408 | " name: []const u8,\n" |
| 6409 | " value: usize,\n" |
| 6410 | "};\n" |
| 6411 | "\n" |
| 6412 | "pub const EnumInfo = struct {\n" |
| 6413 | " layout: ContainerLayout,\n" |
| 6414 | " tag_type: IntInfo,\n" |
| 6415 | " fields: []EnumFieldInfo,\n" |
| 6416 | "};\n" |
| 6417 | "\n" |
| 6418 | "pub const UnionFieldInfo = struct {\n" |
| 6419 | " name: []const u8,\n" |
| 6420 | " enum_field: EnumFieldInfo,\n" |
| 6421 | " type_info: TypeInfo,\n" |
| 6422 | "};\n" |
| 6423 | "\n" |
| 6424 | "pub const UnionInfo = struct {\n" |
| 6425 | " layout: ContainerLayout,\n" |
| 6426 | " tag_type: ?EnumInfo,\n" |
| 6427 | " fields: []UnionFieldInfo,\n" |
| 6428 | "};\n" |
| 6429 | "\n" |
| 6430 | "pub const CallingConvention = enum {\n" |
| 6431 | " Unspecified,\n" |
| 6432 | " C,\n" |
| 6433 | " Cold,\n" |
| 6434 | " Naked,\n" |
| 6435 | " Stdcall,\n" |
| 6436 | " Async,\n" |
| 6437 | "};\n" |
| 6438 | "\n" |
| 6439 | "pub const FnArgInfo = struct {\n" |
| 6440 | " is_comptime: bool,\n" |
| 6441 | " name: []const u8,\n" |
| 6442 | " type_info: TypeInfo,\n" |
| 6443 | "};\n" |
| 6444 | "\n" |
| 6445 | "pub const FnInfo = struct {\n" |
| 6446 | " calling_convention: CallingConvention,\n" |
| 6447 | " is_generic: bool,\n" |
| 6448 | " is_varargs: bool,\n" |
| 6449 | " return_type: &TypeInfo,\n" |
| 6450 | " args: []FnArgInfo,\n" |
| 6451 | "};\n" |
| 6452 | "\n" |
| 6453 | "pub const BoundFnInfo = struct {\n" |
| 6454 | " bound_type: &TypeInfo,\n" |
| 6455 | " fn_info: FnInfo,\n" |
| 6456 | "};\n" |
| 6457 | "\n" |
| 6458 | "pub const PromiseInfo = struct {\n" |
| 6459 | " child: ?&TypeInfo,\n" |
| 6460 | "};\n" |
| 6461 | "\n" |
| 6462 | "pub const TypeInfo = union(TypeId) {\n" |
| 6463 | " Type: void,\n" |
| 6464 | " Void: void,\n" |
| 6465 | " Bool: void,\n" |
| 6466 | " NoReturn: void,\n" |
| 6467 | " Int: IntInfo,\n" |
| 6468 | " Float: FloatInfo,\n" |
| 6469 | " Pointer: PointerInfo,\n" |
| 6470 | " Array: ArrayInfo,\n" |
| 6471 | " Struct: StructInfo,\n" |
| 6472 | " FloatLiteral: void,\n" |
| 6473 | " IntLiteral: void,\n" |
| 6474 | " UndefinedLiteral: void,\n" |
| 6475 | " NullLiteral: void,\n" |
| 6476 | " Nullable: NullableInfo,\n" |
| 6477 | " ErrorUnion: ErrorUnionInfo,\n" |
| 6478 | " ErrorSet: ErrorSetInfo,\n" |
| 6479 | " Enum: EnumInfo,\n" |
| 6480 | " Union: UnionInfo,\n" |
| 6481 | " Fn: FnInfo,\n" |
| 6482 | " Namespace: void,\n" |
| 6483 | " Block: void,\n" |
| 6484 | " BoundFn: BoundFnInfo,\n" |
| 6485 | " ArgTuple: void,\n" |
| 6486 | " Opaque: void,\n" |
| 6487 | " Promise: PromiseInfo,\n" |
| 6488 | "};\n\n"); |
| 6489 | assert(ContainerLayoutAuto == 0); |
| 6490 | assert(ContainerLayoutExtern == 1); |
| 6491 | assert(ContainerLayoutPacked == 2); |
| 6492 | |
| 6493 | assert(CallingConventionUnspecified == 0); |
| 6494 | assert(CallingConventionC == 1); |
| 6495 | assert(CallingConventionCold == 2); |
| 6496 | assert(CallingConventionNaked == 3); |
| 6497 | assert(CallingConventionStdcall == 4); |
| 6498 | assert(CallingConventionAsync == 5); |
| 6499 | } |
| 6347 | 6500 | { |
| 6348 | 6501 | buf_appendf(contents, |
| 6349 | 6502 | "pub const FloatMode = enum {\n" |