Skip to content

Commit

Permalink
In llvmbindins, cleanups, consistifications, and a new getDebugLoc.
Browse files Browse the repository at this point in the history
 Changes to be committed:

	modified:   LLVM.i3
	modified:   LLVMTypes.i3
	modified:   M3DIBuilder.cpp
	modified:   M3DIBuilder.h
	modified:   M3DIBuilder.i3
	modified:   M3Extras.cpp
	modified:   M3Extras.h
  • Loading branch information
RodneyBates committed Aug 6, 2015
1 parent e4a095d commit 8646ea6
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 103 deletions.
24 changes: 18 additions & 6 deletions m3-sys/llvmbindings/src/LLVM.i3
Expand Up @@ -17,11 +17,13 @@

<*EXTERNAL*> INTERFACE LLVM;

IMPORT Word;
FROM Cstdint IMPORT uint8_t, uint64_t;
FROM Ctypes
IMPORT int, unsigned, char_star, const_char_star, char_star_star,
unsigned_long_long, double, long_long;
FROM Cstdint IMPORT uint8_t, uint64_t;
IMPORT Word;

FROM LLVMTypes IMPORT Bool, False, True;

(**
* @defgroup LLVMC LLVM-C: C interface to LLVM
Expand Down Expand Up @@ -69,10 +71,6 @@ FROM Cstdint IMPORT uint8_t, uint64_t;
* @{
*)

TYPE Bool = BOOLEAN;
CONST False = FALSE;
CONST True = TRUE;

(* Opaque types. *)

TYPE Opaque = RECORD END;
Expand Down Expand Up @@ -104,6 +102,20 @@ TYPE TypeRef = UNTRACED BRANDED "LLVMOpaqueType" REF Opaque;
*)
TYPE ValueRef = UNTRACED BRANDED "LLVMOpaqueValue" REF Opaque;

(* Currently unused ---- :
(* From llvm/ADT/ArrayRef.h: *)

(* class ArrayRef<Value *> (NOTE: this is not a pointer). *)
; TYPE ArrayRefOfValueRef
= RECORD
Data : UNTRACED REF ValueRef (* 0th element, a la C/C++ *)
; Length : size_t
END
; CONST ArrayRefOfValueRefEmpty
= ArrayRefOfValueRef { Data := NIL , Length := 0 }

---- unused. *)

