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. | |
void | setHideImpliedExts (bool val) |
Toggle whether implied extensions are hidden. | |
virtual void | resetDefaults (void) |
Set printing options to their default value. | |
virtual void | initializeFromArchitecture (void) |
Initialize architecture specific aspects of printer. | |
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 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, const PcodeOp *readOp) |
Emit a INT_ZEXT operator. | |
virtual void | opIntSext (const PcodeOp *op, const PcodeOp *readOp) |
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. | |
virtual void | opInsertOp (const PcodeOp *op) |
Emit an INSERT operator. | |
virtual void | opExtractOp (const PcodeOp *op) |
Emit an EXTRACT operator. | |
virtual void | opPopcountOp (const PcodeOp *op) |
Emit a POPCOUNT operator. | |
virtual void | opLzcountOp (const PcodeOp *op) |
Emit a LZCOUNT operator. | |
Public Member Functions inherited from ghidra::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 | 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. | |
void | setNamespaceStrategy (namespace_strategy strat) |
Set how namespace tokens are displayed. | |
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 | emitsMarkup (void) const |
Does the low-level emitter, emit markup. | |
void | setMarkup (bool val) |
Set whether the low-level emitter, emits 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... | |
virtual string | unnamedField (int4 off, int4 size) |
Generate an artificial field name. More... | |
Static Public Attributes | |
static const string | EMPTY_STRING = "" |
An empty token. | |
static const string | OPEN_CURLY = "{" |
"{" token | |
static const string | CLOSE_CURLY = "}" |
"}" token | |
static const string | SEMICOLON = ";" |
";" token | |
static const string | COLON = ":" |
":" token | |
static const string | EQUALSIGN = "=" |
"=" token | |
static const string | COMMA = "," |
"," token | |
static const string | DOTDOTDOT = "..." |
"..." token | |
static const string | KEYWORD_VOID = "void" |
"void" keyword | |
static const string | KEYWORD_TRUE = "true" |
"true" keyword | |
static const string | KEYWORD_FALSE = "false" |
"false" keyword | |
static const string | KEYWORD_IF = "if" |
"if" keyword | |
static const string | KEYWORD_ELSE = "else" |
"else" keyword | |
static const string | KEYWORD_DO = "do" |
"do" keyword | |
static const string | KEYWORD_WHILE = "while" |
"while" keyword | |
static const string | KEYWORD_FOR = "for" |
"for" keyword | |
static const string | KEYWORD_GOTO = "goto" |
"goto" keyword | |
static const string | KEYWORD_BREAK = "break" |
"break" keyword | |
static const string | KEYWORD_CONTINUE = "continue" |
"continue" keyword | |
static const string | KEYWORD_CASE = "case" |
"case" keyword | |
static const string | KEYWORD_SWITCH = "switch" |
"switch" keyword | |
static const string | KEYWORD_DEFAULT = "default" |
"default" keyword | |
static const string | KEYWORD_RETURN = "return" |
"return" keyword | |
static const string | KEYWORD_NEW = "new" |
"new" keyword | |
static const string | typePointerRelToken = "ADJ" |
The token to print indicating PTRSUB relative to a TypePointerRel. | |
Static Public Attributes inherited from ghidra::PrintLanguage | |
static const string | OPEN_PAREN = "(" |
"(" token | |
static const string | CLOSE_PAREN = ")" |
")" token | |
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... | |
void | pushSymbolScope (const Symbol *symbol) |
Push tokens resolving a symbol's scope. More... | |
void | emitSymbolScope (const Symbol *symbol) |
Emit tokens resolving a symbol's scope. 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 Datatype *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 *symScope) |
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 | emitCommentBlockTree (const FlowBlock *bl) |
Emit any comments under the given control-flow subtree. More... | |
void | emitCommentFuncHeader (const Funcdata *fd) |
Emit comments in the given function's header. More... | |
void | emitForLoop (const BlockWhileDo *bl) |
Emit block as a for loop. 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) |
Push the given p-code op using type-cast syntax to the RPN stack. More... | |
void | opHiddenFunc (const PcodeOp *op) |
Push the given p-code op as a hidden token. More... | |
bool | printCharacterConstant (ostream &s, const Address &addr, Datatype *charType) const |
Print a quoted (unicode) string at the given address. More... | |
int4 | getHiddenThisSlot (const PcodeOp *op, FuncProto *fc) |
Get position of "this" pointer needing to be hidden. More... | |
void | resetDefaultsPrintC (void) |
Set default values for options specific to PrintC. | |
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, int4 inslot) |
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 | pushImpliedField (const Varnode *vn, const PcodeOp *op) |
Push the implied field of a given Varnode as an object member extraction operation. 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 *symScope, 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... | |
void | pushTypePointerRel (const PcodeOp *op) |
Push a token indicating a PTRSUB (a -> operator) is acting at an offset from the original pointer. More... | |
Protected Member Functions inherited from ghidra::PrintLanguage | |
bool | isSet (uint4 m) const |
Is the given printing modification active. | |
void | pushScope (const 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 | pushVn (const Varnode *vn, const PcodeOp *op, uint4 m) |
Push an expression rooted at a Varnode onto the RPN stack. More... | |
void | pushVnExplicit (const Varnode *vn, const PcodeOp *op) |
Push an explicit variable onto the RPN stack. More... | |
void | pushSymbolDetail (const Varnode *vn, const PcodeOp *op, bool isRead) |
Push symbol name with adornments matching given Varnode. More... | |
bool | parentheses (const OpToken *op2) |
Determine if the given token should be emitted in its own parenthetic expression. More... | |
void | emitOp (const ReversePolish &entry) |
Send an operator token from the RPN to the emitter. More... | |
void | emitAtom (const Atom &atom) |
Send an variable token from the RPN to the emitter. More... | |
bool | escapeCharacterData (ostream &s, const uint1 *buf, int4 count, int4 charsize, bool bigend) const |
Emit a byte buffer to the stream as unicode characters. More... | |
void | recurse (void) |
Emit from the RPN stack as much as possible. More... | |
void | opBinary (const OpToken *tok, const PcodeOp *op) |
Push a binary operator onto the RPN stack. More... | |
void | opUnary (const OpToken *tok, const PcodeOp *op) |
Push a unary operator onto the RPN stack. More... | |
int4 | getPending (void) const |
Get the number of pending nodes yet to be put on the RPN stack. | |
void | resetDefaultsInternal (void) |
Reset options to default for PrintLanguage. | |
virtual void | emitLineComment (int4 indent, const Comment *comm) |
Emit a comment line. More... | |
Static Protected Member Functions | |
static void | printCharHexEscape (ostream &s, int4 val) |
Print value as an escaped hex sequence. More... | |
Static Protected Member Functions inherited from ghidra::PrintLanguage | |
static bool | unicodeNeedsEscape (int4 codepoint) |
Determine if the given codepoint needs to be escaped. 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. | |
bool | option_hide_exts |
Set to true if we should hide implied extension operations. | |
string | nullToken |
Token to use for 'null'. | |
string | sizeSuffix |
Characters to print to indicate a long integer token. | |
CommentSorter | commsorter |
Container/organizer for comments in the current function. | |
Protected Attributes inherited from ghidra::PrintLanguage | |
Architecture * | glb |
The Architecture owning the language emitter. | |
const Scope * | curscope |
The current symbol scope. | |
CastStrategy * | castStrategy |
The strategy for emitting explicit case operations. | |
Emit * | 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. | |
namespace_strategy | namespc_strategy |
How should namespace tokens be displayed. | |
Static Protected Attributes | |
static OpToken | hidden = { "", "", 1, 70, false, OpToken::hiddenfunction, 0, 0, (OpToken *)0 } |
Hidden functional (that may force parentheses) | |
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 | shift_sright = { ">>", "", 2, 46, false, OpToken::binary, 1, 0, (OpToken *)0 } |
The signed 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 ghidra::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, pending_brace = 0x8000 } |
Possible context sensitive modifiers to how tokens get emitted. More... | |
enum | tagtype { syntax, vartoken, functoken, optoken, typetoken, fieldtoken, blanktoken } |
Possible types of Atom. More... | |
enum | namespace_strategy { MINIMAL_NAMESPACES = 0, NO_NAMESPACES = 1, ALL_NAMESPACES = 2 } |
Strategies for displaying namespace tokens. More... | |
Static Public Member Functions inherited from ghidra::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:
ghidra::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 ghidra::PrintLanguage::castStrategy, equal, greater_equal, greater_than, less_equal, less_than, ghidra::OpToken::negate, not_equal, nullToken, and resetDefaultsPrintC().
|
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 ghidra::Datatype::getMetatype(), ghidra::Datatype::getName(), ghidra::FuncProto::getOutputType(), ghidra::TypeFactory::getTypeVoid(), ghidra::PrintLanguage::glb, ghidra::TYPE_ARRAY, ghidra::TYPE_CODE, ghidra::TYPE_PTR, and ghidra::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 ghidra::PcodeOp::code(), ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, ghidra::CPUI_SEGMENTOP, ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::Varnode::isImplied(), and ghidra::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 ghidra::PrintLanguage.
References ghidra::PcodeOp::code(), ghidra::CPUI_MAX, ghidra::Varnode::getDef(), ghidra::Varnode::isImplied(), and ghidra::Varnode::isWritten().
Referenced by opBoolNegate(), and opCbranch().
|
virtual |
Emit the declaration (and body) of a function.
fd | is the function to emit |
Implements ghidra::PrintLanguage.
Reimplemented in ghidra::PrintJava.
References ghidra::Emit::beginFunction(), ghidra::PrintLanguage::clear(), CLOSE_CURLY, ghidra::Architecture::commentdb, commsorter, ghidra::PrintLanguage::emit, emitBlockGraph(), emitCommentFuncHeader(), emitFunctionDeclaration(), emitLocalVarDecls(), ghidra::Emit::endFunction(), ghidra::PrintLanguage::flat, ghidra::Emit::flush(), ghidra::Funcdata::getArch(), ghidra::Funcdata::getBasicBlocks(), ghidra::Funcdata::getStructure(), ghidra::Funcdata::hasNoStructBlocks(), ghidra::PrintLanguage::head_comment_type, ghidra::PrintLanguage::instr_comment_type, ghidra::Funcdata::isProcStarted(), ghidra::PrintLanguage::isSet(), ghidra::PrintLanguage::mods, OPEN_CURLY, option_unplaced, ghidra::PrintLanguage::popScope(), ghidra::Emit::print(), ghidra::CommentSorter::setupFunctionList(), ghidra::Emit::startIndent(), ghidra::Emit::stopIndent(), and ghidra::Emit::tagLine().
Referenced by ghidra::PrintJava::docFunction().
|
virtual |
Emit the declaration for a single (global) Symbol.
sym | is the Symbol to declare |
Implements ghidra::PrintLanguage.
References ghidra::Emit::beginDocument(), ghidra::PrintLanguage::emit, emitVarDeclStatement(), ghidra::Emit::endDocument(), ghidra::Emit::flush(), and ghidra::Emit::tagLine().
|
virtual |
Emit definitions of data-types.
typegrp | is the container for the data-types that should be defined |
Implements ghidra::PrintLanguage.
References ghidra::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 ghidra::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(), ghidra::FlowBlock::getFrontLeaf(), and ghidra::FlowBlock::isLabelBumpUp().
Referenced by emitBlockCopy(), emitBlockDoWhile(), emitBlockInfLoop(), emitBlockWhileDo(), and emitForLoop().
|
protected |
Emit any comments under the given control-flow subtree.
With the control-flow hierarchy, print any comments associated with basic blocks in the specified subtree. Used where statements from multiple basic blocks are printed on one line and a normal comment would get printed in the middle of this line.
bl | is the root of the control-flow subtree |
References commsorter, emitCommentGroup(), ghidra::BlockGraph::getSize(), ghidra::FlowBlock::getType(), ghidra::CommentSorter::setupBlockList(), ghidra::FlowBlock::subBlock(), and ghidra::BlockGraph::subBlock().
Referenced by emitBlockIf(), emitBlockWhileDo(), and emitForLoop().
|
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, ghidra::PrintLanguage::emit, ghidra::PrintLanguage::emitLineComment(), ghidra::Funcdata::getAddress(), ghidra::CommentSorter::getNext(), ghidra::Comment::getType(), ghidra::CommentSorter::hasNext(), ghidra::PrintLanguage::head_comment_type, ghidra::CommentSorter::header_basic, ghidra::CommentSorter::header_unplaced, ghidra::Comment::isEmitted(), option_nocasts, option_unplaced, ghidra::CommentSorter::setupHeader(), ghidra::Emit::tagLine(), and ghidra::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, ghidra::PrintLanguage::emitLineComment(), ghidra::CommentSorter::getNext(), ghidra::Comment::getType(), ghidra::CommentSorter::hasNext(), ghidra::PrintLanguage::instr_comment_type, ghidra::Comment::isEmitted(), and ghidra::CommentSorter::setupOpList().
Referenced by emitBlockBasic(), and emitCommentBlockTree().
|
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 ghidra::TypeEnum::beginEnum(), ghidra::PrintLanguage::clear(), CLOSE_CURLY, ghidra::Emit::const_color, ghidra::PrintLanguage::emit, ghidra::TypeEnum::endEnum(), EQUALSIGN, ghidra::Datatype::getDisplayName(), ghidra::Datatype::getMetatype(), ghidra::Datatype::getName(), ghidra::Datatype::getSize(), ghidra::Emit::keyword_color, ghidra::Emit::no_color, OPEN_CURLY, ghidra::PrintLanguage::popMod(), ghidra::Emit::print(), push_integer(), ghidra::PrintLanguage::pushMod(), ghidra::PrintLanguage::recurse(), SEMICOLON, ghidra::Emit::spaces(), ghidra::Emit::startIndent(), ghidra::Emit::stopIndent(), ghidra::Emit::tagLine(), and ghidra::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 ghidra::PrintLanguage.
References assignment, ghidra::PcodeOp::doesSpecialPrinting(), emitInplaceOp(), ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOpcode(), ghidra::PcodeOp::getOut(), opConstructor(), option_inplace_ops, ghidra::TypeOp::push(), ghidra::PrintLanguage::pushOp(), ghidra::PrintLanguage::pushSymbolDetail(), and ghidra::PrintLanguage::recurse().
Referenced by emitBlockBasic(), emitForLoop(), and emitStatement().
|
protected |
Emit block as a for loop.
Print the loop using the keyword for, followed by a semicolon separated
Then print the body of the loop
References ghidra::Emit::beginBlock(), ghidra::Emit::beginStatement(), CLOSE_CURLY, ghidra::PrintLanguage::CLOSE_PAREN, ghidra::Emit::closeParen(), ghidra::PrintLanguage::comma_separate, ghidra::FlowBlock::emit(), ghidra::PrintLanguage::emit, emitAnyLabelStatement(), emitCommentBlockTree(), emitExpression(), ghidra::Emit::endBlock(), ghidra::Emit::endStatement(), ghidra::BlockGraph::getBlock(), ghidra::BlockWhileDo::getInitializeOp(), ghidra::BlockWhileDo::getIterateOp(), ghidra::Emit::keyword_color, KEYWORD_FOR, ghidra::FlowBlock::lastOp(), ghidra::PrintLanguage::no_branch, ghidra::PrintLanguage::only_branch, OPEN_CURLY, ghidra::PrintLanguage::OPEN_PAREN, ghidra::Emit::openParen(), ghidra::PrintLanguage::popMod(), ghidra::Emit::print(), ghidra::PrintLanguage::pushMod(), SEMICOLON, ghidra::PrintLanguage::setMod(), ghidra::Emit::spaces(), ghidra::Emit::startIndent(), ghidra::Emit::stopIndent(), ghidra::Emit::tagLine(), ghidra::Emit::tagOp(), and ghidra::PrintLanguage::unsetMod().
Referenced by emitBlockWhileDo().
|
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 ghidra::PrintLanguage.
References ghidra::Emit::beginFuncProto(), ghidra::OpToken::bump, ghidra::PrintLanguage::CLOSE_PAREN, ghidra::Emit::closeGroup(), ghidra::Emit::closeParen(), ghidra::PrintLanguage::emit, emitPrototypeInputs(), emitPrototypeOutput(), emitSymbolScope(), ghidra::Emit::endFuncProto(), ghidra::Emit::error_color, ghidra::Emit::funcname_color, function_call, ghidra::Funcdata::getDisplayName(), ghidra::Funcdata::getFuncProto(), ghidra::FuncProto::getModelName(), ghidra::Funcdata::getSymbol(), ghidra::FuncProto::isModelUnknown(), ghidra::Emit::keyword_color, ghidra::PrintLanguage::OPEN_PAREN, ghidra::Emit::openGroup(), ghidra::Emit::openParen(), option_convention, ghidra::Emit::print(), ghidra::FuncProto::printModelInDecl(), ghidra::PrintLanguage::pushScope(), ghidra::Emit::spaces(), ghidra::OpToken::spacing, and ghidra::Emit::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.
symScope | is the given scope |
References ghidra::Scope::childrenBegin(), ghidra::Scope::childrenEnd(), emitScopeVarDecls(), ghidra::Scope::isGlobal(), and ghidra::Symbol::no_category.
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 ghidra::Emit::beginStatement(), ghidra::PrintLanguage::emit, emitLabel(), ghidra::Emit::endStatement(), ghidra::FlowBlock::f_break_goto, ghidra::FlowBlock::f_continue_goto, ghidra::FlowBlock::f_goto_goto, KEYWORD_BREAK, ghidra::Emit::keyword_color, KEYWORD_CONTINUE, KEYWORD_GOTO, ghidra::FlowBlock::lastOp(), ghidra::Emit::print(), SEMICOLON, and ghidra::Emit::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, ghidra::PcodeOp::code(), ghidra::CPUI_INT_ADD, ghidra::CPUI_INT_AND, ghidra::CPUI_INT_DIV, ghidra::CPUI_INT_LEFT, ghidra::CPUI_INT_MULT, ghidra::CPUI_INT_OR, ghidra::CPUI_INT_REM, ghidra::CPUI_INT_RIGHT, ghidra::CPUI_INT_SDIV, ghidra::CPUI_INT_SREM, ghidra::CPUI_INT_SRIGHT, ghidra::CPUI_INT_SUB, ghidra::CPUI_INT_XOR, divequal, ghidra::Varnode::getHigh(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOut(), leftequal, minusequal, ghidra::PrintLanguage::mods, multequal, orequal, plusequal, ghidra::PrintLanguage::pushOp(), ghidra::PrintLanguage::pushVn(), ghidra::PrintLanguage::pushVnExplicit(), ghidra::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 ghidra::PrintLanguage::emit, ghidra::Symbol::getDisplayName(), ghidra::BlockBasic::getEntryAddr(), ghidra::FlowBlock::getFrontLeaf(), ghidra::Address::getOffset(), ghidra::Address::getShortcut(), ghidra::Address::getSpace(), ghidra::BlockBasic::getType(), ghidra::FlowBlock::hasSpecialLabel(), ghidra::FlowBlock::isDuplicated(), ghidra::FlowBlock::isJoined(), ghidra::Emit::no_color, ghidra::Address::printRaw(), ghidra::Scope::queryCodeLabel(), ghidra::FlowBlock::subBlock(), and ghidra::Emit::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 COLON, ghidra::PrintLanguage::emit, emitLabel(), ghidra::PrintLanguage::flat, ghidra::FlowBlock::getType(), ghidra::FlowBlock::isJumpTarget(), ghidra::PrintLanguage::isSet(), ghidra::FlowBlock::isUnstructuredTarget(), ghidra::PrintLanguage::only_branch, ghidra::Emit::print(), and ghidra::Emit::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 ghidra::Scope::childrenBegin(), ghidra::Scope::childrenEnd(), ghidra::PrintLanguage::emit, emitScopeVarDecls(), ghidra::Funcdata::getScopeLocal(), ghidra::Symbol::no_category, and ghidra::Emit::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 ghidra::PrintLanguage::blanktoken, COMMA, DOTDOTDOT, ghidra::PrintLanguage::emit, emitVarDecl(), EMPTY_STRING, ghidra::FuncProto::getParam(), ghidra::ProtoParameter::getSymbol(), ghidra::ProtoParameter::getType(), ghidra::PrintLanguage::hide_thisparam, ghidra::FuncProto::isDotdotdot(), ghidra::PrintLanguage::isSet(), ghidra::ProtoParameter::isThisPointer(), ghidra::Emit::keyword_color, KEYWORD_VOID, ghidra::Emit::no_color, ghidra::FuncProto::numParams(), ghidra::Emit::print(), ghidra::PrintLanguage::pushAtom(), pushTypeEnd(), pushTypeStart(), and ghidra::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 ghidra::Emit::beginReturnType(), ghidra::PrintLanguage::emit, ghidra::Emit::endReturnType(), ghidra::Funcdata::getFirstReturnOp(), ghidra::PcodeOp::getIn(), ghidra::Datatype::getMetatype(), ghidra::FuncProto::getOutputType(), ghidra::PcodeOp::numInput(), pushType(), ghidra::PrintLanguage::recurse(), and ghidra::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.
symScope | is the given Scope |
cat | is the category of variable to declare |
Implements ghidra::PrintLanguage.
References ghidra::Scope::begin(), ghidra::Scope::beginDynamic(), emitVarDeclStatement(), ghidra::Scope::end(), ghidra::Scope::endDynamic(), ghidra::Symbol::getCategory(), ghidra::Scope::getCategorySize(), ghidra::Scope::getCategorySymbol(), ghidra::Symbol::getFirstWholeMap(), ghidra::Symbol::getName(), ghidra::SymbolEntry::getSymbol(), ghidra::Symbol::isMultiEntry(), ghidra::Symbol::isNameUndefined(), and ghidra::SymbolEntry::isPiece().
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 ghidra::Emit::beginStatement(), ghidra::PrintLanguage::comma_separate, ghidra::PrintLanguage::emit, emitExpression(), ghidra::Emit::endStatement(), ghidra::PrintLanguage::isSet(), ghidra::Emit::print(), and SEMICOLON.
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 ghidra::TypeStruct::beginField(), ghidra::PrintLanguage::clear(), CLOSE_CURLY, COMMA, ghidra::PrintLanguage::emit, ghidra::TypeStruct::endField(), ghidra::Datatype::getDisplayName(), ghidra::Datatype::getName(), ghidra::Emit::keyword_color, OPEN_CURLY, ghidra::Emit::print(), ghidra::PrintLanguage::pushAtom(), pushTypeEnd(), pushTypeStart(), SEMICOLON, ghidra::Emit::spaces(), ghidra::Emit::startIndent(), ghidra::Emit::stopIndent(), ghidra::PrintLanguage::syntax, ghidra::Emit::tagLine(), and ghidra::Emit::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 COLON, ghidra::PrintLanguage::emit, ghidra::BlockSwitch::getLabel(), ghidra::BlockSwitch::getNumLabels(), ghidra::BlockSwitch::getSwitchType(), ghidra::BlockSwitch::isDefaultCase(), KEYWORD_CASE, ghidra::Emit::keyword_color, KEYWORD_DEFAULT, ghidra::Emit::print(), pushConstant(), ghidra::PrintLanguage::recurse(), ghidra::Emit::spaces(), and ghidra::Emit::tagLine().
Referenced by emitBlockSwitch().
|
protected |
Emit tokens resolving a symbol's scope.
Emit the elements of the given symbol's namespace path that distinguish it within the current scope.
symbol | is the given Symbol |
References ghidra::PrintLanguage::ALL_NAMESPACES, ghidra::PrintLanguage::curscope, ghidra::PrintLanguage::emit, ghidra::Scope::getParent(), ghidra::Symbol::getResolutionDepth(), ghidra::Symbol::getScope(), ghidra::Emit::global_color, ghidra::PrintLanguage::MINIMAL_NAMESPACES, ghidra::PrintLanguage::namespc_strategy, ghidra::Emit::no_color, ghidra::Emit::print(), ghidra::OpToken::print1, and scope.
Referenced by emitFunctionDeclaration().
|
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 ghidra::PrintLanguage::clear(), emitEnumDefinition(), emitStructDefinition(), ghidra::Datatype::getMetatype(), ghidra::Datatype::isEnumType(), and ghidra::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 ghidra::PrintLanguage.
References ghidra::Emit::beginVarDecl(), ghidra::PrintLanguage::emit, ghidra::Emit::endVarDecl(), ghidra::Symbol::getType(), pushSymbol(), pushTypeEnd(), pushTypeStart(), and ghidra::PrintLanguage::recurse().
Referenced by emitPrototypeInputs(), and emitVarDeclStatement().
|
protectedvirtual |
Emit a variable declaration statement.
sym | is the Symbol to be declared |
Implements ghidra::PrintLanguage.
References ghidra::PrintLanguage::emit, emitVarDecl(), ghidra::Emit::print(), SEMICOLON, and ghidra::Emit::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 ghidra::Address::printRaw().
Referenced by opCall().
|
protectedvirtual |
Generate a generic name for an unnamed data-type.
ct | is the given data-type |
References ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::TYPE_FLOAT, ghidra::TYPE_INT, ghidra::TYPE_SPACEBASE, ghidra::TYPE_UINT, and ghidra::TYPE_UNKNOWN.
Referenced by ghidra::PrintJava::pushTypeStart(), and pushTypeStart().
Get position of "this" pointer needing to be hidden.
For the given CALL op, if a "this" pointer exists and needs to be hidden because of the print configuration, return the Varnode slot corresponding to the "this". Otherwise return -1.
op | is the given CALL PcodeOp |
fc | is the function prototype corresponding to the CALL |
References ghidra::FuncProto::getParam(), ghidra::FuncProto::hasThisPointer(), ghidra::PrintLanguage::hide_thisparam, ghidra::PrintLanguage::isSet(), ghidra::ProtoParameter::isThisPointer(), and ghidra::PcodeOp::numInput().
Referenced by ghidra::PrintJava::opCallind(), and opCallind().
|
virtual |
Print the BOOL_NEGATE but check for opportunities to flip the next operator instead
op | is the BOOL_NEGATE PcodeOp |
Implements ghidra::PrintLanguage.
References boolean_not, checkPrintNegation(), ghidra::PcodeOp::getIn(), ghidra::PrintLanguage::isSet(), ghidra::PrintLanguage::mods, ghidra::PrintLanguage::negatetoken, ghidra::PrintLanguage::pushOp(), ghidra::PrintLanguage::pushVn(), and ghidra::PrintLanguage::unsetMod().
|
virtual |
Print the branching condition:
op | is the CBRANCH PcodeOp |
Implements ghidra::PrintLanguage.
References boolean_not, checkPrintNegation(), ghidra::PrintLanguage::CLOSE_PAREN, ghidra::Emit::closeGroup(), ghidra::Emit::closeParen(), ghidra::PrintLanguage::comma_separate, ghidra::PrintLanguage::emit, ghidra::PrintLanguage::falsebranch, ghidra::PrintLanguage::flat, ghidra::PcodeOp::getIn(), ghidra::PcodeOp::isBooleanFlip(), ghidra::PcodeOp::isFallthruTrue(), ghidra::PrintLanguage::isSet(), ghidra::Emit::keyword_color, KEYWORD_GOTO, KEYWORD_IF, ghidra::PrintLanguage::mods, ghidra::PrintLanguage::negatetoken, ghidra::PrintLanguage::OPEN_PAREN, ghidra::Emit::openGroup(), ghidra::Emit::openParen(), ghidra::Emit::print(), ghidra::PrintLanguage::pushOp(), ghidra::PrintLanguage::pushVn(), ghidra::PrintLanguage::recurse(), ghidra::Emit::spaces(), and ghidra::Emit::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 ghidra::PrintLanguage::blanktoken, comma, EMPTY_STRING, function_call, ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOpcode(), ghidra::TypeOp::getOperatorName(), ghidra::PrintLanguage::mods, ghidra::Emit::no_color, ghidra::PcodeOp::numInput(), ghidra::PrintLanguage::optoken, ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), and ghidra::PrintLanguage::pushVn().
Referenced by opExtractOp(), opInsertOp(), opIntSext(), opIntZext(), and opSubpiece().
|
protected |
Push the given p-code op as a hidden token.
The syntax represents the given op using a function with one input, where the function name is not printed. The input expression is simply printed without adornment inside the larger expression, with one minor difference. The hidden operator protects against confusing evaluation order between the operators inside and outside the hidden function. If both the inside and outside operators are the same associative token, the hidden token makes sure the inner expression is surrounded with parentheses.
op | is the given PcodeOp |
References ghidra::PcodeOp::getIn(), hidden, ghidra::PrintLanguage::mods, ghidra::PrintLanguage::pushOp(), and ghidra::PrintLanguage::pushVn().
Referenced by opIntSext(), and opIntZext().
|
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 ghidra::PrintLanguage.
References addressof, ghidra::AddrSpace::addressToByteInt(), ghidra::calc_mask(), ghidra::PrintLanguage::clear(), dereference, ghidra::PrintLanguage::fieldtoken, ghidra::Datatype::findTruncation(), ghidra::PcodeOp::getAddr(), ghidra::TypeSpacebase::getAddress(), ghidra::ResolvedUnion::getFieldNum(), ghidra::BlockBasic::getFuncdata(), ghidra::Varnode::getHigh(), ghidra::Varnode::getHighTypeReadFacing(), ghidra::PcodeOp::getIn(), ghidra::Datatype::getMetatype(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getParent(), ghidra::TypePointerRel::getParent(), ghidra::TypePointerRel::getPointerOffset(), ghidra::TypePointer::getPtrTo(), ghidra::Varnode::getSize(), ghidra::Datatype::getSize(), ghidra::HighVariable::getSymbol(), ghidra::HighVariable::getSymbolOffset(), ghidra::Symbol::getType(), ghidra::Funcdata::getUnionField(), ghidra::TypePointer::getWordSize(), ghidra::TypeField::ident, ghidra::Datatype::isFormalPointerRel(), ghidra::PrintLanguage::mods, ghidra::TypeField::name, ghidra::Emit::no_color, object_member, pointer_member, ghidra::PrintLanguage::print_load_value, ghidra::PrintLanguage::print_store_value, push_integer(), ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), pushPartialSymbol(), pushSymbol(), pushTypePointerRel(), pushUnnamedLocation(), ghidra::PrintLanguage::pushVn(), subscript, ghidra::TypeField::type, ghidra::TYPE_ARRAY, ghidra::TYPE_CODE, ghidra::TYPE_PTR, ghidra::TYPE_SPACEBASE, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.
|
virtual |
op | is the SEGMENTOP PcodeOp |
Implements ghidra::PrintLanguage.
References ghidra::PcodeOp::getIn(), ghidra::PrintLanguage::mods, and ghidra::PrintLanguage::pushVn().
|
protected |
Push 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 ghidra::Varnode::getHighTypeDefFacing(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOut(), ghidra::PrintLanguage::mods, option_nocasts, ghidra::PrintLanguage::pushOp(), pushType(), ghidra::PrintLanguage::pushVn(), and typecast.
Referenced by 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 |
charType | is the underlying character data-type |
References doEmitWideCharPrefix(), ghidra::PrintLanguage::escapeCharacterData(), ghidra::Datatype::getSize(), ghidra::StringManager::getStringData(), ghidra::PrintLanguage::glb, ghidra::Translate::isBigEndian(), ghidra::Datatype::isOpaqueString(), ghidra::Architecture::stringManager, and ghidra::Architecture::translate.
Referenced by pushPtrCharConstant().
|
staticprotected |
Print value as an escaped hex sequence.
Print the given value using the standard character hexadecimal escape sequence.
s | is the stream to write to |
val | is the given value |
Referenced by printUnicode(), push_integer(), and pushCharConstant().
|
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 ghidra::PrintLanguage.
Reimplemented in ghidra::PrintJava.
References printCharHexEscape(), ghidra::PrintLanguage::unicodeNeedsEscape(), and ghidra::StringManager::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 ghidra::Emit::const_color, ghidra::FloatFormat::extractSign(), ghidra::PrintLanguage::force_scinote, ghidra::FloatFormat::getDecimalPrecision(), ghidra::Translate::getFloatFormat(), ghidra::FloatFormat::getHostFloat(), ghidra::PrintLanguage::glb, ghidra::FloatFormat::infinity, ghidra::PrintLanguage::mods, ghidra::FloatFormat::nan, ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::syntax, ghidra::Architecture::translate, and ghidra::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 ghidra::calc_mask(), ghidra::Emit::const_color, doEmitWideCharPrefix(), ghidra::Symbol::equate, ghidra::Symbol::force_char, ghidra::PrintLanguage::force_dec, ghidra::Symbol::force_dec, ghidra::PrintLanguage::force_hex, ghidra::Symbol::force_hex, ghidra::Symbol::force_oct, ghidra::PrintLanguage::formatBinary(), ghidra::Symbol::getCategory(), ghidra::Datatype::getDisplayFormat(), ghidra::Symbol::getDisplayFormat(), ghidra::Varnode::getHigh(), ghidra::HighVariable::getSymbol(), ghidra::HighVariable::getType(), ghidra::Varnode::isAnnotation(), ghidra::Varnode::isLongPrint(), ghidra::Symbol::isNameLocked(), ghidra::Varnode::isUnsignedPrint(), ghidra::PrintLanguage::mods, ghidra::PrintLanguage::mostNaturalBase(), printCharHexEscape(), printUnicode(), ghidra::PrintLanguage::pushAtom(), pushEquate(), sizeSuffix, ghidra::PrintLanguage::syntax, and ghidra::PrintLanguage::vartoken.
Referenced by emitEnumDefinition(), ghidra::PrintJava::opLoad(), opPtrsub(), ghidra::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 ghidra::PrintLanguage.
References ghidra::AddrSpace::byteToAddress(), ghidra::PcodeOp::code(), ghidra::CPUI_CALLOTHER, ghidra::UserPcodeOp::extractAnnotationSize(), ghidra::PcodeOp::getAddr(), ghidra::Varnode::getAddr(), ghidra::AddrSpace::getAddrSize(), ghidra::SymbolEntry::getFirst(), ghidra::BlockBasic::getFuncdata(), ghidra::PcodeOp::getIn(), ghidra::AddrSpace::getName(), ghidra::Varnode::getOffset(), ghidra::UserOpManage::getOp(), ghidra::PcodeOp::getParent(), ghidra::Translate::getRegisterName(), ghidra::Funcdata::getScopeLocal(), ghidra::SymbolEntry::getSize(), ghidra::Varnode::getSize(), ghidra::Varnode::getSpace(), ghidra::SymbolEntry::getSymbol(), ghidra::AddrSpace::getWordSize(), ghidra::PrintLanguage::glb, ghidra::PrintLanguage::pushAtom(), pushPartialSymbol(), pushSymbol(), ghidra::Scope::queryContainer(), ghidra::Emit::special_color, ghidra::Architecture::translate, ghidra::Architecture::userops, and ghidra::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 ghidra::Emit::const_color, KEYWORD_FALSE, KEYWORD_TRUE, ghidra::PrintLanguage::pushAtom(), and ghidra::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. Characters come in with the compiler's raw encoding.
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 ghidra::CastStrategy::caresAboutCharRepresentation(), ghidra::PrintLanguage::castStrategy, ghidra::Emit::const_color, doEmitWideCharPrefix(), ghidra::Symbol::equate, ghidra::Symbol::force_char, ghidra::Symbol::force_hex, ghidra::Symbol::getCategory(), ghidra::Datatype::getDisplayFormat(), ghidra::Symbol::getDisplayFormat(), ghidra::Varnode::getHigh(), ghidra::Datatype::getMetatype(), ghidra::Varnode::getSize(), ghidra::Datatype::getSize(), ghidra::HighVariable::getSymbol(), ghidra::HighVariable::getType(), ghidra::Varnode::isAnnotation(), ghidra::Symbol::isNameLocked(), printCharHexEscape(), printUnicode(), push_integer(), ghidra::PrintLanguage::pushAtom(), pushEquate(), ghidra::TYPE_INT, and ghidra::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 ghidra::PrintLanguage.
References ghidra::PrintLanguage::clear(), ghidra::PrintLanguage::force_dec, ghidra::PrintLanguage::force_hex, ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::Datatype::isCharPrint(), ghidra::Datatype::isEnumType(), ghidra::PrintLanguage::isSet(), nullToken, option_nocasts, option_NULL, ghidra::PrintLanguage::popMod(), push_float(), push_integer(), ghidra::PrintLanguage::pushAtom(), pushBoolConstant(), pushCharConstant(), pushEnumConstant(), ghidra::PrintLanguage::pushMod(), ghidra::PrintLanguage::pushOp(), pushPtrCharConstant(), pushPtrCodeConstant(), pushType(), ghidra::PrintLanguage::setMod(), ghidra::TYPE_ARRAY, ghidra::TYPE_BOOL, ghidra::TYPE_CODE, ghidra::TYPE_FLOAT, ghidra::TYPE_INT, ghidra::TYPE_PARTIALSTRUCT, ghidra::TYPE_PARTIALUNION, ghidra::TYPE_PTR, ghidra::TYPE_PTRREL, ghidra::TYPE_SPACEBASE, ghidra::TYPE_STRUCT, ghidra::TYPE_UINT, ghidra::TYPE_UNION, ghidra::TYPE_UNKNOWN, ghidra::TYPE_VOID, typecast, ghidra::Emit::var_color, and ghidra::PrintLanguage::vartoken.
Referenced by emitSwitchCase().
|
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, ghidra::Emit::const_color, enum_cat, ghidra::TypeEnum::getMatches(), ghidra::Datatype::getSize(), push_integer(), ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), and ghidra::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 ghidra::PrintLanguage.
References binary_minus, binary_plus, bitwise_not, ghidra::calc_mask(), ghidra::EquateSymbol::getValue(), push_integer(), ghidra::PrintLanguage::pushOp(), pushSymbol(), and unary_minus.
Referenced by push_integer(), and pushCharConstant().
Push the implied field of a given Varnode as an object member extraction operation.
If a Varnode is implied and has a union data-type, the particular read of the varnode may correspond to a particular field that needs to get printed as a token, even though the Varnode itself is printed directly. This method pushes the field name token.
Implements ghidra::PrintLanguage.
References ghidra::PrintLanguage::fieldtoken, ghidra::Varnode::getDef(), ghidra::ResolvedUnion::getFieldNum(), ghidra::BlockBasic::getFuncdata(), ghidra::Varnode::getHigh(), ghidra::Datatype::getMetatype(), ghidra::PcodeOp::getOpcode(), ghidra::PcodeOp::getParent(), ghidra::PcodeOp::getSlot(), ghidra::HighVariable::getType(), ghidra::Funcdata::getUnionField(), ghidra::TypeField::ident, ghidra::TypeField::name, ghidra::Datatype::needsResolution(), ghidra::Emit::no_color, object_member, ghidra::TypeOp::push(), ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), ghidra::TYPE_PTR, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.
|
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 ghidra::PrintLanguage.
References ghidra::Varnode::getAddr(), ghidra::Symbol::getDisplayName(), ghidra::PrintLanguage::pushAtom(), pushUnnamedLocation(), ghidra::Emit::var_color, and ghidra::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 |
inslot | is the input slot of vn with op, or -1 if op writes vn |
Implements ghidra::PrintLanguage.
References ghidra::PrintLanguage::castStrategy, ghidra::Emit::const_color, ghidra::PrintLanguage::fieldtoken, ghidra::Datatype::findResolve(), ghidra::Datatype::findTruncation(), ghidra::SymbolEntry::getAddr(), ghidra::Symbol::getFirstWholeMap(), ghidra::Varnode::getHigh(), ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::Address::getSpace(), ghidra::HighVariable::getType(), ghidra::Symbol::getType(), ghidra::TypeField::ident, ghidra::AddrSpace::isBigEndian(), ghidra::CastStrategy::isSubpieceCastEndian(), ghidra::Datatype::name, ghidra::TypeField::name, ghidra::Datatype::needsResolution(), ghidra::Emit::no_color, object_member, option_nocasts, ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), pushSymbol(), pushType(), subscript, ghidra::PrintLanguage::syntax, ghidra::PartialSymbolEntry::token, ghidra::TypeField::type, ghidra::TYPE_ARRAY, ghidra::TYPE_PTR, ghidra::TYPE_STRUCT, ghidra::TYPE_UNION, typecast, and ghidra::PrintLanguage::unnamedField().
Referenced by opPtrsub(), opSubpiece(), 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 ghidra::PrintLanguage::blanktoken, comma, DOTDOTDOT, EMPTY_STRING, ghidra::FuncProto::getParam(), ghidra::ProtoParameter::getType(), ghidra::FuncProto::isDotdotdot(), ghidra::Emit::keyword_color, KEYWORD_VOID, ghidra::Emit::no_color, ghidra::FuncProto::numParams(), ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), pushTypeEnd(), pushTypeStart(), and ghidra::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 (may be null) |
op | is the PcodeOp using the value (may be null) |
References ghidra::Emit::const_color, ghidra::PcodeOp::getAddr(), ghidra::AddrSpaceManager::getDefaultDataSpace(), ghidra::Database::getGlobalScope(), ghidra::TypePointer::getPtrTo(), ghidra::Datatype::getSize(), ghidra::PrintLanguage::glb, ghidra::Address::isInvalid(), ghidra::Scope::isReadOnly(), printCharacterConstant(), ghidra::PrintLanguage::pushAtom(), ghidra::AddrSpaceManager::resolveConstant(), ghidra::Architecture::symboltab, and ghidra::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 ghidra::AddrSpace::addressToByte(), ghidra::Emit::funcname_color, ghidra::PrintLanguage::functoken, ghidra::AddrSpaceManager::getDefaultCodeSpace(), ghidra::Database::getGlobalScope(), ghidra::AddrSpace::getWordSize(), ghidra::PrintLanguage::glb, ghidra::PrintLanguage::pushAtom(), ghidra::Scope::queryFunction(), and ghidra::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 ghidra::PrintLanguage.
References ghidra::Symbol::function_parameter, ghidra::Symbol::getCategory(), ghidra::Symbol::getDisplayName(), ghidra::Varnode::getHigh(), ghidra::Symbol::getMapEntryPosition(), ghidra::Symbol::getScope(), ghidra::SymbolEntry::getSymbol(), ghidra::HighVariable::getSymbolEntry(), ghidra::Emit::global_color, ghidra::Symbol::hasMergeProblems(), ghidra::Scope::isGlobal(), ghidra::HighVariable::isUnmerged(), ghidra::Symbol::isVolatile(), ghidra::Emit::param_color, ghidra::PrintLanguage::pushAtom(), pushSymbolScope(), ghidra::Emit::special_color, ghidra::Emit::var_color, and ghidra::PrintLanguage::vartoken.
Referenced by emitVarDecl(), opPtrsub(), pushAnnotation(), pushEquate(), and pushPartialSymbol().
|
protected |
Push tokens resolving a symbol's scope.
Calculate what elements of a given symbol's namespace path are necessary to distinguish it within the current scope. Then print these elements.
symbol | is the given symbol |
References ghidra::PrintLanguage::ALL_NAMESPACES, ghidra::PrintLanguage::curscope, ghidra::Scope::getParent(), ghidra::Symbol::getResolutionDepth(), ghidra::Symbol::getScope(), ghidra::Emit::global_color, ghidra::PrintLanguage::MINIMAL_NAMESPACES, ghidra::PrintLanguage::namespc_strategy, ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), scope, and ghidra::PrintLanguage::syntax.
Referenced by opCall(), and pushSymbol().
|
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 ghidra::PrintLanguage.
References ghidra::PrintLanguage::blanktoken, EMPTY_STRING, ghidra::Emit::no_color, ghidra::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 ghidra::PrintJava.
References ghidra::PrintLanguage::blanktoken, EMPTY_STRING, ghidra::PrintLanguage::force_dec, ghidra::TypeArray::getBase(), ghidra::Datatype::getMetatype(), ghidra::Datatype::getName(), ghidra::FuncProto::getOutputType(), ghidra::TypeCode::getPrototype(), ghidra::Emit::no_color, ghidra::TypeArray::numElements(), ghidra::PrintLanguage::popMod(), push_integer(), ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushMod(), pushPrototypeInputs(), ghidra::PrintLanguage::setMod(), ghidra::TYPE_ARRAY, ghidra::TYPE_CODE, and ghidra::TYPE_PTR.
Referenced by emitPrototypeInputs(), emitStructDefinition(), emitVarDecl(), pushPrototypeInputs(), and pushType().
|
inlineprotected |
Push a token indicating a PTRSUB (a -> operator) is acting at an offset from the original pointer.
When a variable has TypePointerRel as its data-type, PTRSUB acts relative to the parent data-type. We print a specific token to indicate this relative shift is happening.
op | is is the PTRSUB op |
References ghidra::Emit::funcname_color.
Referenced by opPtrsub().
|
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 ghidra::PrintJava.
References array_expr, buildTypeStack(), ghidra::PrintLanguage::clear(), function_call, genericTypeName(), ghidra::Datatype::getDisplayName(), ghidra::Datatype::getMetatype(), ghidra::Datatype::getName(), ptr_expr, ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), ghidra::TYPE_ARRAY, ghidra::TYPE_CODE, ghidra::Emit::type_color, type_expr_nospace, type_expr_space, ghidra::TYPE_PTR, and ghidra::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 ghidra::PrintLanguage.
References ghidra::AddrSpace::getName(), ghidra::Address::getSpace(), ghidra::Address::printRaw(), ghidra::PrintLanguage::pushAtom(), ghidra::Emit::var_color, and ghidra::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 ghidra::PrintLanguage.
References setCPlusPlusStyleComments(), and setCStyleComments().