aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/MachineDebugInfo.cpp
blob: d2a5fd5eb356979efe673344aaf08e0e2ad5e192 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//===-- llvm/CodeGen/MachineDebugInfo.cpp -----------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file was developed by James M. Laskey and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Collect debug information for a module.  This information should be in a
// neutral form that can be used by different debugging schemes.
//
//===----------------------------------------------------------------------===//

#include "llvm/CodeGen/MachineDebugInfo.h"

using namespace llvm;

// Handle the Pass registration stuff necessary to use TargetData's.
namespace {
  RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information");
}
  
/// doInitialization - Initialize the debug state for a new module.
///
bool MachineDebugInfo::doInitialization() {
  return false;
}

/// doFinalization - Tear down the debug state after completion of a module.
///
bool MachineDebugInfo::doFinalization() {
  return false;
}

/// getUniqueSourceID - Register a source file with debug info.  Returns an id.
///
unsigned MachineDebugInfo::getUniqueSourceID(const std::string &fname,
                                             const std::string &dirname) {
  // Compose a key
  const std::string path = dirname + "/" + fname;
  // Check if the source file is already recorded
  std::map<std::string, unsigned>::iterator
      SMI = SourceMap.lower_bound(path);
  // If already there return existing id
  if (SMI != SourceMap.end() && SMI->first == path) return SMI->second;
  // Bump up the count
  ++SourceCount;
  // Record the count
  SourceMap.insert(SMI, std::make_pair(path, SourceCount));
  // Return id
  return SourceCount;
}

/// getSourceFiles - Return a vector of files.  Vector index + 1 equals id.
///
std::vector<std::string> MachineDebugInfo::getSourceFiles() const {
  std::vector<std::string> Sources(SourceCount);
  
  for (std::map<std::string, unsigned>::const_iterator SMI = SourceMap.begin(),
                                                       E = SourceMap.end();
                                                       SMI != E; SMI++) {
    unsigned Index = SMI->second - 1;
    const std::string &Path = SMI->first;
    Sources[Index] = Path;
  }
  return Sources;
}