Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 17 | using namespace llvm; |
| 18 | |
| 19 | // Handle the Pass registration stuff necessary to use TargetData's. |
| 20 | namespace { |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 21 | RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information"); |
| 22 | } |
| 23 | |
| 24 | /// doInitialization - Initialize the debug state for a new module. |
| 25 | /// |
| 26 | bool MachineDebugInfo::doInitialization() { |
| 27 | return false; |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 30 | /// doFinalization - Tear down the debug state after completion of a module. |
| 31 | /// |
| 32 | bool MachineDebugInfo::doFinalization() { |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | /// getUniqueSourceID - Register a source file with debug info. Returns an id. |
| 37 | /// |
| 38 | unsigned MachineDebugInfo::getUniqueSourceID(const std::string &fname, |
| 39 | const std::string &dirname) { |
| 40 | // Compose a key |
| 41 | const std::string path = dirname + "/" + fname; |
| 42 | // Check if the source file is already recorded |
| 43 | std::map<std::string, unsigned>::iterator |
| 44 | SMI = SourceMap.lower_bound(path); |
| 45 | // If already there return existing id |
| 46 | if (SMI != SourceMap.end() && SMI->first == path) return SMI->second; |
| 47 | // Bump up the count |
| 48 | ++SourceCount; |
| 49 | // Record the count |
| 50 | SourceMap.insert(SMI, std::make_pair(path, SourceCount)); |
| 51 | // Return id |
| 52 | return SourceCount; |
| 53 | } |
| 54 | |
| 55 | /// getSourceFiles - Return a vector of files. Vector index + 1 equals id. |
| 56 | /// |
| 57 | std::vector<std::string> MachineDebugInfo::getSourceFiles() const { |
| 58 | std::vector<std::string> Sources(SourceCount); |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 59 | |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 60 | for (std::map<std::string, unsigned>::const_iterator SMI = SourceMap.begin(), |
| 61 | E = SourceMap.end(); |
| 62 | SMI != E; SMI++) { |
| 63 | unsigned Index = SMI->second - 1; |
| 64 | const std::string &Path = SMI->first; |
| 65 | Sources[Index] = Path; |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 66 | } |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 67 | return Sources; |
| 68 | } |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 69 | |