about summary refs log tree commit diff
path: root/src/rustllvm/RustWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-20 09:10:34 -0700
committerbors <bors@rust-lang.org>2013-07-20 09:10:34 -0700
commit8aae6edce09a8e2a32a154acb55c9879dbebf99c (patch)
treed77d6659847631f404dcf08529e3b3bd0b7fa4e2 /src/rustllvm/RustWrapper.cpp
parent3a1db2d1e631feede472396fced1806dfd3cf677 (diff)
parenta1303cc81565a019d59be28940a94caf0f9329bf (diff)
downloadrust-8aae6edce09a8e2a32a154acb55c9879dbebf99c.tar.gz
rust-8aae6edce09a8e2a32a154acb55c9879dbebf99c.zip
auto merge of #7710 : michaelwoerister/rust/WP4, r=jdm
This pull request includes various improvements:

+ Composite types (structs, tuples, boxes, etc) are now handled more cleanly by debuginfo generation. Most notably, field offsets are now extracted directly from LLVM types, as opposed to trying to reconstruct them. This leads to more stable handling of edge cases (e.g. packed structs or structs implementing drop).

+ `debuginfo.rs` in general has seen a major cleanup. This includes better formatting, more readable variable and function names, removal of dead code, and better factoring of functionality.

+ Handling of `VariantInfo` in `ty.rs` has been improved. That is, the `type VariantInfo = @VariantInfo_` typedef has been replaced with explicit uses of @VariantInfo, and the duplicated logic for creating VariantInfo instances in `ty::enum_variants()` and `typeck::check::mod::check_enum_variants()` has been unified into a single constructor function. Both function now look nicer too :)

+ Debug info generation for enum types is now mostly supported. This includes:
  + Good support for C-style enums. Both DWARF and `gdb` know how to handle them.
  + Proper description of tuple- and struct-style enum variants as unions of structs.
  + Proper handling of univariant enums without discriminator field.
  + Unfortunately `gdb` always prints all possible interpretations of a union, so debug output of enums is verbose and unintuitive. Neither `LLVM` nor `gdb` support DWARF's `DW_TAG_variant` which allows to properly describe tagged unions. Adding support for this to `LLVM` seems doable. `gdb` however is another story. In the future we might be able to use `gdb`'s Python scripting support to alleviate this problem. In agreement with @jdm this is not a high priority for now.

+ The debuginfo test suite has been extended with 14 test files including tests for packed structs (with Drop), boxed structs, boxed vecs, vec slices, c-style enums (standalone and embedded), empty enums, tuple- and struct-style enums, and various pointer types to the above.

~~What is not yet included is DI support for some enum edge-cases represented as described in `trans::adt::NullablePointer`.~~

Cheers,
Michael

