Merge branch 'master' into msp430
[llvm/msp430.git] / lib / Debugger / SourceLanguage-Unknown.cpp
blobb806fc779ef7e9065e4cce711e7aa4e6db8fd94a
1 //===-- SourceLanguage-Unknown.cpp - Implement itf for unknown languages --===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // If the LLVM debugger does not have a module for a particular language, it
11 // falls back on using this one to perform the source-language interface. This
12 // interface is not wonderful, but it gets the job done.
14 //===----------------------------------------------------------------------===//
16 #include "llvm/Debugger/SourceLanguage.h"
17 #include "llvm/Debugger/ProgramInfo.h"
18 #include "llvm/Support/Streams.h"
19 #include <cassert>
20 #include <ostream>
21 using namespace llvm;
23 //===----------------------------------------------------------------------===//
24 // Implement the SourceLanguage cache for the Unknown language.
27 namespace {
28 /// SLUCache - This cache allows for efficient lookup of source functions by
29 /// name.
30 ///
31 struct SLUCache : public SourceLanguageCache {
32 ProgramInfo &PI;
33 std::multimap<std::string, SourceFunctionInfo*> FunctionMap;
34 public:
35 SLUCache(ProgramInfo &pi);
37 typedef std::multimap<std::string, SourceFunctionInfo*>::const_iterator
38 fm_iterator;
40 std::pair<fm_iterator, fm_iterator>
41 getFunction(const std::string &Name) const {
42 return FunctionMap.equal_range(Name);
45 SourceFunctionInfo *addSourceFunction(SourceFunctionInfo *SF) {
46 FunctionMap.insert(std::make_pair(SF->getSymbolicName(), SF));
47 return SF;
52 SLUCache::SLUCache(ProgramInfo &pi) : PI(pi) {
56 //===----------------------------------------------------------------------===//
57 // Implement SourceLanguageUnknown class, which is used to handle unrecognized
58 // languages.
61 namespace {
62 static struct SLU : public SourceLanguage {
63 //===------------------------------------------------------------------===//
64 // Implement the miscellaneous methods...
66 virtual const char *getSourceLanguageName() const {
67 return "unknown";
70 /// lookupFunction - Given a textual function name, return the
71 /// SourceFunctionInfo descriptor for that function, or null if it cannot be
72 /// found. If the program is currently running, the RuntimeInfo object
73 /// provides information about the current evaluation context, otherwise it
74 /// will be null.
75 ///
76 virtual SourceFunctionInfo *lookupFunction(const std::string &FunctionName,
77 ProgramInfo &PI,
78 RuntimeInfo *RI = 0) const;
80 //===------------------------------------------------------------------===//
81 // We do use a cache for information...
83 typedef SLUCache CacheType;
84 SLUCache *createSourceLanguageCache(ProgramInfo &PI) const {
85 return new SLUCache(PI);
88 /// createSourceFunctionInfo - Create the new object and inform the cache of
89 /// the new function.
90 virtual SourceFunctionInfo *
91 createSourceFunctionInfo(const GlobalVariable *Desc, ProgramInfo &PI) const;
93 } TheUnknownSourceLanguageInstance;
96 const SourceLanguage &SourceLanguage::getUnknownLanguageInstance() {
97 return TheUnknownSourceLanguageInstance;
101 SourceFunctionInfo *
102 SLU::createSourceFunctionInfo(const GlobalVariable *Desc,
103 ProgramInfo &PI) const {
104 SourceFunctionInfo *Result = new SourceFunctionInfo(PI, Desc);
105 return PI.getLanguageCache(this).addSourceFunction(Result);
109 /// lookupFunction - Given a textual function name, return the
110 /// SourceFunctionInfo descriptor for that function, or null if it cannot be
111 /// found. If the program is currently running, the RuntimeInfo object
112 /// provides information about the current evaluation context, otherwise it will
113 /// be null.
115 SourceFunctionInfo *SLU::lookupFunction(const std::string &FunctionName,
116 ProgramInfo &PI, RuntimeInfo *RI) const{
117 SLUCache &Cache = PI.getLanguageCache(this);
118 std::pair<SLUCache::fm_iterator, SLUCache::fm_iterator> IP
119 = Cache.getFunction(FunctionName);
121 if (IP.first == IP.second) {
122 if (PI.allSourceFunctionsRead())
123 return 0; // Nothing found
125 // Otherwise, we might be able to find the function if we read all of them
126 // in. Do so now.
127 PI.getSourceFunctions();
128 assert(PI.allSourceFunctionsRead() && "Didn't read in all functions?");
129 return lookupFunction(FunctionName, PI, RI);
132 SourceFunctionInfo *Found = IP.first->second;
133 ++IP.first;
134 if (IP.first != IP.second)
135 cout << "Whoa, found multiple functions with the same name. I should"
136 << " ask the user which one to use: FIXME!\n";
137 return Found;