Ghidra Decompiler Analysis Engine
printlanguage.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 __PRINT_LANGUAGE__
20 #define __PRINT_LANGUAGE__
21 
22 #include "capability.hh"
23 #include "cast.hh"
24 #include "prettyprint.hh"
25 
26 class PrintLanguage;
27 
40  static vector<PrintLanguageCapability *> thelist;
41 protected:
42  string name;
43  bool isdefault;
44 public:
45  const string &getName(void) const { return name; }
46  virtual void initialize(void);
47 
53  virtual PrintLanguage *buildLanguage(Architecture *glb)=0;
54 
55  static PrintLanguageCapability *getDefault(void);
56  static PrintLanguageCapability *findCapability(const string &name);
57 };
58 
59 class BlockGraph;
60 class BlockBasic;
61 class BlockList;
62 class BlockCopy;
63 class BlockGoto;
64 class BlockIf;
65 class BlockCondition;
66 class BlockWhileDo;
67 class BlockDoWhile;
68 class BlockInfLoop;
69 class BlockSwitch;
70 class Scope;
71 class Symbol;
72 class EquateSymbol;
73 class Comment;
74 
81 class OpToken {
82 public:
84  enum tokentype {
91  };
92  const char *print;
93  int4 stage;
94  int4 precedence;
95  bool associative;
97  int4 spacing;
98  int4 bump;
100 };
101 
135 public:
137  enum modifiers {
138  force_hex = 1,
139  force_dec = 2,
140  bestfit = 4,
142  force_pointer = 0x10,
145  no_branch = 0x80,
146  only_branch = 0x100,
147  comma_separate = 0x200,
148  flat = 0x400,
149  falsebranch = 0x800,
150  nofallthru = 0x1000,
151  negatetoken = 0x2000,
152  hide_thisparam = 0x4000
153  };
155  enum tagtype {
163  };
164 
170  };
171 
173  struct ReversePolish {
174  const OpToken *tok;
175  int4 visited;
176  bool paren;
177  const PcodeOp *op;
178  int4 id;
179  mutable int4 id2;
180  };
181 
186  struct NodePending {
187  const Varnode *vn;
188  const PcodeOp *op;
189  uint4 vnmod;
190 
192  NodePending(const Varnode *v,const PcodeOp *o,uint4 m) {
193  vn = v; op = o; vnmod = m; }
194  };
195 
201  struct Atom {
202  const string &name;
205  const PcodeOp *op;
206  union {
207  const Varnode *vn;
208  const Funcdata *fd;
209  const Datatype *ct;
210  } ptr_second;
211  int4 offset;
212 
214  Atom(const string &nm,tagtype t,EmitXml::syntax_highlight hl)
215  : name(nm) { type = t; highlight = hl; }
216 
218  Atom(const string &nm,tagtype t,EmitXml::syntax_highlight hl,const Datatype *c)
219  : name(nm) { type = t; highlight = hl; ptr_second.ct = c; }
220 
222  Atom(const string &nm,tagtype t,EmitXml::syntax_highlight hl,const Datatype *c,int4 off)
223  : name(nm) { type = t; highlight = hl; ptr_second.ct = c; offset = off; }
224 
226  Atom(const string &nm,tagtype t,EmitXml::syntax_highlight hl,const PcodeOp *o)
227  : name(nm) { type = t; highlight = hl; op = o; }
228 
230  Atom(const string &nm,tagtype t,EmitXml::syntax_highlight hl,const PcodeOp *o,const Varnode *v)
231  : name(nm) { type=t; highlight = hl; ptr_second.vn = v; op = o; }
232 
234  Atom(const string &nm,tagtype t,EmitXml::syntax_highlight hl,const PcodeOp *o,const Funcdata *f)
235  : name(nm) { type=t; highlight = hl; op = o; ptr_second.fd = f; }
236  };
237 private:
238  string name;
239  vector<uint4> modstack;
240  vector<const Scope *> scopestack;
241  vector<ReversePolish> revpol;
242  vector<NodePending> nodepend;
243  int4 pending;
244  int4 line_commentindent;
245  string commentstart;
246  string commentend;
247 protected:
249  const Scope *curscope;
252  uint4 mods;
256 #ifdef CPUI_DEBUG
257  bool isStackEmpty(void) const { return (nodepend.empty()&&revpol.empty()); }
258  bool isModStackEmpty(void) const { return modstack.empty(); }
259 #endif
260  // Routines that are probably consistent across languages
261  bool isSet(uint4 m) const { return ((mods & m)!=0); }
262  void pushScope(const Scope *sc) { scopestack.push_back(sc); curscope = sc; }
263  void popScope(void);
264  void pushMod(void) { modstack.push_back(mods); }
265  void popMod(void) { mods = modstack.back(); modstack.pop_back(); }
266  void setMod(uint4 m) { mods |= m; }
267  void unsetMod(uint4 m) { mods &= ~m; }
268  void pushOp(const OpToken *tok,const PcodeOp *op);
269  void pushAtom(const Atom &atom);
270  void pushVnImplied(const Varnode *vn,const PcodeOp *op,uint4 m);
271  void pushVnExplicit(const Varnode *vn,const PcodeOp *op);
272  void pushVnLHS(const Varnode *vn,const PcodeOp *op);
273 
274  bool parentheses(const OpToken *op2);
275  void emitOp(const ReversePolish &entry);
276  void emitAtom(const Atom &atom);
277  static bool unicodeNeedsEscape(int4 codepoint);
278  bool escapeCharacterData(ostream &s,const uint1 *buf,int4 count,int4 charsize,bool bigend) const;
279  void recurse(void);
280  void opBinary(const OpToken *tok,const PcodeOp *op);
281  void opUnary(const OpToken *tok,const PcodeOp *op);
282  int4 getPending(void) const { return pending; }
283  void resetDefaultsInternal(void);
284 
285 
291  virtual void printUnicode(ostream &s,int4 onechar) const=0;
292 
297  virtual void pushType(const Datatype *ct)=0;
298 
306  virtual void pushConstant(uintb val,const Datatype *ct,
307  const Varnode *vn,const PcodeOp *op)=0;
308 
317  virtual bool pushEquate(uintb val,int4 sz,const EquateSymbol *sym,const Varnode *vn,const PcodeOp *op)=0;
318 
324  virtual void pushAnnotation(const Varnode *vn,const PcodeOp *op)=0;
325 
331  virtual void pushSymbol(const Symbol *sym,const Varnode *vn,
332  const PcodeOp *op)=0;
333 
341  virtual void pushUnnamedLocation(const Address &addr,
342  const Varnode *vn,const PcodeOp *op)=0;
343 
353  virtual void pushPartialSymbol(const Symbol *sym,int4 off,int4 sz,
354  const Varnode *vn,const PcodeOp *op,Datatype *outtype)=0;
355 
365  virtual void pushMismatchSymbol(const Symbol *sym,int4 off,int4 sz,
366  const Varnode *vn,const PcodeOp *op)=0;
367 
368  virtual void emitLineComment(int4 indent,const Comment *comm);
369 
374  virtual void emitVarDecl(const Symbol *sym)=0;
375 
379  virtual void emitVarDeclStatement(const Symbol *sym)=0;
380 
387  virtual bool emitScopeVarDecls(const Scope *scope,int4 cat)=0;
388 
394  virtual void emitExpression(const PcodeOp *op)=0;
395 
400  virtual void emitFunctionDeclaration(const Funcdata *fd)=0;
401 
408  virtual bool checkPrintNegation(const Varnode *vn)=0;
409 public:
410  PrintLanguage(Architecture *g,const string &nm);
411  virtual ~PrintLanguage(void);
412  const string &getName(void) const { return name; }
413  CastStrategy *getCastStrategy(void) const { return castStrategy; }
414  ostream *getOutputStream(void) const { return emit->getOutputStream(); }
415  void setOutputStream(ostream *t) { emit->setOutputStream(t); }
416  void setMaxLineSize(int4 mls) { emit->setMaxLineSize(mls); }
417  void setIndentIncrement(int4 inc) { emit->setIndentIncrement(inc); }
418  void setLineCommentIndent(int4 val);
419  void setCommentDelimeter(const string &start,const string &stop,
420  bool usecommentfill);
421  uint4 getInstructionComment(void) const { return instr_comment_type; }
422  void setInstructionComment(uint4 val) { instr_comment_type = val; }
423  void setNamespaceStrategy(namespace_strategy strat) { namespc_strategy = strat; }
424  uint4 getHeaderComment(void) const { return head_comment_type; }
425  void setHeaderComment(uint4 val) { head_comment_type = val; }
426  bool emitsXml(void) const { return emit->emitsXml(); }
427  void setXML(bool val);
428  void setFlat(bool val);
429 
430  virtual void adjustTypeOperators(void)=0;
431  virtual void resetDefaults(void);
432  virtual void clear(void);
433  virtual void setIntegerFormat(const string &nm);
434 
440  virtual void setCommentStyle(const string &nm)=0;
441 
445  virtual void docTypeDefinitions(const TypeFactory *typegrp)=0;
446 
448  virtual void docAllGlobals(void)=0;
449 
453  virtual void docSingleGlobal(const Symbol *sym)=0;
454 
458  virtual void docFunction(const Funcdata *fd)=0;
459 
460  virtual void emitBlockBasic(const BlockBasic *bb)=0;
461  virtual void emitBlockGraph(const BlockGraph *bl)=0;
462  virtual void emitBlockCopy(const BlockCopy *bl)=0;
463  virtual void emitBlockGoto(const BlockGoto *bl)=0;
464  virtual void emitBlockLs(const BlockList *bl)=0;
465  virtual void emitBlockCondition(const BlockCondition *bl)=0;
466  virtual void emitBlockIf(const BlockIf *bl)=0;
467  virtual void emitBlockWhileDo(const BlockWhileDo *bl)=0;
468  virtual void emitBlockDoWhile(const BlockDoWhile *bl)=0;
469  virtual void emitBlockInfLoop(const BlockInfLoop *bl)=0;
470  virtual void emitBlockSwitch(const BlockSwitch *bl)=0;
471 
472  virtual void opCopy(const PcodeOp *op)=0;
473  virtual void opLoad(const PcodeOp *op)=0;
474  virtual void opStore(const PcodeOp *op)=0;
475  virtual void opBranch(const PcodeOp *op)=0;
476  virtual void opCbranch(const PcodeOp *op)=0;
477  virtual void opBranchind(const PcodeOp *op)=0;
478  virtual void opCall(const PcodeOp *op)=0;
479  virtual void opCallind(const PcodeOp *op)=0;
480  virtual void opCallother(const PcodeOp *op)=0;
481  virtual void opConstructor(const PcodeOp *op,bool withNew)=0;
482  virtual void opReturn(const PcodeOp *op)=0;
483  virtual void opIntEqual(const PcodeOp *op)=0;
484  virtual void opIntNotEqual(const PcodeOp *op)=0;
485  virtual void opIntSless(const PcodeOp *op)=0;
486  virtual void opIntSlessEqual(const PcodeOp *op)=0;
487  virtual void opIntLess(const PcodeOp *op)=0;
488  virtual void opIntLessEqual(const PcodeOp *op)=0;
489  virtual void opIntZext(const PcodeOp *op,const PcodeOp *readOp)=0;
490  virtual void opIntSext(const PcodeOp *op,const PcodeOp *readOp)=0;
491  virtual void opIntAdd(const PcodeOp *op)=0;
492  virtual void opIntSub(const PcodeOp *op)=0;
493  virtual void opIntCarry(const PcodeOp *op)=0;
494  virtual void opIntScarry(const PcodeOp *op)=0;
495  virtual void opIntSborrow(const PcodeOp *op)=0;
496  virtual void opInt2Comp(const PcodeOp *op)=0;
497  virtual void opIntNegate(const PcodeOp *op)=0;
498  virtual void opIntXor(const PcodeOp *op)=0;
499  virtual void opIntAnd(const PcodeOp *op)=0;
500  virtual void opIntOr(const PcodeOp *op)=0;
501  virtual void opIntLeft(const PcodeOp *op)=0;
502  virtual void opIntRight(const PcodeOp *op)=0;
503  virtual void opIntSright(const PcodeOp *op)=0;
504  virtual void opIntMult(const PcodeOp *op)=0;
505  virtual void opIntDiv(const PcodeOp *op)=0;
506  virtual void opIntSdiv(const PcodeOp *op)=0;
507  virtual void opIntRem(const PcodeOp *op)=0;
508  virtual void opIntSrem(const PcodeOp *op)=0;
509  virtual void opBoolNegate(const PcodeOp *op)=0;
510  virtual void opBoolXor(const PcodeOp *op)=0;
511  virtual void opBoolAnd(const PcodeOp *op)=0;
512  virtual void opBoolOr(const PcodeOp *op)=0;
513  virtual void opFloatEqual(const PcodeOp *op)=0;
514  virtual void opFloatNotEqual(const PcodeOp *op)=0;
515  virtual void opFloatLess(const PcodeOp *op)=0;
516  virtual void opFloatLessEqual(const PcodeOp *op)=0;
517  virtual void opFloatNan(const PcodeOp *op)=0;
518  virtual void opFloatAdd(const PcodeOp *op)=0;
519  virtual void opFloatDiv(const PcodeOp *op)=0;
520  virtual void opFloatMult(const PcodeOp *op)=0;
521  virtual void opFloatSub(const PcodeOp *op)=0;
522  virtual void opFloatNeg(const PcodeOp *op)=0;
523  virtual void opFloatAbs(const PcodeOp *op)=0;
524  virtual void opFloatSqrt(const PcodeOp *op)=0;
525  virtual void opFloatInt2Float(const PcodeOp *op)=0;
526  virtual void opFloatFloat2Float(const PcodeOp *op)=0;
527  virtual void opFloatTrunc(const PcodeOp *op)=0;
528  virtual void opFloatCeil(const PcodeOp *op)=0;
529  virtual void opFloatFloor(const PcodeOp *op)=0;
530  virtual void opFloatRound(const PcodeOp *op)=0;
531  virtual void opMultiequal(const PcodeOp *op)=0;
532  virtual void opIndirect(const PcodeOp *op)=0;
533  virtual void opPiece(const PcodeOp *op)=0;
534  virtual void opSubpiece(const PcodeOp *op)=0;
535  virtual void opCast(const PcodeOp *op)=0;
536  virtual void opPtradd(const PcodeOp *op)=0;
537  virtual void opPtrsub(const PcodeOp *op)=0;
538  virtual void opSegmentOp(const PcodeOp *op)=0;
539  virtual void opCpoolRefOp(const PcodeOp *op)=0;
540  virtual void opNewOp(const PcodeOp *op)=0;
541  virtual void opInsertOp(const PcodeOp *op)=0;
542  virtual void opExtractOp(const PcodeOp *op)=0;
543  virtual void opPopcountOp(const PcodeOp *op)=0;
544 
545  static int4 mostNaturalBase(uintb val);
546  static void formatBinary(ostream &s,uintb val);
547 };
548 
549 #endif
PrintLanguage::NodePending::vn
const Varnode * vn
The implied Varnode.
Definition: printlanguage.hh:187
PrintLanguage::opFloatMult
virtual void opFloatMult(const PcodeOp *op)=0
Emit a FLOAT_MULT operator.
PrintLanguage::Atom::ct
const Datatype * ct
A type associated with the token.
Definition: printlanguage.hh:209
PrintLanguage::only_branch
@ only_branch
Print only the branch instruction.
Definition: printlanguage.hh:146
PrintLanguage
The base class API for emitting a high-level language.
Definition: printlanguage.hh:134
PrintLanguage::namespc_strategy
namespace_strategy namespc_strategy
How should namespace tokens be displayed.
Definition: printlanguage.hh:255
PrintLanguage::~PrintLanguage
virtual ~PrintLanguage(void)
Destructor.
Definition: printlanguage.cc:70
PrintLanguage::opIntSrem
virtual void opIntSrem(const PcodeOp *op)=0
Emit a INT_SREM operator.
PrintLanguage::opIntAnd
virtual void opIntAnd(const PcodeOp *op)=0
Emit a INT_AND operator.
PrintLanguage::opIntScarry
virtual void opIntScarry(const PcodeOp *op)=0
Emit a INT_SCARRY operator.
BlockGraph
A control-flow block built out of sub-components.
Definition: block.hh:271
PrintLanguageCapability::name
string name
Unique identifier for language capability.
Definition: printlanguage.hh:42
PrintLanguage::opFloatAbs
virtual void opFloatAbs(const PcodeOp *op)=0
Emit a FLOAT_ABS operator.
PrintLanguage::typetoken
@ typetoken
Emit atom as operator.
Definition: printlanguage.hh:160
OpToken::negate
OpToken * negate
The token representing the negation of this token.
Definition: printlanguage.hh:99
OpToken::space
@ space
No explicitly printed token.
Definition: printlanguage.hh:89
PrintLanguageCapability::getDefault
static PrintLanguageCapability * getDefault(void)
Retrieve the default language capability.
Definition: printlanguage.cc:25
PrintLanguage::emitBlockCopy
virtual void emitBlockCopy(const BlockCopy *bl)=0
Emit a basic block (with any labels)
PrintLanguage::opFloatEqual
virtual void opFloatEqual(const PcodeOp *op)=0
Emit a FLOAT_EQUAL operator.
PrintLanguage::no_branch
@ no_branch
Do not print branch instruction.
Definition: printlanguage.hh:145
PrintLanguage::emitScopeVarDecls
virtual bool emitScopeVarDecls(const Scope *scope, int4 cat)=0
Emit all the variable declarations for a given scope.
PrintLanguage::opIntRight
virtual void opIntRight(const PcodeOp *op)=0
Emit a INT_RIGHT operator.
PrintLanguage::opInt2Comp
virtual void opInt2Comp(const PcodeOp *op)=0
Emit a INT_2COMP operator.
PrintLanguage::opIntSub
virtual void opIntSub(const PcodeOp *op)=0
Emit a INT_SUB operator.
PrintLanguage::emitBlockLs
virtual void emitBlockLs(const BlockList *bl)=0
Emit a sequence of blocks.
PrintLanguage::hide_thisparam
@ hide_thisparam
Do not print the 'this' parameter in argument lists.
Definition: printlanguage.hh:152
PrintLanguage::Atom::Atom
Atom(const string &nm, tagtype t, EmitXml::syntax_highlight hl)
Construct a token with no associated data-flow annotations.
Definition: printlanguage.hh:214
PrintLanguage::emitLineComment
virtual void emitLineComment(int4 indent, const Comment *comm)
Emit a comment line.
Definition: printlanguage.cc:586
PrintLanguage::opBoolXor
virtual void opBoolXor(const PcodeOp *op)=0
Emit a BOOL_XOR operator.
PrintLanguage::pushSymbol
virtual void pushSymbol(const Symbol *sym, const Varnode *vn, const PcodeOp *op)=0
Push a specific Symbol onto the RPN stack.
BlockDoWhile
A loop structure where the condition is checked at the bottom.
Definition: block.hh:618
PrintLanguage::checkPrintNegation
virtual bool checkPrintNegation(const Varnode *vn)=0
Check whether a given boolean Varnode can be printed in negated form.
OpToken::unary_prefix
@ unary_prefix
Unary operator form (printed before its input)
Definition: printlanguage.hh:86
PrintLanguage::emitBlockGoto
virtual void emitBlockGoto(const BlockGoto *bl)=0
Emit a block ending with a goto statement.
PrintLanguage::opCpoolRefOp
virtual void opCpoolRefOp(const PcodeOp *op)=0
Emit a CPOOLREF operator.
PrintLanguage::formatBinary
static void formatBinary(ostream &s, uintb val)
Print a number in binary form.
Definition: printlanguage.cc:767
PrintLanguage::emitAtom
void emitAtom(const Atom &atom)
Send an variable token from the RPN to the emitter.
Definition: printlanguage.cc:380
PrintLanguage::setIntegerFormat
virtual void setIntegerFormat(const string &nm)
Set the default integer format.
Definition: printlanguage.cc:685
EmitXml::syntax_highlight
syntax_highlight
Possible types of syntax highlighting.
Definition: prettyprint.hh:88
PrintLanguage::unicodeNeedsEscape
static bool unicodeNeedsEscape(int4 codepoint)
Determine if the given codepoint needs to be escaped.
Definition: printlanguage.cc:415
PrintLanguage::comma_separate
@ comma_separate
Statements within condition.
Definition: printlanguage.hh:147
PrintLanguage::opFloatDiv
virtual void opFloatDiv(const PcodeOp *op)=0
Emit a FLOAT_DIV operator.
PrintLanguage::glb
Architecture * glb
The Architecture owning the language emitter.
Definition: printlanguage.hh:248
PrintLanguage::Atom::Atom
Atom(const string &nm, tagtype t, EmitXml::syntax_highlight hl, const Datatype *c)
Construct a token for a data-type name.
Definition: printlanguage.hh:218
PrintLanguage::opUnary
void opUnary(const OpToken *tok, const PcodeOp *op)
Push a unary operator onto the RPN stack.
Definition: printlanguage.cc:563
PrintLanguage::mostNaturalBase
static int4 mostNaturalBase(uintb val)
Determine the most natural base for an integer.
Definition: printlanguage.cc:705
PrintLanguage::opFloatNan
virtual void opFloatNan(const PcodeOp *op)=0
Emit a FLOAT_NAN operator.
PrintLanguage::recurse
void recurse(void)
Emit from the RPN stack as much as possible.
Definition: printlanguage.cc:516
PrintLanguage::opIntCarry
virtual void opIntCarry(const PcodeOp *op)=0
Emit a INT_CARRY operator.
PrintLanguage::opPiece
virtual void opPiece(const PcodeOp *op)=0
Emit a PIECE operator.
PrintLanguage::opCall
virtual void opCall(const PcodeOp *op)=0
Emit a CALL operator.
PrintLanguage::Atom::fd
const Funcdata * fd
A function associated with the token.
Definition: printlanguage.hh:208
PrintLanguage::opFloatTrunc
virtual void opFloatTrunc(const PcodeOp *op)=0
Emit a FLOAT_TRUNC operator.
cast.hh
API and specific strategies for applying type casts.
OpToken::binary
@ binary
Binary operator form (printed between its inputs)
Definition: printlanguage.hh:85
OpToken::print
const char * print
Printing characters for the token.
Definition: printlanguage.hh:92
PrintLanguage::opIntSright
virtual void opIntSright(const PcodeOp *op)=0
Emit a INT_SRIGHT operator.
OpToken::associative
bool associative
True if the operator is associative.
Definition: printlanguage.hh:95
PrintLanguage::emitBlockIf
virtual void emitBlockIf(const BlockIf *bl)=0
Emit an if/else style construct.
PrintLanguage::emitBlockWhileDo
virtual void emitBlockWhileDo(const BlockWhileDo *bl)=0
Emit a loop structure, check at top.
PrintLanguage::setCommentStyle
virtual void setCommentStyle(const string &nm)=0
Set the way comments are displayed in decompiler output.
PrintLanguage::opInsertOp
virtual void opInsertOp(const PcodeOp *op)=0
Emit an INSERT operator.
PrintLanguage::Atom
A single non-operator token emitted by the decompiler.
Definition: printlanguage.hh:201
PrintLanguage::emitBlockDoWhile
virtual void emitBlockDoWhile(const BlockDoWhile *bl)=0
Emit a loop structure, check at bottom.
PrintLanguage::opBranch
virtual void opBranch(const PcodeOp *op)=0
Emit a BRANCH operator.
PrintLanguage::opFloatSqrt
virtual void opFloatSqrt(const PcodeOp *op)=0
Emit a FLOAT_SQRT operator.
Scope
A collection of Symbol objects within a single (namespace or functional) scope.
Definition: database.hh:402
PrintLanguage::ReversePolish
An entry on the reverse polish notation (RPN) stack.
Definition: printlanguage.hh:173
PrintLanguage::blanktoken
@ blanktoken
For anonymous types.
Definition: printlanguage.hh:162
PrintLanguage::resetDefaultsInternal
void resetDefaultsInternal(void)
Reset options to default for PrintLanguage.
Definition: printlanguage.cc:572
PrintLanguage::parentheses
bool parentheses(const OpToken *op2)
Determine if the given token should be emitted in its own parenthetic expression.
Definition: printlanguage.cc:274
PrintLanguage::opIntRem
virtual void opIntRem(const PcodeOp *op)=0
Emit a INT_REM operator.
OpToken::type
tokentype type
The basic token type.
Definition: printlanguage.hh:96
PrintLanguage::Atom::Atom
Atom(const string &nm, tagtype t, EmitXml::syntax_highlight hl, const Datatype *c, int4 off)
Construct a token for a field name.
Definition: printlanguage.hh:222
PrintLanguage::emitFunctionDeclaration
virtual void emitFunctionDeclaration(const Funcdata *fd)=0
Emit a function declaration.
PrintLanguage::opConstructor
virtual void opConstructor(const PcodeOp *op, bool withNew)=0
Emit an operator constructing an object.
PrintLanguage::adjustTypeOperators
virtual void adjustTypeOperators(void)=0
Set basic data-type information for p-code operators.
PrintLanguage::opFloatLessEqual
virtual void opFloatLessEqual(const PcodeOp *op)=0
Emit a FLOAT_LESSEQUAL operator.
PrintLanguage::opBranchind
virtual void opBranchind(const PcodeOp *op)=0
Emit a BRANCHIND operator.
PrintLanguage::Atom::Atom
Atom(const string &nm, tagtype t, EmitXml::syntax_highlight hl, const PcodeOp *o)
Construct a token with an associated PcodeOp.
Definition: printlanguage.hh:226
PrintLanguage::Atom::Atom
Atom(const string &nm, tagtype t, EmitXml::syntax_highlight hl, const PcodeOp *o, const Funcdata *f)
Construct a token for a function name.
Definition: printlanguage.hh:234
BlockBasic
A basic block for p-code operations.
Definition: block.hh:365
PrintLanguageCapability::isdefault
bool isdefault
Set to true to treat this as the default language.
Definition: printlanguage.hh:43
PrintLanguage::opNewOp
virtual void opNewOp(const PcodeOp *op)=0
Emit a NEW operator.
PrintLanguage::Atom::op
const PcodeOp * op
A p-code operation associated with the token.
Definition: printlanguage.hh:205
PrintLanguage::popScope
void popScope(void)
Pop to the previous symbol scope.
Definition: printlanguage.cc:108
PrintLanguage::opFloatLess
virtual void opFloatLess(const PcodeOp *op)=0
Emit a FLOAT_LESS operator.
PcodeOp
Lowest level operation of the p-code language.
Definition: op.hh:58
PrintLanguage::opFloatAdd
virtual void opFloatAdd(const PcodeOp *op)=0
Emit a FLOAT_ADD operator.
Architecture
Manager for all the major decompiler subsystems.
Definition: architecture.hh:119
PrintLanguage::tagtype
tagtype
Possible types of Atom.
Definition: printlanguage.hh:155
PrintLanguage::opIntSlessEqual
virtual void opIntSlessEqual(const PcodeOp *op)=0
Emit a INT_SLESSEQUAL operator.
PrintLanguage::opFloatNeg
virtual void opFloatNeg(const PcodeOp *op)=0
Emit a FLOAT_NEG operator.
PrintLanguage::opIntOr
virtual void opIntOr(const PcodeOp *op)=0
Emit a INT_OR operator.
EmitXml::setMaxLineSize
virtual void setMaxLineSize(int4 mls)
Provide a maximum line size to the pretty printer.
Definition: prettyprint.hh:180
OpToken::postsurround
@ postsurround
Function or array operator form.
Definition: printlanguage.hh:87
PrintLanguage::opIntLeft
virtual void opIntLeft(const PcodeOp *op)=0
Emit a INT_LEFT operator.
OpToken::precedence
int4 precedence
Precedence level of this token (higher binds more tightly)
Definition: printlanguage.hh:94
PrintLanguage::castStrategy
CastStrategy * castStrategy
The strategy for emitting explicit case operations.
Definition: printlanguage.hh:250
PrintLanguage::NodePending
A pending data-flow node; waiting to be placed on the reverse polish notation stack.
Definition: printlanguage.hh:186
PrintLanguage::force_scinote
@ force_scinote
Force scientific notation for floats.
Definition: printlanguage.hh:141
PrintLanguage::opExtractOp
virtual void opExtractOp(const PcodeOp *op)=0
Emit an EXTRACT operator.
PrintLanguage::opIntZext
virtual void opIntZext(const PcodeOp *op, const PcodeOp *readOp)=0
Emit a INT_ZEXT operator.
capability.hh
Infrastructure for discovering code extensions to the decompiler.
PrintLanguage::functoken
@ functoken
Emit atom as function name.
Definition: printlanguage.hh:158
OpToken::spacing
int4 spacing
Spaces to print around operator.
Definition: printlanguage.hh:97
PrintLanguage::opFloatNotEqual
virtual void opFloatNotEqual(const PcodeOp *op)=0
Emit a FLOAT_NOTEQUAL operator.
OpToken::tokentype
tokentype
The possible types of operator token.
Definition: printlanguage.hh:84
PrintLanguage::Atom::Atom
Atom(const string &nm, tagtype t, EmitXml::syntax_highlight hl, const PcodeOp *o, const Varnode *v)
Construct a token with an associated PcodeOp and Varnode.
Definition: printlanguage.hh:230
EmitXml::setIndentIncrement
void setIndentIncrement(int4 val)
Set the number of characters indented per level of nesting.
Definition: prettyprint.hh:216
BlockInfLoop
An infinite loop structure.
Definition: block.hh:632
PrintLanguage::fieldtoken
@ fieldtoken
Emit atom as structure field.
Definition: printlanguage.hh:161
PrintLanguage::pushOp
void pushOp(const OpToken *tok, const PcodeOp *op)
Push an operator token onto the RPN stack.
Definition: printlanguage.cc:124
PrintLanguage::curscope
const Scope * curscope
The current symbol scope.
Definition: printlanguage.hh:249
Varnode
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
prettyprint.hh
Routines for emitting high-level (C) language syntax in a well formatted way.
PrintLanguage::opStore
virtual void opStore(const PcodeOp *op)=0
Emit a STORE operator.
PrintLanguage::force_pointer
@ force_pointer
Force '*' notation for pointers.
Definition: printlanguage.hh:142
PrintLanguage::Atom::name
const string & name
The actual printed characters of the token.
Definition: printlanguage.hh:202
PrintLanguage::nofallthru
@ nofallthru
Fall-thru no longer exists.
Definition: printlanguage.hh:150
PrintLanguage::opCbranch
virtual void opCbranch(const PcodeOp *op)=0
Emit a CBRANCH operator.
PrintLanguage::emitExpression
virtual void emitExpression(const PcodeOp *op)=0
Emit a full expression.
PrintLanguage::instr_comment_type
uint4 instr_comment_type
Type of instruction comments to display.
Definition: printlanguage.hh:253
PrintLanguage::pushPartialSymbol
virtual void pushPartialSymbol(const Symbol *sym, int4 off, int4 sz, const Varnode *vn, const PcodeOp *op, Datatype *outtype)=0
Push a variable that represents only part of a symbol onto the RPN stack.
PrintLanguage::Atom::highlight
EmitXml::syntax_highlight highlight
The type of highlighting to use when emitting the token.
Definition: printlanguage.hh:204
PrintLanguage::resetDefaults
virtual void resetDefaults(void)
Set printing options to their default value.
Definition: printlanguage.cc:658
BlockGoto
A block that terminates with an unstructured (goto) branch to another block.
Definition: block.hh:444
PrintLanguage::emitOp
void emitOp(const ReversePolish &entry)
Send an operator token from the RPN to the emitter.
Definition: printlanguage.cc:333
PrintLanguage::opIntSdiv
virtual void opIntSdiv(const PcodeOp *op)=0
Emit a INT_SDIV operator.
PrintLanguage::clear
virtual void clear(void)
Clear the RPN stack and the low-level emitter.
Definition: printlanguage.cc:665
PrintLanguage::emitBlockCondition
virtual void emitBlockCondition(const BlockCondition *bl)=0
Emit a conditional statement.
PrintLanguage::pushType
virtual void pushType(const Datatype *ct)=0
Push a data-type name onto the RPN expression stack.
PrintLanguage::optoken
@ optoken
Emit atom as operator.
Definition: printlanguage.hh:159
EmitXml::emitsXml
virtual bool emitsXml(void) const
Determine if this is an XML markup emitter.
Definition: prettyprint.hh:198
CastStrategy
A strategy for applying type casts.
Definition: cast.hh:40
PrintLanguage::opCopy
virtual void opCopy(const PcodeOp *op)=0
Emit a COPY operator.
PrintLanguage::force_hex
@ force_hex
Force printing of hex.
Definition: printlanguage.hh:138
PrintLanguage::opBinary
void opBinary(const OpToken *tok, const PcodeOp *op)
Push a binary operator onto the RPN stack.
Definition: printlanguage.cc:543
PrintLanguage::head_comment_type
uint4 head_comment_type
Type of header comments to display.
Definition: printlanguage.hh:254
PrintLanguage::emitBlockGraph
virtual void emitBlockGraph(const BlockGraph *bl)=0
Emit (an unspecified) list of blocks.
PrintLanguage::docSingleGlobal
virtual void docSingleGlobal(const Symbol *sym)=0
Emit the declaration for a single (global) Symbol.
PrintLanguage::namespace_strategy
namespace_strategy
Strategies for displaying namespace tokens.
Definition: printlanguage.hh:166
EquateSymbol
A Symbol that holds equate information for a constant.
Definition: database.hh:270
PrintLanguage::force_dec
@ force_dec
Force printing of dec.
Definition: printlanguage.hh:139
PrintLanguage::opCast
virtual void opCast(const PcodeOp *op)=0
Emit a CAST operator.
PrintLanguage::pushUnnamedLocation
virtual void pushUnnamedLocation(const Address &addr, const Varnode *vn, const PcodeOp *op)=0
Push an address as a substitute for a Symbol onto the RPN stack.
Address
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
PrintLanguage::opSubpiece
virtual void opSubpiece(const PcodeOp *op)=0
Emit a SUBPIECE operator.
Funcdata
Container for data structures associated with a single function.
Definition: funcdata.hh:45
Datatype
The base datatype class for the decompiler.
Definition: type.hh:62
BlockList
A series of blocks that execute in sequence.
Definition: block.hh:497
PrintLanguage::pushVnImplied
void pushVnImplied(const Varnode *vn, const PcodeOp *op, uint4 m)
Push an implied variable onto the RPN stack.
Definition: printlanguage.cc:192
PrintLanguage::emitVarDecl
virtual void emitVarDecl(const Symbol *sym)=0
Emit a variable declaration.
PrintLanguage::emitVarDeclStatement
virtual void emitVarDeclStatement(const Symbol *sym)=0
Emit a variable declaration statement.
PrintLanguage::pushAtom
void pushAtom(const Atom &atom)
Push a variable token onto the RPN stack.
Definition: printlanguage.cc:157
TypeFactory
Container class for all Datatype objects in an Architecture.
Definition: type.hh:396
PrintLanguage::NodePending::NodePending
NodePending(const Varnode *v, const PcodeOp *o, uint4 m)
Construct a pending data-flow node.
Definition: printlanguage.hh:192
PrintLanguage::opReturn
virtual void opReturn(const PcodeOp *op)=0
Emit a RETURN operator.
PrintLanguage::syntax
@ syntax
Emit atom as syntax.
Definition: printlanguage.hh:156
OpToken::stage
int4 stage
Additional elements consumed from the RPN stack when emitting this token.
Definition: printlanguage.hh:93
PrintLanguage::opFloatFloat2Float
virtual void opFloatFloat2Float(const PcodeOp *op)=0
Emit a FLOAT_FLOAT2FLOAT operator.
CapabilityPoint
Class for automatically registering extension points to the decompiler.
Definition: capability.hh:36
PrintLanguage::pushAnnotation
virtual void pushAnnotation(const Varnode *vn, const PcodeOp *op)=0
Push an address which is not in the normal data-flow.
PrintLanguage::docAllGlobals
virtual void docAllGlobals(void)=0
Emit declarations of global variables.
PrintLanguage::opFloatRound
virtual void opFloatRound(const PcodeOp *op)=0
Emit a FLOAT_ROUND operator.
PrintLanguage::opIntLess
virtual void opIntLess(const PcodeOp *op)=0
Emit a INT_LESS operator.
PrintLanguage::Atom::offset
int4 offset
The offset (within the parent structure) for a field token.
Definition: printlanguage.hh:211
PrintLanguage::ReversePolish::op
const PcodeOp * op
The PcodeOp associated with the operator token.
Definition: printlanguage.hh:177
PrintLanguage::pushMismatchSymbol
virtual void pushMismatchSymbol(const Symbol *sym, int4 off, int4 sz, const Varnode *vn, const PcodeOp *op)=0
Push an identifier for a variable that mismatches with its Symbol.
PrintLanguage::negatetoken
@ negatetoken
Print the token representing the negation of current token.
Definition: printlanguage.hh:151
PrintLanguage::ReversePolish::id2
int4 id2
The id of the token group this surrounds (for surround operator tokens)
Definition: printlanguage.hh:179
BlockWhileDo
A loop structure where the condition is checked at the top.
Definition: block.hh:590
PrintLanguage::opFloatFloor
virtual void opFloatFloor(const PcodeOp *op)=0
Emit a FLOAT_FLOOR operator.
PrintLanguage::pushEquate
virtual bool pushEquate(uintb val, int4 sz, const EquateSymbol *sym, const Varnode *vn, const PcodeOp *op)=0
Push a constant marked up by and EquateSymbol onto the RPN stack.
PrintLanguage::Atom::type
tagtype type
The type of Atom.
Definition: printlanguage.hh:203
PrintLanguage::opPtradd
virtual void opPtradd(const PcodeOp *op)=0
Emit a PTRADD operator.
PrintLanguage::opLoad
virtual void opLoad(const PcodeOp *op)=0
Emit a LOAD operator.
PrintLanguage::opPopcountOp
virtual void opPopcountOp(const PcodeOp *op)=0
Emit a POPCOUNT operator.
PrintLanguage::Atom::ptr_second
union PrintLanguage::Atom::@34 ptr_second
Other meta-data associated with the token.
EmitXml
Base class (and interface) for pretty printing and XML markup of tokens.
Definition: prettyprint.hh:76
PrintLanguage::opIntMult
virtual void opIntMult(const PcodeOp *op)=0
Emit a INT_MULT operator.
BlockIf
A basic "if" block.
Definition: block.hh:555
PrintLanguage::opMultiequal
virtual void opMultiequal(const PcodeOp *op)=0
Emit a MULTIEQUAL operator.
PrintLanguage::opIntSless
virtual void opIntSless(const PcodeOp *op)=0
Emit a INT_SLESS operator.
PrintLanguage::emitBlockSwitch
virtual void emitBlockSwitch(const BlockSwitch *bl)=0
Emit a switch structure.
PrintLanguageCapability::buildLanguage
virtual PrintLanguage * buildLanguage(Architecture *glb)=0
Build the main PrintLanguage object corresponding to this capability.
PrintLanguage::opIntAdd
virtual void opIntAdd(const PcodeOp *op)=0
Emit a INT_ADD operator.
PrintLanguage::opFloatCeil
virtual void opFloatCeil(const PcodeOp *op)=0
Emit a FLOAT_CEIL operator.
PrintLanguageCapability
Base class for high-level language capabilities.
Definition: printlanguage.hh:39
PrintLanguage::opIntXor
virtual void opIntXor(const PcodeOp *op)=0
Emit a INT_XOR operator.
PrintLanguage::falsebranch
@ falsebranch
Print the false branch (for flat)
Definition: printlanguage.hh:149
PrintLanguage::setCommentDelimeter
void setCommentDelimeter(const string &start, const string &stop, bool usecommentfill)
Establish comment delimiters for the language.
Definition: printlanguage.cc:93
PrintLanguage::opIntNotEqual
virtual void opIntNotEqual(const PcodeOp *op)=0
Emit a INT_NOTEQUAL operator.
PrintLanguage::opPtrsub
virtual void opPtrsub(const PcodeOp *op)=0
Emit a PTRSUB operator.
PrintLanguage::ReversePolish::paren
bool paren
True if parentheses are required.
Definition: printlanguage.hh:176
PrintLanguage::opIntNegate
virtual void opIntNegate(const PcodeOp *op)=0
Emit a INT_NEGATE operator.
PrintLanguage::flat
@ flat
Do not print block structure.
Definition: printlanguage.hh:148
PrintLanguage::opIndirect
virtual void opIndirect(const PcodeOp *op)=0
Emit a INDIRECT operator.
PrintLanguage::opFloatSub
virtual void opFloatSub(const PcodeOp *op)=0
Emit a FLOAT_SUB operator.
PrintLanguage::modifiers
modifiers
Possible context sensitive modifiers to how tokens get emitted.
Definition: printlanguage.hh:137
PrintLanguage::emitBlockBasic
virtual void emitBlockBasic(const BlockBasic *bb)=0
Emit statements in a basic block.
PrintLanguage::bestfit
@ bestfit
Decide on most aesthetic form.
Definition: printlanguage.hh:140
Comment
A comment attached to a specific function and code address.
Definition: comment.hh:37
PrintLanguage::docFunction
virtual void docFunction(const Funcdata *fd)=0
Emit the declaration (and body) of a function.
PrintLanguage::vartoken
@ vartoken
Emit atom as variable.
Definition: printlanguage.hh:157
PrintLanguage::setFlat
void setFlat(bool val)
Set whether nesting code structure should be emitted.
Definition: printlanguage.cc:649
PrintLanguage::ReversePolish::id
int4 id
The id of the token group which this belongs to.
Definition: printlanguage.hh:178
PrintLanguage::emitBlockInfLoop
virtual void emitBlockInfLoop(const BlockInfLoop *bl)=0
Emit an infinite loop structure.
PrintLanguage::docTypeDefinitions
virtual void docTypeDefinitions(const TypeFactory *typegrp)=0
Emit definitions of data-types.
PrintLanguage::PrintLanguage
PrintLanguage(Architecture *g, const string &nm)
Constructor.
Definition: printlanguage.cc:57
PrintLanguage::pushConstant
virtual void pushConstant(uintb val, const Datatype *ct, const Varnode *vn, const PcodeOp *op)=0
Push a constant onto the RPN stack.
PrintLanguage::printUnicode
virtual void printUnicode(ostream &s, int4 onechar) const =0
Print a single unicode character as a character constant for the high-level language.
PrintLanguage::NodePending::vnmod
uint4 vnmod
Printing modifications to enforce on the expression.
Definition: printlanguage.hh:189
PrintLanguage::NodePending::op
const PcodeOp * op
The single operator consuming value from the implied Varnode.
Definition: printlanguage.hh:188
PrintLanguage::setLineCommentIndent
void setLineCommentIndent(int4 val)
Set the number of characters to indent comment lines.
Definition: printlanguage.cc:79
PrintLanguage::opIntSext
virtual void opIntSext(const PcodeOp *op, const PcodeOp *readOp)=0
Emit a INT_SEXT operator.
PrintLanguage::setXML
void setXML(bool val)
Set whether the low-level emitter, emits XML markup.
Definition: printlanguage.cc:640
PrintLanguage::opIntEqual
virtual void opIntEqual(const PcodeOp *op)=0
Emit a INT_EQUAL operator.
PrintLanguage::MINIMAL_NAMESPACES
@ MINIMAL_NAMESPACES
(default) Print just enough namespace info to fully resolve symbol
Definition: printlanguage.hh:167
PrintLanguageCapability::findCapability
static PrintLanguageCapability * findCapability(const string &name)
Find a language capability by name.
Definition: printlanguage.cc:44
PrintLanguage::opSegmentOp
virtual void opSegmentOp(const PcodeOp *op)=0
Emit a SEGMENTOP operator.
PrintLanguage::opBoolAnd
virtual void opBoolAnd(const PcodeOp *op)=0
Emit a BOOL_AND operator.
PrintLanguage::opIntSborrow
virtual void opIntSborrow(const PcodeOp *op)=0
Emit a INT_SBORROW operator.
PrintLanguage::pushVnExplicit
void pushVnExplicit(const Varnode *vn, const PcodeOp *op)
Push an explicit variable onto the RPN stack.
Definition: printlanguage.cc:213
PrintLanguageCapability::initialize
virtual void initialize(void)
Complete initialization of an extension point.
Definition: printlanguage.cc:33
PrintLanguage::opIntDiv
virtual void opIntDiv(const PcodeOp *op)=0
Emit a INT_DIV operator.
BlockCondition
Two conditional blocks combined into one conditional using BOOL_AND or BOOL_OR.
Definition: block.hh:518
PrintLanguage::ALL_NAMESPACES
@ ALL_NAMESPACES
Always print all namespace information.
Definition: printlanguage.hh:169
PrintLanguage::Atom::vn
const Varnode * vn
A Varnode associated with the token.
Definition: printlanguage.hh:207
PrintLanguage::opCallother
virtual void opCallother(const PcodeOp *op)=0
Emit a CALLOTHER operator.
OpToken::presurround
@ presurround
Modifier form (like a cast operation)
Definition: printlanguage.hh:88
OpToken
A token representing an operator in the high-level language.
Definition: printlanguage.hh:81
PrintLanguage::pushVnLHS
void pushVnLHS(const Varnode *vn, const PcodeOp *op)
Push a variable as the left-hand side of an expression.
Definition: printlanguage.cc:248
Symbol
The base class for a symbol in a symbol table or scope.
Definition: database.hh:152
PrintLanguage::opIntLessEqual
virtual void opIntLessEqual(const PcodeOp *op)=0
Emit a INT_LESSEQUAL operator.
PrintLanguage::print_load_value
@ print_load_value
Hide pointer deref for load with other ops.
Definition: printlanguage.hh:143
PrintLanguage::opFloatInt2Float
virtual void opFloatInt2Float(const PcodeOp *op)=0
Emit a FLOAT_INT2FLOAT operator.
PrintLanguage::NO_NAMESPACES
@ NO_NAMESPACES
Never print namespace information.
Definition: printlanguage.hh:168
PrintLanguage::ReversePolish::visited
int4 visited
The current stage of printing for the operator.
Definition: printlanguage.hh:175
PrintLanguage::print_store_value
@ print_store_value
Hide pointer deref for store with other ops.
Definition: printlanguage.hh:144
OpToken::bump
int4 bump
Spaces to indent if we break here.
Definition: printlanguage.hh:98
PrintLanguage::escapeCharacterData
bool escapeCharacterData(ostream &s, const uint1 *buf, int4 count, int4 charsize, bool bigend) const
Emit a byte buffer to the stream as unicode characters.
Definition: printlanguage.cc:500
PrintLanguage::ReversePolish::tok
const OpToken * tok
The operator token.
Definition: printlanguage.hh:174
PrintLanguage::mods
uint4 mods
Currently active printing modifications.
Definition: printlanguage.hh:252
PrintLanguage::emit
EmitXml * emit
The low-level token emitter.
Definition: printlanguage.hh:251
PrintLanguage::opBoolOr
virtual void opBoolOr(const PcodeOp *op)=0
Emit a BOOL_OR operator.
BlockSwitch
A structured switch construction.
Definition: block.hh:649
OpToken::hiddenfunction
@ hiddenfunction
Operation that isn't explicitly printed.
Definition: printlanguage.hh:90
PrintLanguage::opBoolNegate
virtual void opBoolNegate(const PcodeOp *op)=0
Emit a BOOL_NEGATE operator.
PrintLanguage::opCallind
virtual void opCallind(const PcodeOp *op)=0
Emit a CALLIND operator.
BlockCopy
This class is used to mirror the BlockBasic objects in the fixed control-flow graph for a function.
Definition: block.hh:419