Skip to content

Commit 147267d

Browse files
committed
Merge pull request #450 from redstar/debuginfo
Preliminary fix for debug info generation with LLVM 3.4.
2 parents 6875d8a + 6bd7849 commit 147267d

File tree

2 files changed

+69
-19
lines changed

2 files changed

+69
-19
lines changed

gen/dibuilder.cpp

+60-19
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,54 @@ llvm::DIType ldc::DIBuilder::CreateSArrayType(Type *type)
434434
);
435435
}
436436

437+
llvm::DIType ldc::DIBuilder::CreateAArrayType(Type *type)
438+
{
439+
// FIXME: Implement
440+
#if LDC_LLVM_VER >= 304
441+
return DBuilder.createUnspecifiedType(type->toChars());
442+
#else
443+
return llvm::DIType(NULL);
444+
#endif
445+
}
446+
447+
////////////////////////////////////////////////////////////////////////////////
448+
449+
ldc::DIFunctionType ldc::DIBuilder::CreateFunctionType(Type *type)
450+
{
451+
TypeFunction *t = static_cast<TypeFunction*>(type);
452+
Type *retType = t->next;
453+
454+
llvm::DIFile file = CreateFile(Loc(IR->dmodule, 0));
455+
456+
// Create "dummy" subroutine type for the return type
457+
llvm::SmallVector<llvm::Value*, 16> Elts;
458+
Elts.push_back(CreateTypeDescription(retType, NULL, true));
459+
llvm::DIArray EltTypeArray = DBuilder.getOrCreateArray(Elts);
460+
return DBuilder.createSubroutineType(file, EltTypeArray);
461+
}
462+
463+
ldc::DIFunctionType ldc::DIBuilder::CreateDelegateType(Type *type)
464+
{
465+
// FIXME: Implement
466+
TypeDelegate *t = static_cast<TypeDelegate*>(type);
467+
468+
llvm::DIFile file = CreateFile(Loc(IR->dmodule, 0));
469+
470+
// Create "dummy" subroutine type for the return type
471+
llvm::SmallVector<llvm::Value*, 16> Elts;
472+
Elts.push_back(
473+
#if LDC_LLVM_VER >= 304
474+
DBuilder.createUnspecifiedType(type->toChars())
475+
#else
476+
llvm::DIType(NULL)
477+
#endif
478+
);
479+
llvm::DIArray EltTypeArray = DBuilder.getOrCreateArray(Elts);
480+
return DBuilder.createSubroutineType(file, EltTypeArray);
481+
}
482+
483+
////////////////////////////////////////////////////////////////////////////////
484+
437485
llvm::DIType ldc::DIBuilder::CreateTypeDescription(Type* type,
438486
const char* c_name,
439487
bool derefclass)
@@ -445,7 +493,7 @@ llvm::DIType ldc::DIBuilder::CreateTypeDescription(Type* type,
445493
t = type->toBasetype();
446494
}
447495

448-
if (t->ty == Tvoid)
496+
if (t->ty == Tvoid || t->ty == Tnull)
449497
#if LDC_LLVM_VER >= 304
450498
return DBuilder.createUnspecifiedType(t->toChars());
451499
#else
@@ -465,10 +513,17 @@ llvm::DIType ldc::DIBuilder::CreateTypeDescription(Type* type,
465513
return CreateArrayType(type);
466514
else if (t->ty == Tsarray)
467515
return CreateSArrayType(type);
516+
else if (t->ty == Taarray)
517+
return CreateAArrayType(type);
468518
else if (t->ty == Tstruct || t->ty == Tclass)
469519
return CreateCompositeType(type);
520+
else if (t->ty == Tfunction)
521+
return CreateFunctionType(type);
522+
else if (t->ty == Tdelegate)
523+
return CreateDelegateType(type);
470524

471-
return llvm::DIType(NULL);
525+
// Crash if the type is not supported.
526+
llvm_unreachable("Unsupported type in debug info");
472527
}
473528

474529
////////////////////////////////////////////////////////////////////////////////
@@ -515,18 +570,9 @@ llvm::DISubprogram ldc::DIBuilder::EmitSubProgram(FuncDeclaration *fd)
515570
assert(CU && CU.Verify() && "Compilation unit missing or corrupted in DIBuilder::EmitSubProgram");
516571

517572
llvm::DIFile file = CreateFile(fd->loc);
518-
Type *retType = static_cast<TypeFunction*>(fd->type)->next;
519573

520-
// Create "dummy" subroutine type for the return type
521-
llvm::SmallVector<llvm::Value*, 16> Elts;
522-
Elts.push_back(CreateTypeDescription(retType, NULL, true));
523-
llvm::DIArray EltTypeArray = DBuilder.getOrCreateArray(Elts);
524-
#if LDC_LLVM_VER >= 304
525-
llvm::DICompositeType
526-
#else
527-
llvm::DIType
528-
#endif
529-
DIFnType = DBuilder.createSubroutineType(file, EltTypeArray);
574+
// Create subroutine type
575+
ldc::DIFunctionType DIFnType = CreateFunctionType(static_cast<TypeFunction*>(fd->type));
530576

531577
// FIXME: duplicates ?
532578
return DBuilder.createFunction(
@@ -560,12 +606,7 @@ llvm::DISubprogram ldc::DIBuilder::EmitSubProgramInternal(llvm::StringRef pretty
560606
llvm::SmallVector<llvm::Value *, 1> Elts;
561607
Elts.push_back(llvm::DIType(NULL));
562608
llvm::DIArray EltTypeArray = DBuilder.getOrCreateArray(Elts);
563-
#if LDC_LLVM_VER >= 304
564-
llvm::DICompositeType
565-
#else
566-
llvm::DIType
567-
#endif
568-
DIFnType = DBuilder.createSubroutineType(file, EltTypeArray);
609+
ldc::DIFunctionType DIFnType = DBuilder.createSubroutineType(file, EltTypeArray);
569610

570611
// FIXME: duplicates ?
571612
return DBuilder.createFunction(

gen/dibuilder.h

+9
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ extern const llvm::TargetData* gDataLayout;
6464

6565
namespace ldc {
6666

67+
#if LDC_LLVM_VER >= 304
68+
typedef llvm::DICompositeType DIFunctionType;
69+
#else
70+
typedef llvm::DIType DIFunctionType;
71+
#endif
72+
6773
class DIBuilder
6874
{
6975
IRState *const IR;
@@ -141,6 +147,9 @@ class DIBuilder
141147
llvm::DIType CreateCompositeType(Type *type);
142148
llvm::DIType CreateArrayType(Type *type);
143149
llvm::DIType CreateSArrayType(Type *type);
150+
llvm::DIType CreateAArrayType(Type *type);
151+
DIFunctionType CreateFunctionType(Type *type);
152+
DIFunctionType CreateDelegateType(Type *type);
144153
llvm::DIType CreateTypeDescription(Type* type, const char* c_name, bool derefclass = false);
145154

146155
public:

0 commit comments

Comments
 (0)