Index: llvm/trunk/bindings/go/llvm/DIBuilderBindings.h =================================================================== --- llvm/trunk/bindings/go/llvm/DIBuilderBindings.h +++ llvm/trunk/bindings/go/llvm/DIBuilderBindings.h @@ -1,40 +0,0 @@ -//===- DIBuilderBindings.h - Bindings for DIBuilder -------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines C bindings for the DIBuilder class. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_BINDINGS_GO_LLVM_DIBUILDERBINDINGS_H -#define LLVM_BINDINGS_GO_LLVM_DIBUILDERBINDINGS_H - -#include "IRBindings.h" -#include "llvm-c/Core.h" -#include "llvm-c/DebugInfo.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// FIXME: These bindings shouldn't be Go-specific and should eventually move to -// a (somewhat) less stable collection of C APIs for use in creating bindings of -// LLVM in other languages. - -typedef struct LLVMOpaqueDIBuilder *LLVMDIBuilderRef; - -LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef D, - LLVMMetadataRef Ty, const char *Name, - LLVMMetadataRef File, unsigned Line, - LLVMMetadataRef Context); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif Index: llvm/trunk/bindings/go/llvm/DIBuilderBindings.cpp =================================================================== --- llvm/trunk/bindings/go/llvm/DIBuilderBindings.cpp +++ llvm/trunk/bindings/go/llvm/DIBuilderBindings.cpp @@ -1,30 +0,0 @@ -//===- DIBuilderBindings.cpp - Bindings for DIBuilder ---------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines C bindings for the DIBuilder class. -// -//===----------------------------------------------------------------------===// - -#include "DIBuilderBindings.h" -#include "IRBindings.h" -#include "llvm/IR/DIBuilder.h" -#include "llvm/IR/IRBuilder.h" -#include "llvm/IR/Module.h" - -using namespace llvm; - -LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref, - LLVMMetadataRef Ty, const char *Name, - LLVMMetadataRef File, unsigned Line, - LLVMMetadataRef Context) { - DIBuilder *D = unwrap(Dref); - return wrap(D->createTypedef(unwrap(Ty), Name, - File ? unwrap(File) : nullptr, Line, - Context ? unwrap(Context) : nullptr)); -} Index: llvm/trunk/bindings/go/llvm/IRBindings.h =================================================================== --- llvm/trunk/bindings/go/llvm/IRBindings.h +++ llvm/trunk/bindings/go/llvm/IRBindings.h @@ -15,6 +15,7 @@ #define LLVM_BINDINGS_GO_LLVM_IRBINDINGS_H #include "llvm-c/Core.h" +#include "llvm-c/DebugInfo.h" #ifdef __cplusplus #include "llvm/IR/Metadata.h" #include "llvm/Support/CBindingWrapping.h" Index: llvm/trunk/bindings/go/llvm/dibuilder.go =================================================================== --- llvm/trunk/bindings/go/llvm/dibuilder.go +++ llvm/trunk/bindings/go/llvm/dibuilder.go @@ -14,7 +14,7 @@ package llvm /* -#include "DIBuilderBindings.h" +#include "IRBindings.h" #include */ import "C" @@ -514,6 +514,7 @@ d.ref, t.Type.C, name, + C.size_t(len(t.Name)), t.File.C, C.unsigned(t.Line), t.Context.C, Index: llvm/trunk/include/llvm-c/DebugInfo.h =================================================================== --- llvm/trunk/include/llvm-c/DebugInfo.h +++ llvm/trunk/include/llvm-c/DebugInfo.h @@ -674,6 +674,21 @@ LLVMDIBuilderCreateNullPtrType(LLVMDIBuilderRef Builder); /** + * Create debugging information entry for a typedef. + * \param Builder The DIBuilder. + * \param Type Original type. + * \param Name Typedef name. + * \param File File where this type is defined. + * \param LineNo Line number. + * \param Scope The surrounding context for the typedef. +*/ +LLVMMetadataRef +LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type, + const char *Name, size_t NameLen, + LLVMMetadataRef File, unsigned LineNo, + LLVMMetadataRef Scope); + +/** * Create a permanent forward-declared type. * \param Builder The DIBuilder. * \param Tag A unique tag for this type. Index: llvm/trunk/lib/IR/DebugInfo.cpp =================================================================== --- llvm/trunk/lib/IR/DebugInfo.cpp +++ llvm/trunk/lib/IR/DebugInfo.cpp @@ -1019,6 +1019,17 @@ } LLVMMetadataRef +LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type, + const char *Name, size_t NameLen, + LLVMMetadataRef File, unsigned LineNo, + LLVMMetadataRef Scope) { + return wrap(unwrap(Builder)->createTypedef( + unwrapDI(Type), {Name, NameLen}, + unwrapDI(File), LineNo, + unwrapDI(Scope))); +} + +LLVMMetadataRef LLVMDIBuilderCreateForwardDecl( LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, Index: llvm/trunk/test/Bindings/llvm-c/debug_info.ll =================================================================== --- llvm/trunk/test/Bindings/llvm-c/debug_info.ll +++ llvm/trunk/test/Bindings/llvm-c/debug_info.ll @@ -3,48 +3,49 @@ ; CHECK: ; ModuleID = 'debuginfo.c' ; CHECK-NEXT: source_filename = "debuginfo.c" -; CHECK: define i64 @foo(i64, i64, <10 x i64>) !dbg !16 { +; CHECK: define i64 @foo(i64, i64, <10 x i64>) !dbg !17 { ; CHECK-NEXT: entry: -; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !23, metadata !DIExpression()), !dbg !28 -; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !24, metadata !DIExpression()), !dbg !28 -; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !25, metadata !DIExpression()), !dbg !28 +; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !24, metadata !DIExpression()), !dbg !29 +; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !25, metadata !DIExpression()), !dbg !29 +; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !26, metadata !DIExpression()), !dbg !29 ; CHECK: vars: -; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 0, metadata !26, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !29 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 0, metadata !27, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !30 ; CHECK-NEXT: } ; CHECK: declare void @llvm.dbg.declare(metadata, metadata, metadata) #0 ; CHECK: declare void @llvm.dbg.value(metadata, metadata, metadata) #0 ; CHECK: !llvm.dbg.cu = !{!0} -; CHECK: !FooType = !{!12} +; CHECK: !FooType = !{!13} -; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, imports: !8, splitDebugInlining: false) +; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, imports: !9, splitDebugInlining: false) ; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".") ; CHECK-NEXT: !2 = !{} ; CHECK-NEXT: !3 = !{!4} ; CHECK-NEXT: !4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)) ; CHECK-NEXT: !5 = distinct !DIGlobalVariable(name: "global", scope: !6, file: !1, line: 1, type: !7, isLocal: true, isDefinition: true) ; CHECK-NEXT: !6 = !DIModule(scope: null, name: "llvm-c-test", includePath: "/test/include/llvm-c-test.h") -; CHECK-NEXT: !7 = !DIBasicType(name: "Int64", size: 64) -; CHECK-NEXT: !8 = !{!9, !11} -; CHECK-NEXT: !9 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !10, file: !1, line: 42) -; CHECK-NEXT: !10 = !DIModule(scope: null, name: "llvm-c-test-import", includePath: "/test/include/llvm-c-test-import.h") -; CHECK-NEXT: !11 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !9, file: !1, line: 42) -; CHECK-NEXT: !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 192, dwarfAddressSpace: 0) -; CHECK-NEXT: !13 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !14, file: !1, size: 192, elements: !15, runtimeLang: DW_LANG_C89, identifier: "MyStruct") -; CHECK-NEXT: !14 = !DINamespace(name: "NameSpace", scope: !6) -; CHECK-NEXT: !15 = !{!7, !7, !7} -; CHECK-NEXT: !16 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !17, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, retainedNodes: !22) -; CHECK-NEXT: !17 = !DISubroutineType(types: !18) -; CHECK-NEXT: !18 = !{!7, !7, !19} -; CHECK-NEXT: !19 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 640, flags: DIFlagVector, elements: !20) -; CHECK-NEXT: !20 = !{!21} -; CHECK-NEXT: !21 = !DISubrange(count: 10) -; CHECK-NEXT: !22 = !{!23, !24, !25, !26} -; CHECK-NEXT: !23 = !DILocalVariable(name: "a", arg: 1, scope: !16, file: !1, line: 42, type: !7) -; CHECK-NEXT: !24 = !DILocalVariable(name: "b", arg: 2, scope: !16, file: !1, line: 42, type: !7) -; CHECK-NEXT: !25 = !DILocalVariable(name: "c", arg: 3, scope: !16, file: !1, line: 42, type: !19) -; CHECK-NEXT: !26 = !DILocalVariable(name: "d", scope: !27, file: !1, line: 43, type: !7) -; CHECK-NEXT: !27 = distinct !DILexicalBlock(scope: !16, file: !1, line: 42) -; CHECK-NEXT: !28 = !DILocation(line: 42, scope: !16) -; CHECK-NEXT: !29 = !DILocation(line: 43, scope: !16) +; CHECK-NEXT: !7 = !DIDerivedType(tag: DW_TAG_typedef, name: "int64_t", scope: !1, file: !1, line: 42, baseType: !8) +; CHECK-NEXT: !8 = !DIBasicType(name: "Int64", size: 64) +; CHECK-NEXT: !9 = !{!10, !12} +; CHECK-NEXT: !10 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !11, file: !1, line: 42) +; CHECK-NEXT: !11 = !DIModule(scope: null, name: "llvm-c-test-import", includePath: "/test/include/llvm-c-test-import.h") +; CHECK-NEXT: !12 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !10, file: !1, line: 42) +; CHECK-NEXT: !13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 192, dwarfAddressSpace: 0) +; CHECK-NEXT: !14 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !15, file: !1, size: 192, elements: !16, runtimeLang: DW_LANG_C89, identifier: "MyStruct") +; CHECK-NEXT: !15 = !DINamespace(name: "NameSpace", scope: !6) +; CHECK-NEXT: !16 = !{!8, !8, !8} +; CHECK-NEXT: !17 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !18, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, retainedNodes: !23) +; CHECK-NEXT: !18 = !DISubroutineType(types: !19) +; CHECK-NEXT: !19 = !{!8, !8, !20} +; CHECK-NEXT: !20 = !DICompositeType(tag: DW_TAG_array_type, baseType: !8, size: 640, flags: DIFlagVector, elements: !21) +; CHECK-NEXT: !21 = !{!22} +; CHECK-NEXT: !22 = !DISubrange(count: 10) +; CHECK-NEXT: !23 = !{!24, !25, !26, !27} +; CHECK-NEXT: !24 = !DILocalVariable(name: "a", arg: 1, scope: !17, file: !1, line: 42, type: !8) +; CHECK-NEXT: !25 = !DILocalVariable(name: "b", arg: 2, scope: !17, file: !1, line: 42, type: !8) +; CHECK-NEXT: !26 = !DILocalVariable(name: "c", arg: 3, scope: !17, file: !1, line: 42, type: !20) +; CHECK-NEXT: !27 = !DILocalVariable(name: "d", scope: !28, file: !1, line: 43, type: !8) +; CHECK-NEXT: !28 = distinct !DILexicalBlock(scope: !17, file: !1, line: 42) +; CHECK-NEXT: !29 = !DILocation(line: 42, scope: !17) +; CHECK-NEXT: !30 = !DILocation(line: 43, scope: !17) Index: llvm/trunk/tools/llvm-c-test/debuginfo.c =================================================================== --- llvm/trunk/tools/llvm-c-test/debuginfo.c +++ llvm/trunk/tools/llvm-c-test/debuginfo.c @@ -50,10 +50,13 @@ LLVMMetadataRef Int64Ty = LLVMDIBuilderCreateBasicType(DIB, "Int64", 5, 64, 0); + LLVMMetadataRef Int64TypeDef = + LLVMDIBuilderCreateTypedef(DIB, Int64Ty, "int64_t", 7, File, 42, File); + LLVMMetadataRef GlobalVarValueExpr = LLVMDIBuilderCreateConstantValueExpression(DIB, 0); LLVMDIBuilderCreateGlobalVariableExpression(DIB, Module, "global", 6, - "", 0, File, 1, Int64Ty, + "", 0, File, 1, Int64TypeDef, true, GlobalVarValueExpr, NULL, 0);