Ghidra Decompiler Analysis Engine
sleighbase.hh
Go to the documentation of this file.
1 /* ###
2  * IP: GHIDRA
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
18 #ifndef __SLEIGHBASE__
19 #define __SLEIGHBASE__
20 
21 #include "translate.hh"
22 #include "slghsymbol.hh"
23 
25 
35 public:
36  SourceFileIndexer() {leastUnusedIndex = 0;}
37  ~SourceFileIndexer(void) { }
39  int4 index(const string filename);
40  int4 getIndex(const string);
41  string getFilename(int4);
42  void restoreXml(const Element *el);
43  void saveXml(ostream&) const;
44 
45 private:
46  int4 leastUnusedIndex;
47  map<int4, string> indexToFile;
48  map<string, int4> fileToIndex;
49 };
50 
52 
57 class SleighBase : public Translate {
58  static const int4 SLA_FORMAT_VERSION;
59  vector<string> userop;
60  map<VarnodeData,string> varnode_xref;
61 protected:
66  uint4 numSections;
68  void buildXrefs(vector<string> &errorPairs);
69  void reregisterContext(void);
70  void restoreXml(const Element *el);
71 public:
72  static const uintb MAX_UNIQUE_SIZE;
73  SleighBase(void);
74  bool isInitialized(void) const { return (root != (SubtableSymbol *)0); }
75  virtual ~SleighBase(void) {}
76  virtual void addRegister(const string &nm,AddrSpace *base,uintb offset,int4 size);
77  virtual const VarnodeData &getRegister(const string &nm) const;
78  virtual string getRegisterName(AddrSpace *base,uintb off,int4 size) const;
79  virtual void getAllRegisters(map<VarnodeData,string> &reglist) const;
80  virtual void getUserOpNames(vector<string> &res) const;
81 
82  SleighSymbol *findSymbol(const string &nm) const { return symtab.findSymbol(nm); }
83  SleighSymbol *findSymbol(uintm id) const { return symtab.findSymbol(id); }
84  SleighSymbol *findGlobalSymbol(const string &nm) const { return symtab.findGlobalSymbol(nm); }
85  void saveXml(ostream &s) const;
86 };
87 
88 #endif
SleighBase::indexer
SourceFileIndexer indexer
source file index used when generating SLEIGH constructor debug info
Definition: sleighbase.hh:67
SleighBase::reregisterContext
void reregisterContext(void)
Reregister context fields for a new executable.
Definition: sleighbase.cc:109
SourceFileIndexer::index
int4 index(const string filename)
Returns the index of the file. If the file is not in the index it is added.
Definition: sleighbase.cc:22
AddrSpace
A region where processor data is stored.
Definition: space.hh:73
translate.hh
Classes for disassembly and pcode generation.
SleighBase::getAllRegisters
virtual void getAllRegisters(map< VarnodeData, string > &reglist) const
Get a list of all register names and the corresponding location.
Definition: sleighbase.cc:171
SleighBase::SleighBase
SleighBase(void)
Construct an uninitialized translator.
Definition: sleighbase.cc:62
SourceFileIndexer
class for recording source file information for SLEIGH constructors.
Definition: sleighbase.hh:34
SleighBase::getRegisterName
virtual string getRegisterName(AddrSpace *base, uintb off, int4 size) const
Get the name of a register given its location.
Definition: sleighbase.cc:145
Element
An XML element. A node in the DOM tree.
Definition: xml.hh:150
SourceFileIndexer::saveXml
void saveXml(ostream &) const
save the index mapping to an XML file
Definition: sleighbase.cc:51
SleighBase::getRegister
virtual const VarnodeData & getRegister(const string &nm) const
Get a register as VarnodeData given its name.
Definition: sleighbase.cc:134
SubtableSymbol
Definition: slghsymbol.hh:564
SleighBase::buildXrefs
void buildXrefs(vector< string > &errorPairs)
Build register map. Collect user-ops and context-fields.
Definition: sleighbase.cc:73
SourceFileIndexer::getFilename
string getFilename(int4)
get the filename corresponding to an index
Definition: sleighbase.cc:36
SourceFileIndexer::restoreXml
void restoreXml(const Element *el)
read a stored index mapping from an XML file
Definition: sleighbase.cc:40
SleighBase::getUserOpNames
virtual void getUserOpNames(vector< string > &res) const
Get a list of all user-defined pcode ops.
Definition: sleighbase.cc:177
SleighBase::MAX_UNIQUE_SIZE
static const uintb MAX_UNIQUE_SIZE
Maximum size of a varnode in the unique space (should match value in SleighBase.java)
Definition: sleighbase.hh:72
SleighBase::maxdelayslotbytes
uint4 maxdelayslotbytes
Maximum number of bytes in a delay-slot directive.
Definition: sleighbase.hh:64
SleighBase::root
SubtableSymbol * root
The root SLEIGH decoding symbol.
Definition: sleighbase.hh:62
Translate
The interface to a translation engine for a processor.
Definition: translate.hh:294
SymbolTable
Definition: slghsymbol.hh:70
SleighBase
Common core of classes that read or write SLEIGH specification files natively.
Definition: sleighbase.hh:57
VarnodeData
Data defining a specific memory location.
Definition: pcoderaw.hh:33
SleighBase::unique_allocatemask
uint4 unique_allocatemask
Bits that are guaranteed to be zero in the unique allocation scheme.
Definition: sleighbase.hh:65
SleighBase::saveXml
void saveXml(ostream &s) const
Write out the SLEIGH specification as an XML <sleigh> tag.
Definition: sleighbase.cc:185
SleighBase::addRegister
virtual void addRegister(const string &nm, AddrSpace *base, uintb offset, int4 size)
Add a named register to the model for this processor.
Definition: sleighbase.cc:127
SleighSymbol
Definition: slghsymbol.hh:23
SleighBase::restoreXml
void restoreXml(const Element *el)
Read a SLEIGH specification from XML.
Definition: sleighbase.cc:222
SourceFileIndexer::getIndex
int4 getIndex(const string)
get the index of a file. Error if the file is not in the index.
Definition: sleighbase.cc:32
SleighBase::symtab
SymbolTable symtab
The SLEIGH symbol table.
Definition: sleighbase.hh:63
SleighBase::numSections
uint4 numSections
Number of named sections.
Definition: sleighbase.hh:66