decompiler
1.0.0
|
The base class API for emitting a high-level language. More...
#include <printlanguage.hh>
Classes | |
struct | Atom |
A single non-operator token emitted by the decompiler. More... | |
struct | NodePending |
A pending data-flow node; waiting to be placed on the reverse polish notation stack. More... | |
struct | ReversePolish |
An entry on the reverse polish notation (RPN) stack. More... | |
Public Types | |
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... | |
Public Member Functions | |
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 | initializeFromArchitecture (void)=0 |
Initialize architecture specific aspects of printer. | |
virtual void | adjustTypeOperators (void)=0 |
Set basic data-type information for p-code operators. | |
virtual void | resetDefaults (void) |
Set printing options to their default value. | |
virtual void | clear (void) |
Clear the RPN stack and the low-level emitter. | |
virtual void | setIntegerFormat (const string &nm) |
Set the default integer format. More... | |
virtual void | setCommentStyle (const string &nm)=0 |
Set the way comments are displayed in decompiler output. More... | |
virtual void | docTypeDefinitions (const TypeFactory *typegrp)=0 |
Emit definitions of data-types. More... | |
virtual void | docAllGlobals (void)=0 |
Emit declarations of global variables. | |
virtual void | docSingleGlobal (const Symbol *sym)=0 |
Emit the declaration for a single (global) Symbol. More... | |
virtual void | docFunction (const Funcdata *fd)=0 |
Emit the declaration (and body) of a function. More... | |
virtual void | emitBlockBasic (const BlockBasic *bb)=0 |
Emit statements in a basic block. | |
virtual void | emitBlockGraph (const BlockGraph *bl)=0 |
Emit (an unspecified) list of blocks. | |
virtual void | emitBlockCopy (const BlockCopy *bl)=0 |
Emit a basic block (with any labels) | |
virtual void | emitBlockGoto (const BlockGoto *bl)=0 |
Emit a block ending with a goto statement. | |
virtual void | emitBlockLs (const BlockList *bl)=0 |
Emit a sequence of blocks. | |
virtual void | emitBlockCondition (const BlockCondition *bl)=0 |
Emit a conditional statement. | |
virtual void | emitBlockIf (const BlockIf *bl)=0 |
Emit an if/else style construct. | |
virtual void | emitBlockWhileDo (const BlockWhileDo *bl)=0 |
Emit a loop structure, check at top. | |
virtual void | emitBlockDoWhile (const BlockDoWhile *bl)=0 |
Emit a loop structure, check at bottom. | |
virtual void | emitBlockInfLoop (const BlockInfLoop *bl)=0 |
Emit an infinite loop structure. | |
virtual void | emitBlockSwitch (const BlockSwitch *bl)=0 |
Emit a switch structure. | |
virtual void | opCopy (const PcodeOp *op)=0 |
Emit a COPY operator. | |
virtual void | opLoad (const PcodeOp *op)=0 |
Emit a LOAD operator. | |
virtual void | opStore (const PcodeOp *op)=0 |
Emit a STORE operator. | |
virtual void | opBranch (const PcodeOp *op)=0 |
Emit a BRANCH operator. | |
virtual void | opCbranch (const PcodeOp *op)=0 |
Emit a CBRANCH operator. | |
virtual void | opBranchind (const PcodeOp *op)=0 |
Emit a BRANCHIND operator. | |
virtual void | opCall (const PcodeOp *op)=0 |
Emit a CALL operator. | |
virtual void | opCallind (const PcodeOp *op)=0 |
Emit a CALLIND operator. | |
virtual void | opCallother (const PcodeOp *op)=0 |
Emit a CALLOTHER operator. | |
virtual void | opConstructor (const PcodeOp *op, bool withNew)=0 |
Emit an operator constructing an object. | |
virtual void | opReturn (const PcodeOp *op)=0 |
Emit a RETURN operator. | |
virtual void | opIntEqual (const PcodeOp *op)=0 |
Emit a INT_EQUAL operator. | |
virtual void | opIntNotEqual (const PcodeOp *op)=0 |
Emit a INT_NOTEQUAL operator. | |
virtual void | opIntSless (const PcodeOp *op)=0 |
Emit a INT_SLESS operator. | |
virtual void | opIntSlessEqual (const PcodeOp *op)=0 |
Emit a INT_SLESSEQUAL operator. | |
virtual void | opIntLess (const PcodeOp *op)=0 |
Emit a INT_LESS operator. | |
virtual void | opIntLessEqual (const PcodeOp *op)=0 |
Emit a INT_LESSEQUAL operator. | |
virtual void | opIntZext (const PcodeOp *op, const PcodeOp *readOp)=0 |
Emit a INT_ZEXT operator. | |
virtual void | opIntSext (const PcodeOp *op, const PcodeOp *readOp)=0 |
Emit a INT_SEXT operator. | |
virtual void | opIntAdd (const PcodeOp *op)=0 |
Emit a INT_ADD operator. | |
virtual void | opIntSub (const PcodeOp *op)=0 |
Emit a INT_SUB operator. | |
virtual void | opIntCarry (const PcodeOp *op)=0 |
Emit a INT_CARRY operator. | |
virtual void | opIntScarry (const PcodeOp *op)=0 |
Emit a INT_SCARRY operator. | |
virtual void | opIntSborrow (const PcodeOp *op)=0 |
Emit a INT_SBORROW operator. | |
virtual void | opInt2Comp (const PcodeOp *op)=0 |
Emit a INT_2COMP operator. | |
virtual void | opIntNegate (const PcodeOp *op)=0 |
Emit a INT_NEGATE operator. | |
virtual void | opIntXor (const PcodeOp *op)=0 |
Emit a INT_XOR operator. | |
virtual void | opIntAnd (const PcodeOp *op)=0 |
Emit a INT_AND operator. | |
virtual void | opIntOr (const PcodeOp *op)=0 |
Emit a INT_OR operator. | |
virtual void | opIntLeft (const PcodeOp *op)=0 |
Emit a INT_LEFT operator. | |
virtual void | opIntRight (const PcodeOp *op)=0 |
Emit a INT_RIGHT operator. | |
virtual void | opIntSright (const PcodeOp *op)=0 |
Emit a INT_SRIGHT operator. | |
virtual void | opIntMult (const PcodeOp *op)=0 |
Emit a INT_MULT operator. | |
virtual void | opIntDiv (const PcodeOp *op)=0 |
Emit a INT_DIV operator. | |
virtual void | opIntSdiv (const PcodeOp *op)=0 |
Emit a INT_SDIV operator. | |
virtual void | opIntRem (const PcodeOp *op)=0 |
Emit a INT_REM operator. | |
virtual void | opIntSrem (const PcodeOp *op)=0 |
Emit a INT_SREM operator. | |
virtual void | opBoolNegate (const PcodeOp *op)=0 |
Emit a BOOL_NEGATE operator. | |
virtual void | opBoolXor (const PcodeOp *op)=0 |
Emit a BOOL_XOR operator. | |
virtual void | opBoolAnd (const PcodeOp *op)=0 |
Emit a BOOL_AND operator. | |
virtual void | opBoolOr (const PcodeOp *op)=0 |
Emit a BOOL_OR operator. | |
virtual void | opFloatEqual (const PcodeOp *op)=0 |
Emit a FLOAT_EQUAL operator. | |
virtual void | opFloatNotEqual (const PcodeOp *op)=0 |
Emit a FLOAT_NOTEQUAL operator. | |
virtual void | opFloatLess (const PcodeOp *op)=0 |
Emit a FLOAT_LESS operator. | |
virtual void | opFloatLessEqual (const PcodeOp *op)=0 |
Emit a FLOAT_LESSEQUAL operator. | |
virtual void | opFloatNan (const PcodeOp *op)=0 |
Emit a FLOAT_NAN operator. | |
virtual void | opFloatAdd (const PcodeOp *op)=0 |
Emit a FLOAT_ADD operator. | |
virtual void | opFloatDiv (const PcodeOp *op)=0 |
Emit a FLOAT_DIV operator. | |
virtual void | opFloatMult (const PcodeOp *op)=0 |
Emit a FLOAT_MULT operator. | |
virtual void | opFloatSub (const PcodeOp *op)=0 |
Emit a FLOAT_SUB operator. | |
virtual void | opFloatNeg (const PcodeOp *op)=0 |
Emit a FLOAT_NEG operator. | |
virtual void | opFloatAbs (const PcodeOp *op)=0 |
Emit a FLOAT_ABS operator. | |
virtual void | opFloatSqrt (const PcodeOp *op)=0 |
Emit a FLOAT_SQRT operator. | |
virtual void | opFloatInt2Float (const PcodeOp *op)=0 |
Emit a FLOAT_INT2FLOAT operator. | |
virtual void | opFloatFloat2Float (const PcodeOp *op)=0 |
Emit a FLOAT_FLOAT2FLOAT operator. | |
virtual void | opFloatTrunc (const PcodeOp *op)=0 |
Emit a FLOAT_TRUNC operator. | |
virtual void | opFloatCeil (const PcodeOp *op)=0 |
Emit a FLOAT_CEIL operator. | |
virtual void | opFloatFloor (const PcodeOp *op)=0 |
Emit a FLOAT_FLOOR operator. | |
virtual void | opFloatRound (const PcodeOp *op)=0 |
Emit a FLOAT_ROUND operator. | |
virtual void | opMultiequal (const PcodeOp *op)=0 |
Emit a MULTIEQUAL operator. | |
virtual void | opIndirect (const PcodeOp *op)=0 |
Emit a INDIRECT operator. | |
virtual void | opPiece (const PcodeOp *op)=0 |
Emit a PIECE operator. | |
virtual void | opSubpiece (const PcodeOp *op)=0 |
Emit a SUBPIECE operator. | |
virtual void | opCast (const PcodeOp *op)=0 |
Emit a CAST operator. | |
virtual void | opPtradd (const PcodeOp *op)=0 |
Emit a PTRADD operator. | |
virtual void | opPtrsub (const PcodeOp *op)=0 |
Emit a PTRSUB operator. | |
virtual void | opSegmentOp (const PcodeOp *op)=0 |
Emit a SEGMENTOP operator. | |
virtual void | opCpoolRefOp (const PcodeOp *op)=0 |
Emit a CPOOLREF operator. | |
virtual void | opNewOp (const PcodeOp *op)=0 |
Emit a NEW operator. | |
virtual void | opInsertOp (const PcodeOp *op)=0 |
Emit an INSERT operator. | |
virtual void | opExtractOp (const PcodeOp *op)=0 |
Emit an EXTRACT operator. | |
virtual void | opPopcountOp (const PcodeOp *op)=0 |
Emit a POPCOUNT operator. | |
virtual void | opLzcountOp (const PcodeOp *op)=0 |
Emit a LZCOUNT operator. | |
virtual string | unnamedField (int4 off, int4 size) |
Generate an artificial field name. More... | |
Static Public Member Functions | |
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... | |
Static Public Attributes | |
static const string | OPEN_PAREN = "(" |
"(" token | |
static const string | CLOSE_PAREN = ")" |
")" token | |
Protected Member Functions | |
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 | printUnicode (ostream &s, int4 onechar) const =0 |
Print a single unicode character as a character constant for the high-level language. More... | |
virtual void | pushType (const Datatype *ct)=0 |
Push a data-type name onto the RPN expression stack. More... | |
virtual void | pushConstant (uintb val, const Datatype *ct, const Varnode *vn, const PcodeOp *op)=0 |
Push a constant onto the RPN stack. More... | |
virtual bool | pushEquate (uintb val, int4 sz, const EquateSymbol *sym, const Varnode *vn, const PcodeOp *op)=0 |
Push a constant marked up by and EquateSymbol onto the RPN stack. More... | |
virtual void | pushAnnotation (const Varnode *vn, const PcodeOp *op)=0 |
Push an address which is not in the normal data-flow. More... | |
virtual void | pushSymbol (const Symbol *sym, const Varnode *vn, const PcodeOp *op)=0 |
Push a specific Symbol onto the RPN stack. More... | |
virtual void | pushUnnamedLocation (const Address &addr, const Varnode *vn, const PcodeOp *op)=0 |
Push an address as a substitute for a Symbol onto the RPN stack. More... | |
virtual void | pushPartialSymbol (const Symbol *sym, int4 off, int4 sz, const Varnode *vn, const PcodeOp *op, int4 inslot)=0 |
Push a variable that represents only part of a symbol onto the RPN stack. More... | |
virtual void | pushMismatchSymbol (const Symbol *sym, int4 off, int4 sz, const Varnode *vn, const PcodeOp *op)=0 |
Push an identifier for a variable that mismatches with its Symbol. More... | |
virtual void | pushImpliedField (const Varnode *vn, const PcodeOp *op)=0 |
Push the implied field of a given Varnode as an object member extraction operation. More... | |
virtual void | emitLineComment (int4 indent, const Comment *comm) |
Emit a comment line. More... | |
virtual void | emitVarDecl (const Symbol *sym)=0 |
Emit a variable declaration. More... | |
virtual void | emitVarDeclStatement (const Symbol *sym)=0 |
Emit a variable declaration statement. More... | |
virtual bool | emitScopeVarDecls (const Scope *symScope, int4 cat)=0 |
Emit all the variable declarations for a given scope. More... | |
virtual void | emitExpression (const PcodeOp *op)=0 |
Emit a full expression. More... | |
virtual void | emitFunctionDeclaration (const Funcdata *fd)=0 |
Emit a function declaration. More... | |
virtual bool | checkPrintNegation (const Varnode *vn)=0 |
Check whether a given boolean Varnode can be printed in negated form. More... | |
Static Protected Member Functions | |
static bool | unicodeNeedsEscape (int4 codepoint) |
Determine if the given codepoint needs to be escaped. More... | |
Protected Attributes | |
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. | |
Private Attributes | |
string | name |
The name of the high-level language. | |
vector< uint4 > | modstack |
Printing modification stack. | |
vector< const Scope * > | scopestack |
The symbol scope stack. | |
vector< ReversePolish > | revpol |
The Reverse Polish Notation (RPN) token stack. | |
vector< NodePending > | nodepend |
Data-flow nodes waiting to be pushed onto the RPN stack. | |
int4 | pending |
Number of data-flow nodes waiting to be pushed. | |
int4 | line_commentindent |
Number of characters a comment line should be indented. | |
string | commentstart |
Delimiter characters for the start of a comment. | |
string | commentend |
Delimiter characters (if any) for the end of a comment. | |
The base class API for emitting a high-level language.
Instances of this object are responsible for converting a function's (transformed) data-flow graph into the final stream of tokens of a high-level source code language. There a few main entry points including:
The system is responsible for printing:
As part of all this printing, the system is also responsible for
To accomplish this, the API is broken up into three sections. The first section are the main entry point 'doc' methods. The second section are 'emit' methods, which are responsible for printing a representation of a particular high-level code construct. The third section are 'push' and 'op' methods, which are responsible for walking expression trees. The order in which tokens are emitted for an expression is determined by a Reverse Polish Notation (RPN) stack, that the 'push' methods manipulate. Operators and variables are pushed onto this stack and are ultimately emitted in the correct order.
The base class provides a generic printing modifications stack and a symbol scope stack to provide a printing context mechanism for derived classes.
Possible context sensitive modifiers to how tokens get emitted.
ghidra::PrintLanguage::PrintLanguage | ( | Architecture * | g, |
const string & | nm | ||
) |
Constructor.
g | is the Architecture that owns and will use this PrintLanguage |
nm | is the formal name of the language |
References ghidra::PrintLanguageCapability::name.
|
protectedpure virtual |
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 |
Implemented in ghidra::PrintC.
|
pure virtual |
Emit the declaration (and body) of a function.
fd | is the function to emit |
Implemented in ghidra::PrintC, and ghidra::PrintJava.
|
pure virtual |
Emit the declaration for a single (global) Symbol.
sym | is the Symbol to declare |
Implemented in ghidra::PrintC.
|
pure virtual |
Emit definitions of data-types.
typegrp | is the container for the data-types that should be defined |
Implemented in ghidra::PrintC.
|
protected |
Send an variable token from the RPN to the emitter.
Send the given Atom to the low-level emitter, marking it up according to its type
atom | is the given Atom to emit |
References ghidra::PrintLanguage::Atom::ct, ghidra::PrintLanguage::Atom::fd, ghidra::PrintLanguage::Atom::highlight, ghidra::PrintLanguage::Atom::name, ghidra::PrintLanguage::Atom::offset, ghidra::PrintLanguage::Atom::op, ghidra::PrintLanguage::Atom::ptr_second, ghidra::PrintLanguage::Atom::type, and ghidra::PrintLanguage::Atom::vn.
|
protectedpure virtual |
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 |
Implemented in ghidra::PrintC.
|
protectedpure virtual |
Emit a function declaration.
This prints the formal defining prototype for a function.
fd | is the Funcdata object representing the function to be emitted |
Implemented in ghidra::PrintC.
|
protectedvirtual |
Emit a comment line.
The comment will get emitted as a single line using the high-level language's delimiters with the given indent level
indent | is the number of characters to indent |
comm | is the Comment object containing the character data and associated markup info |
References ghidra::Emit::comment_color, ghidra::Comment::getAddr(), ghidra::Address::getOffset(), ghidra::Address::getSpace(), ghidra::Comment::getText(), and ghidra::Comment::setEmitted().
Referenced by ghidra::PrintC::emitCommentFuncHeader(), and ghidra::PrintC::emitCommentGroup().
|
protected |
Send an operator token from the RPN to the emitter.
An OpToken directly from the RPN is sent to the low-level emitter, resolving any final spacing or parentheses.
entry | is the RPN entry to be emitted |
References ghidra::OpToken::binary, ghidra::OpToken::bump, ghidra::OpToken::hiddenfunction, ghidra::PrintLanguage::ReversePolish::id2, ghidra::Emit::no_color, ghidra::PrintLanguage::ReversePolish::op, ghidra::OpToken::postsurround, ghidra::OpToken::presurround, ghidra::OpToken::print1, ghidra::OpToken::print2, ghidra::OpToken::space, ghidra::OpToken::spacing, ghidra::PrintLanguage::ReversePolish::tok, ghidra::OpToken::type, ghidra::OpToken::unary_prefix, and ghidra::PrintLanguage::ReversePolish::visited.
Referenced by ghidra::PrintC::emitBlockCondition().
|
protectedpure virtual |
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 |
Implemented in ghidra::PrintC.
|
protectedpure virtual |
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 |
Implemented in ghidra::PrintC.
|
protectedpure virtual |
Emit a variable declaration statement.
sym | is the Symbol to be declared |
Implemented in ghidra::PrintC.
|
protected |
Emit a byte buffer to the stream as unicode characters.
Characters are emitted until we reach a terminator character or count bytes is consumed.
s | is the output stream |
buf | is the byte buffer |
count | is the maximum number of bytes to consume |
charsize | is 1 for UTF8, 2 for UTF16, or 4 for UTF32 |
bigend | is true for a big endian encoding of UTF elements |
References ghidra::StringManager::getCodepoint().
Referenced by ghidra::PrintJava::opCpoolRefOp(), ghidra::PrintC::opCpoolRefOp(), and ghidra::PrintC::printCharacterConstant().
|
static |
Print a number in binary form.
Print a string a '0' and '1' characters representing the given value
s | is the output stream |
val | is the given value |
Referenced by ghidra::PrintC::push_integer().
|
static |
Determine the most natural base for an integer.
Count '0' and '9' digits base 10. Count '0' and 'f' digits base 16. The highest count is the preferred base.
val | is the given integer |
Referenced by ghidra::PrintC::push_integer().
Push a binary operator onto the RPN stack.
Push an operator onto the stack that has a normal binary format. Both of its input expressions are also pushed.
tok | is the operator token to push |
op | is the associated PcodeOp |
References ghidra::PcodeOp::getIn(), and ghidra::OpToken::negate.
Push a unary operator onto the RPN stack.
Push an operator onto the stack that has a normal unary format. Its input expression is also pushed.
tok | is the operator token to push |
op | is the associated PcodeOp |
References ghidra::PcodeOp::getIn().
|
protected |
Determine if the given token should be emitted in its own parenthetic expression.
The token at the top of the stack is being emitted. Check if its input expression, ending with the given operator token, needs to be surrounded by parentheses to convey the proper meaning.
op2 | is the input token to this operator |
References ghidra::OpToken::binary, ghidra::OpToken::hiddenfunction, ghidra::OpToken::postsurround, ghidra::OpToken::precedence, ghidra::OpToken::presurround, ghidra::OpToken::space, ghidra::OpToken::type, and ghidra::OpToken::unary_prefix.
|
protectedpure virtual |
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 |
Implemented in ghidra::PrintC, and ghidra::PrintJava.
|
protectedpure virtual |
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.
Implemented in ghidra::PrintC.
|
protected |
Push a variable token onto the RPN stack.
Push a single token (an Atom) onto the RPN stack. This may trigger some amount of the RPN stack to get emitted, depending on what was pushed previously. The 'emit' routines are called, popping off as much as possible.
atom | is the token to be pushed |
Referenced by ghidra::PrintC::emitPrototypeInputs(), ghidra::PrintC::emitStructDefinition(), ghidra::PrintC::opCall(), ghidra::PrintJava::opCallind(), ghidra::PrintC::opCallind(), ghidra::PrintC::opCallother(), ghidra::PrintC::opConstructor(), ghidra::PrintJava::opCpoolRefOp(), ghidra::PrintC::opCpoolRefOp(), ghidra::PrintC::opFunc(), ghidra::PrintC::opNewOp(), ghidra::PrintC::opPtrsub(), ghidra::PrintC::opReturn(), ghidra::PrintC::opSubpiece(), ghidra::PrintC::push_float(), ghidra::PrintC::push_integer(), ghidra::PrintC::pushAnnotation(), ghidra::PrintC::pushBoolConstant(), ghidra::PrintC::pushCharConstant(), ghidra::PrintC::pushConstant(), ghidra::PrintC::pushEnumConstant(), ghidra::PrintC::pushImpliedField(), ghidra::PrintC::pushMismatchSymbol(), ghidra::PrintC::pushPartialSymbol(), ghidra::PrintC::pushPrototypeInputs(), ghidra::PrintC::pushPtrCharConstant(), ghidra::PrintC::pushPtrCodeConstant(), ghidra::PrintC::pushSymbol(), ghidra::PrintC::pushSymbolScope(), ghidra::PrintC::pushType(), ghidra::PrintC::pushTypeEnd(), ghidra::PrintJava::pushTypeStart(), ghidra::PrintC::pushTypeStart(), and ghidra::PrintC::pushUnnamedLocation().
|
protectedpure virtual |
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) |
Implemented in ghidra::PrintC.
|
protectedpure virtual |
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) |
Implemented in ghidra::PrintC.
|
protectedpure virtual |
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.
Implemented in ghidra::PrintC.
|
protectedpure virtual |
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 |
Implemented in ghidra::PrintC.
Push an operator token onto the RPN stack.
This generally will recursively push an entire expression onto the RPN stack, up to Varnode objects marked as explicit, and will decide token order and parenthesis placement. As the ordering gets resolved, some amount of the expression may get emitted.
tok | is the operator token to push |
op | is the PcodeOp associated with the token |
Referenced by ghidra::PrintC::emitExpression(), ghidra::PrintC::emitInplaceOp(), ghidra::PrintC::opBoolNegate(), ghidra::PrintC::opCall(), ghidra::PrintJava::opCallind(), ghidra::PrintC::opCallind(), ghidra::PrintC::opCallother(), ghidra::PrintC::opCbranch(), ghidra::PrintC::opConstructor(), ghidra::PrintJava::opCpoolRefOp(), ghidra::PrintC::opCpoolRefOp(), ghidra::PrintC::opFunc(), ghidra::PrintC::opHiddenFunc(), ghidra::PrintJava::opLoad(), ghidra::PrintC::opLoad(), ghidra::PrintC::opNewOp(), ghidra::PrintC::opPtradd(), ghidra::PrintC::opPtrsub(), ghidra::PrintC::opReturn(), ghidra::PrintJava::opStore(), ghidra::PrintC::opStore(), ghidra::PrintC::opSubpiece(), ghidra::PrintC::opTypeCast(), ghidra::PrintC::pushConstant(), ghidra::PrintC::pushEnumConstant(), ghidra::PrintC::pushEquate(), ghidra::PrintC::pushImpliedField(), ghidra::PrintC::pushPartialSymbol(), ghidra::PrintC::pushPrototypeInputs(), ghidra::PrintC::pushSymbolScope(), ghidra::PrintJava::pushTypeStart(), and ghidra::PrintC::pushTypeStart().
|
protectedpure virtual |
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 |
Implemented in ghidra::PrintC.
|
protected |
Push symbol name with adornments matching given Varnode.
We know that the given Varnode matches part of a single Symbol. Push a set of tokens that represents the Varnode, which may require extracting subfields or casting to get the correct value.
vn | is the given Varnode |
op | is the PcodeOp involved in the expression with the Varnode |
isRead | is true if the PcodeOp reads the Varnode |
References ghidra::Varnode::getAddr(), ghidra::Varnode::getHigh(), ghidra::HighVariable::getNameRepresentative(), ghidra::Varnode::getSize(), ghidra::Datatype::getSize(), ghidra::PcodeOp::getSlot(), ghidra::HighVariable::getSymbol(), ghidra::HighVariable::getSymbolOffset(), ghidra::Symbol::getType(), and ghidra::Datatype::needsResolution().
Referenced by ghidra::PrintC::emitExpression().
|
protectedpure virtual |
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 |
Implemented in ghidra::PrintC.
|
protectedpure virtual |
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 |
Implemented in ghidra::PrintC.
Push an expression rooted at a Varnode onto the RPN stack.
For a given implied Varnode, the entire expression producing it is recursively pushed onto the RPN stack.
When calling this method multiple times to push Varnode inputs for a single p-code op, the inputs must be pushed in reverse order.
vn | is the given implied Varnode |
op | is PcodeOp taking the Varnode as input |
m | is the set of printing modifications to apply for this sub-expression |
Referenced by ghidra::PrintC::emitInplaceOp(), ghidra::PrintC::opBoolNegate(), ghidra::PrintC::opBranch(), ghidra::PrintC::opBranchind(), ghidra::PrintC::opCall(), ghidra::PrintJava::opCallind(), ghidra::PrintC::opCallind(), ghidra::PrintC::opCallother(), ghidra::PrintC::opCbranch(), ghidra::PrintC::opConstructor(), ghidra::PrintC::opCopy(), ghidra::PrintJava::opCpoolRefOp(), ghidra::PrintC::opCpoolRefOp(), ghidra::PrintC::opFunc(), ghidra::PrintC::opHiddenFunc(), ghidra::PrintJava::opLoad(), ghidra::PrintC::opLoad(), ghidra::PrintC::opNewOp(), ghidra::PrintC::opPtradd(), ghidra::PrintC::opPtrsub(), ghidra::PrintC::opReturn(), ghidra::PrintC::opSegmentOp(), ghidra::PrintJava::opStore(), ghidra::PrintC::opStore(), ghidra::PrintC::opSubpiece(), and ghidra::PrintC::opTypeCast().
Push an explicit variable onto the RPN stack.
This method pushes a given Varnode as a leaf of the current expression. It decides how the Varnode should get emitted, as a symbol, constant, etc., and then pushes the resulting leaf Atom onto the stack.
vn | is the given explicit Varnode |
op | is the PcodeOp incorporating the Varnode into the current expression |
References ghidra::Varnode::getHighTypeReadFacing(), ghidra::Varnode::getOffset(), ghidra::Varnode::isAnnotation(), and ghidra::Varnode::isConstant().
Referenced by ghidra::PrintC::emitInplaceOp().
|
protected |
Emit from the RPN stack as much as possible.
Any complete sub-expressions that are still on the RPN will get emitted.
References ghidra::Varnode::getDef(), ghidra::PcodeOp::getOpcode(), ghidra::Varnode::hasImpliedField(), ghidra::Varnode::isImplied(), and ghidra::TypeOp::push().
Referenced by ghidra::PrintC::emitEnumDefinition(), ghidra::PrintC::emitExpression(), ghidra::PrintC::emitInplaceOp(), ghidra::PrintC::emitPrototypeInputs(), ghidra::PrintC::emitPrototypeOutput(), ghidra::PrintC::emitSwitchCase(), ghidra::PrintC::emitVarDecl(), ghidra::PrintC::opBranchind(), and ghidra::PrintC::opCbranch().
void ghidra::PrintLanguage::setCommentDelimeter | ( | const string & | start, |
const string & | stop, | ||
bool | usecommentfill | ||
) |
Establish comment delimiters for the language.
By default, comments are indicated in the high-level language by preceding them with a specific sequence of delimiter characters, and optionally by ending the comment with another set of delimiter characters.
start | is the initial sequence of characters delimiting a comment |
stop | if not empty is the sequence delimiting the end of the comment |
usecommentfill | is true if the delimiter needs to be emitted after every line break |
|
pure 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 |
Implemented in ghidra::PrintC.
Referenced by ghidra::OptionCommentStyle::apply().
void ghidra::PrintLanguage::setFlat | ( | bool | val | ) |
Set whether nesting code structure should be emitted.
Emitting formal code structuring can be turned off, causing all control-flow to be represented as goto statements and labels.
val | is true if no code structuring should be emitted |
|
virtual |
Set the default integer format.
This determines how integers are displayed by default. Possible values are "hex" and "dec" to force a given format, or "best" can be used to let the decompiler select what it thinks best for each individual integer.
nm | is "hex", "dec", or "best" |
Referenced by ghidra::OptionIntegerFormat::apply().
void ghidra::PrintLanguage::setLineCommentIndent | ( | int4 | val | ) |
Set the number of characters to indent comment lines.
val | is the number of characters |
Referenced by ghidra::OptionCommentIndent::apply().
void ghidra::PrintLanguage::setMarkup | ( | bool | val | ) |
Set whether the low-level emitter, emits markup.
Tell the emitter whether to emit just the raw tokens or if additional mark-up should be provided.
val | is true for additional mark-up |
Referenced by ghidra::ArchitectureGhidra::ArchitectureGhidra().
|
staticprotected |
Determine if the given codepoint needs to be escaped.
Separate unicode characters that can be clearly emitted in a source code string (letters, numbers, punctuation, symbols) from characters that are better represented in source code with an escape sequence (control characters, unusual spaces, separators, private use characters etc.
codepoint | is the given unicode codepoint to categorize. |
Referenced by ghidra::PrintJava::printUnicode(), and ghidra::PrintC::printUnicode().
|
virtual |
Generate an artificial field name.
This is used if a value is extracted from a structured data-type, but the natural name is not available. An artificial name is generated given just the offset into the data-type and the size in bytes.
off | is the byte offset into the data-type |
size | is the number of bytes in the extracted value |
Referenced by ghidra::PrintC::pushPartialSymbol().