blob: 2cd30fad18b3a5ce6acb3cc8a30b9547d4b366ba [file] [log] [blame]
Jim Laskey44317392006-01-04 13:36:38 +00001//===-- llvm/CodeGen/MachineDebugInfo.cpp -----------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by James M. Laskey and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Collect debug information for a module. This information should be in a
11// neutral form that can be used by different debugging schemes.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/CodeGen/MachineDebugInfo.h"
16
17using namespace llvm;
18
19// Handle the Pass registration stuff necessary to use TargetData's.
20namespace {
21 RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information",
22 PassInfo::Analysis | PassInfo::Optimization);
23}
24
25namespace llvm {
26
27 /// DebugInfo - Keep track of debug information for the function.
28 ///
29 // FIXME - making it global until we can find a proper place to hang it from.
30 MachineDebugInfo *DebugInfo;
31
32 // FIXME - temporary hack until we can find a place to hand debug info from.
33 ModulePass *createDebugInfoPass() {
34 if (!DebugInfo) DebugInfo = new MachineDebugInfo();
35 return (ModulePass *)DebugInfo;
36 }
37
38 /// getDebugInfo - Returns the DebugInfo.
39 MachineDebugInfo &getMachineDebugInfo() {
40 assert(DebugInfo && "DebugInfo pass not created");
41 return *DebugInfo;
42 }
43
44 /// doInitialization - Initialize the debug state for a new module.
45 ///
46 bool MachineDebugInfo::doInitialization() {
47 return true;
48 }
49
50 /// doFinalization - Tear down the debug state after completion of a module.
51 ///
52 bool MachineDebugInfo::doFinalization() {
53 return true;
54 }
55
56 /// RecordSource - Register a source file with debug info. Returns an id.
57 ///
58 unsigned MachineDebugInfo::RecordSource(std::string fname,
59 std::string dirname) {
60 // Compose a key
61 std::string path = dirname + "/" + fname;
62 // Check if the source file is already recorded
63 StrIntMapIter SMI = SourceMap.find(path);
64 // If already there return existing id
65 if (SMI != SourceMap.end()) return SMI->second;
66 // Bump up the count
67 ++SourceCount;
68 // Record the count
69 SourceMap[path] = SourceCount;
70 // Return id
71 return SourceCount;
72 }
73
74 /// getSourceFiles - Return a vector of files. Vector index + 1 equals id.
75 ///
76 std::vector<std::string> MachineDebugInfo::getSourceFiles() {
77 std::vector<std::string> Sources(SourceCount);
78
79 for (StrIntMapIter SMI = SourceMap.begin(), E = SourceMap.end(); SMI != E;
80 SMI++) {
81 unsigned Index = SMI->second - 1;
82 std::string Path = SMI->first;
83 Sources[Index] = Path;
84 }
85 return Sources;
86 }
87
88
89};
90