decompiler  1.0.0
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
PrintC Class Reference

The c-language token emitter. More...

#include <printc.hh>

Inheritance diagram for PrintC:
PrintLanguage PrintJava

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.
 
CastStrategygetCastStrategy (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
Architectureglb
 The Architecture owning the language emitter.
 
CastStrategycastStrategy
 The strategy for emitting explicit case operations.
 
EmitXmlemit
 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...
 

Detailed Description

The c-language token emitter.

The c-language specific rules for emitting:

Constructor & Destructor Documentation

◆ PrintC()

PrintC::PrintC ( Architecture g,
const string &  nm = "c-language" 
)

Constructor.

Parameters
gis the Architecture owning this c-language emitter
nmis 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().

Member Function Documentation

◆ buildTypeStack()

void PrintC::buildTypeStack ( const Datatype ct,
vector< const Datatype * > &  typestack 
)
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

Parameters
ctis the data-type being emitted
typestackwill 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().

◆ checkArrayDeref()

bool PrintC::checkArrayDeref ( const Varnode vn) const
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.

Parameters
vnis the root of the pointer expression (feeding into LOAD or STORE)
Returns
false if '*' syntax is required, true if some other syntax is used

References PcodeOp::code(), CPUI_PTRADD, CPUI_PTRSUB, CPUI_SEGMENTOP, Varnode::getDef(), PcodeOp::getIn(), Varnode::isImplied(), and Varnode::isWritten().

Referenced by opLoad(), and opStore().

◆ checkPrintNegation()

bool PrintC::checkPrintNegation ( const Varnode vn)
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.

Parameters
vnis the given boolean Varnode
Returns
true if the value can be easily inverted

Implements PrintLanguage.

References PcodeOp::code(), CPUI_MAX, get_booleanflip(), Varnode::getDef(), Varnode::isImplied(), and Varnode::isWritten().

Referenced by opBoolNegate(), and opCbranch().

◆ docFunction()

void PrintC::docFunction ( const Funcdata fd)
virtual

◆ docSingleGlobal()

void PrintC::docSingleGlobal ( const Symbol sym)
virtual

Emit the declaration for a single (global) Symbol.

Parameters
symis the Symbol to declare

Implements PrintLanguage.

References EmitXml::beginDocument(), PrintLanguage::emit, emitVarDeclStatement(), EmitXml::endDocument(), EmitXml::flush(), and EmitXml::tagLine().

◆ docTypeDefinitions()

void PrintC::docTypeDefinitions ( const TypeFactory typegrp)
virtual

Emit definitions of data-types.

Parameters
typegrpis the container for the data-types that should be defined

Implements PrintLanguage.

References TypeFactory::dependentOrder(), and emitTypeDefinition().

◆ doEmitWideCharPrefix()

bool PrintC::doEmitWideCharPrefix ( void  ) const
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

Returns
true if a prefix should be printed

Reimplemented in PrintJava.

Referenced by printCharacterConstant(), push_integer(), and pushCharConstant().

◆ emitAnyLabelStatement()

void PrintC::emitAnyLabelStatement ( const FlowBlock bl)
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.

Parameters
blis the given control-flow block

References emitLabelStatement(), FlowBlock::getFrontLeaf(), and FlowBlock::isLabelBumpUp().

Referenced by emitBlockCopy(), emitBlockDoWhile(), emitBlockInfLoop(), and emitBlockWhileDo().

◆ emitCommentFuncHeader()

void PrintC::emitCommentFuncHeader ( const Funcdata fd)
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.

Parameters
fdis 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().

◆ emitCommentGroup()

void PrintC::emitCommentGroup ( const PcodeOp inst)
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

Parameters
instis the given PcodeOp

References commsorter, PrintLanguage::emitLineComment(), CommentSorter::getNext(), Comment::getType(), CommentSorter::hasNext(), PrintLanguage::instr_comment_type, and CommentSorter::setupOpList().

Referenced by emitBlockBasic().

◆ emitEnumDefinition()

void PrintC::emitEnumDefinition ( const TypeEnum ct)
protected

◆ emitExpression()

void PrintC::emitExpression ( const PcodeOp op)
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.

Parameters
opis 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().

◆ emitFunctionDeclaration()

void PrintC::emitFunctionDeclaration ( const Funcdata fd)
protectedvirtual

◆ emitGlobalVarDeclsRecursive()

void PrintC::emitGlobalVarDeclsRecursive ( Scope scope)
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.

Parameters
scopeis the given scope

References emitScopeVarDecls(), and scope.

Referenced by docAllGlobals().

◆ emitGotoStatement()

void PrintC::emitGotoStatement ( const FlowBlock bl,
const FlowBlock exp_bl,
uint4  type 
)
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.

Parameters
blis the source block
exp_blis the destination block (which may provide a label)
typeis 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().

◆ emitInplaceOp()

bool PrintC::emitInplaceOp ( const PcodeOp op)
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.

Parameters
opis the given PcodeOp
Returns
true if the expression was emitted (as in-place), or false if not emitted at all

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().

◆ emitLabel()

void PrintC::emitLabel ( const FlowBlock bl)
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.

Parameters
blis 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().

◆ emitLabelStatement()

void PrintC::emitLabelStatement ( const FlowBlock bl)
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.

Parameters
blis 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().

◆ emitLocalVarDecls()

void PrintC::emitLocalVarDecls ( const Funcdata fd)
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.

Parameters
fdis the function being emitted

References Scope::childrenBegin(), Scope::childrenEnd(), PrintLanguage::emit, emitScopeVarDecls(), Funcdata::getScopeLocal(), and EmitXml::tagLine().

Referenced by docFunction().

◆ emitPrototypeInputs()

void PrintC::emitPrototypeInputs ( const FuncProto proto)
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.

Parameters
protois 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().

◆ emitPrototypeOutput()

void PrintC::emitPrototypeOutput ( const FuncProto proto,
const Funcdata fd 
)
protected

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.

Parameters
protois the function prototype object
fdis 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().

◆ emitScopeVarDecls()

bool PrintC::emitScopeVarDecls ( const Scope scope,
int4  cat 
)
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.

Parameters
scopeis the given Scope
catis the category of variable to declare

Implements PrintLanguage.

References emitVarDeclStatement(), Symbol::getCategory(), Symbol::getName(), Symbol::isNameUndefined(), and scope.

Referenced by emitGlobalVarDeclsRecursive(), and emitLocalVarDecls().

◆ emitStatement()

void PrintC::emitStatement ( const PcodeOp inst)
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.

Parameters
instis 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().

◆ emitStructDefinition()

void PrintC::emitStructDefinition ( const TypeStruct ct)
protected

Emit the definition of a structure data-type.

Print all the components making up the data-type, using the struct keyword

Parameters
ctis 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().

◆ emitSwitchCase()

void PrintC::emitSwitchCase ( int4  casenum,
const BlockSwitch switchbl 
)
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.

Parameters
casenumis the given index of the case block
switchblis 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().

◆ emitTypeDefinition()

void PrintC::emitTypeDefinition ( const Datatype ct)
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)

