annotate gen/todebug.cpp @ 139:0ab29b838084 trunk

[svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :) Fixed: tango.io.Console seems to be working now.
author lindquist
date Tue, 22 Jan 2008 00:01:16 +0100
parents 0e28624814e8
children ffcc9a2f3d9d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
1 #include "gen/llvm.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
2 #include "llvm/Support/Dwarf.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
3 #include "llvm/CodeGen/MachineModuleInfo.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
4
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
5 #include "declaration.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
6 #include "module.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
7 #include "mars.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
8
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
9 #include "gen/todebug.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
10 #include "gen/irstate.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
11 #include "gen/tollvm.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
12 #include "gen/logger.h"
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
13
139
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
14 #include "ir/irmodule.h"
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
15
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
16 using namespace llvm::dwarf;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
17
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
18 static const llvm::PointerType* ptrTy(const llvm::Type* t)
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
19 {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 131
diff changeset
20 return llvm::PointerType::get(t, 0);
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
21 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
22
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
23 static const llvm::PointerType* dbgArrTy()
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
24 {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
25 std::vector<const llvm::Type*> t;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
26 return ptrTy(llvm::StructType::get(t));
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
27 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
28
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
29 static llvm::Constant* dbgToArrTy(llvm::Constant* c)
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
30 {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
31 Logger::cout() << "casting: " << *c << '\n';
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
32 return llvm::ConstantExpr::getBitCast(c, dbgArrTy());
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
33 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
34
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
35 #define Ty(X) llvm::Type::X
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
36
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
37 //////////////////////////////////////////////////////////////////////////////////////////////////
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
38
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
39 static llvm::GlobalVariable* dbg_compile_units = 0;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
40 static llvm::GlobalVariable* dbg_global_variables = 0;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
41 static llvm::GlobalVariable* dbg_subprograms = 0;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
42
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
43 const llvm::StructType* GetDwarfAnchorType()
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
44 {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
45 /*
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
46 %llvm.dbg.anchor.type = type {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
47 uint, ;; Tag = 0 + LLVMDebugVersion
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
48 uint ;; Tag of descriptors grouped by the anchor
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
49 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
50 */
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
51 std::vector<const llvm::Type*> elems(2, Ty(Int32Ty));
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
52 const llvm::StructType* t = isaStruct(gIR->module->getTypeByName("llvm.dbg.anchor.type"));
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
53
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
54 /*
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
55 %llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { uint 0, uint 17 } ;; DW_TAG_compile_unit
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
56 %llvm.dbg.global_variables = linkonce constant %llvm.dbg.anchor.type { uint 0, uint 52 } ;; DW_TAG_variable
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
57 %llvm.dbg.subprograms = linkonce constant %llvm.dbg.anchor.type { uint 0, uint 46 } ;; DW_TAG_subprogram
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
58 */
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
59 if (!gIR->module->getNamedGlobal("llvm.dbg.compile_units")) {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
60 std::vector<llvm::Constant*> vals;
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
61 vals.push_back(DtoConstUint(llvm::LLVMDebugVersion));
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
62 vals.push_back(DtoConstUint(DW_TAG_compile_unit));
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
63 llvm::Constant* i = llvm::ConstantStruct::get(t, vals);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
64 dbg_compile_units = new llvm::GlobalVariable(t,true,llvm::GlobalValue::LinkOnceLinkage,i,"llvm.dbg.compile_units",gIR->module);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
65 dbg_compile_units->setSection("llvm.metadata");
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
66 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
67 if (!gIR->module->getNamedGlobal("llvm.dbg.global_variables")) {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
68 std::vector<llvm::Constant*> vals;
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
69 vals.push_back(DtoConstUint(llvm::LLVMDebugVersion));
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
70 vals.push_back(DtoConstUint(DW_TAG_variable));
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
71 llvm::Constant* i = llvm::ConstantStruct::get(t, vals);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
72 dbg_global_variables = new llvm::GlobalVariable(t,true,llvm::GlobalValue::LinkOnceLinkage,i,"llvm.dbg.global_variables",gIR->module);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
73 dbg_global_variables->setSection("llvm.metadata");
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
74 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
75 if (!gIR->module->getNamedGlobal("llvm.dbg.subprograms")) {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
76 std::vector<llvm::Constant*> vals;
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
77 vals.push_back(DtoConstUint(llvm::LLVMDebugVersion));
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
78 vals.push_back(DtoConstUint(DW_TAG_subprogram));
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
79 llvm::Constant* i = llvm::ConstantStruct::get(t, vals);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
80 dbg_subprograms = new llvm::GlobalVariable(t,true,llvm::GlobalValue::LinkOnceLinkage,i,"llvm.dbg.subprograms",gIR->module);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
81 dbg_subprograms->setSection("llvm.metadata");
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
82 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
83
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
84 return t;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
85 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
86
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
87 llvm::Constant* GetDwarfAnchor(llvm::dwarf::dwarf_constants c)
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
88 {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
89 GetDwarfAnchorType();
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
90 switch (c)
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
91 {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
92 case DW_TAG_compile_unit:
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
93 return dbg_compile_units;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
94 case DW_TAG_variable:
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
95 return dbg_global_variables;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
96 case DW_TAG_subprogram:
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
97 return dbg_subprograms;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
98 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
99 assert(0);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
100 return 0;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
101 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
102
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
103 //////////////////////////////////////////////////////////////////////////////////////////////////
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
104
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
105 const llvm::StructType* GetDwarfCompileUnitType() {
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
106 return isaStruct(gIR->module->getTypeByName("llvm.dbg.compile_unit.type"));
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
107 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
108
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
109 const llvm::StructType* GetDwarfSubProgramType() {
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
110 return isaStruct(gIR->module->getTypeByName("llvm.dbg.subprogram.type"));
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
111 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
112
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
113 //////////////////////////////////////////////////////////////////////////////////////////////////
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
114
139
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
115 llvm::GlobalVariable* DtoDwarfCompileUnit(Module* m)
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
116 {
139
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
117 if (!m->irModule)
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
118 m->irModule = new IrModule(m);
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
119 else if (m->irModule->dwarfCompileUnit)
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
120 {
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
121 if (m->irModule->dwarfCompileUnit->getParent() == gIR->module)
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
122 return m->irModule->dwarfCompileUnit;
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
123 }
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
124
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
125 // create a valid compile unit constant for the current module
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
126
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
127 llvm::Constant* c = NULL;
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
128
139
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
129 std::vector<llvm::Constant*> vals;
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
130 vals.push_back(llvm::ConstantExpr::getAdd(
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
131 DtoConstUint(DW_TAG_compile_unit),
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
132 DtoConstUint(llvm::LLVMDebugVersion)));
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
133 vals.push_back(dbgToArrTy(GetDwarfAnchor(DW_TAG_compile_unit)));
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
134
139
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
135 vals.push_back(DtoConstUint(DW_LANG_C));// _D)); // doesn't seem to work
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
136 vals.push_back(DtoConstStringPtr(m->srcfile->name->toChars(), "llvm.metadata"));
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
137 std::string srcpath(FileName::path(m->srcfile->name->toChars()));
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
138 if (srcpath.empty())
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
139 srcpath = ".";
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
140 vals.push_back(DtoConstStringPtr(srcpath.c_str(), "llvm.metadata"));
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
141 vals.push_back(DtoConstStringPtr("LLVMDC (http://www.dsource.org/projects/llvmdc)", "llvm.metadata"));
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
142
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
143 c = llvm::ConstantStruct::get(GetDwarfCompileUnitType(), vals);
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
144
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
145 llvm::GlobalVariable* gv = new llvm::GlobalVariable(GetDwarfCompileUnitType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.compile_unit", gIR->module);
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
146 gv->setSection("llvm.metadata");
139
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
147
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
148 m->irModule->dwarfCompileUnit = gv;
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
149 return gv;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
150 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
151
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
152 //////////////////////////////////////////////////////////////////////////////////////////////////
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
153
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
154 llvm::GlobalVariable* DtoDwarfSubProgram(FuncDeclaration* fd, llvm::GlobalVariable* compileUnit)
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
155 {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
156 std::vector<llvm::Constant*> vals;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
157 vals.push_back(llvm::ConstantExpr::getAdd(
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
158 DtoConstUint(DW_TAG_subprogram),
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
159 DtoConstUint(llvm::LLVMDebugVersion)));
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
160 vals.push_back(dbgToArrTy(GetDwarfAnchor(DW_TAG_subprogram)));
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
161
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
162 vals.push_back(dbgToArrTy(compileUnit));
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
163 vals.push_back(DtoConstStringPtr(fd->toPrettyChars(), "llvm.metadata"));
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
164 vals.push_back(vals.back());
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
165 vals.push_back(DtoConstStringPtr(fd->mangle(), "llvm.metadata"));
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 86
diff changeset
166 vals.push_back(dbgToArrTy(compileUnit));
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
167 vals.push_back(DtoConstUint(fd->loc.linnum));
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
168 vals.push_back(llvm::ConstantPointerNull::get(dbgArrTy()));
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
169 vals.push_back(DtoConstBool(fd->protection == PROTprivate));
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
170 vals.push_back(DtoConstBool(fd->getModule() == gIR->dmodule));
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
171
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
172 llvm::Constant* c = llvm::ConstantStruct::get(GetDwarfSubProgramType(), vals);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
173 llvm::GlobalVariable* gv = new llvm::GlobalVariable(c->getType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.subprogram", gIR->module);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
174 gv->setSection("llvm.metadata");
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
175 return gv;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
176 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
177
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
178 //////////////////////////////////////////////////////////////////////////////////////////////////
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
179
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
180 void DtoDwarfFuncStart(FuncDeclaration* fd)
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
181 {
136
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
182 assert(fd->irFunc->dwarfSubProg);
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
183 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), dbgToArrTy(fd->irFunc->dwarfSubProg));
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
184 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
185
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
186 void DtoDwarfFuncEnd(FuncDeclaration* fd)
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
187 {
136
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
188 assert(fd->irFunc->dwarfSubProg);
0e28624814e8 [svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents: 133
diff changeset
189 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), dbgToArrTy(fd->irFunc->dwarfSubProg));
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
190 }
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
191
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
192 //////////////////////////////////////////////////////////////////////////////////////////////////
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
193
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
194 void DtoDwarfStopPoint(unsigned ln)
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
195 {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
196 std::vector<llvm::Value*> args;
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
197 args.push_back(DtoConstUint(ln));
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
198 args.push_back(DtoConstUint(0));
139
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
199 FuncDeclaration* fd = gIR->func()->decl;
0ab29b838084 [svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
lindquist
parents: 136
diff changeset
200 args.push_back(dbgToArrTy(DtoDwarfCompileUnit(fd->getModule())));
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
201 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.stoppoint"), args.begin(), args.end());
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
diff changeset
202 }