1 //===-- llvm/CodeGen/MachineDebugInfo.cpp -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // Collect debug information for a module. This information should be in a
11 // neutral form that can be used by different debugging schemes.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/CodeGen/MachineDebugInfo.h"
19 // Handle the Pass registration stuff necessary to use TargetData's.
21 RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information");
24 /// doInitialization - Initialize the debug state for a new module.
26 bool MachineDebugInfo::doInitialization() {
30 /// doFinalization - Tear down the debug state after completion of a module.
32 bool MachineDebugInfo::doFinalization() {
36 /// getUniqueSourceID - Register a source file with debug info. Returns an id.
38 unsigned MachineDebugInfo::getUniqueSourceID(const std::string &fname,
39 const std::string &dirname) {
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;
50 SourceMap.insert(SMI, std::make_pair(path, SourceCount));
55 /// getSourceFiles - Return a vector of files. Vector index + 1 equals id.
57 std::vector<std::string> MachineDebugInfo::getSourceFiles() const {
58 std::vector<std::string> Sources(SourceCount);
60 for (std::map<std::string, unsigned>::const_iterator SMI = SourceMap.begin(),
63 unsigned Index = SMI->second - 1;
64 const std::string &Path = SMI->first;
65 Sources[Index] = Path;