Parameters
ctis the given data-type

References PrintLanguage::clear(), emitEnumDefinition(), emitStructDefinition(), Datatype::getMetatype(), Datatype::isEnumType(), and TYPE_STRUCT.

Referenced by docTypeDefinitions().

◆ emitVarDecl()

void PrintC::emitVarDecl ( const Symbol sym)
protectedvirtual

Emit a variable declaration.

This can be part of a full a statement, or just the declaration of a function parameter

Parameters
symis 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().

◆ emitVarDeclStatement()

void PrintC::emitVarDeclStatement ( const Symbol sym)
protectedvirtual

Emit a variable declaration statement.

Parameters
symis the Symbol to be declared

Implements PrintLanguage.

References PrintLanguage::emit, emitVarDecl(), EmitXml::print(), and EmitXml::tagLine().

Referenced by docSingleGlobal(), and emitScopeVarDecls().

◆ genericFunctionName()

string PrintC::genericFunctionName ( const Address addr)
protectedvirtual

Create a generic function name base on the entry point address.

Parameters
addris the entry point address of the function
Returns
the generated name

References Address::printRaw().

Referenced by opCall().

◆ genericTypeName()

string PrintC::genericTypeName ( const Datatype ct)
protectedvirtual

Generate a generic name for an unnamed data-type.

Parameters
ctis the given data-type
Returns
the generated name

References Datatype::getMetatype(), Datatype::getSize(), TYPE_FLOAT, TYPE_INT, TYPE_SPACEBASE, TYPE_UINT, and TYPE_UNKNOWN.

