|
| PrintLanguage (Architecture *g, const string &nm) |
| Constructor. More...
|
|
virtual | ~PrintLanguage (void) |
| Destructor.
|
|
const string & | getName (void) const |
| Get the language name.
|
|
CastStrategy * | getCastStrategy (void) const |
| Get the casting strategy for the language.
|
|
ostream * | getOutputStream (void) const |
| Get the output stream being emitted to.
|
|
void | setOutputStream (ostream *t) |
| Set the output stream to emit to.
|
|
void | setScope (Scope *sc) |
| Set the current Symbol scope.
|
|
void | setMaxLineSize (int4 mls) |
| Set the maximum number of characters per line.
|
|
void | setIndentIncrement (int4 inc) |
| Set the number of characters to indent per level of code nesting.
|
|
void | setLineCommentIndent (int4 val) |
| Set the number of characters to indent comment lines. More...
|
|
void | setCommentDelimeter (const string &start, const string &stop, bool usecommentfill) |
| Establish comment delimiters for the language. More...
|
|
uint4 | getInstructionComment (void) const |
| Get the type of comments suitable within the body of a function.
|
|
void | setInstructionComment (uint4 val) |
| Set the type of comments suitable within the body of a function.
|
|
uint4 | getHeaderComment (void) const |
| Get the type of comments suitable for a function header.
|
|
void | setHeaderComment (uint4 val) |
| Set the type of comments suitable for a function header.
|
|
bool | emitsXml (void) const |
| Does the low-level emitter, emit XML markup.
|
|
void | setXML (bool val) |
| Set whether the low-level emitter, emits XML markup. More...
|
|
void | setFlat (bool val) |
| Set whether nesting code structure should be emitted. More...
|
|
virtual void | adjustTypeOperators (void)=0 |
| Set basic data-type information for p-code operators.
|
|
virtual void | clear (void) |
| Clear the RPN stack and the low-level emitter.
|
|
virtual void | setIntegerFormat (const string &nm) |
| Set the default integer format. More...
|
|
virtual void | setCommentStyle (const string &nm)=0 |
| Set the way comments are displayed in decompiler output. More...
|
|
virtual bool | isCharacterConstant (const uint1 *buf, int4 size, int4 charsize) const =0 |
| Decide is the given byte array looks like a character string. More...
|
|
virtual void | docTypeDefinitions (const TypeFactory *typegrp)=0 |
| Emit definitions of data-types. More...
|
|
virtual void | docAllGlobals (void)=0 |
| Emit declarations of global variables.
|
|
virtual void | docSingleGlobal (const Symbol *sym)=0 |
| Emit the declaration for a single (global) Symbol. More...
|
|
virtual void | docFunction (const Funcdata *fd)=0 |
| Emit the declaration (and body) of a function. More...
|
|
virtual void | emitBlockBasic (const BlockBasic *bb)=0 |
| Emit statements in a basic block.
|
|
virtual void | emitBlockGraph (const BlockGraph *bl)=0 |
| Emit (an unspecified) list of blocks.
|
|
virtual void | emitBlockCopy (const BlockCopy *bl)=0 |
| Emit a basic block (with any labels)
|
|
virtual void | emitBlockGoto (const BlockGoto *bl)=0 |
| Emit a block ending with a goto statement.
|
|
virtual void | emitBlockLs (const BlockList *bl)=0 |
| Emit a sequence of blocks.
|
|
virtual void | emitBlockCondition (const BlockCondition *bl)=0 |
| Emit a conditional statement.
|
|
virtual void | emitBlockIf (const BlockIf *bl)=0 |
| Emit an if/else style construct.
|
|
virtual void | emitBlockWhileDo (const BlockWhileDo *bl)=0 |
| Emit a loop structure, check at top.
|
|
virtual void | emitBlockDoWhile (const BlockDoWhile *bl)=0 |
| Emit a loop structure, check at bottom.
|
|
virtual void | emitBlockInfLoop (const BlockInfLoop *bl)=0 |
| Emit an infinite loop structure.
|
|
virtual void | emitBlockSwitch (const BlockSwitch *bl)=0 |
| Emit a switch structure.
|
|
virtual void | opCopy (const PcodeOp *op)=0 |
| Emit a COPY operator.
|
|
virtual void | opLoad (const PcodeOp *op)=0 |
| Emit a LOAD operator.
|
|
virtual void | opStore (const PcodeOp *op)=0 |
| Emit a STORE operator.
|
|
virtual void | opBranch (const PcodeOp *op)=0 |
| Emit a BRANCH operator.
|
|
virtual void | opCbranch (const PcodeOp *op)=0 |
| Emit a CBRANCH operator.
|
|
virtual void | opBranchind (const PcodeOp *op)=0 |
| Emit a BRANCHIND operator.
|
|
virtual void | opCall (const PcodeOp *op)=0 |
| Emit a CALL operator.
|
|
virtual void | opCallind (const PcodeOp *op)=0 |
| Emit a CALLIND operator.
|
|
virtual void | opCallother (const PcodeOp *op)=0 |
| Emit a CALLOTHER operator.
|
|
virtual void | opConstructor (const PcodeOp *op, bool withNew)=0 |
| Emit an operator constructing an object.
|
|
virtual void | opReturn (const PcodeOp *op)=0 |
| Emit a RETURN operator.
|
|
virtual void | opIntEqual (const PcodeOp *op)=0 |
| Emit a INT_EQUAL operator.
|
|
virtual void | opIntNotEqual (const PcodeOp *op)=0 |
| Emit a INT_NOTEQUAL operator.
|
|
virtual void | opIntSless (const PcodeOp *op)=0 |
| Emit a INT_SLESS operator.
|
|
virtual void | opIntSlessEqual (const PcodeOp *op)=0 |
| Emit a INT_SLESSEQUAL operator.
|
|
virtual void | opIntLess (const PcodeOp *op)=0 |
| Emit a INT_LESS operator.
|
|
virtual void | opIntLessEqual (const PcodeOp *op)=0 |
| Emit a INT_LESSEQUAL operator.
|
|
virtual void | opIntZext (const PcodeOp *op, const PcodeOp *readOp)=0 |
| Emit a INT_ZEXT operator.
|
|
virtual void | opIntSext (const PcodeOp *op, const PcodeOp *readOp)=0 |
| Emit a INT_SEXT operator.
|
|
virtual void | opIntAdd (const PcodeOp *op)=0 |
| Emit a INT_ADD operator.
|
|
virtual void | opIntSub (const PcodeOp *op)=0 |
| Emit a INT_SUB operator.
|
|
virtual void | opIntCarry (const PcodeOp *op)=0 |
| Emit a INT_CARRY operator.
|
|
virtual void | opIntScarry (const PcodeOp *op)=0 |
| Emit a INT_SCARRY operator.
|
|
virtual void | opIntSborrow (const PcodeOp *op)=0 |
| Emit a INT_SBORROW operator.
|
|
virtual void | opInt2Comp (const PcodeOp *op)=0 |
| Emit a INT_2COMP operator.
|
|
virtual void | opIntNegate (const PcodeOp *op)=0 |
| Emit a INT_NEGATE operator.
|
|
virtual void | opIntXor (const PcodeOp *op)=0 |
| Emit a INT_XOR operator.
|
|
virtual void | opIntAnd (const PcodeOp *op)=0 |
| Emit a INT_AND operator.
|
|
virtual void | opIntOr (const PcodeOp *op)=0 |
| Emit a INT_OR operator.
|
|
virtual void | opIntLeft (const PcodeOp *op)=0 |
| Emit a INT_LEFT operator.
|
|
virtual void | opIntRight (const PcodeOp *op)=0 |
| Emit a INT_RIGHT operator.
|
|
virtual void | opIntSright (const PcodeOp *op)=0 |
| Emit a INT_SRIGHT operator.
|
|
virtual void | opIntMult (const PcodeOp *op)=0 |
| Emit a INT_MULT operator.
|
|
virtual void | opIntDiv (const PcodeOp *op)=0 |
| Emit a INT_DIV operator.
|
|
virtual void | opIntSdiv (const PcodeOp *op)=0 |
| Emit a INT_SDIV operator.
|
|
virtual void | opIntRem (const PcodeOp *op)=0 |
| Emit a INT_REM operator.
|
|
virtual void | opIntSrem (const PcodeOp *op)=0 |
| Emit a INT_SREM operator.
|
|
virtual void | opBoolNegate (const PcodeOp *op)=0 |
| Emit a BOOL_NEGATE operator.
|
|
virtual void | opBoolXor (const PcodeOp *op)=0 |
| Emit a BOOL_XOR operator.
|
|
virtual void | opBoolAnd (const PcodeOp *op)=0 |
| Emit a BOOL_AND operator.
|
|
virtual void | opBoolOr (const PcodeOp *op)=0 |
| Emit a BOOL_OR operator.
|
|
virtual void | opFloatEqual (const PcodeOp *op)=0 |
| Emit a FLOAT_EQUAL operator.
|
|
virtual void | opFloatNotEqual (const PcodeOp *op)=0 |
| Emit a FLOAT_NOTEQUAL operator.
|
|
virtual void | opFloatLess (const PcodeOp *op)=0 |
| Emit a FLOAT_LESS operator.
|
|
virtual void | opFloatLessEqual (const PcodeOp *op)=0 |
| Emit a FLOAT_LESSEQUAL operator.
|
|
virtual void | opFloatNan (const PcodeOp *op)=0 |
| Emit a FLOAT_NAN operator.
|
|
virtual void | opFloatAdd (const PcodeOp *op)=0 |
| Emit a FLOAT_ADD operator.
|
|
virtual void | opFloatDiv (const PcodeOp *op)=0 |
| Emit a FLOAT_DIV operator.
|
|
virtual void | opFloatMult (const PcodeOp *op)=0 |
| Emit a FLOAT_MULT operator.
|
|
virtual void | opFloatSub (const PcodeOp *op)=0 |
| Emit a FLOAT_SUB operator.
|
|
virtual void | opFloatNeg (const PcodeOp *op)=0 |
| Emit a FLOAT_NEG operator.
|
|
virtual void | opFloatAbs (const PcodeOp *op)=0 |
| Emit a FLOAT_ABS operator.
|
|
virtual void | opFloatSqrt (const PcodeOp *op)=0 |
| Emit a FLOAT_SQRT operator.
|
|
virtual void | opFloatInt2Float (const PcodeOp *op)=0 |
| Emit a FLOAT_INT2FLOAT operator.
|
|
virtual void | opFloatFloat2Float (const PcodeOp *op)=0 |
| Emit a FLOAT_FLOAT2FLOAT operator.
|
|
virtual void | opFloatTrunc (const PcodeOp *op)=0 |
| Emit a FLOAT_TRUNC operator.
|
|
virtual void | opFloatCeil (const PcodeOp *op)=0 |
| Emit a FLOAT_CEIL operator.
|
|
virtual void | opFloatFloor (const PcodeOp *op)=0 |
| Emit a FLOAT_FLOOR operator.
|
|
virtual void | opFloatRound (const PcodeOp *op)=0 |
| Emit a FLOAT_ROUND operator.
|
|
virtual void | opMultiequal (const PcodeOp *op)=0 |
| Emit a MULTIEQUAL operator.
|
|
virtual void | opIndirect (const PcodeOp *op)=0 |
| Emit a INDIRECT operator.
|
|
virtual void | opPiece (const PcodeOp *op)=0 |
| Emit a PIECE operator.
|
|
virtual void | opSubpiece (const PcodeOp *op)=0 |
| Emit a SUBPIECE operator.
|
|
virtual void | opCast (const PcodeOp *op)=0 |
| Emit a CAST operator.
|
|
virtual void | opPtradd (const PcodeOp *op)=0 |
| Emit a PTRADD operator.
|
|
virtual void | opPtrsub (const PcodeOp *op)=0 |
| Emit a PTRSUB operator.
|
|
virtual void | opSegmentOp (const PcodeOp *op)=0 |
| Emit a SEGMENTOP operator.
|
|
virtual void | opCpoolRefOp (const PcodeOp *op)=0 |
| Emit a CPOOLREF operator.
|
|
virtual void | opNewOp (const PcodeOp *op)=0 |
| Emit a NEW operator.
|
|
virtual void | opInsertOp (const PcodeOp *op)=0 |
| Emit an INSERT operator.
|
|
virtual void | opExtractOp (const PcodeOp *op)=0 |
| Emit an EXTRACT operator.
|
|
virtual void | opPopcountOp (const PcodeOp *op)=0 |
| Emit a POPCOUNT operator.
|
|
|
bool | isSet (uint4 m) const |
| Is the given printing modification active.
|
|
void | pushScope (Scope *sc) |
| Push a new symbol scope.
|
|
void | popScope (void) |
| Pop to the previous symbol scope.
|
|
void | pushMod (void) |
| Push current printing modifications to the stack.
|
|
void | popMod (void) |
| Pop to the previous printing modifications.
|
|
void | setMod (uint4 m) |
| Activate the given printing modification.
|
|
void | unsetMod (uint4 m) |
| Deactivate the given printing modification.
|
|
void | pushOp (const OpToken *tok, const PcodeOp *op) |
| Push an operator token onto the RPN stack. More...
|
|
void | pushAtom (const Atom &atom) |
| Push a variable token onto the RPN stack. More...
|
|
void | pushVnImplied (const Varnode *vn, const PcodeOp *op, uint4 m) |
| Push an implied variable onto the RPN stack. More...
|
|
void | pushVnExplicit (const Varnode *vn, const PcodeOp *op) |
| Push an explicit variable onto the RPN stack. More...
|
|
void | pushVnLHS (const Varnode *vn, const PcodeOp *op) |
| Push a variable as the left-hand side of an expression. More...
|
|
bool | parentheses (const OpToken *op2) |
| Determine if the given token should be emitted in its own parenthetic expression. More...
|
|
void | emitOp (const ReversePolish &entry) |
| Send an operator token from the RPN to the emitter. More...
|
|
void | emitAtom (const Atom &atom) |
| Send an variable token from the RPN to the emitter. More...
|
|
bool | escapeCharacterData (ostream &s, const uint1 *buf, int4 count, int4 charsize, bool bigend) const |
| Emit a byte buffer to the stream as unicode characters. More...
|
|
void | recurse (void) |
| Emit from the RPN stack as much as possible. More...
|
|
void | opBinary (const OpToken *tok, const PcodeOp *op) |
| Push a binary operator onto the RPN stack. More...
|
|
void | opUnary (const OpToken *tok, const PcodeOp *op) |
| Push a unary operator onto the RPN stack. More...
|
|
int4 | getPending (void) const |
| Get the number of pending nodes yet to be put on the RPN stack.
|
|
virtual void | printUnicode (ostream &s, int4 onechar) const =0 |
| Print a single unicode character as a character constant for the high-level language. More...
|
|
virtual void | pushType (const Datatype *ct)=0 |
| Push a data-type name onto the RPN expression stack. More...
|
|
virtual void | pushConstant (uintb val, const Datatype *ct, const Varnode *vn, const PcodeOp *op)=0 |
| Push a constant onto the RPN stack. More...
|
|
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. More...
|
|
virtual void | pushAnnotation (const Varnode *vn, const PcodeOp *op)=0 |
| Push an address which is not in the normal data-flow. More...
|
|
virtual void | pushSymbol (const Symbol *sym, const Varnode *vn, const PcodeOp *op)=0 |
| Push a specific Symbol onto the RPN stack. More...
|
|
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. More...
|
|
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. More...
|
|
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. More...
|
|
virtual void | emitLineComment (int4 indent, const Comment *comm) |
| Emit a comment line. More...
|
|
virtual void | emitVarDecl (const Symbol *sym)=0 |
| Emit a variable declaration. More...
|
|
virtual void | emitVarDeclStatement (const Symbol *sym)=0 |
| Emit a variable declaration statement. More...
|
|
virtual bool | emitScopeVarDecls (const Scope *scope, int4 cat)=0 |
| Emit all the variable declarations for a given scope. More...
|
|
virtual void | emitExpression (const PcodeOp *op)=0 |
| Emit a full expression. More...
|
|
virtual void | emitFunctionDeclaration (const Funcdata *fd)=0 |
| Emit a function declaration. More...
|
|
virtual bool | checkPrintNegation (const Varnode *vn)=0 |
| Check whether a given boolean Varnode can be printed in negated form. More...
|
|
The base class API for emitting a high-level language.
Instances of this object are responsible for converting a function's (transformed) data-flow graph into the final stream of tokens of a high-level source code language. There a few main entry points including:
The system is responsible for printing:
- Control-flow structures
- Expressions
- Type declarations
- Function prototypes
- Comments
As part of all this printing, the system is also responsible for
- Emitting integers, floats, and character constants
- Placing parentheses within expressions to properly represent data-flow
- Deciding whether cast operations need an explicit cast token
- Indenting and line wrapping
To accomplish this, the API is broken up into three sections. The first section are the main entry point 'doc' methods. The second section are 'emit' methods, which are responsible for printing a representation of a particular high-level code construct. The third section are 'push' and 'op' methods, which are responsible for walking expression trees. The order in which tokens are emitted for an expression is determined by a Reverse Polish Notation (RPN) stack, that the 'push' methods manipulate. Operators and variables are pushed onto this stack and are ultimately emitted in the correct order.
The base class provides a generic printing modifications stack and a symbol scope stack to provide a printing context mechanism for derived classes.