(**
* Represents a constant in LLVM IR.
*
Expand Down
22 changes: 5 additions & 17 deletions m3-sys/llvmbindings/src/LLVMTypes.i3
Expand Up @@ -15,16 +15,16 @@ INTERFACE LLVMTypes

; IMPORT Word

; FROM LLVM IMPORT ValueRef

(* These could come from almost anywhere. *)
(* TODO: Figure out where/how to get the right types for these: *)
; TYPE size_t = INTEGER
; TYPE int64_t = INTEGER
; TYPE uint64_t = Word . T
; TYPE bool = [ 0 .. 1 ]
; CONST false = 0
; CONST true = 1
; TYPE Bool = BOOLEAN
(* NOTE: All the bindings to llvm assume a Modula3 BOOLEAN can be passed in
and out to a C/C++ int and work as expected. *)
; CONST False = FALSE
; CONST True = TRUE
; TYPE unsigned = [ 0 .. 16_7FFFFFFF ]

; TYPE Opaque = RECORD END (* This duplicates a decl in LLV. *)
Expand Down Expand Up @@ -55,18 +55,6 @@ INTERFACE LLVMTypes

; CONST StringRefEmpty = StringRef { Data := NIL , Length := 0 }

(* From llvm/ADT/ArrayRef.h: *)

(* class ArrayRef<Value *> (NOTE: this is not a pointer). *)
; TYPE ArrayRefOfValueRef
= RECORD
Data : UNTRACED REF ValueRef (* 0th element, a la C/C++ *)
; Length : size_t
END

; CONST ArrayRefOfValueRefEmpty
= ArrayRefOfValueRef { Data := NIL , Length := 0 }

; TYPE MetadataRef = UNTRACED BRANDED "LLVMMetadata" REF (* LLVM . *) Opaque

(* class ArrayRef<Metadata *> (NOTE: this is not a pointer). *)
Expand Down
101 changes: 64 additions & 37 deletions m3-sys/llvmbindings/src/M3DIBuilder.cpp
Expand Up @@ -107,6 +107,13 @@ inline LLVMDIBuilderRef wrapDIBuilder(const llvm::DIBuilder *unwrapped) {
const char NullChar = 0;
const char * NullCharPtr = & NullChar;

#if 0
// From DIBuilderBindings.cpp:
template <typename T> T unwrapDI(LLVMMetadataPtr v) {
return v ? T(unwrap<llvm::MDNode>(v)) : T();
}
#endif

inline llvm::StringRef unwrapStringRef(LLVMStringRef R) {
if (R->Data == NULL) { return llvm::StringRef (NullCharPtr, 0); }
else { return llvm::StringRef (R->Data, R->Length); }
Expand Down Expand Up @@ -162,7 +169,7 @@ inline llvm::DITypeRef unwrapDITypeRef (LLVMDITypeRef LLVMDINode) {

/// Constructor of a DIBuilder.
LLVMDIBuilderRef
DIBBuilderCreate(LLVMModuleRef Mod, bool AllowUnresolved) {
DIBBuilderCreate(LLVMModuleRef Mod, LLVMBool AllowUnresolved) {
return wrapDIBuilder
(new llvm::DIBuilder(*llvm::unwrap(Mod), AllowUnresolved));
}
Expand Down Expand Up @@ -206,18 +213,18 @@ LLVMDICompileUnit DIBcreateCompileUnit(LLVMDIBuilderRef Builder,
LLVMStringRef File,
LLVMStringRef Dir,
LLVMStringRef Producer,
bool isOptimized,
LLVMBool isOptimized,
LLVMStringRef Flags,
unsigned RV,
LLVMStringRef SplitName,
llvm::DIBuilder::DebugEmissionKind Kind,
bool EmitDebugInfo) {
LLVMBool EmitDebugInfo) {
return wrap(unwrapBuilder(Builder)-> createCompileUnit(
/*unsigned*/ Lang,
unwrapStringRef(File),
unwrapStringRef(Dir),
unwrapStringRef(Producer),
/*bool*/ isOptimized,
/*LLVMBool*/ isOptimized,
unwrapStringRef(Flags),
/*unsigned*/ RV,
unwrapStringRef(SplitName),
Expand Down Expand Up @@ -929,7 +936,7 @@ DIBcreateGlobalVariable
LLVMDIFile File,
unsigned LineNo,
LLVMDITypeRef Ty,
bool isLocalToUnit,
LLVMBool isLocalToUnit,
LLVMConstantRef Val,
LLVMMDNodePtr Decl) {
return wrap(unwrapBuilder(Builder)-> createGlobalVariable(
Expand All @@ -939,7 +946,7 @@ DIBcreateGlobalVariable
unwrap(/*LLVMDIFile*/ File),
/*unsigned*/ LineNo,
unwrapDITypeRef(/*LLVMDITypeRef*/ Ty),
/*bool*/ isLocalToUnit,
/*LLVMBool*/ isLocalToUnit,
unwrap(/*LLVMConstantRef*/ Val),
unwrapMDNodePtr(Decl)));
}
Expand All @@ -955,7 +962,7 @@ DIBcreateTempGlobalVariableFwdDecl
LLVMDIFile File,
unsigned LineNo,
LLVMDITypeRef Ty,
bool isLocalToUnit,
LLVMBool isLocalToUnit,
LLVMConstantRef Val,
LLVMMDNodePtr Decl) {
return wrap(unwrapBuilder(Builder)-> createGlobalVariable(
Expand All @@ -965,7 +972,7 @@ DIBcreateTempGlobalVariableFwdDecl
unwrap(/*LLVMDIFile*/ File),
/*unsigned*/ LineNo,
unwrapDITypeRef(/*LLVMDITypeRef*/ Ty),
/*bool*/ isLocalToUnit,
/*LLVMBool*/ isLocalToUnit,
unwrap(/*LLVMConstantRef*/ Val),
unwrapMDNodePtr(Decl)));
}
Expand All @@ -991,7 +998,7 @@ LLVMDIVariable DIBcreateLocalVariable(LLVMDIBuilderRef Builder,
LLVMDIFile File,
unsigned LineNo,
LLVMDITypeRef Ty,
bool AlwaysPreserve,
LLVMBool AlwaysPreserve,
unsigned Flags,
unsigned ArgNo) {
return wrap(unwrapBuilder(Builder)-> createLocalVariable(
Expand All @@ -1001,7 +1008,7 @@ LLVMDIVariable DIBcreateLocalVariable(LLVMDIBuilderRef Builder,
unwrap(/*LLVMDIFile*/ File),
/*unsigned*/ LineNo,
unwrapDITypeRef(/*LLVMDITypeRef*/ Ty),
/*bool*/ AlwaysPreserve,
/*LLVMBool*/ AlwaysPreserve,
/*unsigned*/ Flags,
/*unsigned*/ ArgNo));
}
Expand Down Expand Up @@ -1054,11 +1061,11 @@ LLVMDISubprogram DIBcreateFunction( LLVMDIBuilderRef Builder,
LLVMDIFile File,
unsigned LineNo,
LLVMDICompositeType Ty,
bool isLocalToUnit,
bool isDefinition,
LLVMBool isLocalToUnit,
LLVMBool isDefinition,
unsigned ScopeLine,
unsigned Flags,
bool isOptimized,
LLVMBool isOptimized,
LLVMValueRef Fn,
LLVMMDNodePtr TParam,
LLVMMDNodePtr Decl) {
Expand All @@ -1069,11 +1076,11 @@ LLVMDISubprogram DIBcreateFunction( LLVMDIBuilderRef Builder,
unwrap(/*LLVMDIFile*/ File),
/*unsigned*/ LineNo,
unwrap(/*LLVMDICompositeType*/ Ty),
/*bool*/ isLocalToUnit,
/*bool*/ isDefinition,
/*LLVMBool*/ isLocalToUnit,
/*LLVMBool*/ isDefinition,
/*unsigned*/ ScopeLine,
/*unsigned*/ Flags,
/*bool*/ isOptimized,
/*LLVMBool*/ isOptimized,
llvm::unwrap<llvm::Function>(Fn),
unwrapMDNodePtr(TParam),
unwrapMDNodePtr(Decl)));
Expand All @@ -1089,11 +1096,11 @@ LLVMDISubprogram DIBcreateTempFunctionFunctionFwdDecl( LLVMDIBuilderRef Builder,
LLVMDIFile File,
unsigned LineNo,
LLVMDICompositeType Ty,
bool isLocalToUnit,
bool isDefinition,
LLVMBool isLocalToUnit,
LLVMBool isDefinition,
unsigned ScopeLine,
unsigned Flags,
bool isOptimized,
LLVMBool isOptimized,
LLVMValueRef Fn,
LLVMMDNodePtr TParam,
LLVMMDNodePtr Decl) {
Expand All @@ -1104,11 +1111,11 @@ LLVMDISubprogram DIBcreateTempFunctionFunctionFwdDecl( LLVMDIBuilderRef Builder,
unwrap(/*LLVMDIFile*/ File),
/*unsigned*/ LineNo,
unwrap(/*LLVMDICompositeType*/ Ty),
/*bool*/ isLocalToUnit,
/*bool*/ isDefinition,
/*LLVMBool*/ isLocalToUnit,
/*LLVMBool*/ isDefinition,
/*unsigned*/ ScopeLine,
/*unsigned*/ Flags,
/*bool*/ isOptimized,
/*LLVMBool*/ isOptimized,
llvm::unwrap<llvm::Function>(Fn),
unwrapMDNodePtr(TParam),
unwrapMDNodePtr(Decl)));
Expand All @@ -1125,11 +1132,11 @@ LLVMDISubprogram DIBcreateFunctionFromScope(LLVMDIBuilderRef Builder,
LLVMDIFile File,
unsigned LineNo,
LLVMDICompositeType Ty,
bool isLocalToUnit,
bool isDefinition,
LLVMBool isLocalToUnit,
LLVMBool isDefinition,
unsigned ScopeLine,
unsigned Flags,
bool isOptimized,
LLVMBool isOptimized,
LLVMValueRef Fn,
LLVMMDNodePtr TParam,
LLVMMDNodePtr Decl) {
Expand All @@ -1140,11 +1147,11 @@ LLVMDISubprogram DIBcreateFunctionFromScope(LLVMDIBuilderRef Builder,
unwrap(/*LLVMDIFile*/ File),
/*unsigned*/ LineNo,
unwrap(/*LLVMDICompositeType*/ Ty),
/*bool*/ isLocalToUnit,
/*bool*/ isDefinition,
/*LLVMBool*/ isLocalToUnit,
/*LLVMBool*/ isDefinition,
/*unsigned*/ ScopeLine,
/*unsigned*/ Flags,
/*bool*/ isOptimized,
/*LLVMBool*/ isOptimized,
llvm::unwrap<llvm::Function>(Fn),
unwrapMDNodePtr(TParam),
unwrapMDNodePtr(Decl)));
Expand Down Expand Up @@ -1177,13 +1184,13 @@ LLVMDISubprogram DIBcreateMethod( LLVMDIBuilderRef Builder,
LLVMDIFile File,
unsigned LineNo,
LLVMDICompositeType Ty,
bool isLocalToUnit,
bool isDefinition,
LLVMBool isLocalToUnit,
LLVMBool isDefinition,
unsigned Virtuality,
unsigned VTableIndex,
LLVMDIType VTableHolder,
unsigned Flags,
bool isOptimized,
LLVMBool isOptimized,
LLVMValueRef Fn,
LLVMMDNodePtr TParam) {
return wrap(unwrapBuilder(Builder)-> createMethod(
Expand All @@ -1193,13 +1200,13 @@ LLVMDISubprogram DIBcreateMethod( LLVMDIBuilderRef Builder,
unwrap(/*LLVMDIFile*/ File),
/*unsigned*/ LineNo,
unwrap(/*LLVMDICompositeType*/ Ty),
/*bool*/ isLocalToUnit,
/*bool*/ isDefinition,
/*LLVMBool*/ isLocalToUnit,
/*LLVMBool*/ isDefinition,
/*unsigned*/ Virtuality,
/*unsigned*/ VTableIndex,
unwrap(/*LLVMDIType*/ VTableHolder),
/*unsigned*/ Flags,
/*bool*/ isOptimized,
/*LLVMBool*/ isOptimized,
llvm::unwrap<llvm::Function>(Fn),
unwrapMDNodePtr(TParam)));
}
Expand Down Expand Up @@ -1417,7 +1424,7 @@ LLVMValueRef /*Instruction*/ DIBinsertDbgValueIntrinsicBefore(LLVMDIBuilderRef B
///
/// If this creates a self reference, it may orphan some unresolved cycles
/// in the operands of \c T, so \a DIBuilder needs to track that.
void LLVMReplaceVTableHolder(LLVMDIBuilderRef Builder,
void DIBreplaceVTableHolder(LLVMDIBuilderRef Builder,
LLVMDICompositeType *T,
LLVMDICompositeType VTableHolder) {
// Replace pass-by-reference of T by copy-in-copy-out.
Expand All @@ -1434,7 +1441,7 @@ void LLVMReplaceVTableHolder(LLVMDIBuilderRef Builder,
/// If \c T is resolved, but the arrays aren't -- which can happen if \c T
/// has a self-reference -- \a DIBuilder needs to track the array to
/// resolve cycles.
void LLVMReplaceArrays(LLVMDIBuilderRef Builder,
void DIBreplaceArrays(LLVMDIBuilderRef Builder,
LLVMDICompositeType *T,
LLVMDIArray Elements,
LLVMDIArray TParems) {
Expand All @@ -1446,6 +1453,26 @@ void LLVMReplaceArrays(LLVMDIBuilderRef Builder,
unwrap(/*LLVMDIARRAY*/ Elements),
unwrap(/*LLVMDIARRAY*/ TParems));
*T = wrap(LT);
}
}

// This apparently was in bindings/go/llvm/DIBuilderBindings.h of an earlier
// llvm than 3.6.1 It is in DIBuilder because that is where the stuff needed
// by its implementation is found.
//changed scope was *
LLVMValueRef DIBgetDebugLoc(unsigned Line,
unsigned Col,
LLVMDIDescriptor Scope) {
// MDNode *S = unwrapDI<DIDescriptor>(*Scope);
// DebugLoc loc = DebugLoc::get(Line,Col,S);

llvm::DIDescriptor S = unwrap(/*LLVMDIDescriptor*/ Scope);
llvm::DebugLoc loc = llvm::DebugLoc::get(Line,Col,S);
llvm::LLVMContext &ctx = S->getContext();
llvm::MDNode *L = loc.getAsMDNode(ctx);
llvm::Value *V = llvm::MetadataAsValue::get(ctx,L);
return wrap(V);
}

//End M3DIBuilder.cpp


0 comments on commit 8646ea6

Please sign in to comment.