Referenced by PrintJava::pushTypeStart(), and pushTypeStart().

◆ hasCharTerminator()

bool PrintC::hasCharTerminator ( uint1 *  buffer,
int4  size,
int4  charsize 
)
staticprotected

Check if the byte buffer has a (unicode) string terminator.

Parameters
bufferis the byte buffer
sizeis the number of bytes in the buffer
charsizeis the presumed size (in bytes) of character elements
Returns
true if a string terminator is found

Referenced by printCharacterConstant().

◆ isCharacterConstant()

bool PrintC::isCharacterConstant ( const uint1 *  buf,
int4  size,
int4  charsize 
) const
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

Parameters
bufis a pointer to the byte array
sizeis the number of bytes in the array
charsizeis 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().

◆ opBoolNegate()

void PrintC::opBoolNegate ( const PcodeOp op)
virtual

Print the BOOL_NEGATE but check for opportunities to flip the next operator instead

Parameters
opis 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().

◆ opCbranch()

void PrintC::opCbranch ( const PcodeOp op)
virtual

◆ opFunc()

void PrintC::opFunc ( const PcodeOp op)
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.

Parameters
opis 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().

◆ opPtrsub()

void PrintC::opPtrsub ( const PcodeOp op)
virtual

◆ opSegmentOp()

void PrintC::opSegmentOp ( const PcodeOp op)
virtual
  • slot 0 is the spaceid constant
  • slot 1 is the segment, we could conceivably try to annotate the segment here
  • slot 2 is the pointer we are really interested in printing
Parameters
opis the SEGMENTOP PcodeOp

Implements PrintLanguage.

References PcodeOp::getIn(), PrintLanguage::mods, and PrintLanguage::pushVnImplied().

◆ opTypeCast()

void PrintC::opTypeCast ( const PcodeOp op)
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.

Parameters
opis 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().

◆ printCharacterConstant()

bool PrintC::printCharacterConstant ( ostream &  s,
const Address addr,
int4  charsize 
) const
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.

Parameters
sis the output stream to print to
addris the address of the string data within the LoadImage
charsizeis the number of bytes in an encoded element (i.e. UTF8, UTF16, or UTF32)
Returns
true if a proper string was found and printed to the stream

References doEmitWideCharPrefix(), PrintLanguage::escapeCharacterData(), PrintLanguage::glb, hasCharTerminator(), Translate::isBigEndian(), isCharacterConstant(), Architecture::loader, LoadImage::loadFill(), and Architecture::translate.

Referenced by pushPtrCharConstant(), and pushSymbol().

◆ printUnicode()

void PrintC::printUnicode ( ostream &  s,
int4  onechar 
) const
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.

Parameters
sis the output stream
onecharis 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().

◆ push_float()

void PrintC::push_float ( uintb  val,
int4  sz,
const Varnode vn,
const PcodeOp op 
)
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.

Parameters
valis the given encoded floating-point value
szis the size (in bytes) of the encoded value
vnis the Varnode holding the value
opis 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().

◆ push_integer()

void PrintC::push_integer ( uintb  val,
int4  sz,
bool  sign,
const Varnode vn,
const PcodeOp op 
)
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.

Parameters
valis the given integer value
szis the size (in bytes) to associate with the integer
signis set to true if the integer should be treated as a signed value
vnis the Varnode holding the value
opis 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().

◆ pushAnnotation()

void PrintC::pushAnnotation ( const Varnode vn,
const PcodeOp op 
)
protectedvirtual

◆ pushBoolConstant()

void PrintC::pushBoolConstant ( uintb  val,
const TypeBase ct,
const Varnode vn,
const PcodeOp op 
)
protected

Push a true or false token to the RPN stack.

A single Atom representing the boolean value is emitted

Parameters
valis the boolean value (non-zero for true)
ctis the data-type associated with the value
vnis the Varnode holding the value
opis the PcodeOp using the value

References EmitXml::const_color, PrintLanguage::pushAtom(), and PrintLanguage::vartoken.

Referenced by pushConstant().

◆ pushCharConstant()

void PrintC::pushCharConstant ( uintb  val,
const TypeChar ct,
const Varnode vn,
const PcodeOp op 
)
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.

Parameters
valis the constant value
ctis data-type attached to the value
vnis the Varnode holding the value
opis the PcodeOp using the value

