1 //===-- SourceLanguage-Unknown.cpp - Implement itf for unknown languages --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
23 //===----------------------------------------------------------------------===//
24 // Implement the SourceLanguage cache for the Unknown language.
28 /// SLUCache - This cache allows for efficient lookup of source functions by
31 struct SLUCache
: public SourceLanguageCache
{
33 std::multimap
<std::string
, SourceFunctionInfo
*> FunctionMap
;
35 SLUCache(ProgramInfo
&pi
);
37 typedef std::multimap
<std::string
, SourceFunctionInfo
*>::const_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
));
52 SLUCache::SLUCache(ProgramInfo
&pi
) : PI(pi
) {
56 //===----------------------------------------------------------------------===//
57 // Implement SourceLanguageUnknown class, which is used to handle unrecognized
62 static struct SLU
: public SourceLanguage
{
63 //===------------------------------------------------------------------===//
64 // Implement the miscellaneous methods...
66 virtual const char *getSourceLanguageName() const {
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
76 virtual SourceFunctionInfo
*lookupFunction(const std::string
&FunctionName
,
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
90 virtual SourceFunctionInfo
*
91 createSourceFunctionInfo(const GlobalVariable
*Desc
, ProgramInfo
&PI
) const;
93 } TheUnknownSourceLanguageInstance
;
96 const SourceLanguage
&SourceLanguage::getUnknownLanguageInstance() {
97 return TheUnknownSourceLanguageInstance
;
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
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
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
;
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";