PS: closes #7819,  fixes #7712
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
-rw-r--r--src/rustllvm/RustWrapper.cpp138
1 files changed, 96 insertions, 42 deletions
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp
index 614c1723c5f..2a1f26bf441 100644
--- a/src/rustllvm/RustWrapper.cpp
+++ b/src/rustllvm/RustWrapper.cpp
@@ -565,8 +565,8 @@ extern "C" bool LLVMRustStartMultithreading() {
 typedef DIBuilder* DIBuilderRef;
 
 template<typename DIT>
-DIT unwrapDI(LLVMValueRef ref) { 
-    return DIT(ref ? unwrap<MDNode>(ref) : NULL); 
+DIT unwrapDI(LLVMValueRef ref) {
+    return DIT(ref ? unwrap<MDNode>(ref) : NULL);
 }
 
 extern "C" DIBuilderRef LLVMDIBuilderCreate(LLVMModuleRef M) {
@@ -604,21 +604,21 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateFile(
 
 extern "C" LLVMValueRef LLVMDIBuilderCreateSubroutineType(
     DIBuilderRef Builder,
-    LLVMValueRef File, 
+    LLVMValueRef File,
     LLVMValueRef ParameterTypes) {
     return wrap(Builder->createSubroutineType(
-        unwrapDI<DIFile>(File), 
+        unwrapDI<DIFile>(File),
         unwrapDI<DIArray>(ParameterTypes)));
 }
 
 extern "C" LLVMValueRef LLVMDIBuilderCreateFunction(
     DIBuilderRef Builder,
-    LLVMValueRef Scope, 
+    LLVMValueRef Scope,
     const char* Name,
     const char* LinkageName,
-    LLVMValueRef File,  
+    LLVMValueRef File,
     unsigned LineNo,
-    LLVMValueRef Ty, 
+    LLVMValueRef Ty,
     bool isLocalToUnit,
     bool isDefinition,
     unsigned ScopeLine,
@@ -628,11 +628,11 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateFunction(
     LLVMValueRef TParam,
     LLVMValueRef Decl) {
     return wrap(Builder->createFunction(
-        unwrapDI<DIScope>(Scope), Name, LinkageName, 
-        unwrapDI<DIFile>(File), LineNo, 
-        unwrapDI<DIType>(Ty), isLocalToUnit, isDefinition, ScopeLine, 
+        unwrapDI<DIScope>(Scope), Name, LinkageName,
+        unwrapDI<DIFile>(File), LineNo,
+        unwrapDI<DIType>(Ty), isLocalToUnit, isDefinition, ScopeLine,
         Flags, isOptimized,
-        unwrap<Function>(Fn), 
+        unwrap<Function>(Fn),
         unwrapDI<MDNode*>(TParam),
         unwrapDI<MDNode*>(Decl)));
 }
@@ -644,10 +644,10 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateBasicType(
     uint64_t AlignInBits,
     unsigned Encoding) {
     return wrap(Builder->createBasicType(
-        Name, SizeInBits, 
+        Name, SizeInBits,
         AlignInBits, Encoding));
 }
-    
+
 extern "C" LLVMValueRef LLVMDIBuilderCreatePointerType(
     DIBuilderRef Builder,
     LLVMValueRef PointeeTy,
@@ -672,11 +672,11 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateStructType(
     unsigned RunTimeLang,
     LLVMValueRef VTableHolder) {
     return wrap(Builder->createStructType(
-        unwrapDI<DIDescriptor>(Scope), Name, 
-        unwrapDI<DIFile>(File), LineNumber, 
-        SizeInBits, AlignInBits, Flags, 
-        unwrapDI<DIType>(DerivedFrom), 
-        unwrapDI<DIArray>(Elements), RunTimeLang, 
+        unwrapDI<DIDescriptor>(Scope), Name,
+        unwrapDI<DIFile>(File), LineNumber,
+        SizeInBits, AlignInBits, Flags,
+        unwrapDI<DIType>(DerivedFrom),
+        unwrapDI<DIArray>(Elements), RunTimeLang,
         unwrapDI<MDNode*>(VTableHolder)));
 }
 
@@ -692,12 +692,12 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateMemberType(
     unsigned Flags,
     LLVMValueRef Ty) {
     return wrap(Builder->createMemberType(
-        unwrapDI<DIDescriptor>(Scope), Name, 
+        unwrapDI<DIDescriptor>(Scope), Name,
         unwrapDI<DIFile>(File), LineNo,
-        SizeInBits, AlignInBits, OffsetInBits, Flags, 
+        SizeInBits, AlignInBits, OffsetInBits, Flags,
         unwrapDI<DIType>(Ty)));
 }
-    
+
 extern "C" LLVMValueRef LLVMDIBuilderCreateLexicalBlock(
     DIBuilderRef Builder,
     LLVMValueRef Scope,
@@ -705,10 +705,10 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateLexicalBlock(
     unsigned Line,
     unsigned Col) {
     return wrap(Builder->createLexicalBlock(
-        unwrapDI<DIDescriptor>(Scope), 
+        unwrapDI<DIDescriptor>(Scope),
         unwrapDI<DIFile>(File), Line, Col));
 }
-    
+
 extern "C" LLVMValueRef LLVMDIBuilderCreateLocalVariable(
     DIBuilderRef Builder,
     unsigned Tag,
@@ -720,45 +720,45 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateLocalVariable(
     bool AlwaysPreserve,
     unsigned Flags,
     unsigned ArgNo) {
-    return wrap(Builder->createLocalVariable(Tag, 
-        unwrapDI<DIDescriptor>(Scope), Name, 
-        unwrapDI<DIFile>(File), 
-        LineNo, 
+    return wrap(Builder->createLocalVariable(Tag,
+        unwrapDI<DIDescriptor>(Scope), Name,
+        unwrapDI<DIFile>(File),
+        LineNo,
         unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, ArgNo));
 }
 
 extern "C" LLVMValueRef LLVMDIBuilderCreateArrayType(
     DIBuilderRef Builder,
-    uint64_t Size,  
-    uint64_t AlignInBits,  
-    LLVMValueRef Ty, 
+    uint64_t Size,
+    uint64_t AlignInBits,
+    LLVMValueRef Ty,
     LLVMValueRef Subscripts) {
     return wrap(Builder->createArrayType(Size, AlignInBits,
-        unwrapDI<DIType>(Ty), 
+        unwrapDI<DIType>(Ty),
         unwrapDI<DIArray>(Subscripts)));
 }
 
 extern "C" LLVMValueRef LLVMDIBuilderCreateVectorType(
     DIBuilderRef Builder,
-    uint64_t Size,  
-    uint64_t AlignInBits,  
-    LLVMValueRef Ty, 
+    uint64_t Size,
+    uint64_t AlignInBits,
+    LLVMValueRef Ty,
     LLVMValueRef Subscripts) {
     return wrap(Builder->createVectorType(Size, AlignInBits,
-        unwrapDI<DIType>(Ty), 
+        unwrapDI<DIType>(Ty),
         unwrapDI<DIArray>(Subscripts)));
 }
 
 extern "C" LLVMValueRef LLVMDIBuilderGetOrCreateSubrange(
-    DIBuilderRef Builder, 
-    int64_t Lo, 
+    DIBuilderRef Builder,
+    int64_t Lo,
     int64_t Count) {
     return wrap(Builder->getOrCreateSubrange(Lo, Count));
 }
 
 extern "C" LLVMValueRef LLVMDIBuilderGetOrCreateArray(
     DIBuilderRef Builder,
-    LLVMValueRef* Ptr, 
+    LLVMValueRef* Ptr,
     unsigned Count) {
     return wrap(Builder->getOrCreateArray(
         ArrayRef<Value*>(reinterpret_cast<Value**>(Ptr), Count)));
@@ -770,8 +770,8 @@ extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
     LLVMValueRef VarInfo,
     LLVMBasicBlockRef InsertAtEnd) {
     return wrap(Builder->insertDeclare(
-        unwrap(Val), 
-        unwrapDI<DIVariable>(VarInfo), 
+        unwrap(Val),
+        unwrapDI<DIVariable>(VarInfo),
         unwrap(InsertAtEnd)));
 }
 
@@ -781,7 +781,61 @@ extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareBefore(
     LLVMValueRef VarInfo,
     LLVMValueRef InsertBefore) {
     return wrap(Builder->insertDeclare(
-        unwrap(Val), 
-        unwrapDI<DIVariable>(VarInfo), 
+        unwrap(Val),
+        unwrapDI<DIVariable>(VarInfo),
         unwrap<Instruction>(InsertBefore)));
 }
+
+extern "C" LLVMValueRef LLVMDIBuilderCreateEnumerator(
+    DIBuilderRef Builder,
+    const char* Name,
+    uint64_t Val)
+{
+    return wrap(Builder->createEnumerator(Name, Val));
+}
+
+extern "C" LLVMValueRef LLVMDIBuilderCreateEnumerationType(
+    DIBuilderRef Builder,
+    LLVMValueRef Scope,
+    const char* Name,
+    LLVMValueRef File,
+    unsigned LineNumber,
+    uint64_t SizeInBits,
+    uint64_t AlignInBits,
+    LLVMValueRef Elements,
+    LLVMValueRef ClassType)
+{
+    return wrap(Builder->createEnumerationType(
+        unwrapDI<DIDescriptor>(Scope),
+        Name,
+        unwrapDI<DIFile>(File),
+        LineNumber,
+        SizeInBits,
+        AlignInBits,
+        unwrapDI<DIArray>(Elements),
+        unwrapDI<DIType>(ClassType)));
+}
+
+extern "C" LLVMValueRef LLVMDIBuilderCreateUnionType(
+    DIBuilderRef Builder,
+    LLVMValueRef Scope,
+    const char* Name,
+    LLVMValueRef File,
+    unsigned LineNumber,
+    uint64_t SizeInBits,
+    uint64_t AlignInBits,
+    unsigned Flags,
+    LLVMValueRef Elements,
+    unsigned RunTimeLang)
+{
+    return wrap(Builder->createUnionType(
+        unwrapDI<DIDescriptor>(Scope),
+        Name,
+        unwrapDI<DIFile>(File),
+        LineNumber,
+        SizeInBits,
+        AlignInBits,
+        Flags,
+        unwrapDI<DIArray>(Elements),
+        RunTimeLang));
+}
\ No newline at end of file