1 //===-- SourceLanguage-Unknown.cpp - Implement itf for unknown languages --===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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"
21 //===----------------------------------------------------------------------===//
22 // Implement the SourceLanguage cache for the Unknown language.
26 /// SLUCache - This cache allows for efficient lookup of source functions by
29 struct SLUCache : public SourceLanguageCache {
31 std::multimap<std::string, SourceFunctionInfo*> FunctionMap;
33 SLUCache(ProgramInfo &pi);
35 typedef std::multimap<std::string, SourceFunctionInfo*>::const_iterator
38 std::pair<fm_iterator, fm_iterator>
39 getFunction(const std::string &Name) const {
40 return FunctionMap.equal_range(Name);
43 SourceFunctionInfo *addSourceFunction(SourceFunctionInfo *SF) {
44 FunctionMap.insert(std::make_pair(SF->getSymbolicName(), SF));
50 SLUCache::SLUCache(ProgramInfo &pi) : PI(pi) {
54 //===----------------------------------------------------------------------===//
55 // Implement SourceLanguageUnknown class, which is used to handle unrecognized
60 struct SLU : public SourceLanguage {
61 //===------------------------------------------------------------------===//
62 // Implement the miscellaneous methods...
64 virtual const char *getSourceLanguageName() const {
68 /// lookupFunction - Given a textual function name, return the
69 /// SourceFunctionInfo descriptor for that function, or null if it cannot be
70 /// found. If the program is currently running, the RuntimeInfo object
71 /// provides information about the current evaluation context, otherwise it
74 virtual SourceFunctionInfo *lookupFunction(const std::string &FunctionName,
76 RuntimeInfo *RI = 0) const;
78 //===------------------------------------------------------------------===//
79 // We do use a cache for information...
81 typedef SLUCache CacheType;
82 SLUCache *createSourceLanguageCache(ProgramInfo &PI) const {
83 return new SLUCache(PI);
86 /// createSourceFunctionInfo - Create the new object and inform the cache of
88 virtual SourceFunctionInfo *
89 createSourceFunctionInfo(const GlobalVariable *Desc, ProgramInfo &PI) const;
91 } TheUnknownSourceLanguageInstance;
94 const SourceLanguage &SourceLanguage::getUnknownLanguageInstance() {
95 return TheUnknownSourceLanguageInstance;
100 SLU::createSourceFunctionInfo(const GlobalVariable *Desc,
101 ProgramInfo &PI) const {
102 SourceFunctionInfo *Result = new SourceFunctionInfo(PI, Desc);
103 return PI.getLanguageCache(this).addSourceFunction(Result);
107 /// lookupFunction - Given a textual function name, return the
108 /// SourceFunctionInfo descriptor for that function, or null if it cannot be
109 /// found. If the program is currently running, the RuntimeInfo object
110 /// provides information about the current evaluation context, otherwise it will
113 SourceFunctionInfo *SLU::lookupFunction(const std::string &FunctionName,
114 ProgramInfo &PI, RuntimeInfo *RI) const{
115 SLUCache &Cache = PI.getLanguageCache(this);
116 std::pair<SLUCache::fm_iterator, SLUCache::fm_iterator> IP
117 = Cache.getFunction(FunctionName);
119 if (IP.first == IP.second) {
120 if (PI.allSourceFunctionsRead())
121 return 0; // Nothing found
123 // Otherwise, we might be able to find the function if we read all of them
125 PI.getSourceFunctions();
126 assert(PI.allSourceFunctionsRead() && "Didn't read in all functions?");
127 return lookupFunction(FunctionName, PI, RI);
130 SourceFunctionInfo *Found = IP.first->second;
132 if (IP.first != IP.second)
133 std::cout << "Whoa, found multiple functions with the same name. I should"
134 << " ask the user which one to use: FIXME!\n";