blob: 514afa3bc24725fa66a1c21c0db641fb4b8283d9 [file] [log] [blame]
Chris Lattner2eacf262004-01-05 05:25:10 +00001//===-- SourceLanguage-Unknown.cpp - Implement itf for unknown languages --===//
Misha Brukmanedf128a2005-04-21 22:36:52 +00002//
Chris Lattner2eacf262004-01-05 05:25:10 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanedf128a2005-04-21 22:36:52 +00007//
Chris Lattner2eacf262004-01-05 05:25:10 +00008//===----------------------------------------------------------------------===//
Misha Brukmanedf128a2005-04-21 22:36:52 +00009//
Chris Lattner2eacf262004-01-05 05:25:10 +000010// 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.
13//
14//===----------------------------------------------------------------------===//
15
16#include "llvm/Debugger/SourceLanguage.h"
17#include "llvm/Debugger/ProgramInfo.h"
Bill Wendlingbcd24982006-12-07 20:28:15 +000018#include "llvm/Support/Streams.h"
Chris Lattner60a57582004-01-05 05:45:25 +000019#include <cassert>
Bill Wendling1a097e32006-12-07 23:41:45 +000020#include <ostream>
Chris Lattner2eacf262004-01-05 05:25:10 +000021using namespace llvm;
22
23//===----------------------------------------------------------------------===//
24// Implement the SourceLanguage cache for the Unknown language.
25//
26
27namespace {
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);
36
37 typedef std::multimap<std::string, SourceFunctionInfo*>::const_iterator
38 fm_iterator;
39
40 std::pair<fm_iterator, fm_iterator>
41 getFunction(const std::string &Name) const {
42 return FunctionMap.equal_range(Name);
43 }
44
45 SourceFunctionInfo *addSourceFunction(SourceFunctionInfo *SF) {
46 FunctionMap.insert(std::make_pair(SF->getSymbolicName(), SF));
47 return SF;
48 }
49 };
50}
51
52SLUCache::SLUCache(ProgramInfo &pi) : PI(pi) {
53}
54
55
56//===----------------------------------------------------------------------===//
57// Implement SourceLanguageUnknown class, which is used to handle unrecognized
58// languages.
59//
60
61namespace {
62 struct SLU : public SourceLanguage {
63 //===------------------------------------------------------------------===//
64 // Implement the miscellaneous methods...
65 //
66 virtual const char *getSourceLanguageName() const {
67 return "unknown";
68 }
69
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;
79
80 //===------------------------------------------------------------------===//
81 // We do use a cache for information...
82 //
83 typedef SLUCache CacheType;
84 SLUCache *createSourceLanguageCache(ProgramInfo &PI) const {
85 return new SLUCache(PI);
86 }
87
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;
92
93 } TheUnknownSourceLanguageInstance;
94}
95
96const SourceLanguage &SourceLanguage::getUnknownLanguageInstance() {
97 return TheUnknownSourceLanguageInstance;
98}
99
100
101SourceFunctionInfo *
102SLU::createSourceFunctionInfo(const GlobalVariable *Desc,
103 ProgramInfo &PI) const {
104 SourceFunctionInfo *Result = new SourceFunctionInfo(PI, Desc);
105 return PI.getLanguageCache(this).addSourceFunction(Result);
106}
107
108
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.
114///
115SourceFunctionInfo *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);
120
121 if (IP.first == IP.second) {
122 if (PI.allSourceFunctionsRead())
123 return 0; // Nothing found
124
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);
130 }
131
132 SourceFunctionInfo *Found = IP.first->second;
133 ++IP.first;
134 if (IP.first != IP.second)
Bill Wendlingbcd24982006-12-07 20:28:15 +0000135 cout << "Whoa, found multiple functions with the same name. I should"
136 << " ask the user which one to use: FIXME!\n";
Chris Lattner2eacf262004-01-05 05:25:10 +0000137 return Found;
138}