Skip to content

Commit

Permalink
Add support for LLVM 10.
Browse files Browse the repository at this point in the history
  • Loading branch information
QuLogic committed Feb 11, 2020
1 parent a72a6d3 commit bf39077
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
13 changes: 13 additions & 0 deletions backports.cpp
Expand Up @@ -3,6 +3,7 @@
#include "llvm/IR/Instructions.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/Coroutines.h"
#include "llvm-c/DebugInfo.h"

namespace llvm {

Expand All @@ -26,3 +27,15 @@ void LLVMGlobalObjectAddMetadata(LLVMValueRef Global, unsigned KindID, LLVMMetad
llvm::GlobalObject *O = llvm::unwrap<llvm::GlobalObject>(Global);
O->addMetadata(KindID, *N);
}

LLVMMetadataRef
LLVMDIBuilderCreateTypedef_LLVM10(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
const char *Name, size_t NameLen,
LLVMMetadataRef File, unsigned LineNo,
LLVMMetadataRef Scope, uint32_t AlignInBits) {
#if LLVM_VERSION_MAJOR >= 10
return LLVMDIBuilderCreateTypedef(Builder, Type, Name, NameLen, File, LineNo, Scope, AlignInBits);
#else
return LLVMDIBuilderCreateTypedef(Builder, Type, Name, NameLen, File, LineNo, Scope);
#endif
}
5 changes: 5 additions & 0 deletions backports.h
Expand Up @@ -10,6 +10,11 @@ void LLVMPassManagerBuilderAddCoroutinePassesToExtensionPoints_backport(LLVMPass

void LLVMGlobalObjectAddMetadata(LLVMValueRef objValue, unsigned KindID, LLVMMetadataRef md);

LLVMMetadataRef
LLVMDIBuilderCreateTypedef_LLVM10(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
const char *Name, size_t NameLen,
LLVMMetadataRef File, unsigned LineNo,
LLVMMetadataRef Scope, uint32_t AlignInBits);
#ifdef __cplusplus
}
#endif /* defined(__cplusplus) */
16 changes: 9 additions & 7 deletions dibuilder.go
Expand Up @@ -45,7 +45,7 @@ const (
FlagProtected
FlagFwdDecl
FlagAppleBlock
FlagBlockByrefStruct
FlagReserved
FlagVirtual
FlagArtificial
FlagExplicit
Expand Down Expand Up @@ -537,25 +537,27 @@ func (d *DIBuilder) CreateArrayType(t DIArrayType) Metadata {

// DITypedef holds the values for creating typedef type debug metadata.
type DITypedef struct {
Type Metadata
Name string
File Metadata
Line int
Context Metadata
Type Metadata
Name string
File Metadata
Line int
Context Metadata
AlignInBits uint32
}

// CreateTypedef creates typedef type debug metadata.
func (d *DIBuilder) CreateTypedef(t DITypedef) Metadata {
name := C.CString(t.Name)
defer C.free(unsafe.Pointer(name))
result := C.LLVMDIBuilderCreateTypedef(
result := C.LLVMDIBuilderCreateTypedef_LLVM10(
d.ref,
t.Type.C,
name,
C.size_t(len(t.Name)),
t.File.C,
C.unsigned(t.Line),
t.Context.C,
C.uint32_t(t.AlignInBits),
)
return Metadata{C: result}
}
Expand Down

0 comments on commit bf39077

Please sign in to comment.