References EmitXml::const_color, doEmitWideCharPrefix(), Datatype::getSize(), printUnicode(), push_integer(), PrintLanguage::pushAtom(), and PrintLanguage::vartoken.

Referenced by pushConstant().

◆ pushConstant()

void PrintC::pushConstant ( uintb  val,
const Datatype ct,
const Varnode vn,
const PcodeOp op 
)
protectedvirtual

◆ pushEnumConstant()

void PrintC::pushEnumConstant ( uintb  val,
const TypeEnum ct,
const Varnode vn,
const PcodeOp op 
)
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

Parameters
valis the enumerated value being pushed
ctis the enumerated data-type attached to the value
vnis the Varnode holding the value
opis 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().

◆ pushEquate()

bool PrintC::pushEquate ( uintb  val,
int4  sz,
const EquateSymbol sym,
const Varnode vn,
const PcodeOp op 
)
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

Parameters
valis the value of the constant
szis the number of bytes to use for the encoding
symis the EquateSymbol that marks up the constant
vnis the Varnode holding the constant (optional)
opis 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().

◆ pushMismatchSymbol()

void PrintC::pushMismatchSymbol ( const Symbol sym,
int4  off,
int4  sz,
const Varnode vn,
const PcodeOp op 
)
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

Parameters
symis the overlapped symbol
offis the byte offset of the variable relative to the symbol
szis the size of the variable in bytes
vnis the Varnode representing the variable
opis a PcodeOp associated with the Varnode

Implements PrintLanguage.

References Varnode::getAddr(), Symbol::getName(), PrintLanguage::name, PrintLanguage::pushAtom(), pushUnnamedLocation(), EmitXml::var_color, and PrintLanguage::vartoken.

◆ pushPartialSymbol()

void PrintC::pushPartialSymbol ( const Symbol sym,
int4  off,
int4  sz,
const Varnode vn,
const PcodeOp op,
Datatype outtype 
)
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.

Parameters
symis the root Symbol
offis the byte offset, within the Symbol, of the partial variable
szis the number of bytes in the partial variable
vnis the Varnode holding the partial value
opis a PcodeOp associate with the Varnode
outtypeis 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().

◆ pushPrototypeInputs()

void PrintC::pushPrototypeInputs ( const FuncProto proto)
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

Parameters
protois 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().

◆ pushPtrCharConstant()

bool PrintC::pushPtrCharConstant ( uintb  val,
const TypePointer ct,
const Varnode vn,
const PcodeOp op 
)
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

Parameters
valis the value of the given constant pointer
ctis the pointer data-type attached to the value
vnis the Varnode holding the value
opis the PcodeOp using the value
Returns
true if a quoted string was pushed to the RPN stack

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().

◆ pushPtrCodeConstant()

bool PrintC::pushPtrCodeConstant ( uintb  val,
const TypePointer ct,
const Varnode vn,
const PcodeOp op 
)
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.

Parameters
valis the given constant pointer value
ctis the pointer data-type attached to the value
vnis the Varnode holding the value
opis the PcodeOp using the value
Returns
true if a name was pushed to the RPN stack, return false otherwise

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().

◆ pushSymbol()

void PrintC::pushSymbol ( const Symbol sym,
const Varnode vn,
const PcodeOp op 
)
protectedvirtual

◆ pushType()

void PrintC::pushType ( const Datatype ct)
protectedvirtual

Push a data-type name onto the RPN expression stack.

The data-type is generally emitted as if for a cast.

Parameters
ctis 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().

◆ pushTypeEnd()

void PrintC::pushTypeEnd ( const Datatype ct)
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

  • array subscripts . [ # ] and
  • function parameters . ( paramlist )
Parameters
ctis 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().

◆ pushTypeStart()

void PrintC::pushTypeStart ( const Datatype ct,
bool  noident 
)
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

Parameters
ctis the data-type to push
noidentis 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().

◆ pushUnnamedLocation()

void PrintC::pushUnnamedLocation ( const Address addr,
const Varnode vn,
const PcodeOp op 
)
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.

Parameters
addris the storage address
vnis the Varnode representing the variable (if present)
opis 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().

◆ setCommentStyle()

void PrintC::setCommentStyle ( const string &  nm)
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

Parameters
nmis the configuration description

Implements PrintLanguage.

References setCPlusPlusStyleComments(), and setCStyleComments().


The documentation for this class was generated from the following files: