My Project
sleigh_arch.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 
19 #ifndef __SLEIGH_ARCH__
20 #define __SLEIGH_ARCH__
21 
22 #include "filemanage.hh"
23 #include "architecture.hh"
24 #include "sleigh.hh"
25 
29 class CompilerTag {
30  string name;
31  string spec;
32  string id;
33 public:
34  CompilerTag(void) {}
35  void restoreXml(const Element *el);
36  const string &getName(void) const { return name; }
37  const string &getSpec(void) const { return spec; }
38  const string &getId(void) const { return id; }
39 };
40 
50  string processor;
51  bool isbigendian;
52  int4 size;
53  string variant;
54  string version;
55  string slafile;
56  string processorspec;
57  string id;
58  string description;
59  bool deprecated;
60  vector<CompilerTag> compilers;
61  vector<TruncationTag> truncations;
62 public:
64  void restoreXml(const Element *el);
65  const string &getProcessor(void) const { return processor; }
66  bool isBigEndian(void) const { return isbigendian; }
67  int4 getSize(void) const { return size; }
68  const string &getVariant(void) const { return variant; }
69  const string &getVersion(void) const { return version; }
70  const string &getSlaFile(void) const { return slafile; }
71  const string &getProcessorSpec(void) const { return processorspec; }
72  const string &getId(void) const { return id; }
73  const string &getDescription(void) const { return description; }
74  bool isDeprecated(void) const { return deprecated; }
75  const CompilerTag &getCompiler(const string &nm) const;
76  int4 numTruncations(void) const { return truncations.size(); }
77  const TruncationTag &getTruncation(int4 i) const { return truncations[i]; }
78 };
79 
90  static Sleigh *last_sleigh;
91  static int4 last_languageindex;
92  static vector<LanguageDescription> description;
93  int4 languageindex;
94  string filename;
95  string target;
96  static void loadLanguageDescription(const string &specfile,ostream &errs);
97  bool isTranslateReused(void);
98 protected:
99  ostream *errorstream;
100  // buildLoader must be filled in by derived class
101  static void collectSpecFiles(ostream &errs);
102  virtual Translate *buildTranslator(DocumentStorage &store);
103  virtual PcodeInjectLibrary *buildPcodeInjectLibrary(void);
104  virtual void buildSpecFile(DocumentStorage &store);
105  virtual void modifySpaces(Translate *trans);
106  virtual void resolveArchitecture(void);
107 public:
108  SleighArchitecture(const string &fname,const string &targ,ostream *estream);
109  const string &getFilename(void) const { return filename; }
110  const string &getTarget(void) const { return target; }
111  void saveXmlHeader(ostream &s) const;
112  void restoreXmlHeader(const Element *el);
113  virtual void printMessage(const string &message) const { *errorstream << message << endl; }
114  virtual ~SleighArchitecture(void);
115  virtual string getDescription(void) const;
116 
117  static string normalizeProcessor(const string &nm);
118  static string normalizeEndian(const string &nm);
119  static string normalizeSize(const string &nm);
120  static string normalizeArchitecture(const string &nm);
121  static void scanForSleighDirectories(const string &rootpath);
122  static void shutdown(void);
124 };
125 
126 #endif
A container for parsed XML documents.
Definition: xml.hh:249
ostream * errorstream
Error stream associated with this SleighArchitecture.
Definition: sleigh_arch.hh:99
Architecture and associated classes that help manage a single processor architecture and load image...
A collection of p-code injection payloads.
Definition: pcodeinject.hh:162
static FileManage specpaths
Known directories that contain .ldefs files.
Definition: sleigh_arch.hh:123
const string & getId(void) const
Get the string used as part of language id.
Definition: sleigh_arch.hh:38
Contents of the <language> tag in a .ldefs file.
Definition: sleigh_arch.hh:49
bool isDeprecated(void) const
Return true if this specification is deprecated.
Definition: sleigh_arch.hh:74
void restoreXml(const Element *el)
Restore the record from an XML stream.
Definition: sleigh_arch.cc:27
const string & getSlaFile(void) const
Get filename of the SLEIGH specification.
Definition: sleigh_arch.hh:70
An Architecture that uses the decompiler&#39;s native SLEIGH translation engine.
Definition: sleigh_arch.hh:89
const string & getVersion(void) const
Get the processor version.
Definition: sleigh_arch.hh:69
bool isBigEndian(void) const
Return true if the processor is big-endian.
Definition: sleigh_arch.hh:66
const string & getName(void) const
Get the human readable name of the spec.
Definition: sleigh_arch.hh:36
Definition: sleigh.hh:105
const string & getProcessorSpec(void) const
Get the filename of the processor specification.
Definition: sleigh_arch.hh:71
CompilerTag(void)
Constructor.
Definition: sleigh_arch.hh:34
The interface to a translation engine for a processor.
Definition: translate.hh:293
Manager for all the major decompiler subsystems.
Definition: architecture.hh:117
LanguageDescription(void)
Constructor.
Definition: sleigh_arch.hh:63
Object for describing how a space should be truncated.
Definition: translate.hh:63
An XML element. A node in the DOM tree.
Definition: xml.hh:150
Definition: filemanage.hh:29
const string & getDescription(void) const
Get a description of the processor.
Definition: sleigh_arch.hh:73
const string & getFilename(void) const
Get the executable filename.
Definition: sleigh_arch.hh:109
const TruncationTag & getTruncation(int4 i) const
Get the i-th truncation record.
Definition: sleigh_arch.hh:77
int4 getSize(void) const
Get the size of the address bus.
Definition: sleigh_arch.hh:67
virtual void printMessage(const string &message) const
Print an error message to console.
Definition: sleigh_arch.hh:113
const string & getSpec(void) const
Get the file-name.
Definition: sleigh_arch.hh:37
const string & getProcessor(void) const
Get the name of the processor.
Definition: sleigh_arch.hh:65
const string & getTarget(void) const
Get the language id of the active processor.
Definition: sleigh_arch.hh:110
const string & getId(void) const
Get the language id string associated with this processor.
Definition: sleigh_arch.hh:72
const string & getVariant(void) const
Get the processor variant.
Definition: sleigh_arch.hh:68
int4 numTruncations(void) const
Get the number of truncation records.
Definition: sleigh_arch.hh:76
Contents of a <compiler> tag in a .ldefs file.
Definition: sleigh_arch.hh:29