19 #ifndef __PRINT_LANGUAGE__ 20 #define __PRINT_LANGUAGE__ 40 static vector<PrintLanguageCapability *> thelist;
142 force_pointer = 0x10,
143 print_load_value = 0x20,
144 print_store_value = 0x40,
147 comma_separate = 0x200,
151 negatetoken = 0x2000,
152 hide_thisparam = 0x4000
186 vn = v; op = o; vnmod = m; }
208 : name(nm) { type = t; highlight = hl; }
212 : name(nm) { type = t; highlight = hl; ptr_second.ct = c; }
216 : name(nm) { type = t; highlight = hl; ptr_second.ct = c; offset = off; }
220 : name(nm) { type = t; highlight = hl; op = o; }
224 : name(nm) { type=t; highlight = hl; ptr_second.vn = v; op = o; }
228 : name(nm) { type=t; highlight = hl; op = o; ptr_second.fd = f; }
232 vector<uint4> modstack;
233 vector<Scope *> scopestack;
235 vector<ReversePolish> revpol;
236 vector<NodePending> nodepend;
238 int4 line_commentindent;
249 bool isStackEmpty(
void)
const {
return (nodepend.empty()&&revpol.empty()); }
250 bool isModStackEmpty(
void)
const {
return modstack.empty(); }
253 bool isSet(uint4 m)
const {
return ((mods & m)!=0); }
255 void popScope(
void) { scopestack.pop_back(); curscope = scopestack.back(); }
256 void pushMod(
void) { modstack.push_back(mods); }
257 void popMod(
void) { mods = modstack.back(); modstack.pop_back(); }
261 void pushAtom(
const Atom &atom);
266 bool parentheses(
const OpToken *op2);
268 void emitAtom(
const Atom &atom);
269 static bool unicodeNeedsEscape(int4 codepoint);
270 static void writeUtf8(ostream &s,int4 codepoint);
271 static int4 readUtf16(
const uint1 *buf,
bool bigend);
272 static int4 getCodepoint(
const uint1 *buf,int4 charsize,
bool bigend,int4 &skip);
273 bool escapeCharacterData(ostream &s,
const uint1 *buf,int4 count,int4 charsize,
bool bigend)
const;
284 virtual void printUnicode(ostream &s,int4 onechar)
const=0;
290 virtual void pushType(
const Datatype *ct)=0;
299 virtual void pushConstant(uintb val,
const Datatype *ct,
317 virtual void pushAnnotation(
const Varnode *vn,
const PcodeOp *op)=0;
334 virtual void pushUnnamedLocation(
const Address &addr,
346 virtual void pushPartialSymbol(
const Symbol *sym,int4 off,int4 sz,
358 virtual void pushMismatchSymbol(
const Symbol *sym,int4 off,int4 sz,
361 virtual void emitLineComment(int4 indent,
const Comment *comm);
367 virtual void emitVarDecl(
const Symbol *sym)=0;
372 virtual void emitVarDeclStatement(
const Symbol *sym)=0;
380 virtual bool emitScopeVarDecls(
const Scope *scope,int4 cat)=0;
387 virtual void emitExpression(
const PcodeOp *op)=0;
393 virtual void emitFunctionDeclaration(
const Funcdata *fd)=0;
401 virtual bool checkPrintNegation(
const Varnode *vn)=0;
412 void setLineCommentIndent(int4 val);
413 void setCommentDelimeter(
const string &start,
const string &stop,
414 bool usecommentfill);
420 void setXML(
bool val);
421 void setFlat(
bool val);
423 virtual void adjustTypeOperators(
void)=0;
424 virtual void clear(
void);
425 virtual void setIntegerFormat(
const string &nm);
432 virtual void setCommentStyle(
const string &nm)=0;
440 virtual bool isCharacterConstant(
const uint1 *buf,int4 size,int4 charsize)
const=0;
445 virtual void docTypeDefinitions(
const TypeFactory *typegrp)=0;
448 virtual void docAllGlobals(
void)=0;
453 virtual void docSingleGlobal(
const Symbol *sym)=0;
458 virtual void docFunction(
const Funcdata *fd)=0;
460 virtual void emitBlockBasic(
const BlockBasic *bb)=0;
461 virtual void emitBlockGraph(
const BlockGraph *bl)=0;
462 virtual void emitBlockCopy(
const BlockCopy *bl)=0;
463 virtual void emitBlockGoto(
const BlockGoto *bl)=0;
464 virtual void emitBlockLs(
const BlockList *bl)=0;
466 virtual void emitBlockIf(
const BlockIf *bl)=0;
467 virtual void emitBlockWhileDo(
const BlockWhileDo *bl)=0;
468 virtual void emitBlockDoWhile(
const BlockDoWhile *bl)=0;
469 virtual void emitBlockInfLoop(
const BlockInfLoop *bl)=0;
470 virtual void emitBlockSwitch(
const BlockSwitch *bl)=0;
472 virtual void opCopy(
const PcodeOp *op)=0;
473 virtual void opLoad(
const PcodeOp *op)=0;
474 virtual void opStore(
const PcodeOp *op)=0;
475 virtual void opBranch(
const PcodeOp *op)=0;
476 virtual void opCbranch(
const PcodeOp *op)=0;
477 virtual void opBranchind(
const PcodeOp *op)=0;
478 virtual void opCall(
const PcodeOp *op)=0;
479 virtual void opCallind(
const PcodeOp *op)=0;
480 virtual void opCallother(
const PcodeOp *op)=0;
481 virtual void opConstructor(
const PcodeOp *op,
bool withNew)=0;
482 virtual void opReturn(
const PcodeOp *op)=0;
483 virtual void opIntEqual(
const PcodeOp *op)=0;
484 virtual void opIntNotEqual(
const PcodeOp *op)=0;
485 virtual void opIntSless(
const PcodeOp *op)=0;
486 virtual void opIntSlessEqual(
const PcodeOp *op)=0;
487 virtual void opIntLess(
const PcodeOp *op)=0;
488 virtual void opIntLessEqual(
const PcodeOp *op)=0;
489 virtual void opIntZext(
const PcodeOp *op,
const PcodeOp *readOp)=0;
490 virtual void opIntSext(
const PcodeOp *op,
const PcodeOp *readOp)=0;
491 virtual void opIntAdd(
const PcodeOp *op)=0;
492 virtual void opIntSub(
const PcodeOp *op)=0;
493 virtual void opIntCarry(
const PcodeOp *op)=0;
494 virtual void opIntScarry(
const PcodeOp *op)=0;
495 virtual void opIntSborrow(
const PcodeOp *op)=0;
496 virtual void opInt2Comp(
const PcodeOp *op)=0;
497 virtual void opIntNegate(
const PcodeOp *op)=0;
498 virtual void opIntXor(
const PcodeOp *op)=0;
499 virtual void opIntAnd(
const PcodeOp *op)=0;
500 virtual void opIntOr(
const PcodeOp *op)=0;
501 virtual void opIntLeft(
const PcodeOp *op)=0;
502 virtual void opIntRight(
const PcodeOp *op)=0;
503 virtual void opIntSright(
const PcodeOp *op)=0;
504 virtual void opIntMult(
const PcodeOp *op)=0;
505 virtual void opIntDiv(
const PcodeOp *op)=0;
506 virtual void opIntSdiv(
const PcodeOp *op)=0;
507 virtual void opIntRem(
const PcodeOp *op)=0;
508 virtual void opIntSrem(
const PcodeOp *op)=0;
509 virtual void opBoolNegate(
const PcodeOp *op)=0;
510 virtual void opBoolXor(
const PcodeOp *op)=0;
511 virtual void opBoolAnd(
const PcodeOp *op)=0;
512 virtual void opBoolOr(
const PcodeOp *op)=0;
513 virtual void opFloatEqual(
const PcodeOp *op)=0;
514 virtual void opFloatNotEqual(
const PcodeOp *op)=0;
515 virtual void opFloatLess(
const PcodeOp *op)=0;
516 virtual void opFloatLessEqual(
const PcodeOp *op)=0;
517 virtual void opFloatNan(
const PcodeOp *op)=0;
518 virtual void opFloatAdd(
const PcodeOp *op)=0;
519 virtual void opFloatDiv(
const PcodeOp *op)=0;
520 virtual void opFloatMult(
const PcodeOp *op)=0;
521 virtual void opFloatSub(
const PcodeOp *op)=0;
522 virtual void opFloatNeg(
const PcodeOp *op)=0;
523 virtual void opFloatAbs(
const PcodeOp *op)=0;
524 virtual void opFloatSqrt(
const PcodeOp *op)=0;
525 virtual void opFloatInt2Float(
const PcodeOp *op)=0;
526 virtual void opFloatFloat2Float(
const PcodeOp *op)=0;
527 virtual void opFloatTrunc(
const PcodeOp *op)=0;
528 virtual void opFloatCeil(
const PcodeOp *op)=0;
529 virtual void opFloatFloor(
const PcodeOp *op)=0;
530 virtual void opFloatRound(
const PcodeOp *op)=0;
531 virtual void opMultiequal(
const PcodeOp *op)=0;
532 virtual void opIndirect(
const PcodeOp *op)=0;
533 virtual void opPiece(
const PcodeOp *op)=0;
534 virtual void opSubpiece(
const PcodeOp *op)=0;
535 virtual void opCast(
const PcodeOp *op)=0;
536 virtual void opPtradd(
const PcodeOp *op)=0;
537 virtual void opPtrsub(
const PcodeOp *op)=0;
538 virtual void opSegmentOp(
const PcodeOp *op)=0;
539 virtual void opCpoolRefOp(
const PcodeOp *op)=0;
540 virtual void opNewOp(
const PcodeOp *op)=0;
541 virtual void opInsertOp(
const PcodeOp *op)=0;
542 virtual void opExtractOp(
const PcodeOp *op)=0;
543 virtual void opPopcountOp(
const PcodeOp *op)=0;
545 static int4 mostNaturalBase(uintb val);
546 static void formatBinary(ostream &s,uintb val);
NodePending(const Varnode *v, const PcodeOp *o, uint4 m)
Construct a pending data-flow node.
Definition: printlanguage.hh:185
Atom(const string &nm, tagtype t, EmitXml::syntax_highlight hl, const Datatype *c)
Construct a token for a data-type name.
Definition: printlanguage.hh:211
const string & getName(void) const
Get the language name.
Definition: printlanguage.hh:405
void unsetMod(uint4 m)
Deactivate the given printing modification.
Definition: printlanguage.hh:259
CastStrategy * castStrategy
The strategy for emitting explicit case operations.
Definition: printlanguage.hh:243
uint4 mods
Currently active printing modifications.
Definition: printlanguage.hh:245
void pushScope(Scope *sc)
Push a new symbol scope.
Definition: printlanguage.hh:254
virtual void setOutputStream(ostream *t)
Set the output stream for the emitter.
Definition: prettyprint.hh:139
void popMod(void)
Pop to the previous printing modifications.
Definition: printlanguage.hh:257
The base datatype class for the decompiler.
Definition: type.hh:62
Modifier form (like a cast operation)
Definition: printlanguage.hh:88
A loop structure where the condition is checked at the bottom.
Definition: block.hh:599
API and specific strategies for applying type casts.
void setScope(Scope *sc)
Set the current Symbol scope.
Definition: printlanguage.hh:409
ostream * getOutputStream(void) const
Get the output stream being emitted to.
Definition: printlanguage.hh:407
int4 id2
The id of the token group this surrounds (for surround operator tokens)
Definition: printlanguage.hh:172
string name
Unique identifier for language capability.
Definition: printlanguage.hh:42
Container for data structures associated with a single function.
Definition: funcdata.hh:45
virtual ostream * getOutputStream(void) const
Get the current output stream.
Definition: prettyprint.hh:140
bool emitsXml(void) const
Does the low-level emitter, emit XML markup.
Definition: printlanguage.hh:419
Base class (and interface) for pretty printing and XML markup of tokens.
Definition: prettyprint.hh:76
Atom(const string &nm, tagtype t, EmitXml::syntax_highlight hl, const Datatype *c, int4 off)
Construct a token for a field name.
Definition: printlanguage.hh:215
Emit atom as structure field.
Definition: printlanguage.hh:161
const Datatype * ct
A type associated with the token.
Definition: printlanguage.hh:202
Atom(const string &nm, tagtype t, EmitXml::syntax_highlight hl)
Construct a token with no associated data-flow annotations.
Definition: printlanguage.hh:207
bool isdefault
Set to true to treat this as the default language.
Definition: printlanguage.hh:43
Atom(const string &nm, tagtype t, EmitXml::syntax_highlight hl, const PcodeOp *o, const Funcdata *f)
Construct a token for a function name.
Definition: printlanguage.hh:227
A loop structure where the condition is checked at the top.
Definition: block.hh:583
static PrintLanguageCapability * getDefault(void)
Retrieve the default language capability.
Definition: printlanguage.cc:25
const Varnode * vn
The implied Varnode.
Definition: printlanguage.hh:180
No explicitly printed token.
Definition: printlanguage.hh:89
uint4 instr_comment_type
Type of instruction comments to display.
Definition: printlanguage.hh:246
Emit atom as syntax.
Definition: printlanguage.hh:156
void setMod(uint4 m)
Activate the given printing modification.
Definition: printlanguage.hh:258
Infrastructure for discovering code extensions to the decompiler.
virtual bool emitsXml(void) const
Determine if this is an XML markup emitter.
Definition: prettyprint.hh:197
const Funcdata * fd
A function associated with the token.
Definition: printlanguage.hh:201
void pushMod(void)
Push current printing modifications to the stack.
Definition: printlanguage.hh:256
const string & getName(void) const
Get the high-level language name.
Definition: printlanguage.hh:45
void popScope(void)
Pop to the previous symbol scope.
Definition: printlanguage.hh:255
bool paren
True if parentheses are required.
Definition: printlanguage.hh:169
tokentype
The possible types of operator token.
Definition: printlanguage.hh:84
virtual void setMaxLineSize(int4 mls)
Provide a maximum line size to the pretty printer.
Definition: prettyprint.hh:179
An infinite loop structure.
Definition: block.hh:613
Atom(const string &nm, tagtype t, EmitXml::syntax_highlight hl, const PcodeOp *o, const Varnode *v)
Construct a token with an associated PcodeOp and Varnode.
Definition: printlanguage.hh:223
void setMaxLineSize(int4 mls)
Set the maximum number of characters per line.
Definition: printlanguage.hh:410
const string & name
The actual printed characters of the token.
Definition: printlanguage.hh:195
An entry on the reverse polish notation (RPN) stack.
Definition: printlanguage.hh:166
A strategy for applying type casts.
Definition: cast.hh:40
A token representing an operator in the high-level language.
Definition: printlanguage.hh:81
A pending data-flow node; waiting to be placed on the reverse polish notation stack.
Definition: printlanguage.hh:179
Lowest level operation of the p-code language.
Definition: op.hh:58
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
Binary operator form (printed between its inputs)
Definition: printlanguage.hh:85
void setOutputStream(ostream *t)
Set the output stream to emit to.
Definition: printlanguage.hh:408
A basic "if" block.
Definition: block.hh:553
A single non-operator token emitted by the decompiler.
Definition: printlanguage.hh:194
bool associative
True if the operator is associative.
Definition: printlanguage.hh:95
int4 precedence
Precedence level of this token (higher binds more tightly)
Definition: printlanguage.hh:94
Atom(const string &nm, tagtype t, EmitXml::syntax_highlight hl, const PcodeOp *o)
Construct a token with an associated PcodeOp.
Definition: printlanguage.hh:219
syntax_highlight
Possible types of syntax highlighting.
Definition: prettyprint.hh:87
const PcodeOp * op
The PcodeOp associated with the operator token.
Definition: printlanguage.hh:170
const PcodeOp * op
A p-code operation associated with the token.
Definition: printlanguage.hh:198
Manager for all the major decompiler subsystems.
Definition: architecture.hh:117
A control-flow block built out of sub-components.
Definition: block.hh:270
modifiers
Possible context sensitive modifiers to how tokens get emitted.
Definition: printlanguage.hh:137
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
A basic block for p-code operations.
Definition: block.hh:363
uint4 getInstructionComment(void) const
Get the type of comments suitable within the body of a function.
Definition: printlanguage.hh:415
void setIndentIncrement(int4 val)
Set the number of characters indented per level of nesting.
Definition: prettyprint.hh:212
CastStrategy * getCastStrategy(void) const
Get the casting strategy for the language.
Definition: printlanguage.hh:406
int4 visited
The current stage of printing for the operator.
Definition: printlanguage.hh:168
int4 getPending(void) const
Get the number of pending nodes yet to be put on the RPN stack.
Definition: printlanguage.hh:277
A series of blocks that execute in sequence.
Definition: block.hh:495
EmitXml::syntax_highlight highlight
The type of highlighting to use when emitting the token.
Definition: printlanguage.hh:197
Routines for emitting high-level (C) language syntax in a well formatted way.
void setInstructionComment(uint4 val)
Set the type of comments suitable within the body of a function.
Definition: printlanguage.hh:416
static PrintLanguageCapability * findCapability(const string &name)
Find a language capability by name.
Definition: printlanguage.cc:44
A Symbol that holds equate information for a constant.
Definition: database.hh:270
void setIndentIncrement(int4 inc)
Set the number of characters to indent per level of code nesting.
Definition: printlanguage.hh:411
A block that terminates with an unstructured (goto) branch to another block.
Definition: block.hh:442
int4 bump
Spaces to indent if we break here.
Definition: printlanguage.hh:98
virtual void initialize(void)
Complete initialization of an extension point.
Definition: printlanguage.cc:33
int4 stage
Additional elements consumed from the RPN stack when emitting this token.
Definition: printlanguage.hh:93
A structured switch construction.
Definition: block.hh:630
const OpToken * tok
The operator token.
Definition: printlanguage.hh:167
Container class for all Datatype objects in an Architecture.
Definition: type.hh:380
const Varnode * vn
A Varnode associated with the token.
Definition: printlanguage.hh:200
tokentype type
The basic token type.
Definition: printlanguage.hh:96
uint4 getHeaderComment(void) const
Get the type of comments suitable for a function header.
Definition: printlanguage.hh:417
Emit atom as function name.
Definition: printlanguage.hh:158
The base class for a symbol in a symbol table or scope.
Definition: database.hh:153
Unary operator form (printed before its input)
Definition: printlanguage.hh:86
Class for automatically registering extension points to the decompiler.
Definition: capability.hh:36
Emit atom as operator.
Definition: printlanguage.hh:160
int4 offset
The offset (within the parent structure) for a field token.
Definition: printlanguage.hh:204
EmitXml * emit
The low-level token emitter.
Definition: printlanguage.hh:244
Architecture * glb
The Architecture owning the language emitter.
Definition: printlanguage.hh:242
Emit atom as operator.
Definition: printlanguage.hh:159
Function or array operator form.
Definition: printlanguage.hh:87
tagtype type
The type of Atom.
Definition: printlanguage.hh:196
void setHeaderComment(uint4 val)
Set the type of comments suitable for a function header.
Definition: printlanguage.hh:418
virtual PrintLanguage * buildLanguage(Architecture *glb)=0
Build the main PrintLanguage object corresponding to this capability.
Two conditional blocks combined into one conditional using BOOL_AND or BOOL_OR.
Definition: block.hh:516
Emit atom as variable.
Definition: printlanguage.hh:157
int4 id
The id of the token group which this belongs to.
Definition: printlanguage.hh:171
The base class API for emitting a high-level language.
Definition: printlanguage.hh:134
uint4 head_comment_type
Type of header comments to display.
Definition: printlanguage.hh:247
int4 spacing
Spaces to print around operator.
Definition: printlanguage.hh:97
OpToken * negate
The token representing the negation of this token.
Definition: printlanguage.hh:99
uint4 vnmod
Printing modifications to enforce on the expression.
Definition: printlanguage.hh:182
const PcodeOp * op
The single operator consuming value from the implied Varnode.
Definition: printlanguage.hh:181
bool isSet(uint4 m) const
Is the given printing modification active.
Definition: printlanguage.hh:253
Base class for high-level language capabilities.
Definition: printlanguage.hh:39
This class is used to mirror the BlockBasic objects in the fixed control-flow graph for a function...
Definition: block.hh:417
const char * print
Printing characters for the token.
Definition: printlanguage.hh:92
A collection of Symbol objects within a single (namespace or functional) scope.
Definition: database.hh:413
tagtype
Possible types of Atom.
Definition: printlanguage.hh:155