Merge pull request #11085 from ziglang/llvm-debug-info

stage2 LLVM debug info
This commit is contained in:
Andrew Kelley 2022-03-08 21:09:20 -05:00 committed by GitHub
commit a91753219d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 1415 additions and 79 deletions

View File

@ -1317,7 +1317,7 @@ const @"identifier with spaces in it" = 0xff;
const @"1SmallStep4Man" = 112358; const @"1SmallStep4Man" = 112358;
const c = @import("std").c; const c = @import("std").c;
pub extern "c" fn @"error"() anyopaque; pub extern "c" fn @"error"() void;
pub extern "c" fn @"fstat$INODE64"(fd: c.fd_t, buf: *c.Stat) c_int; pub extern "c" fn @"fstat$INODE64"(fd: c.fd_t, buf: *c.Stat) c_int;
const Color = enum { const Color = enum {

View File

@ -226,6 +226,21 @@ pub const LNCT = struct {
pub const hi_user = 0x3fff; pub const hi_user = 0x3fff;
}; };
pub const CC = enum(u8) {
normal = 0x1,
program = 0x2,
nocall = 0x3,
pass_by_reference = 0x4,
pass_by_value = 0x5,
lo_user = 0x40,
hi_user = 0xff,
GNU_renesas_sh = 0x40,
GNU_borland_fastcall_i386 = 0x41,
};
const PcRange = struct { const PcRange = struct {
start: u64, start: u64,
end: u64, end: u64,

View File

@ -898,7 +898,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
// We put the `Compilation` itself in the arena. Freeing the arena will free the module. // We put the `Compilation` itself in the arena. Freeing the arena will free the module.
// It's initialized later after we prepare the initialization options. // It's initialized later after we prepare the initialization options.
const comp = try arena.create(Compilation); const comp = try arena.create(Compilation);
const root_name = try arena.dupe(u8, options.root_name); const root_name = try arena.dupeZ(u8, options.root_name);
const ofmt = options.object_format orelse options.target.getObjectFormat(); const ofmt = options.object_format orelse options.target.getObjectFormat();

View File

@ -12399,7 +12399,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
var anon_decl = try block.startAnonDecl(LazySrcLoc.unneeded); var anon_decl = try block.startAnonDecl(LazySrcLoc.unneeded);
defer anon_decl.deinit(); defer anon_decl.deinit();
const bytes = try ty.nameAlloc(anon_decl.arena()); const bytes = try ty.nameAllocArena(anon_decl.arena());
const new_decl = try anon_decl.finish( const new_decl = try anon_decl.finish(
try Type.Tag.array_u8_sentinel_0.create(anon_decl.arena(), bytes.len), try Type.Tag.array_u8_sentinel_0.create(anon_decl.arena(), bytes.len),

File diff suppressed because it is too large Load Diff

View File

@ -184,12 +184,18 @@ pub const Value = opaque {
pub const setFunctionCallConv = LLVMSetFunctionCallConv; pub const setFunctionCallConv = LLVMSetFunctionCallConv;
extern fn LLVMSetFunctionCallConv(Fn: *const Value, CC: CallConv) void; extern fn LLVMSetFunctionCallConv(Fn: *const Value, CC: CallConv) void;
pub const fnSetSubprogram = ZigLLVMFnSetSubprogram;
extern fn ZigLLVMFnSetSubprogram(f: *const Value, subprogram: *DISubprogram) void;
pub const setValueName = LLVMSetValueName; pub const setValueName = LLVMSetValueName;
extern fn LLVMSetValueName(Val: *const Value, Name: [*:0]const u8) void; extern fn LLVMSetValueName(Val: *const Value, Name: [*:0]const u8) void;
pub const setValueName2 = LLVMSetValueName2; pub const setValueName2 = LLVMSetValueName2;
extern fn LLVMSetValueName2(Val: *const Value, Name: [*]const u8, NameLen: usize) void; extern fn LLVMSetValueName2(Val: *const Value, Name: [*]const u8, NameLen: usize) void;
pub const getValueName = LLVMGetValueName;
extern fn LLVMGetValueName(Val: *const Value) [*:0]const u8;
pub const takeName = ZigLLVMTakeName; pub const takeName = ZigLLVMTakeName;
extern fn ZigLLVMTakeName(new_owner: *const Value, victim: *const Value) void; extern fn ZigLLVMTakeName(new_owner: *const Value, victim: *const Value) void;
@ -354,6 +360,18 @@ pub const Module = opaque {
Name: [*:0]const u8, Name: [*:0]const u8,
NameLen: usize, NameLen: usize,
) ?*const Value; ) ?*const Value;
pub const setTarget = LLVMSetTarget;
extern fn LLVMSetTarget(M: *const Module, Triple: [*:0]const u8) void;
pub const addModuleDebugInfoFlag = ZigLLVMAddModuleDebugInfoFlag;
extern fn ZigLLVMAddModuleDebugInfoFlag(module: *const Module) void;
pub const addModuleCodeViewFlag = ZigLLVMAddModuleCodeViewFlag;
extern fn ZigLLVMAddModuleCodeViewFlag(module: *const Module) void;
pub const createDIBuilder = ZigLLVMCreateDIBuilder;
extern fn ZigLLVMCreateDIBuilder(module: *const Module, allow_unresolved: bool) *DIBuilder;
}; };
pub const lookupIntrinsicID = LLVMLookupIntrinsicID; pub const lookupIntrinsicID = LLVMLookupIntrinsicID;
@ -821,7 +839,7 @@ pub const Builder = opaque {
pub const buildExactSDiv = LLVMBuildExactSDiv; pub const buildExactSDiv = LLVMBuildExactSDiv;
extern fn LLVMBuildExactSDiv(*const Builder, LHS: *const Value, RHS: *const Value, Name: [*:0]const u8) *const Value; extern fn LLVMBuildExactSDiv(*const Builder, LHS: *const Value, RHS: *const Value, Name: [*:0]const u8) *const Value;
pub const zigSetCurrentDebugLocation = ZigLLVMSetCurrentDebugLocation; pub const setCurrentDebugLocation = ZigLLVMSetCurrentDebugLocation;
extern fn ZigLLVMSetCurrentDebugLocation(builder: *const Builder, line: c_int, column: c_int, scope: *DIScope) void; extern fn ZigLLVMSetCurrentDebugLocation(builder: *const Builder, line: c_int, column: c_int, scope: *DIScope) void;
pub const clearCurrentDebugLocation = ZigLLVMClearCurrentDebugLocation; pub const clearCurrentDebugLocation = ZigLLVMClearCurrentDebugLocation;
@ -1203,7 +1221,7 @@ pub const WriteImportLibrary = ZigLLVMWriteImportLibrary;
extern fn ZigLLVMWriteImportLibrary( extern fn ZigLLVMWriteImportLibrary(
def_path: [*:0]const u8, def_path: [*:0]const u8,
arch: ArchType, arch: ArchType,
output_lib_path: [*c]const u8, output_lib_path: [*:0]const u8,
kill_at: bool, kill_at: bool,
) bool; ) bool;
@ -1400,3 +1418,333 @@ pub const address_space = struct {
pub const constant_buffer_15: c_uint = 23; pub const constant_buffer_15: c_uint = 23;
}; };
}; };
pub const DIEnumerator = opaque {};
pub const DILocalVariable = opaque {};
pub const DIGlobalVariable = opaque {};
pub const DILocation = opaque {};
pub const DIType = opaque {
pub const toScope = ZigLLVMTypeToScope;
extern fn ZigLLVMTypeToScope(ty: *DIType) *DIScope;
};
pub const DIFile = opaque {
pub const toScope = ZigLLVMFileToScope;
extern fn ZigLLVMFileToScope(difile: *DIFile) *DIScope;
};
pub const DILexicalBlock = opaque {
pub const toScope = ZigLLVMLexicalBlockToScope;
extern fn ZigLLVMLexicalBlockToScope(lexical_block: *DILexicalBlock) *DIScope;
};
pub const DICompileUnit = opaque {
pub const toScope = ZigLLVMCompileUnitToScope;
extern fn ZigLLVMCompileUnitToScope(compile_unit: *DICompileUnit) *DIScope;
};
pub const DISubprogram = opaque {
pub const toScope = ZigLLVMSubprogramToScope;
extern fn ZigLLVMSubprogramToScope(subprogram: *DISubprogram) *DIScope;
};
pub const getDebugLoc = ZigLLVMGetDebugLoc;
extern fn ZigLLVMGetDebugLoc(line: c_uint, col: c_uint, scope: *DIScope) *DILocation;
pub const DIBuilder = opaque {
pub const dispose = ZigLLVMDisposeDIBuilder;
extern fn ZigLLVMDisposeDIBuilder(dib: *DIBuilder) void;
pub const finalize = ZigLLVMDIBuilderFinalize;
extern fn ZigLLVMDIBuilderFinalize(dib: *DIBuilder) void;
pub const createPointerType = ZigLLVMCreateDebugPointerType;
extern fn ZigLLVMCreateDebugPointerType(
dib: *DIBuilder,
pointee_type: *DIType,
size_in_bits: u64,
align_in_bits: u64,
name: [*:0]const u8,
) *DIType;
pub const createBasicType = ZigLLVMCreateDebugBasicType;
extern fn ZigLLVMCreateDebugBasicType(
dib: *DIBuilder,
name: [*:0]const u8,
size_in_bits: u64,
encoding: c_uint,
) *DIType;
pub const createArrayType = ZigLLVMCreateDebugArrayType;
extern fn ZigLLVMCreateDebugArrayType(
dib: *DIBuilder,
size_in_bits: u64,
align_in_bits: u64,
elem_type: *DIType,
elem_count: c_int,
) *DIType;
pub const createEnumerator = ZigLLVMCreateDebugEnumerator;
extern fn ZigLLVMCreateDebugEnumerator(
dib: *DIBuilder,
name: [*:0]const u8,
val: i64,
) *DIEnumerator;
pub const createEnumerationType = ZigLLVMCreateDebugEnumerationType;
extern fn ZigLLVMCreateDebugEnumerationType(
dib: *DIBuilder,
scope: *DIScope,
name: [*:0]const u8,
file: *DIFile,
line_number: c_uint,
size_in_bits: u64,
align_in_bits: u64,
enumerator_array: [*]const *DIEnumerator,
enumerator_array_len: c_int,
underlying_type: *DIType,
unique_id: [*:0]const u8,
) *DIType;
pub const createStructType = ZigLLVMCreateDebugStructType;
extern fn ZigLLVMCreateDebugStructType(
dib: *DIBuilder,
scope: *DIScope,
name: [*:0]const u8,
file: ?*DIFile,
line_number: c_uint,
size_in_bits: u64,
align_in_bits: u64,
flags: c_uint,
derived_from: ?*DIType,
types_array: [*]const *DIType,
types_array_len: c_int,
run_time_lang: c_uint,
vtable_holder: ?*DIType,
unique_id: [*:0]const u8,
) *DIType;
pub const createUnionType = ZigLLVMCreateDebugUnionType;
extern fn ZigLLVMCreateDebugUnionType(
dib: *DIBuilder,
scope: *DIScope,
name: [*:0]const u8,
file: *DIFile,
line_number: c_uint,
size_in_bits: u64,
align_in_bits: u64,
flags: c_uint,
types_array: [*]const *DIType,
types_array_len: c_int,
run_time_lang: c_uint,
unique_id: [*:0]const u8,
) *DIType;
pub const createMemberType = ZigLLVMCreateDebugMemberType;
extern fn ZigLLVMCreateDebugMemberType(
dib: *DIBuilder,
scope: *DIScope,
name: [*:0]const u8,
file: ?*DIFile,
line: c_uint,
size_in_bits: u64,
align_in_bits: u64,
offset_in_bits: u64,
flags: c_uint,
ty: *DIType,
) *DIType;
pub const createReplaceableCompositeType = ZigLLVMCreateReplaceableCompositeType;
extern fn ZigLLVMCreateReplaceableCompositeType(
dib: *DIBuilder,
tag: c_uint,
name: [*:0]const u8,
scope: *DIScope,
file: ?*DIFile,
line: c_uint,
) *DIType;
pub const createForwardDeclType = ZigLLVMCreateDebugForwardDeclType;
extern fn ZigLLVMCreateDebugForwardDeclType(
dib: *DIBuilder,
tag: c_uint,
name: [*:0]const u8,
scope: *DIScope,
file: *DIFile,
line: c_uint,
) *DIType;
pub const replaceTemporary = ZigLLVMReplaceTemporary;
extern fn ZigLLVMReplaceTemporary(dib: *DIBuilder, ty: *DIType, replacement: *DIType) void;
pub const replaceDebugArrays = ZigLLVMReplaceDebugArrays;
extern fn ZigLLVMReplaceDebugArrays(
dib: *DIBuilder,
ty: *DIType,
types_array: [*]const *DIType,
types_array_len: c_int,
) void;
pub const createSubroutineType = ZigLLVMCreateSubroutineType;
extern fn ZigLLVMCreateSubroutineType(
dib: *DIBuilder,
types_array: [*]const *DIType,
types_array_len: c_int,
flags: c_uint,
) *DIType;
pub const createAutoVariable = ZigLLVMCreateAutoVariable;
extern fn ZigLLVMCreateAutoVariable(
dib: *DIBuilder,
scope: *DIScope,
name: [*:0]const u8,
file: *DIFile,
line_no: c_uint,
ty: *DIType,
always_preserve: bool,
flags: c_uint,
) *DILocalVariable;
pub const createGlobalVariable = ZigLLVMCreateGlobalVariable;
extern fn ZigLLVMCreateGlobalVariable(
dib: *DIBuilder,
scope: *DIScope,
name: [*:0]const u8,
linkage_name: [*:0]const u8,
file: *DIFile,
line_no: c_uint,
di_type: *DIType,
is_local_to_unit: bool,
) *DIGlobalVariable;
pub const createParameterVariable = ZigLLVMCreateParameterVariable;
extern fn ZigLLVMCreateParameterVariable(
dib: *DIBuilder,
scope: *DIScope,
name: [*:0]const u8,
file: *DIFile,
line_no: c_uint,
ty: *DIType,
always_preserve: bool,
flags: c_uint,
arg_no: c_uint,
) *DILocalVariable;
pub const createLexicalBlock = ZigLLVMCreateLexicalBlock;
extern fn ZigLLVMCreateLexicalBlock(
dib: *DIBuilder,
scope: *DIScope,
file: *DIFile,
line: c_uint,
col: c_uint,
) *DILexicalBlock;
pub const createCompileUnit = ZigLLVMCreateCompileUnit;
extern fn ZigLLVMCreateCompileUnit(
dib: *DIBuilder,
lang: c_uint,
difile: *DIFile,
producer: [*:0]const u8,
is_optimized: bool,
flags: [*:0]const u8,
runtime_version: c_uint,
split_name: [*:0]const u8,
dwo_id: u64,
emit_debug_info: bool,
) *DICompileUnit;
pub const createFile = ZigLLVMCreateFile;
extern fn ZigLLVMCreateFile(
dib: *DIBuilder,
filename: [*:0]const u8,
directory: [*:0]const u8,
) *DIFile;
pub const createFunction = ZigLLVMCreateFunction;
extern fn ZigLLVMCreateFunction(
dib: *DIBuilder,
scope: *DIScope,
name: [*:0]const u8,
linkage_name: [*:0]const u8,
file: *DIFile,
lineno: c_uint,
fn_di_type: *DIType,
is_local_to_unit: bool,
is_definition: bool,
scope_line: c_uint,
flags: c_uint,
is_optimized: bool,
decl_subprogram: ?*DISubprogram,
) *DISubprogram;
pub const createVectorType = ZigLLVMDIBuilderCreateVectorType;
extern fn ZigLLVMDIBuilderCreateVectorType(
dib: *DIBuilder,
SizeInBits: u64,
AlignInBits: u32,
Ty: *DIType,
elem_count: u32,
) *DIType;
pub const insertDeclareAtEnd = ZigLLVMInsertDeclareAtEnd;
extern fn ZigLLVMInsertDeclareAtEnd(
dib: *DIBuilder,
storage: *const Value,
var_info: *DILocalVariable,
debug_loc: *DILocation,
basic_block_ref: *const BasicBlock,
) *const Value;
pub const insertDeclare = ZigLLVMInsertDeclare;
extern fn ZigLLVMInsertDeclare(
dib: *DIBuilder,
storage: *const Value,
var_info: *DILocalVariable,
debug_loc: *DILocation,
insert_before_instr: *const Value,
) *const Value;
pub const insertDbgValueIntrinsicAtEnd = ZigLLVMInsertDbgValueIntrinsicAtEnd;
extern fn ZigLLVMInsertDbgValueIntrinsicAtEnd(
dib: *DIBuilder,
val: *const Value,
var_info: *DILocalVariable,
debug_loc: *DILocation,
basic_block_ref: *const BasicBlock,
) *const Value;
};
pub const DIFlags = opaque {
pub const Zero = 0;
pub const Private = 1;
pub const Protected = 2;
pub const Public = 3;
pub const FwdDecl = 1 << 2;
pub const AppleBlock = 1 << 3;
pub const BlockByrefStruct = 1 << 4;
pub const Virtual = 1 << 5;
pub const Artificial = 1 << 6;
pub const Explicit = 1 << 7;
pub const Prototyped = 1 << 8;
pub const ObjcClassComplete = 1 << 9;
pub const ObjectPointer = 1 << 10;
pub const Vector = 1 << 11;
pub const StaticMember = 1 << 12;
pub const LValueReference = 1 << 13;
pub const RValueReference = 1 << 14;
pub const Reserved = 1 << 15;
pub const SingleInheritance = 1 << 16;
pub const MultipleInheritance = 2 << 16;
pub const VirtualInheritance = 3 << 16;
pub const IntroducedVirtual = 1 << 18;
pub const BitField = 1 << 19;
pub const NoReturn = 1 << 20;
pub const TypePassByValue = 1 << 22;
pub const TypePassByReference = 1 << 23;
pub const EnumClass = 1 << 24;
pub const Thunk = 1 << 25;
pub const NonTrivial = 1 << 26;
pub const BigEndian = 1 << 27;
pub const LittleEndian = 1 << 28;
pub const AllCallsDescribed = 1 << 29;
};

View File

@ -72,7 +72,7 @@ pub const Options = struct {
object_format: std.Target.ObjectFormat, object_format: std.Target.ObjectFormat,
optimize_mode: std.builtin.Mode, optimize_mode: std.builtin.Mode,
machine_code_model: std.builtin.CodeModel, machine_code_model: std.builtin.CodeModel,
root_name: []const u8, root_name: [:0]const u8,
/// Not every Compilation compiles .zig code! For example you could do `zig build-exe foo.o`. /// Not every Compilation compiles .zig code! For example you could do `zig build-exe foo.o`.
module: ?*Module, module: ?*Module,
dynamic_linker: ?[]const u8, dynamic_linker: ?[]const u8,

View File

@ -882,7 +882,7 @@ fn addDbgInfoType(
const abi_size = ty.abiSize(target); const abi_size = ty.abiSize(target);
try leb128.writeULEB128(dbg_info_buffer.writer(), abi_size); try leb128.writeULEB128(dbg_info_buffer.writer(), abi_size);
// DW.AT.name, DW.FORM.string // DW.AT.name, DW.FORM.string
const struct_name = try ty.nameAlloc(arena); const struct_name = try ty.nameAllocArena(arena);
try dbg_info_buffer.ensureUnusedCapacity(struct_name.len + 1); try dbg_info_buffer.ensureUnusedCapacity(struct_name.len + 1);
dbg_info_buffer.appendSliceAssumeCapacity(struct_name); dbg_info_buffer.appendSliceAssumeCapacity(struct_name);
dbg_info_buffer.appendAssumeCapacity(0); dbg_info_buffer.appendAssumeCapacity(0);

View File

@ -9073,8 +9073,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatu
for (uint32_t i = 0; i < field_count; i += 1) { for (uint32_t i = 0; i < field_count; i += 1) {
TypeEnumField *enum_field = &enum_type->data.enumeration.fields[i]; TypeEnumField *enum_field = &enum_type->data.enumeration.fields[i];
// TODO send patch to LLVM to support APInt in createEnumerator instead of int64_t // https://github.com/ziglang/zig/issues/645
// http://lists.llvm.org/pipermail/llvm-dev/2017-December/119456.html
di_enumerators[i] = ZigLLVMCreateDebugEnumerator(g->dbuilder, buf_ptr(enum_field->name), di_enumerators[i] = ZigLLVMCreateDebugEnumerator(g->dbuilder, buf_ptr(enum_field->name),
bigint_as_signed(&enum_field->value)); bigint_as_signed(&enum_field->value));
} }

View File

@ -1766,8 +1766,20 @@ pub const Type = extern union {
} }
} }
pub fn nameAllocArena(ty: Type, arena: Allocator) Allocator.Error![:0]const u8 {
return nameAllocAdvanced(ty, arena, true);
}
pub fn nameAlloc(ty: Type, gpa: Allocator) Allocator.Error![:0]const u8 {
return nameAllocAdvanced(ty, gpa, false);
}
/// Returns a name suitable for `@typeName`. /// Returns a name suitable for `@typeName`.
pub fn nameAlloc(ty: Type, arena: Allocator) Allocator.Error![:0]const u8 { pub fn nameAllocAdvanced(
ty: Type,
ally: Allocator,
is_arena: bool,
) Allocator.Error![:0]const u8 {
const t = ty.tag(); const t = ty.tag();
switch (t) { switch (t) {
.inferred_alloc_const => unreachable, .inferred_alloc_const => unreachable,
@ -1812,71 +1824,79 @@ pub const Type = extern union {
.noreturn, .noreturn,
.var_args_param, .var_args_param,
.bound_fn, .bound_fn,
=> return @tagName(t), => return maybeDupe(@tagName(t), ally, is_arena),
.enum_literal => return "@Type(.EnumLiteral)", .enum_literal => return maybeDupe("@Type(.EnumLiteral)", ally, is_arena),
.@"null" => return "@Type(.Null)", .@"null" => return maybeDupe("@Type(.Null)", ally, is_arena),
.@"undefined" => return "@Type(.Undefined)", .@"undefined" => return maybeDupe("@Type(.Undefined)", ally, is_arena),
.empty_struct, .empty_struct_literal => return "struct {}", .empty_struct, .empty_struct_literal => return maybeDupe("struct {}", ally, is_arena),
.@"struct" => { .@"struct" => {
const struct_obj = ty.castTag(.@"struct").?.data; const struct_obj = ty.castTag(.@"struct").?.data;
return try arena.dupeZ(u8, std.mem.sliceTo(struct_obj.owner_decl.name, 0)); return try ally.dupeZ(u8, std.mem.sliceTo(struct_obj.owner_decl.name, 0));
}, },
.@"union", .union_tagged => { .@"union", .union_tagged => {
const union_obj = ty.cast(Payload.Union).?.data; const union_obj = ty.cast(Payload.Union).?.data;
return try arena.dupeZ(u8, std.mem.sliceTo(union_obj.owner_decl.name, 0)); return try ally.dupeZ(u8, std.mem.sliceTo(union_obj.owner_decl.name, 0));
}, },
.enum_full, .enum_nonexhaustive => { .enum_full, .enum_nonexhaustive => {
const enum_full = ty.cast(Payload.EnumFull).?.data; const enum_full = ty.cast(Payload.EnumFull).?.data;
return try arena.dupeZ(u8, std.mem.sliceTo(enum_full.owner_decl.name, 0)); return try ally.dupeZ(u8, std.mem.sliceTo(enum_full.owner_decl.name, 0));
}, },
.enum_simple => { .enum_simple => {
const enum_simple = ty.castTag(.enum_simple).?.data; const enum_simple = ty.castTag(.enum_simple).?.data;
return try arena.dupeZ(u8, std.mem.sliceTo(enum_simple.owner_decl.name, 0)); return try ally.dupeZ(u8, std.mem.sliceTo(enum_simple.owner_decl.name, 0));
}, },
.enum_numbered => { .enum_numbered => {
const enum_numbered = ty.castTag(.enum_numbered).?.data; const enum_numbered = ty.castTag(.enum_numbered).?.data;
return try arena.dupeZ(u8, std.mem.sliceTo(enum_numbered.owner_decl.name, 0)); return try ally.dupeZ(u8, std.mem.sliceTo(enum_numbered.owner_decl.name, 0));
}, },
.@"opaque" => { .@"opaque" => {
// TODO use declaration name const opaque_obj = ty.cast(Payload.Opaque).?.data;
return "opaque {}"; return try ally.dupeZ(u8, std.mem.sliceTo(opaque_obj.owner_decl.name, 0));
}, },
.anyerror_void_error_union => return "anyerror!void", .anyerror_void_error_union => return maybeDupe("anyerror!void", ally, is_arena),
.const_slice_u8 => return "[]const u8", .const_slice_u8 => return maybeDupe("[]const u8", ally, is_arena),
.const_slice_u8_sentinel_0 => return "[:0]const u8", .const_slice_u8_sentinel_0 => return maybeDupe("[:0]const u8", ally, is_arena),
.fn_noreturn_no_args => return "fn() noreturn", .fn_noreturn_no_args => return maybeDupe("fn() noreturn", ally, is_arena),
.fn_void_no_args => return "fn() void", .fn_void_no_args => return maybeDupe("fn() void", ally, is_arena),
.fn_naked_noreturn_no_args => return "fn() callconv(.Naked) noreturn", .fn_naked_noreturn_no_args => return maybeDupe("fn() callconv(.Naked) noreturn", ally, is_arena),
.fn_ccc_void_no_args => return "fn() callconv(.C) void", .fn_ccc_void_no_args => return maybeDupe("fn() callconv(.C) void", ally, is_arena),
.single_const_pointer_to_comptime_int => return "*const comptime_int", .single_const_pointer_to_comptime_int => return maybeDupe("*const comptime_int", ally, is_arena),
.manyptr_u8 => return "[*]u8", .manyptr_u8 => return maybeDupe("[*]u8", ally, is_arena),
.manyptr_const_u8 => return "[*]const u8", .manyptr_const_u8 => return maybeDupe("[*]const u8", ally, is_arena),
.manyptr_const_u8_sentinel_0 => return "[*:0]const u8", .manyptr_const_u8_sentinel_0 => return maybeDupe("[*:0]const u8", ally, is_arena),
.atomic_order => return "AtomicOrder", .atomic_order => return maybeDupe("AtomicOrder", ally, is_arena),
.atomic_rmw_op => return "AtomicRmwOp", .atomic_rmw_op => return maybeDupe("AtomicRmwOp", ally, is_arena),
.calling_convention => return "CallingConvention", .calling_convention => return maybeDupe("CallingConvention", ally, is_arena),
.address_space => return "AddressSpace", .address_space => return maybeDupe("AddressSpace", ally, is_arena),
.float_mode => return "FloatMode", .float_mode => return maybeDupe("FloatMode", ally, is_arena),
.reduce_op => return "ReduceOp", .reduce_op => return maybeDupe("ReduceOp", ally, is_arena),
.call_options => return "CallOptions", .call_options => return maybeDupe("CallOptions", ally, is_arena),
.prefetch_options => return "PrefetchOptions", .prefetch_options => return maybeDupe("PrefetchOptions", ally, is_arena),
.export_options => return "ExportOptions", .export_options => return maybeDupe("ExportOptions", ally, is_arena),
.extern_options => return "ExternOptions", .extern_options => return maybeDupe("ExternOptions", ally, is_arena),
.type_info => return "Type", .type_info => return maybeDupe("Type", ally, is_arena),
else => { else => {
// TODO this is wasteful and also an incorrect implementation of `@typeName` // TODO this is wasteful and also an incorrect implementation of `@typeName`
var buf = std.ArrayList(u8).init(arena); var buf = std.ArrayList(u8).init(ally);
try buf.writer().print("{}", .{ty}); try buf.writer().print("{}", .{ty});
return try buf.toOwnedSliceSentinel(0); return try buf.toOwnedSliceSentinel(0);
}, },
} }
} }
fn maybeDupe(s: [:0]const u8, ally: Allocator, is_arena: bool) Allocator.Error![:0]const u8 {
if (is_arena) {
return s;
} else {
return try ally.dupeZ(u8, s);
}
}
pub fn toValue(self: Type, allocator: Allocator) Allocator.Error!Value { pub fn toValue(self: Type, allocator: Allocator) Allocator.Error!Value {
switch (self.tag()) { switch (self.tag()) {
.u1 => return Value.initTag(.u1_type), .u1 => return Value.initTag(.u1_type),
@ -4683,7 +4703,10 @@ pub const Type = extern union {
const union_obj = ty.cast(Payload.Union).?.data; const union_obj = ty.cast(Payload.Union).?.data;
return union_obj.owner_decl; return union_obj.owner_decl;
}, },
.@"opaque" => @panic("TODO"), .@"opaque" => {
const opaque_obj = ty.cast(Payload.Opaque).?.data;
return opaque_obj.owner_decl;
},
.atomic_order, .atomic_order,
.atomic_rmw_op, .atomic_rmw_op,
.calling_convention, .calling_convention,
@ -4695,7 +4718,8 @@ pub const Type = extern union {
.export_options, .export_options,
.extern_options, .extern_options,
.type_info, .type_info,
=> @panic("TODO resolve std.builtin types"), => unreachable, // These need to be resolved earlier.
else => unreachable, else => unreachable,
} }
} }

View File

@ -942,6 +942,19 @@ LLVMValueRef ZigLLVMInsertDeclareAtEnd(ZigLLVMDIBuilder *dibuilder, LLVMValueRef
return wrap(result); return wrap(result);
} }
LLVMValueRef ZigLLVMInsertDbgValueIntrinsicAtEnd(ZigLLVMDIBuilder *dib, LLVMValueRef val,
ZigLLVMDILocalVariable *var_info, ZigLLVMDILocation *debug_loc,
LLVMBasicBlockRef basic_block_ref)
{
Instruction *result = reinterpret_cast<DIBuilder*>(dib)->insertDbgValueIntrinsic(
unwrap(val),
reinterpret_cast<DILocalVariable *>(var_info),
reinterpret_cast<DIBuilder*>(dib)->createExpression(),
reinterpret_cast<DILocation*>(debug_loc),
static_cast<BasicBlock*>(unwrap(basic_block_ref)));
return wrap(result);
}
LLVMValueRef ZigLLVMInsertDeclare(ZigLLVMDIBuilder *dibuilder, LLVMValueRef storage, LLVMValueRef ZigLLVMInsertDeclare(ZigLLVMDIBuilder *dibuilder, LLVMValueRef storage,
ZigLLVMDILocalVariable *var_info, ZigLLVMDILocation *debug_loc, LLVMValueRef insert_before_instr) ZigLLVMDILocalVariable *var_info, ZigLLVMDILocation *debug_loc, LLVMValueRef insert_before_instr)
{ {

View File

@ -273,13 +273,20 @@ ZIG_EXTERN_C void ZigLLVMFnSetSubprogram(LLVMValueRef fn, struct ZigLLVMDISubpro
ZIG_EXTERN_C void ZigLLVMDIBuilderFinalize(struct ZigLLVMDIBuilder *dibuilder); ZIG_EXTERN_C void ZigLLVMDIBuilderFinalize(struct ZigLLVMDIBuilder *dibuilder);
ZIG_EXTERN_C LLVMValueRef ZigLLVMInsertDeclareAtEnd(struct ZigLLVMDIBuilder *dibuilder, LLVMValueRef storage, ZIG_EXTERN_C struct ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigned col,
struct ZigLLVMDILocalVariable *var_info, struct ZigLLVMDILocation *debug_loc, struct ZigLLVMDIScope *scope);
LLVMBasicBlockRef basic_block_ref);
ZIG_EXTERN_C LLVMValueRef ZigLLVMInsertDeclare(struct ZigLLVMDIBuilder *dibuilder, LLVMValueRef storage, ZIG_EXTERN_C LLVMValueRef ZigLLVMInsertDeclareAtEnd(struct ZigLLVMDIBuilder *dib,
struct ZigLLVMDILocalVariable *var_info, struct ZigLLVMDILocation *debug_loc, LLVMValueRef insert_before_instr); LLVMValueRef storage, struct ZigLLVMDILocalVariable *var_info,
ZIG_EXTERN_C struct ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigned col, struct ZigLLVMDIScope *scope); struct ZigLLVMDILocation *debug_loc, LLVMBasicBlockRef basic_block_ref);
ZIG_EXTERN_C LLVMValueRef ZigLLVMInsertDeclare(struct ZigLLVMDIBuilder *dib,
LLVMValueRef storage, struct ZigLLVMDILocalVariable *var_info,
struct ZigLLVMDILocation *debug_loc, LLVMValueRef insert_before_instr);
ZIG_EXTERN_C LLVMValueRef ZigLLVMInsertDbgValueIntrinsicAtEnd(struct ZigLLVMDIBuilder *dib,
LLVMValueRef val, struct ZigLLVMDILocalVariable *var_info,
struct ZigLLVMDILocation *debug_loc, LLVMBasicBlockRef basic_block_ref);
ZIG_EXTERN_C void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state); ZIG_EXTERN_C void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state);
ZIG_EXTERN_C void ZigLLVMSetTailCall(LLVMValueRef Call); ZIG_EXTERN_C void ZigLLVMSetTailCall(LLVMValueRef Call);