blob: d2a5fd5eb356979efe673344aaf08e0e2ad5e192 [file] [log] [blame]
Jim Laskey6af56812006-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 {
Jim Laskeyb2efb852006-01-04 22:28:25 +000021 RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information");
22}
23
24/// doInitialization - Initialize the debug state for a new module.
25///
26bool MachineDebugInfo::doInitialization() {
27 return false;
Jim Laskey6af56812006-01-04 13:36:38 +000028}
29
Jim Laskeyb2efb852006-01-04 22:28:25 +000030/// doFinalization - Tear down the debug state after completion of a module.
31///
32bool MachineDebugInfo::doFinalization() {
33 return false;
34}
35
36/// getUniqueSourceID - Register a source file with debug info. Returns an id.
37///
38unsigned 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///
57std::vector<std::string> MachineDebugInfo::getSourceFiles() const {
58 std::vector<std::string> Sources(SourceCount);
Jim Laskey6af56812006-01-04 13:36:38 +000059
Jim Laskeyb2efb852006-01-04 22:28:25 +000060 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 Laskey6af56812006-01-04 13:36:38 +000066 }
Jim Laskeyb2efb852006-01-04 22:28:25 +000067 return Sources;
68}
Jim Laskey6af56812006-01-04 13:36:38 +000069