decompiler
1.0.0
|
The c-language token emitter. More...
#include <printc.hh>
Public Member Functions | |
PrintC (Architecture *g, const string &nm="c-language") | |
Constructor. More... | |
void | setNULLPrinting (bool val) |
Toggle the printing of a 'NULL' token. | |
void | setInplaceOps (bool val) |
Toggle the printing of in-place operators. | |
void | setConvention (bool val) |
Toggle whether calling conventions are printed. | |
void | setNoCastPrinting (bool val) |
Toggle whether casts should not be printed. | |
void | setCStyleComments (void) |
Set c-style "/* */" comment delimiters. | |
void | setCPlusPlusStyleComments (void) |
Set c++-style "//" comment delimiters. | |
void | setDisplayUnplaced (bool val) |
Toggle whether unplaced comments are displayed in the header. | |
virtual void | adjustTypeOperators (void) |
Set basic data-type information for p-code operators. | |
virtual void | setCommentStyle (const string &nm) |
Set the way comments are displayed in decompiler output. More... | |
virtual bool | isCharacterConstant (const uint1 *buf, int4 size, int4 charsize) const |
Decide is the given byte array looks like a character string. More... | |
virtual void | docTypeDefinitions (const TypeFactory *typegrp) |
Emit definitions of data-types. More... | |
virtual void | docAllGlobals (void) |
Emit declarations of global variables. | |
virtual void | docSingleGlobal (const Symbol *sym) |
Emit the declaration for a single (global) Symbol. More... | |
virtual void | docFunction (const Funcdata *fd) |
Emit the declaration (and body) of a function. More... | |
virtual void | emitBlockBasic (const BlockBasic *bb) |
Emit statements in a basic block. | |
virtual void | emitBlockGraph (const BlockGraph *bl) |
Emit (an unspecified) list of blocks. | |
virtual void | emitBlockCopy (const BlockCopy *bl) |
Emit a basic block (with any labels) | |
virtual void | emitBlockGoto (const BlockGoto *bl) |
Emit a block ending with a goto statement. | |
virtual void | emitBlockLs (const BlockList *bl) |
Emit a sequence of blocks. | |
virtual void | emitBlockCondition (const BlockCondition *bl) |
Emit a conditional statement. | |
virtual void | emitBlockIf (const BlockIf *bl) |
Emit an if/else style construct. | |
virtual void | emitBlockWhileDo (const BlockWhileDo *bl) |
Emit a loop structure, check at top. | |
virtual void | emitBlockDoWhile (const BlockDoWhile *bl) |
Emit a loop structure, check at bottom. | |
virtual void | emitBlockInfLoop (const BlockInfLoop *bl) |
Emit an infinite loop structure. | |
virtual void | emitBlockSwitch (const BlockSwitch *bl) |
Emit a switch structure. | |
virtual void | opCopy (const PcodeOp *op) |
Emit a COPY operator. | |
virtual void | opLoad (const PcodeOp *op) |
Emit a LOAD operator. | |
virtual void | opStore (const PcodeOp *op) |
Emit a STORE operator. | |
virtual void | opBranch (const PcodeOp *op) |
Emit a BRANCH operator. | |
virtual void | opCbranch (const PcodeOp *op) |
virtual void | opBranchind (const PcodeOp *op) |
Emit a BRANCHIND operator. | |
virtual void | opCall (const PcodeOp *op) |
Emit a CALL operator. | |
virtual void | opCallind (const PcodeOp *op) |
Emit a CALLIND operator. | |
virtual void | opCallother (const PcodeOp *op) |
Emit a CALLOTHER operator. | |
virtual void | opConstructor (const PcodeOp *op, bool withNew) |
Emit an operator constructing an object. | |
virtual void | opReturn (const PcodeOp *op) |
Emit a RETURN operator. | |
virtual void | opIntEqual (const PcodeOp *op) |
Emit a INT_EQUAL operator. | |
virtual void | opIntNotEqual (const PcodeOp *op) |
Emit a INT_NOTEQUAL operator. | |
virtual void | opIntSless (const PcodeOp *op) |
Emit a INT_SLESS operator. | |
virtual void | opIntSlessEqual (const PcodeOp *op) |
Emit a INT_SLESSEQUAL operator. | |
virtual void | opIntLess (const PcodeOp *op) |
Emit a INT_LESS operator. | |
virtual void | opIntLessEqual (const PcodeOp *op) |
Emit a INT_LESSEQUAL operator. | |
virtual void | opIntZext (const PcodeOp *op) |
Emit a INT_ZEXT operator. | |
virtual void | opIntSext (const PcodeOp *op) |
Emit a INT_SEXT operator. | |
virtual void | opIntAdd (const PcodeOp *op) |
Emit a INT_ADD operator. | |
virtual void | opIntSub (const PcodeOp *op) |
Emit a INT_SUB operator. | |
virtual void | opIntCarry (const PcodeOp *op) |
Emit a INT_CARRY operator. | |
virtual void | opIntScarry (const PcodeOp *op) |
Emit a INT_SCARRY operator. | |
virtual void | opIntSborrow (const PcodeOp *op) |
Emit a INT_SBORROW operator. | |
virtual void | opInt2Comp (const PcodeOp *op) |
Emit a INT_2COMP operator. | |
virtual void | opIntNegate (const PcodeOp *op) |
Emit a INT_NEGATE operator. | |
virtual void | opIntXor (const PcodeOp *op) |
Emit a INT_XOR operator. | |
virtual void | opIntAnd (const PcodeOp *op) |
Emit a INT_AND operator. | |
virtual void | opIntOr (const PcodeOp *op) |
Emit a INT_OR operator. | |
virtual void | opIntLeft (const PcodeOp *op) |
Emit a INT_LEFT operator. | |
virtual void | opIntRight (const PcodeOp *op) |
Emit a INT_RIGHT operator. | |
virtual void | opIntSright (const PcodeOp *op) |
Emit a INT_SRIGHT operator. | |
virtual void | opIntMult (const PcodeOp *op) |
Emit a INT_MULT operator. | |
virtual void | opIntDiv (const PcodeOp *op) |
Emit a INT_DIV operator. | |
virtual void | opIntSdiv (const PcodeOp *op) |
Emit a INT_SDIV operator. | |
virtual void | opIntRem (const PcodeOp *op) |
Emit a INT_REM operator. | |
virtual void | opIntSrem (const PcodeOp *op) |
Emit a INT_SREM operator. | |
virtual void | opBoolNegate (const PcodeOp *op) |
virtual void | opBoolXor (const PcodeOp *op) |
Emit a BOOL_XOR operator. | |
virtual void | opBoolAnd (const PcodeOp *op) |
Emit a BOOL_AND operator. | |
virtual void | opBoolOr (const PcodeOp *op) |
Emit a BOOL_OR operator. | |
virtual void | opFloatEqual (const PcodeOp *op) |
Emit a FLOAT_EQUAL operator. | |
virtual void | opFloatNotEqual (const PcodeOp *op) |
Emit a FLOAT_NOTEQUAL operator. | |
virtual void | opFloatLess (const PcodeOp *op) |
Emit a FLOAT_LESS operator. | |
virtual void | opFloatLessEqual (const PcodeOp *op) |
Emit a FLOAT_LESSEQUAL operator. | |
virtual void | opFloatNan (const PcodeOp *op) |
Emit a FLOAT_NAN operator. | |
virtual void | opFloatAdd (const PcodeOp *op) |
Emit a FLOAT_ADD operator. | |
virtual void | opFloatDiv (const PcodeOp *op) |
Emit a FLOAT_DIV operator. | |
virtual void | opFloatMult (const PcodeOp *op) |
Emit a FLOAT_MULT operator. | |
virtual void | opFloatSub (const PcodeOp *op) |
Emit a FLOAT_SUB operator. | |
virtual void | opFloatNeg (const PcodeOp *op) |
Emit a FLOAT_NEG operator. | |
virtual void | opFloatAbs (const PcodeOp *op) |
Emit a FLOAT_ABS operator. | |
virtual void | opFloatSqrt (const PcodeOp *op) |
Emit a FLOAT_SQRT operator. | |
virtual void | opFloatInt2Float (const PcodeOp *op) |
Emit a FLOAT_INT2FLOAT operator. | |
virtual void | opFloatFloat2Float (const PcodeOp *op) |
Emit a FLOAT_FLOAT2FLOAT operator. | |
virtual void | opFloatTrunc (const PcodeOp *op) |
Emit a FLOAT_TRUNC operator. | |
virtual void | opFloatCeil (const PcodeOp *op) |
Emit a FLOAT_CEIL operator. | |
virtual void | opFloatFloor (const PcodeOp *op) |
Emit a FLOAT_FLOOR operator. | |
virtual void | opFloatRound (const PcodeOp *op) |
Emit a FLOAT_ROUND operator. | |
virtual void | opMultiequal (const PcodeOp *op) |
Emit a MULTIEQUAL operator. | |
virtual void | opIndirect (const PcodeOp *op) |
Emit a INDIRECT operator. | |
virtual void | opPiece (const PcodeOp *op) |
Emit a PIECE operator. | |
virtual void | opSubpiece (const PcodeOp *op) |
Emit a SUBPIECE operator. | |
virtual void | opCast (const PcodeOp *op) |
Emit a CAST operator. | |
virtual void | opPtradd (const PcodeOp *op) |
Emit a PTRADD operator. | |
virtual void | opPtrsub (const PcodeOp *op) |
virtual void | opSegmentOp (const PcodeOp *op) |
virtual void | opCpoolRefOp (const PcodeOp *op) |
Emit a CPOOLREF operator. | |
virtual void | opNewOp (const PcodeOp *op) |
Emit a NEW operator. | |
Public Member Functions inherited from PrintLanguage | |
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 | clear (void) |
Clear the RPN stack and the low-level emitter. | |
virtual void | setIntegerFormat (const string &nm) |
Set the default integer format. More... | |
Protected Member Functions | |
void | buildTypeStack (const Datatype *ct, vector< const Datatype * > &typestack) |
Prepare to push components of a data-type declaration. More... | |
void | pushPrototypeInputs (const FuncProto *proto) |
Push input parameters. More... | |
virtual void | pushTypeStart (const Datatype *ct, bool noident) |
Push part of a data-type declaration onto the RPN stack, up to the identifier. More... | |
virtual void | pushTypeEnd (const Datatype *ct) |
Push the tail ends of a data-type declaration onto the RPN stack. More... | |
void | pushBoolConstant (uintb val, const TypeBase *ct, const Varnode *vn, const PcodeOp *op) |
Push a true or false token to the RPN stack. More... | |
void | pushCharConstant (uintb val, const TypeChar *ct, const Varnode *vn, const PcodeOp *op) |
Push a single character constant to the RPN stack. More... | |
void | pushEnumConstant (uintb val, const TypeEnum *ct, const Varnode *vn, const PcodeOp *op) |
Push an enumerated value to the RPN stack. More... | |
virtual bool | pushPtrCharConstant (uintb val, const TypePointer *ct, const Varnode *vn, const PcodeOp *op) |
Attempt to push a quoted string representing a given constant pointer onto the RPN stack. More... | |
bool | pushPtrCodeConstant (uintb val, const TypePointer *ct, const Varnode *vn, const PcodeOp *op) |
Attempt to push a function name representing a constant pointer onto the RPN stack. More... | |
virtual bool | doEmitWideCharPrefix (void) const |
Return true if this language requires a prefix when expressing wide characters. More... | |
bool | checkArrayDeref (const Varnode *vn) const |
Determine whether a LOAD/STORE expression requires pointer '*' syntax. More... | |
void | emitStructDefinition (const TypeStruct *ct) |
Emit the definition of a structure data-type. More... | |
void | emitEnumDefinition (const TypeEnum *ct) |
Emit the definition of an enumeration data-type. More... | |
void | emitPrototypeOutput (const FuncProto *proto, const Funcdata *fd) |
Emit the output data-type of a function prototype. More... | |
void | emitPrototypeInputs (const FuncProto *proto) |
Emit the input data-types of a function prototype. More... | |
void | emitGlobalVarDeclsRecursive (Scope *scope) |
Emit variable declarations for all global symbols under given scope. More... | |
void | emitLocalVarDecls (const Funcdata *fd) |
Emit variable declarations for a function. More... | |
void | emitStatement (const PcodeOp *inst) |
Emit a statement in the body of a function. More... | |
bool | emitInplaceOp (const PcodeOp *op) |
Attempt to emit an expression rooted at an in-place operator. More... | |
void | emitGotoStatement (const FlowBlock *bl, const FlowBlock *exp_bl, uint4 type) |
Emit a statement representing an unstructured branch. More... | |
void | emitSwitchCase (int4 casenum, const BlockSwitch *switchbl) |
Emit labels for a case block. More... | |
void | emitLabel (const FlowBlock *bl) |
Emit a formal label for a given control-flow block. More... | |
void | emitLabelStatement (const FlowBlock *bl) |
Emit any required label statement for a given basic block. More... | |
void | emitAnyLabelStatement (const FlowBlock *bl) |
Emit any required label statement for a given control-flow block. More... | |
void | emitCommentGroup (const PcodeOp *inst) |
Emit comments associated with a given statement. More... | |
void | emitCommentFuncHeader (const Funcdata *fd) |
Emit comments in the given function's header. More... | |
void | opFunc (const PcodeOp *op) |
Push a functional expression based on the given p-code op to the RPN stack. More... | |
void | opTypeCast (const PcodeOp *op) |
Pus the given p-code op using type-cast syntax to the RPN stack. More... | |
bool | printCharacterConstant (ostream &s, const Address &addr, int4 charsize) const |
Print a quoted (unicode) string at the given address. More... | |
virtual void | pushConstant (uintb val, const Datatype *ct, const Varnode *vn, const PcodeOp *op) |
Push a constant onto the RPN stack. More... | |
virtual bool | pushEquate (uintb val, int4 sz, const EquateSymbol *sym, const Varnode *vn, const PcodeOp *op) |
Push a constant marked up by and EquateSymbol onto the RPN stack. More... | |
virtual void | pushAnnotation (const Varnode *vn, const PcodeOp *op) |
Push an address which is not in the normal data-flow. More... | |
virtual void | pushSymbol (const Symbol *sym, const Varnode *vn, const PcodeOp *op) |
Push a specific Symbol onto the RPN stack. More... | |
virtual void | pushUnnamedLocation (const Address &addr, const Varnode *vn, const PcodeOp *op) |
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) |
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) |
Push an identifier for a variable that mismatches with its Symbol. More... | |
virtual void | push_integer (uintb val, int4 sz, bool sign, const Varnode *vn, const PcodeOp *op) |
Push a constant with an integer data-type to the RPN stack. More... | |
virtual void | push_float (uintb val, int4 sz, const Varnode *vn, const PcodeOp *op) |
Push a constant with a floating-point data-type to the RPN stack. More... | |
virtual void | printUnicode (ostream &s, int4 onechar) const |
Print a single unicode character as a character constant for the high-level language. More... | |
virtual void | pushType (const Datatype *ct) |
Push a data-type name onto the RPN expression stack. More... | |
virtual string | genericFunctionName (const Address &addr) |
Create a generic function name base on the entry point address. More... | |
virtual string | genericTypeName (const Datatype *ct) |
Generate a generic name for an unnamed data-type. More... | |
virtual void | emitExpression (const PcodeOp *op) |
Emit a full expression. More... | |
virtual void | emitVarDecl (const Symbol *sym) |
Emit a variable declaration. More... | |
virtual void | emitVarDeclStatement (const Symbol *sym) |
Emit a variable declaration statement. More... | |
virtual bool | emitScopeVarDecls (const Scope *scope, int4 cat) |
Emit all the variable declarations for a given scope. More... | |
virtual void | emitFunctionDeclaration (const Funcdata *fd) |
Emit a function declaration. More... | |
virtual void | emitTypeDefinition (const Datatype *ct) |
Emit the definition of the given data-type. More... | |
virtual bool | checkPrintNegation (const Varnode *vn) |
Check whether a given boolean Varnode can be printed in negated form. More... | |
Protected Member Functions inherited from PrintLanguage | |
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... | |
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 | emitLineComment (int4 indent, const Comment *comm) |
Emit a comment line. More... | |
Static Protected Member Functions | |
static bool | hasCharTerminator (uint1 *buffer, int4 size, int4 charsize) |
Check if the byte buffer has a (unicode) string terminator. More... | |
Static Protected Member Functions inherited from PrintLanguage | |
static bool | unicodeNeedsEscape (int4 codepoint) |
Determine if the given codepoint needs to be escaped. More... | |
static void | writeUtf8 (ostream &s, int4 codepoint) |
Write unicode character to stream in UTF8 encoding. More... | |
static int4 | readUtf16 (const uint1 *buf, bool bigend) |
Read a 2-byte UTF16 element from a byte array. More... | |
static int4 | getCodepoint (const uint1 *buf, int4 charsize, bool bigend, int4 &skip) |
Extract the next unicode codepoint from an array of character data. More... | |
Protected Attributes | |
bool | option_NULL |
Set to true if we should emit NULL keyword. | |
bool | option_inplace_ops |
Set to true if we should use '+=' '&=' etc. | |
bool | option_convention |
Set to true if we should print calling convention. | |
bool | option_nocasts |
Don't print a cast if true. | |
bool | option_unplaced |
Set to true if we should display unplaced comments. | |
string | nullToken |
Token to use for 'null'. | |
CommentSorter | commsorter |
Container/organizer for comments in the current function. | |
Protected Attributes inherited from PrintLanguage | |
Architecture * | glb |
The Architecture owning the language emitter. | |
CastStrategy * | castStrategy |
The strategy for emitting explicit case operations. | |
EmitXml * | emit |
The low-level token emitter. | |
uint4 | mods |
Currently active printing modifications. | |
uint4 | instr_comment_type |
Type of instruction comments to display. | |
uint4 | head_comment_type |
Type of header comments to display. | |
Static Protected Attributes | |
static OpToken | scope = { "::", 2, 70, true, OpToken::binary, 0, 0, (OpToken *)0 } |
The sub-scope/namespace operator. | |
static OpToken | object_member = { ".", 2, 66, true, OpToken::binary, 0, 0, (OpToken *)0 } |
The member operator. | |
static OpToken | pointer_member = { "->", 2, 66, true, OpToken::binary, 0, 0, (OpToken *)0 } |
The points to member operator. | |
static OpToken | subscript = { "[]", 2, 66, false, OpToken::postsurround, 0, 0, (OpToken *)0 } |
The array subscript operator. | |
static OpToken | function_call = { "()", 2, 66, false, OpToken::postsurround, 0, 10, (OpToken *)0 } |
The function call operator. | |
static OpToken | bitwise_not = { "~", 1, 62, false, OpToken::unary_prefix, 0, 0, (OpToken *)0 } |
The bitwise negate operator. | |
static OpToken | boolean_not = { "!", 1, 62, false, OpToken::unary_prefix, 0, 0, (OpToken *)0 } |
The boolean not operator. | |
static OpToken | unary_minus = { "-", 1, 62, false, OpToken::unary_prefix, 0, 0, (OpToken *)0 } |
The unary minus operator. | |
static OpToken | unary_plus = { "+", 1, 62, false, OpToken::unary_prefix, 0, 0, (OpToken *)0 } |
The unary plus operator. | |
static OpToken | addressof = { "&", 1, 62, false, OpToken::unary_prefix, 0, 0, (OpToken *)0 } |
The address of operator. | |
static OpToken | dereference = { "*", 1, 62, false, OpToken::unary_prefix, 0, 0, (OpToken *)0 } |
The pointer dereference operator. | |
static OpToken | typecast = { "()", 2, 62, false, OpToken::presurround, 0, 0, (OpToken *)0 } |
The type cast operator. | |
static OpToken | multiply = { "*", 2, 54, true, OpToken::binary, 1, 0, (OpToken *)0 } |
The multiplication operator. | |
static OpToken | divide = { "/", 2, 54, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The division operator. | |
static OpToken | modulo = { "%", 2, 54, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The modulo operator. | |
static OpToken | binary_plus = { "+", 2, 50, true, OpToken::binary, 1, 0, (OpToken *)0 } |
The binary addition operator. | |
static OpToken | binary_minus = { "-", 2, 50, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The binary subtraction operator. | |
static OpToken | shift_left = { "<<", 2, 46, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The left shift operator. | |
static OpToken | shift_right = { ">>", 2, 46, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The right shift operator. | |
static OpToken | less_than = { "<", 2, 42, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The less than operator. | |
static OpToken | less_equal = { "<=", 2, 42, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The less than or equal operator. | |
static OpToken | greater_than = { ">", 2, 42, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The greater than operator. | |
static OpToken | greater_equal = { ">=", 2, 42, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The greater than or equal operator. | |
static OpToken | equal = { "==", 2, 38, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The equal operator. | |
static OpToken | not_equal = { "!=", 2, 38, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The not equal operator. | |
static OpToken | bitwise_and = { "&", 2, 34, true, OpToken::binary, 1, 0, (OpToken *)0 } |
The logical and operator. | |
static OpToken | bitwise_xor = { "^", 2, 30, true, OpToken::binary, 1, 0, (OpToken *)0 } |
The logical xor operator. | |
static OpToken | bitwise_or = { "|", 2, 26, true, OpToken::binary, 1, 0, (OpToken *)0 } |
The logical or operator. | |
static OpToken | boolean_and = { "&&", 2, 22, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The boolean and operator. | |
static OpToken | boolean_or = { "||", 2, 18, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The boolean or operator. | |
static OpToken | boolean_xor = { "^^", 2, 20, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The boolean xor operator. | |
static OpToken | assignment = { "=", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 } |
The assignment operator. | |
static OpToken | comma = { ",", 2, 2, true, OpToken::binary, 0, 0, (OpToken *)0 } |
The comma operator (for parameter lists) | |
static OpToken | new_op = { "", 2, 62, false, OpToken::space, 1, 0, (OpToken *)0 } |
The new operator. | |
static OpToken | multequal = { "*=", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 } |
The in-place multiplication operator. | |
static OpToken | divequal = { "/=", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 } |
The in-place division operator. | |
static OpToken | remequal = { "%=", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 } |
The in-place modulo operator. | |
static OpToken | plusequal = { "+=", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 } |
The in-place addition operator. | |
static OpToken | minusequal = { "-=", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 } |
The in-place subtraction operator. | |
static OpToken | leftequal = { "<<=", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 } |
The in-place left shift operator. | |
static OpToken | rightequal = { ">>=", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 } |
The in-place right shift operator. | |
static OpToken | andequal = { "&=", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 } |
The in-place logical and operator. | |
static OpToken | orequal = { "|=", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 } |
The in-place logical or operator. | |
static OpToken | xorequal = { "^=", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 } |
The in-place logical xor operator. | |
static OpToken | type_expr_space = { "", 2, 10, false, OpToken::space, 1, 0, (OpToken *)0 } |
Type declaration involving a space (identifier or adornment) | |
static OpToken | type_expr_nospace = { "", 2, 10, false, OpToken::space, 0, 0, (OpToken *)0 } |
Type declaration with no space. | |
static OpToken | ptr_expr = { "*", 1, 62, false, OpToken::unary_prefix, 0, 0, (OpToken *)0 } |
Pointer adornment for a type declaration. | |
static OpToken | array_expr = { "[]", 2, 66, false, OpToken::postsurround, 1, 0, (OpToken *)0 } |
Array adornment for a type declaration. | |
static OpToken | enum_cat = { "|", 2, 26, true, OpToken::binary, 0, 0, (OpToken *)0 } |
The concatenation operator for enumerated values. | |
Additional Inherited Members | |
Public Types inherited from PrintLanguage | |
enum | modifiers { force_hex = 1, force_dec = 2, bestfit = 4, force_scinote = 8, force_pointer = 0x10, print_load_value = 0x20, print_store_value = 0x40, no_branch = 0x80, only_branch = 0x100, comma_separate = 0x200, flat = 0x400, falsebranch = 0x800, nofallthru = 0x1000, negatetoken = 0x2000, hide_thisparam = 0x4000 } |
Possible context sensitive modifiers to how tokens get emitted. More... | |
enum | tagtype { syntax, vartoken, functoken, optoken, typetoken, fieldtoken, blanktoken } |
Possible types of Atom. More... | |
Static Public Member Functions inherited from PrintLanguage | |
static int4 | mostNaturalBase (uintb val) |
Determine the most natural base for an integer. More... | |
static void | formatBinary (ostream &s, uintb val) |
Print a number in binary form. More... | |
The c-language token emitter.
The c-language specific rules for emitting:
PrintC::PrintC | ( | Architecture * | g, |
const string & | nm = "c-language" |
||
) |
Constructor.
g | is the Architecture owning this c-language emitter |
nm | is the name assigned to this emitter |
References PrintLanguage::castStrategy, equal, greater_equal, greater_than, less_equal, less_than, OpToken::negate, not_equal, nullToken, option_convention, option_inplace_ops, option_nocasts, option_NULL, option_unplaced, and setCStyleComments().
|
protected |
Prepare to push components of a data-type declaration.
Push nested components of a data-type declaration onto a stack, so we can access it bottom up
ct | is the data-type being emitted |
typestack | will hold the sub-types involved in the displaying the declaration |
References Datatype::getMetatype(), Datatype::getName(), FuncProto::getOutputType(), TypeFactory::getTypeVoid(), PrintLanguage::glb, TYPE_ARRAY, TYPE_CODE, TYPE_PTR, and Architecture::types.
Referenced by pushTypeStart().
|
protected |
Determine whether a LOAD/STORE expression requires pointer '*' syntax.
An expression involving a LOAD or STORE can sometimes be emitted using array syntax (or field member syntax). This method determines if this kind of syntax is appropriate or if a '*' operator is required.
vn | is the root of the pointer expression (feeding into LOAD or STORE) |
References PcodeOp::code(), CPUI_PTRADD, CPUI_PTRSUB, CPUI_SEGMENTOP, Varnode::getDef(), PcodeOp::getIn(), Varnode::isImplied(), and Varnode::isWritten().
|
protectedvirtual |
Check whether a given boolean Varnode can be printed in negated form.
In many situations a boolean value can be inverted by flipping the operator token producing it to a complementary token.
vn | is the given boolean Varnode |
Implements PrintLanguage.
References PcodeOp::code(), CPUI_MAX, get_booleanflip(), Varnode::getDef(), Varnode::isImplied(), and Varnode::isWritten().
Referenced by opBoolNegate(), and opCbranch().
|
virtual |
Emit the declaration (and body) of a function.
fd | is the function to emit |
Implements PrintLanguage.
References EmitXml::beginFunction(), PrintLanguage::clear(), Architecture::commentdb, commsorter, PrintLanguage::emit, emitBlockGraph(), emitCommentFuncHeader(), emitFunctionDeclaration(), emitLocalVarDecls(), EmitXml::endFunction(), PrintLanguage::flat, EmitXml::flush(), Funcdata::getArch(), Funcdata::getBasicBlocks(), Funcdata::getStructure(), Funcdata::hasNoStructBlocks(), PrintLanguage::head_comment_type, PrintLanguage::instr_comment_type, Funcdata::isProcStarted(), PrintLanguage::isSet(), PrintLanguage::mods, option_unplaced, EmitXml::print(), CommentSorter::setupFunctionList(), EmitXml::startIndent(), EmitXml::stopIndent(), and EmitXml::tagLine().
|
virtual |
Emit the declaration for a single (global) Symbol.
sym | is the Symbol to declare |
Implements PrintLanguage.
References EmitXml::beginDocument(), PrintLanguage::emit, emitVarDeclStatement(), EmitXml::endDocument(), EmitXml::flush(), and EmitXml::tagLine().
|
virtual |
Emit definitions of data-types.
typegrp | is the container for the data-types that should be defined |
Implements PrintLanguage.
References TypeFactory::dependentOrder(), and emitTypeDefinition().
|
protectedvirtual |
Return true if this language requires a prefix when expressing wide characters.
The c-language standard requires that strings (and character constants) made up of wide character elements have an 'L' prefix added before the quote characters. Other related languages may not do this. Having this as a virtual method lets derived languages to tailor their strings while still using the basic PrintC functionality
Reimplemented in PrintJava.
Referenced by printCharacterConstant(), push_integer(), and pushCharConstant().
|
protected |
Emit any required label statement for a given control-flow block.
The block does not have to be a basic block. This routine finds the entry basic block and prints any necessary labels for that.
bl | is the given control-flow block |
References emitLabelStatement(), FlowBlock::getFrontLeaf(), and FlowBlock::isLabelBumpUp().
Referenced by emitBlockCopy(), emitBlockDoWhile(), emitBlockInfLoop(), and emitBlockWhileDo().
|
protected |
Emit comments in the given function's header.
Collect all comment lines marked as header for the function and emit them with the appropriate delimiters.
fd | is the given function |
References commsorter, PrintLanguage::emit, PrintLanguage::emitLineComment(), Funcdata::getAddress(), CommentSorter::getNext(), Comment::getType(), CommentSorter::hasNext(), PrintLanguage::head_comment_type, CommentSorter::header_basic, CommentSorter::header_unplaced, option_nocasts, option_unplaced, CommentSorter::setupHeader(), EmitXml::tagLine(), and Comment::warningheader.
Referenced by docFunction().
|
protected |
Emit comments associated with a given statement.
Collect any comment lines the sorter has associated with a statement rooted at a given PcodeOp and emit them using appropriate delimiters
inst | is the given PcodeOp |
References commsorter, PrintLanguage::emitLineComment(), CommentSorter::getNext(), Comment::getType(), CommentSorter::hasNext(), PrintLanguage::instr_comment_type, and CommentSorter::setupOpList().
Referenced by emitBlockBasic().
|
protected |
Emit the definition of an enumeration data-type.
Print all the named values making up the data-type, using the enum keyword
ct | is the enumerated data-type |
References TypeEnum::beginEnum(), PrintLanguage::clear(), EmitXml::const_color, PrintLanguage::emit, TypeEnum::endEnum(), Datatype::getMetatype(), Datatype::getName(), Datatype::getSize(), EmitXml::keyword_color, EmitXml::no_color, PrintLanguage::popMod(), EmitXml::print(), push_integer(), PrintLanguage::pushMod(), PrintLanguage::recurse(), EmitXml::spaces(), EmitXml::startIndent(), EmitXml::stopIndent(), EmitXml::tagLine(), and TYPE_INT.
Referenced by emitTypeDefinition().
|
protectedvirtual |
Emit a full expression.
This can be an assignment statement, if the given PcodeOp has an output Varnode, or it can be a statement with no left-hand side.
op | is the given PcodeOp performing the final operation of the expression |
Implements PrintLanguage.
References assignment, PcodeOp::doesSpecialPrinting(), emitInplaceOp(), Varnode::getDef(), PcodeOp::getIn(), PcodeOp::getOut(), opConstructor(), option_inplace_ops, PcodeOp::push(), PrintLanguage::pushOp(), PrintLanguage::pushVnLHS(), and PrintLanguage::recurse().
Referenced by emitBlockBasic(), and emitStatement().
|
protectedvirtual |
Emit a function declaration.
This prints the formal defining prototype for a function.
fd | is the Funcdata object representing the function to be emitted |
Implements PrintLanguage.
References EmitXml::beginFuncProto(), OpToken::bump, EmitXml::closeGroup(), EmitXml::closeParen(), Architecture::defaultfp, PrintLanguage::emit, emitPrototypeInputs(), emitPrototypeOutput(), EmitXml::endFuncProto(), EmitXml::funcname_color, function_call, Funcdata::getArch(), Funcdata::getFuncProto(), FuncProto::getModelName(), Funcdata::getName(), FuncProto::hasMatchingModel(), FuncProto::hasModel(), EmitXml::keyword_color, EmitXml::openGroup(), EmitXml::openParen(), option_convention, EmitXml::print(), EmitXml::spaces(), OpToken::spacing, and EmitXml::tagFuncName().
Referenced by docFunction().
|
protected |
Emit variable declarations for all global symbols under given scope.
For the given scope and all of its children that are not function scopes, emit a variable declaration for each symbol.
scope | is the given scope |
References emitScopeVarDecls(), and scope.
Referenced by docAllGlobals().
|
protected |
Emit a statement representing an unstructured branch.
Given the type of unstructured branch, with source and destination blocks, construct a statement with the appropriate c-language keyword (goto, break, continue) representing a control-flow branch between the blocks.
bl | is the source block |
exp_bl | is the destination block (which may provide a label) |
type | is the given type of the branch |
References EmitXml::beginStatement(), PrintLanguage::emit, emitLabel(), EmitXml::endStatement(), FlowBlock::f_break_goto, FlowBlock::f_continue_goto, FlowBlock::f_goto_goto, EmitXml::keyword_color, FlowBlock::lastOp(), EmitXml::print(), and EmitXml::spaces().
Referenced by emitBlockGoto(), emitBlockIf(), emitBlockSwitch(), and emitBlockWhileDo().
|
protected |
Attempt to emit an expression rooted at an in-place operator.
Check that the given p-code op has an in-place token form and if the first input and the output are references to the same variable. If so, emit the expression using the in-place token.
op | is the given PcodeOp |
References andequal, PcodeOp::code(), CPUI_INT_ADD, CPUI_INT_AND, CPUI_INT_DIV, CPUI_INT_LEFT, CPUI_INT_MULT, CPUI_INT_OR, CPUI_INT_REM, CPUI_INT_RIGHT, CPUI_INT_SDIV, CPUI_INT_SREM, CPUI_INT_SRIGHT, CPUI_INT_SUB, CPUI_INT_XOR, divequal, Varnode::getHigh(), PcodeOp::getIn(), PcodeOp::getOut(), leftequal, minusequal, PrintLanguage::mods, multequal, orequal, plusequal, PrintLanguage::pushOp(), PrintLanguage::pushVnExplicit(), PrintLanguage::pushVnImplied(), PrintLanguage::recurse(), remequal, rightequal, and xorequal.
Referenced by emitExpression().
|
protected |
Emit a formal label for a given control-flow block.
Check for an explicit label that has been registered with the basic block. Otherwise, construct a generic label based on the entry address of the block. Emit the label as a single token.
bl | is the given block |
References PrintLanguage::emit, BlockBasic::getEntryAddr(), FlowBlock::getFrontLeaf(), Symbol::getName(), Address::getOffset(), Address::getShortcut(), Address::getSpace(), BlockBasic::getType(), FlowBlock::hasSpecialLabel(), FlowBlock::isDuplicated(), FlowBlock::isJoined(), EmitXml::no_color, Address::printRaw(), scope, FlowBlock::subBlock(), and EmitXml::tagLabel().
Referenced by emitBlockBasic(), emitGotoStatement(), and emitLabelStatement().
|
protected |
Emit any required label statement for a given basic block.
If the basic block is the destination of a goto statement, emit a label for the block followed by the ':' terminator.
bl | is the given control-flow block |
References PrintLanguage::emit, emitLabel(), PrintLanguage::flat, FlowBlock::getType(), FlowBlock::isJumpTarget(), PrintLanguage::isSet(), FlowBlock::isUnstructuredTarget(), PrintLanguage::only_branch, EmitXml::print(), and EmitXml::tagLine().
Referenced by emitAnyLabelStatement(), and emitBlockBasic().
|
protected |
Emit variable declarations for a function.
A formal variable declaration is emitted for every symbol in the given function scope. I.e. all local variables are declared.
fd | is the function being emitted |
References Scope::childrenBegin(), Scope::childrenEnd(), PrintLanguage::emit, emitScopeVarDecls(), Funcdata::getScopeLocal(), and EmitXml::tagLine().
Referenced by docFunction().
|
protected |
Emit the input data-types of a function prototype.
This emits the individual type declarations of the input parameters to the function as a comma separated list.
proto | is the given prototype of the function |
References PrintLanguage::blanktoken, PrintLanguage::emit, emitVarDecl(), FuncProto::getParam(), ProtoParameter::getSymbol(), ProtoParameter::getType(), FuncProto::isDotdotdot(), EmitXml::keyword_color, EmitXml::no_color, FuncProto::numParams(), EmitXml::print(), PrintLanguage::pushAtom(), pushTypeEnd(), pushTypeStart(), and PrintLanguage::recurse().
Referenced by emitFunctionDeclaration().
Emit the output data-type of a function prototype.
In C, when printing a function prototype, the function's output data-type is displayed first as a type declaration, where the function name acts as the declaration's identifier. This method emits the declaration in preparation for this.
proto | is the function prototype object |
fd | is the (optional) Funcdata object providing additional meta-data about the function |
References EmitXml::beginReturnType(), Funcdata::canonicalReturnOp(), PrintLanguage::emit, EmitXml::endReturnType(), PcodeOp::getIn(), Datatype::getMetatype(), FuncProto::getOutputType(), pushType(), PrintLanguage::recurse(), and TYPE_VOID.
Referenced by emitFunctionDeclaration().
|
protectedvirtual |
Emit all the variable declarations for a given scope.
A subset of all variables can be declared by specifying a category, 0 for parameters, -1 for everything.
scope | is the given Scope |
cat | is the category of variable to declare |
Implements PrintLanguage.
References emitVarDeclStatement(), Symbol::getCategory(), Symbol::getName(), Symbol::isNameUndefined(), and scope.
Referenced by emitGlobalVarDeclsRecursive(), and emitLocalVarDecls().
|
protected |
Emit a statement in the body of a function.
This emits an entire statement rooted at a given operation. All associated expressions on the right-hand and left-hand sides are recursively emitted. Depending on the current printing properties, the statement is usually terminated with ';' character.
inst | is the given root PcodeOp of the statement |
References EmitXml::beginStatement(), PrintLanguage::comma_separate, PrintLanguage::emit, emitExpression(), EmitXml::endStatement(), PrintLanguage::isSet(), and EmitXml::print().
Referenced by emitBlockBasic().
|
protected |
Emit the definition of a structure data-type.
Print all the components making up the data-type, using the struct keyword
ct | is the structure data-type |
References TypeStruct::beginField(), PrintLanguage::clear(), PrintLanguage::emit, TypeStruct::endField(), Datatype::getName(), EmitXml::keyword_color, EmitXml::print(), PrintLanguage::pushAtom(), pushTypeEnd(), pushTypeStart(), EmitXml::spaces(), EmitXml::startIndent(), EmitXml::stopIndent(), PrintLanguage::syntax, EmitXml::tagLine(), and EmitXml::var_color.
Referenced by emitTypeDefinition().
|
protected |
Emit labels for a case block.
Given a switch block and an index indicating a particular case block, look up all the labels associated with that case and emit them using formal labels with the case keyword and a ':' terminator.
casenum | is the given index of the case block |
switchbl | is the root block of the switch |
References PrintLanguage::emit, BlockSwitch::getLabel(), BlockSwitch::getNumLabels(), BlockSwitch::getSwitchType(), BlockSwitch::isDefaultCase(), EmitXml::keyword_color, EmitXml::print(), pushConstant(), PrintLanguage::recurse(), EmitXml::spaces(), and EmitXml::tagLine().
Referenced by emitBlockSwitch().
|
protectedvirtual |
Emit the definition of the given data-type.
This is currently limited to a 'struct' or 'enum' definitions. The definition is emitted so that name associated with data-type object will be associated with the definition (in anything that parses it)
ct | is the given data-type |
References PrintLanguage::clear(), emitEnumDefinition(), emitStructDefinition(), Datatype::getMetatype(), Datatype::isEnumType(), and TYPE_STRUCT.
Referenced by docTypeDefinitions().
|
protectedvirtual |
Emit a variable declaration.
This can be part of a full a statement, or just the declaration of a function parameter
sym | is the Symbol to be declared |
Implements PrintLanguage.
References EmitXml::beginVarDecl(), PrintLanguage::emit, EmitXml::endVarDecl(), Symbol::getType(), pushSymbol(), pushTypeEnd(), pushTypeStart(), and PrintLanguage::recurse().
Referenced by emitPrototypeInputs(), and emitVarDeclStatement().
|
protectedvirtual |
Emit a variable declaration statement.
sym | is the Symbol to be declared |
Implements PrintLanguage.
References PrintLanguage::emit, emitVarDecl(), EmitXml::print(), and EmitXml::tagLine().
Referenced by docSingleGlobal(), and emitScopeVarDecls().
|
protectedvirtual |
Create a generic function name base on the entry point address.
addr | is the entry point address of the function |
References Address::printRaw().
Referenced by opCall().
|
protectedvirtual |
Generate a generic name for an unnamed data-type.
ct | is the given data-type |
References Datatype::getMetatype(), Datatype::getSize(), TYPE_FLOAT, TYPE_INT, TYPE_SPACEBASE, TYPE_UINT, and TYPE_UNKNOWN.
Referenced by PrintJava::pushTypeStart(), and pushTypeStart().
|
staticprotected |
Check if the byte buffer has a (unicode) string terminator.
buffer | is the byte buffer |
size | is the number of bytes in the buffer |
charsize | is the presumed size (in bytes) of character elements |
Referenced by printCharacterConstant().
|
virtual |
Decide is the given byte array looks like a character string.
This looks for encodings and/or a terminator that is appropriate for the high-level language
buf | is a pointer to the byte array |
size | is the number of bytes in the array |
charsize | is the size in bytes of the encoding element (i.e. UTF8, UTF16, etc.) to assume |
Implements PrintLanguage.
References PrintLanguage::getCodepoint(), PrintLanguage::glb, Translate::isBigEndian(), and Architecture::translate.
Referenced by printCharacterConstant().
|
virtual |
Print the BOOL_NEGATE but check for opportunities to flip the next operator instead
op | is the BOOL_NEGATE PcodeOp |
Implements PrintLanguage.
References boolean_not, checkPrintNegation(), PcodeOp::getIn(), PrintLanguage::isSet(), PrintLanguage::mods, PrintLanguage::negatetoken, PrintLanguage::pushOp(), PrintLanguage::pushVnImplied(), and PrintLanguage::unsetMod().
|
virtual |
Print the branching condition:
op | is the CBRANCH PcodeOp |
Implements PrintLanguage.
References boolean_not, checkPrintNegation(), EmitXml::closeGroup(), EmitXml::closeParen(), PrintLanguage::comma_separate, PrintLanguage::emit, PrintLanguage::falsebranch, PrintLanguage::flat, PcodeOp::getIn(), PcodeOp::isBooleanFlip(), PcodeOp::isFallthruTrue(), PrintLanguage::isSet(), EmitXml::keyword_color, PrintLanguage::mods, PrintLanguage::negatetoken, EmitXml::openGroup(), EmitXml::openParen(), EmitXml::print(), PrintLanguage::pushOp(), PrintLanguage::pushVnImplied(), PrintLanguage::recurse(), EmitXml::spaces(), and EmitXml::tagOp().
|
protected |
Push a functional expression based on the given p-code op to the RPN stack.
This is used for expression that require functional syntax, where the name of the function is the name of the operator. The inputs to the p-code op form the roots of the comma separated list of parameters within the syntax.
op | is the given PcodeOp |
References PrintLanguage::blanktoken, comma, function_call, PcodeOp::getIn(), PcodeOp::getOpcode(), TypeOp::getOperatorName(), PrintLanguage::mods, EmitXml::no_color, PcodeOp::numInput(), PrintLanguage::optoken, PrintLanguage::pushAtom(), PrintLanguage::pushOp(), and PrintLanguage::pushVnImplied().
Referenced by opFloatAbs(), opFloatCeil(), opFloatFloor(), opFloatNan(), opFloatRound(), opFloatSqrt(), opIntCarry(), opIntSborrow(), opIntScarry(), opIntSext(), opIntZext(), opPiece(), and opSubpiece().
|
virtual |
We need to distinguish between the following cases:
Then the printing breaks up into the following table:
The '&' is dropped if the output type is an array
op | is the PTRSUB PcodeOp |
Implements PrintLanguage.
References addressof, AddrSpace::addressToByte(), PrintLanguage::clear(), dereference, PrintLanguage::fieldtoken, SymbolEntry::getAddr(), PcodeOp::getAddr(), TypeSpacebase::getAddress(), Varnode::getHigh(), PcodeOp::getIn(), TypeSpacebase::getMap(), Datatype::getMetatype(), Address::getOffset(), SymbolEntry::getOffset(), Varnode::getOffset(), TypePointer::getPtrTo(), Datatype::getSize(), Varnode::getSize(), SymbolEntry::getSymbol(), HighVariable::getType(), Symbol::getType(), TypePointer::getWordSize(), Address::isInvalid(), PrintLanguage::mods, TypeField::name, EmitXml::no_color, object_member, TypeField::offset, pointer_member, PrintLanguage::print_load_value, PrintLanguage::print_store_value, push_integer(), PrintLanguage::pushAtom(), PrintLanguage::pushOp(), pushPartialSymbol(), pushSymbol(), pushUnnamedLocation(), PrintLanguage::pushVnImplied(), scope, subscript, TypeField::type, TYPE_ARRAY, TYPE_CODE, TYPE_PTR, TYPE_SPACEBASE, and TYPE_STRUCT.
|
virtual |
op | is the SEGMENTOP PcodeOp |
Implements PrintLanguage.
References PcodeOp::getIn(), PrintLanguage::mods, and PrintLanguage::pushVnImplied().
|
protected |
Pus the given p-code op using type-cast syntax to the RPN stack.
The syntax represents the given op using a standard c-language cast. The data-type being cast to is obtained from the output variable of the op. The input expression is also recursively pushed.
op | is the given PcodeOp |
References Varnode::getHigh(), PcodeOp::getIn(), PcodeOp::getOut(), HighVariable::getType(), PrintLanguage::mods, option_nocasts, PrintLanguage::pushOp(), pushType(), PrintLanguage::pushVnImplied(), and typecast.
Referenced by opCast(), opFloatFloat2Float(), opFloatInt2Float(), opFloatTrunc(), opIntSext(), opIntZext(), and opSubpiece().
|
protected |
Print a quoted (unicode) string at the given address.
Data for the string is obtained directly from the LoadImage. The bytes are checked for appropriate unicode encoding and the presence of a terminator. If all these checks pass, the string is emitted.
s | is the output stream to print to |
addr | is the address of the string data within the LoadImage |
charsize | is the number of bytes in an encoded element (i.e. UTF8, UTF16, or UTF32) |
References doEmitWideCharPrefix(), PrintLanguage::escapeCharacterData(), PrintLanguage::glb, hasCharTerminator(), Translate::isBigEndian(), isCharacterConstant(), Architecture::loader, LoadImage::loadFill(), and Architecture::translate.
Referenced by pushPtrCharConstant(), and pushSymbol().
|
protectedvirtual |
Print a single unicode character as a character constant for the high-level language.
For most languages, this prints the character surrounded by single quotes.
s | is the output stream |
onechar | is the unicode code point of the character to print |
Implements PrintLanguage.
Reimplemented in PrintJava.
References PrintLanguage::unicodeNeedsEscape(), and PrintLanguage::writeUtf8().
Referenced by push_integer(), and pushCharConstant().
|
protectedvirtual |
Push a constant with a floating-point data-type to the RPN stack.
The encoding is drawn from the underlying Translate object, and the print properties are checked for formatting overrides. In any case, a format is decided upon, and the constant is pushed as a single token.
val | is the given encoded floating-point value |
sz | is the size (in bytes) of the encoded value |
vn | is the Varnode holding the value |
op | is the PcodeOp using the value |
References EmitXml::const_color, FloatFormat::extractSign(), PrintLanguage::force_scinote, Translate::getFloatFormat(), FloatFormat::getHostFloat(), PrintLanguage::glb, FloatFormat::infinity, PrintLanguage::mods, FloatFormat::nan, PrintLanguage::pushAtom(), PrintLanguage::syntax, Architecture::translate, and PrintLanguage::vartoken.
Referenced by pushConstant().
|
protectedvirtual |
Push a constant with an integer data-type to the RPN stack.
Various checks are made to see if the integer should be printed as an equate symbol or if there is other overriding information about what format it should be printed in. In any case, a final determination of the format is made and the integer is pushed as a single token.
val | is the given integer value |
sz | is the size (in bytes) to associate with the integer |
sign | is set to true if the integer should be treated as a signed value |
vn | is the Varnode holding the value |
op | is the PcodeOp using the value |
References calc_mask(), EmitXml::const_color, doEmitWideCharPrefix(), Symbol::force_char, PrintLanguage::force_dec, Symbol::force_dec, PrintLanguage::force_hex, Symbol::force_hex, Symbol::force_oct, PrintLanguage::formatBinary(), Symbol::getCategory(), Symbol::getDisplayFormat(), Varnode::getHigh(), HighVariable::getSymbol(), Varnode::isAnnotation(), Symbol::isNameLocked(), Varnode::isUnsignedPrint(), PrintLanguage::mods, PrintLanguage::mostNaturalBase(), printUnicode(), PrintLanguage::pushAtom(), pushEquate(), PrintLanguage::syntax, and PrintLanguage::vartoken.
Referenced by emitEnumDefinition(), PrintJava::opLoad(), opPtrsub(), PrintJava::opStore(), pushCharConstant(), pushConstant(), pushEnumConstant(), pushEquate(), and pushTypeEnd().
Push an address which is not in the normal data-flow.
The given Varnode is treated as an address, which may or may not have a symbol name.
Implements PrintLanguage.
References AddrSpace::byteToAddress(), PcodeOp::code(), CPUI_CALLOTHER, PcodeOp::getAddr(), Varnode::getAddr(), TypeFactory::getBase(), SymbolEntry::getFirst(), BlockBasic::getFuncdata(), PcodeOp::getIn(), UserPcodeOp::getIndex(), Varnode::getOffset(), PcodeOp::getOut(), PcodeOp::getParent(), Translate::getRegisterName(), Funcdata::getScopeLocal(), SymbolEntry::getSize(), Varnode::getSize(), Varnode::getSpace(), SymbolEntry::getSymbol(), UserOpManage::getVolatileRead(), UserOpManage::getVolatileWrite(), AddrSpace::getWordSize(), PrintLanguage::glb, PrintLanguage::pushAtom(), pushConstant(), pushPartialSymbol(), pushSymbol(), scope, Architecture::translate, TYPE_UINT, Architecture::types, Architecture::userops, EmitXml::var_color, and PrintLanguage::vartoken.
|
protected |
Push a true or false token to the RPN stack.
A single Atom representing the boolean value is emitted
val | is the boolean value (non-zero for true) |
ct | is the data-type associated with the value |
vn | is the Varnode holding the value |
op | is the PcodeOp using the value |
References EmitXml::const_color, PrintLanguage::pushAtom(), and PrintLanguage::vartoken.
Referenced by pushConstant().
|
protected |
Push a single character constant to the RPN stack.
For C, a character constant is usually emitted as the character in single quotes. Handle unicode, wide characters, etc.
val | is the constant value |
ct | is data-type attached to the value |
vn | is the Varnode holding the value |
op | is the PcodeOp using the value |
References EmitXml::const_color, doEmitWideCharPrefix(), Datatype::getSize(), printUnicode(), push_integer(), PrintLanguage::pushAtom(), and PrintLanguage::vartoken.
Referenced by pushConstant().
|
protectedvirtual |
Push a constant onto the RPN stack.
The value is ultimately emitted based on its data-type and other associated mark-up
val | is the value of the constant |
ct | is the data-type of the constant |
vn | is the Varnode holding the constant (optional) |
op | is the PcodeOp using the constant (optional) |
Implements PrintLanguage.
References PrintLanguage::clear(), PrintLanguage::force_dec, PrintLanguage::force_hex, Datatype::getMetatype(), Datatype::getSize(), Datatype::isCharPrint(), Datatype::isEnumType(), PrintLanguage::isSet(), nullToken, option_nocasts, option_NULL, PrintLanguage::popMod(), push_float(), push_integer(), PrintLanguage::pushAtom(), pushBoolConstant(), pushCharConstant(), pushEnumConstant(), PrintLanguage::pushMod(), PrintLanguage::pushOp(), pushPtrCharConstant(), pushPtrCodeConstant(), pushType(), PrintLanguage::setMod(), TYPE_ARRAY, TYPE_BOOL, TYPE_CODE, TYPE_FLOAT, TYPE_INT, TYPE_PTR, TYPE_SPACEBASE, TYPE_STRUCT, TYPE_UINT, TYPE_UNKNOWN, TYPE_VOID, typecast, EmitXml::var_color, and PrintLanguage::vartoken.
Referenced by emitSwitchCase(), and pushAnnotation().
|
protected |
Push an enumerated value to the RPN stack.
Handle cases where the value is built out of multiple named elements of the enumeration or where the value cannot be expressed using named elements
val | is the enumerated value being pushed |
ct | is the enumerated data-type attached to the value |
vn | is the Varnode holding the value |
op | is the PcodeOp using the value |
References bitwise_not, EmitXml::const_color, enum_cat, TypeEnum::getMatches(), Datatype::getSize(), push_integer(), PrintLanguage::pushAtom(), PrintLanguage::pushOp(), and PrintLanguage::vartoken.
Referenced by pushConstant().
|
protectedvirtual |
Push a constant marked up by and EquateSymbol onto the RPN stack.
The equate may substitute a name or force a conversion for the constant
val | is the value of the constant |
sz | is the number of bytes to use for the encoding |
sym | is the EquateSymbol that marks up the constant |
vn | is the Varnode holding the constant (optional) |
op | is the PcodeOp using the constant (optional) |
Implements PrintLanguage.
References binary_minus, binary_plus, bitwise_not, calc_mask(), EquateSymbol::getValue(), push_integer(), PrintLanguage::pushOp(), pushSymbol(), sign_extend(), and unary_minus.
Referenced by push_integer().
|
protectedvirtual |
Push an identifier for a variable that mismatches with its Symbol.
This happens when a Varnode overlaps, but is not contained by a Symbol. This most commonly happens when the size of a Symbol is unknown
sym | is the overlapped symbol |
off | is the byte offset of the variable relative to the symbol |
sz | is the size of the variable in bytes |
vn | is the Varnode representing the variable |
op | is a PcodeOp associated with the Varnode |
Implements PrintLanguage.
References Varnode::getAddr(), Symbol::getName(), PrintLanguage::name, PrintLanguage::pushAtom(), pushUnnamedLocation(), EmitXml::var_color, and PrintLanguage::vartoken.
|
protectedvirtual |
Push a variable that represents only part of a symbol onto the RPN stack.
Generally member syntax specifying a field within a structure gets emitted.
sym | is the root Symbol |
off | is the byte offset, within the Symbol, of the partial variable |
sz | is the number of bytes in the partial variable |
vn | is the Varnode holding the partial value |
op | is a PcodeOp associate with the Varnode |
outtype | is the data-type expected by expression using the partial variable |
Implements PrintLanguage.
References PrintLanguage::castStrategy, EmitXml::const_color, PrintLanguage::fieldtoken, SymbolEntry::getAddr(), Symbol::getFirstWholeMap(), Datatype::getMetatype(), Datatype::getSize(), Address::getSpace(), Symbol::getType(), AddrSpace::isBigEndian(), CastStrategy::isSubpieceCastEndian(), TypeField::name, EmitXml::no_color, object_member, TypeField::offset, option_nocasts, PrintLanguage::pushAtom(), PrintLanguage::pushOp(), pushSymbol(), pushType(), subscript, PrintLanguage::syntax, PartialSymbolEntry::token, TypeField::type, TYPE_ARRAY, TYPE_STRUCT, and typecast.
Referenced by opPtrsub(), and pushAnnotation().
|
protected |
Push input parameters.
Push the comma separated list of data-type declarations onto the RPN stack as part of emitting a given function prototype
proto | is the given function prototype |
References PrintLanguage::blanktoken, comma, FuncProto::getParam(), ProtoParameter::getType(), FuncProto::isDotdotdot(), EmitXml::keyword_color, EmitXml::no_color, FuncProto::numParams(), PrintLanguage::pushAtom(), PrintLanguage::pushOp(), pushTypeEnd(), pushTypeStart(), and PrintLanguage::syntax.
Referenced by pushTypeEnd().
|
protectedvirtual |
Attempt to push a quoted string representing a given constant pointer onto the RPN stack.
Check if the constant pointer refers to character data that can be emitted as a quoted string. If so push the string, if not return false to indicate a token was not pushed
val | is the value of the given constant pointer |
ct | is the pointer data-type attached to the value |
vn | is the Varnode holding the value |
op | is the PcodeOp using the value |
References EmitXml::const_color, PcodeOp::getAddr(), AddrSpaceManager::getDefaultSpace(), Database::getGlobalScope(), TypePointer::getPtrTo(), Datatype::getSize(), PrintLanguage::glb, Address::isInvalid(), Scope::isReadOnly(), printCharacterConstant(), PrintLanguage::pushAtom(), AddrSpaceManager::resolveConstant(), Architecture::symboltab, and PrintLanguage::vartoken.
Referenced by pushConstant().
|
protected |
Attempt to push a function name representing a constant pointer onto the RPN stack.
Given the pointer value, try to look up the function at that address and push the function's name as a single Atom.
val | is the given constant pointer value |
ct | is the pointer data-type attached to the value |
vn | is the Varnode holding the value |
op | is the PcodeOp using the value |
References AddrSpace::addressToByte(), EmitXml::funcname_color, PrintLanguage::functoken, AddrSpaceManager::getDefaultSpace(), Database::getGlobalScope(), AddrSpace::getWordSize(), PrintLanguage::glb, PrintLanguage::pushAtom(), Scope::queryFunction(), and Architecture::symboltab.
Referenced by pushConstant().
|
protectedvirtual |
Push a specific Symbol onto the RPN stack.
sym | is the given Symbol |
vn | is the Varnode holding the Symbol value |
op | is a PcodeOp associated with the Varnode |
Implements PrintLanguage.
References EmitXml::const_color, SymbolEntry::getAddr(), Symbol::getCategory(), Symbol::getFirstWholeMap(), Symbol::getFlags(), Datatype::getMetatype(), Symbol::getName(), Symbol::getScope(), Datatype::getSize(), Symbol::getType(), EmitXml::global_color, Datatype::isCharPrint(), Scope::isGlobal(), EmitXml::param_color, printCharacterConstant(), PrintLanguage::pushAtom(), Varnode::readonly, TYPE_ARRAY, EmitXml::var_color, and PrintLanguage::vartoken.
Referenced by emitVarDecl(), opPtrsub(), pushAnnotation(), pushEquate(), and pushPartialSymbol().
|
protectedvirtual |
Push a data-type name onto the RPN expression stack.
The data-type is generally emitted as if for a cast.
ct | is the data-type to push |
Implements PrintLanguage.
References PrintLanguage::blanktoken, EmitXml::no_color, PrintLanguage::pushAtom(), pushTypeEnd(), and pushTypeStart().
Referenced by emitPrototypeOutput(), opTypeCast(), pushConstant(), and pushPartialSymbol().
|
protectedvirtual |
Push the tail ends of a data-type declaration onto the RPN stack.
Because the front-ends were pushed on base-type -> final-modifier, the tail-ends are pushed on final-modifier -> base-type. The tail-ends amount to
ct | is the data-type being pushed |
Reimplemented in PrintJava.
References PrintLanguage::blanktoken, PrintLanguage::force_dec, TypeArray::getBase(), Datatype::getMetatype(), Datatype::getName(), FuncProto::getOutputType(), TypeCode::getPrototype(), EmitXml::no_color, TypeArray::numElements(), PrintLanguage::popMod(), push_integer(), PrintLanguage::pushAtom(), PrintLanguage::pushMod(), pushPrototypeInputs(), PrintLanguage::setMod(), TYPE_ARRAY, TYPE_CODE, and TYPE_PTR.
Referenced by emitPrototypeInputs(), emitStructDefinition(), emitVarDecl(), pushPrototypeInputs(), and pushType().
|
protectedvirtual |
Push part of a data-type declaration onto the RPN stack, up to the identifier.
Store off array sizes for printing after the identifier
ct | is the data-type to push |
noident | is true if an identifier will not be pushed as part of the declaration |
Reimplemented in PrintJava.
References array_expr, buildTypeStack(), PrintLanguage::clear(), function_call, genericTypeName(), Datatype::getMetatype(), Datatype::getName(), PrintLanguage::name, ptr_expr, PrintLanguage::pushAtom(), PrintLanguage::pushOp(), TYPE_ARRAY, TYPE_CODE, EmitXml::type_color, type_expr_nospace, type_expr_space, TYPE_PTR, and PrintLanguage::typetoken.
Referenced by emitPrototypeInputs(), emitStructDefinition(), emitVarDecl(), pushPrototypeInputs(), and pushType().
|
protectedvirtual |
Push an address as a substitute for a Symbol onto the RPN stack.
If there is no Symbol or other name source for an explicit variable, this method is used to print something to represent the variable based on its storage address.
addr | is the storage address |
vn | is the Varnode representing the variable (if present) |
op | is a PcodeOp associated with the variable |
Implements PrintLanguage.
References AddrSpace::getName(), Address::getSpace(), Address::printRaw(), PrintLanguage::pushAtom(), EmitXml::var_color, and PrintLanguage::vartoken.
Referenced by opPtrsub(), and pushMismatchSymbol().
|
virtual |
Set the way comments are displayed in decompiler output.
This method can either be provided a formal name or a sample of the initial delimiter, then it will choose from among the schemes it knows
nm | is the configuration description |
Implements PrintLanguage.
References setCPlusPlusStyleComments(), and setCStyleComments().