Ghidra Decompiler Analysis Engine
prettyprint.hh
Go to the documentation of this file.
1 /* ###
2  * IP: GHIDRA
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
18 
19 #ifndef __PRETTYPRINT__
20 #define __PRETTYPRINT__
21 
22 #include "type.hh"
23 
24 class Varnode;
25 class PcodeOp;
26 class FlowBlock;
27 class Funcdata;
28 class Symbol;
29 
76 class EmitXml {
77  static const char *highlight[];
78 protected:
79  ostream *s;
80  int4 indentlevel;
81  int4 parenlevel;
83  void resetDefaultsInternal(void) { indentincrement = 2; }
84 public:
85  EmitXml(void) { s = (ostream *)0; indentlevel=0; parenlevel=0; resetDefaultsInternal(); }
86 
91  type_color = 2,
93  var_color = 4,
97  no_color = 8
98  };
99  virtual ~EmitXml(void) {}
100  virtual int4 beginDocument(void);
101  virtual void endDocument(int4 id);
102  virtual int4 beginFunction(const Funcdata *fd);
103  virtual void endFunction(int4 id);
104  virtual int4 beginBlock(const FlowBlock *bl);
105  virtual void endBlock(int4 id);
106  virtual void tagLine(void);
107  virtual void tagLine(int4 indent);
108  virtual int4 beginReturnType(const Varnode *vn);
109  virtual void endReturnType(int4 id);
110  virtual int4 beginVarDecl(const Symbol *sym);
111  virtual void endVarDecl(int4 id);
112  virtual int4 beginStatement(const PcodeOp *op);
113  virtual void endStatement(int4 id);
114  virtual int4 beginFuncProto(void);
115  virtual void endFuncProto(int4 id);
116  virtual void tagVariable(const char *ptr,syntax_highlight hl,
117  const Varnode *vn,const PcodeOp *op);
118  virtual void tagOp(const char *ptr,syntax_highlight hl,const PcodeOp *op);
119  virtual void tagFuncName(const char *ptr,syntax_highlight hl,const Funcdata *fd,const PcodeOp *op);
120  virtual void tagType(const char *ptr,syntax_highlight hl,const Datatype *ct);
121  virtual void tagField(const char *ptr,syntax_highlight hl,const Datatype *ct,int4 off);
122  virtual void tagComment(const char *ptr,syntax_highlight hl,const AddrSpace *spc,uintb off);
123  virtual void tagLabel(const char *ptr,syntax_highlight hl,const AddrSpace *spc,uintb off);
124  virtual void print(const char *str,syntax_highlight hl=no_color);
125  virtual int4 openParen(char o,int4 id=0);
126  virtual void closeParen(char c,int4 id);
127 
132  virtual int4 openGroup(void) { return 0; }
133 
138  virtual void closeGroup(int4 id) {}
139  virtual void clear(void) { parenlevel = 0; indentlevel=0; }
140  virtual void setOutputStream(ostream *t) { s = t; }
141  virtual ostream *getOutputStream(void) const { return s; }
142  virtual void spaces(int4 num,int4 bump=0);
143 
148  virtual int4 startIndent(void) { indentlevel+=indentincrement; return 0; }
149 
155  virtual void stopIndent(int4 id) { indentlevel-=indentincrement; }
156 
161  virtual int4 startComment(void) { return 0; }
162 
167  virtual void stopComment(int4 id) {}
168 
174  virtual void flush(void) {}
175 
180  virtual void setMaxLineSize(int4 mls) {}
181 
186  virtual int4 getMaxLineSize(void) const { return -1; }
187 
193  virtual void setCommentFill(const string &fill) {}
194 
198  virtual bool emitsXml(void) const { return true; }
199 
201  virtual void resetDefaults(void);
202 
206  int4 getParenLevel(void) const { return parenlevel; }
207 
211  int4 getIndentIncrement(void) const { return indentincrement; }
212 
216  void setIndentIncrement(int4 val) { indentincrement = val; }
217 };
218 
224 class EmitNoXml : public EmitXml {
225 public:
226  EmitNoXml(void) : EmitXml() {}
227  virtual int4 beginDocument(void) { return 0; }
228  virtual void endDocument(int4 id) {}
229  virtual int4 beginFunction(const Funcdata *fd) { return 0; }
230  virtual void endFunction(int4 id) {}
231  virtual int4 beginBlock(const FlowBlock *bl) { return 0; }
232  virtual void endBlock(int4 id) {}
233  virtual void tagLine(int4 indent) {
234  *s << endl; for(int4 i=indent;i>0;--i) *s << ' '; }
235  virtual int4 beginReturnType(const Varnode *vn) { return 0; }
236  virtual void endReturnType(int4 id) {}
237  virtual int4 beginVarDecl(const Symbol *sym) { return 0; }
238  virtual void endVarDecl(int4 id) {}
239  virtual int4 beginStatement(const PcodeOp *op) { return 0; }
240  virtual void endStatement(int4 id) {}
241  virtual int4 beginFuncProto(void) { return 0; }
242  virtual void endFuncProto(int4 id) {}
243  virtual void tagVariable(const char *ptr,syntax_highlight hl,
244  const Varnode *vn,const PcodeOp *op) {
245  *s << ptr; }
246  virtual void tagOp(const char *ptr,syntax_highlight hl,const PcodeOp *op) {
247  *s << ptr; }
248  virtual void tagFuncName(const char *ptr,syntax_highlight hl,const Funcdata *fd,const PcodeOp *op) {
249  *s << ptr; }
250  virtual void tagType(const char *ptr,syntax_highlight hl,const Datatype *ct) {
251  *s << ptr; }
252  virtual void tagField(const char *ptr,syntax_highlight hl,const Datatype *ct,int4 off) {
253  *s << ptr; }
254  virtual void tagComment(const char *ptr,syntax_highlight hl,
255  const AddrSpace *spc,uintb off) {
256  *s << ptr; }
257  virtual void tagLabel(const char *ptr,syntax_highlight hl,
258  const AddrSpace *spc,uintb off) {
259  *s << ptr; }
260  virtual void print(const char *str,syntax_highlight hl=no_color) {
261  *s << str; }
262  virtual int4 openParen(char o,int4 id=0) {
263  *s << o; parenlevel += 1; return id; }
264  virtual void closeParen(char c,int4 id) {
265  *s << c; parenlevel -= 1; }
266  virtual bool emitsXml(void) const { return false; }
267 };
268 
282 class TokenSplit {
283 public:
285  enum printclass {
287  end,
295  };
296 
298  enum tag_type {
328  };
329 private:
330  tag_type tagtype;
331  printclass delimtype;
332  string tok;
334  // Additional markup elements for token
335  const PcodeOp *op;
336  union {
337  const Varnode *vn;
338  const FlowBlock *bl;
339  const Funcdata *fd;
340  const Datatype *ct;
341  const AddrSpace *spc;
342  const Symbol *symbol;
343  } ptr_second;
344  uintb off;
345  int4 indentbump;
346  int4 numspaces;
347  int4 size;
348  int4 count;
349  static int4 countbase;
350 public:
351  TokenSplit(void) { }
352 
356  int4 beginDocument(void) {
357  tagtype=docu_b; delimtype=begin; size=0; count=countbase++; return count; }
358 
362  void endDocument(int4 id) {
363  tagtype=docu_e; delimtype=end; size=0; count=id; }
364 
368  int4 beginFunction(const Funcdata *f) {
369  tagtype=func_b; delimtype=begin; size=0; ptr_second.fd=f; count=countbase++; return count; }
370 
374  void endFunction(int4 id) {
375  tagtype=func_e; delimtype=end; size=0; count=id; }
376 
381  int4 beginBlock(const FlowBlock *b) {
382  tagtype=bloc_b; delimtype=ignore; ptr_second.bl=b; count=countbase++; return count; }
383 
387  void endBlock(int4 id) {
388  tagtype=bloc_e; delimtype=ignore; count=id; }
389 
394  int4 beginReturnType(const Varnode *v) {
395  tagtype=rtyp_b; delimtype=begin; ptr_second.vn=v; count=countbase++; return count; }
396 
400  void endReturnType(int4 id) {
401  tagtype=rtyp_e; delimtype=end; count=id; }
402 
407  int4 beginVarDecl(const Symbol *sym) {
408  tagtype=vard_b; delimtype=begin; ptr_second.symbol=sym; count = countbase++; return count; }
409 
413  void endVarDecl(int4 id) {
414  tagtype=vard_e; delimtype=end; count=id; }
415 
420  int4 beginStatement(const PcodeOp *o) {
421  tagtype=stat_b; delimtype=begin; op=o; count=countbase++; return count; }
422 
426  void endStatement(int4 id) {
427  tagtype=stat_e; delimtype=end; count=id; }
428 
432  int4 beginFuncProto(void) {
433  tagtype=prot_b; delimtype=begin; count=countbase++; return count; }
434 
438  void endFuncProto(int4 id) {
439  tagtype=prot_e; delimtype=end; count=id; }
440 
447  void tagVariable(const char *ptr,EmitXml::syntax_highlight h,
448  const Varnode *v,const PcodeOp *o) {
449  tok = ptr; size = tok.size();
450  tagtype=vari_t; delimtype=tokenstring; hl=h; ptr_second.vn=v; op=o; }
451 
457  void tagOp(const char *ptr,EmitXml::syntax_highlight h,const PcodeOp *o) {
458  tok = ptr; size = tok.size();
459  tagtype=op_t; delimtype=tokenstring; hl=h; op=o; }
460 
467  void tagFuncName(const char *ptr,EmitXml::syntax_highlight h,const Funcdata *f,const PcodeOp *o) {
468  tok = ptr; size = tok.size();
469  tagtype=fnam_t; delimtype=tokenstring; hl=h; ptr_second.fd=f; op=o; }
470 
476  void tagType(const char *ptr,EmitXml::syntax_highlight h,const Datatype *ct) {
477  tok = ptr; size = tok.size();
478  tagtype=type_t; delimtype=tokenstring; hl=h; ptr_second.ct=ct; }
479 
486  void tagField(const char *ptr,EmitXml::syntax_highlight h,const Datatype *ct,int4 o) {
487  tok = ptr; size = tok.size();
488  tagtype=field_t; delimtype=tokenstring; hl=h; ptr_second.ct=ct; off=(uintb)o; }
489 
496  void tagComment(const char *ptr,EmitXml::syntax_highlight h,
497  const AddrSpace *s,uintb o) {
498  tok = ptr; size = tok.size(); ptr_second.spc=s; off=o;
499  tagtype=comm_t; delimtype=tokenstring; hl=h; }
500 
507  void tagLabel(const char *ptr,EmitXml::syntax_highlight h,
508  const AddrSpace *s,uintb o) {
509  tok = ptr; size = tok.size(); ptr_second.spc=s; off=o;
510  tagtype=label_t; delimtype=tokenstring; hl=h; }
511 
516  void print(const char *str,EmitXml::syntax_highlight h) {
517  tok = str; size=tok.size();
518  tagtype=synt_t; delimtype=tokenstring; hl=h; }
519 
524  void openParen(char o,int4 id) {
525  tok = o; size = 1;
526  tagtype=opar_t; delimtype=tokenstring; count=id; }
527 
532  void closeParen(char c,int4 id) {
533  tok = c; size = 1;
534  tagtype=cpar_t; delimtype=tokenstring; count=id; }
535 
539  int4 openGroup(void) {
540  tagtype=oinv_t; delimtype=begin; count=countbase++; return count; }
541 
545  void closeGroup(int4 id) {
546  tagtype=cinv_t; delimtype=end; count=id; }
547 
552  int4 startIndent(int4 bump) {
553  tagtype=bump_t; delimtype=begin_indent; indentbump=bump; size=0;
554  count=countbase++; return count; }
555 
559  void stopIndent(int4 id) {
560  tagtype=bump_t; delimtype=end_indent; size=0; count=id; }
561 
565  int4 startComment(void) {
566  tagtype=oinv_t; delimtype=begin_comment; count=countbase++; return count; }
567 
571  void stopComment(int4 id) {
572  tagtype=cinv_t; delimtype=end_comment; count=id; }
573 
578  void spaces(int4 num,int4 bump) {
579  tagtype=spac_t; delimtype=tokenbreak; numspaces=num; indentbump=bump; }
580 
582  void tagLine(void) {
583  tagtype=bump_t; delimtype=tokenbreak; numspaces=999999; indentbump=0; }
584 
586  void tagLine(int4 indent) {
587  tagtype=line_t; delimtype=tokenbreak; numspaces=999999; indentbump=indent; }
588 
589  void print(EmitXml *emit) const;
590  int4 getIndentBump(void) const { return indentbump; }
591  int4 getNumSpaces(void) const { return numspaces; }
592  int4 getSize(void) const { return size; }
593  void setSize(int4 sz) { size = sz; }
594  printclass getClass(void) const { return delimtype; }
595  tag_type getTag(void) const { return tagtype; }
596 #ifdef PRETTY_DEBUG
597  int4 getCount(void) const { return count; }
598  void printDebug(ostream &s) const;
599 #endif
600 };
601 
608 template<typename _type>
610  _type *cache;
611  int4 left;
612  int4 right;
613  int4 max;
614 public:
615  circularqueue(int4 sz);
616  ~circularqueue(void);
617  void setMax(int4 sz);
618  int4 getMax(void) const { return max; }
619  void expand(int4 amount);
620  void clear(void) { left=1; right=0; }
621  bool empty(void) const { return (left == (right+1)%max); }
622  int4 topref(void) const { return right; }
623  int4 bottomref(void) const { return left; }
624  _type &ref(int4 r) { return cache[r]; }
625  _type &top(void) { return cache[right]; }
626  _type &bottom(void) { return cache[left]; }
627  _type &push(void) { right=(right+1)%max; return cache[right]; }
628  _type &pop(void) { int4 tmp=right; right=(right+max-1)%max; return cache[tmp]; }
629  _type &popbottom(void) { int4 tmp=left; left=(left+1)%max; return cache[tmp]; }
630 };
631 
633 template<typename _type>
635 
636 {
637  max = sz;
638  left = 1; // Set queue to be empty
639  right = 0;
640  cache = new _type [ sz ];
641 }
642 
643 template<typename _type>
645 
646 {
647  delete [] cache;
648 }
649 
652 template<typename _type>
654 
655 {
656  if (max != sz) {
657  delete [] cache;
658  max = sz;
659  cache = new _type [ sz ];
660  }
661  left = 1; // This operation empties queue
662  right = 0;
663 }
664 
670 template<typename _type>
672 
673 {
674  _type *newcache = new _type [ max + amount ];
675 
676  int4 i=left;
677  int4 j=0;
678 
679  // Assume there is at least one element in queue
680  while(i != right) {
681  newcache[j++] = cache[i];
682  i = (i+1)%max;
683  }
684  newcache[j] = cache[i]; // Copy rightmost
685  left=0;
686  right = j;
687 
688  delete [] cache;
689  cache = newcache;
690  max += amount;
691 }
692 
706 class EmitPrettyPrint : public EmitXml {
707 #ifdef PRETTY_DEBUG
708  vector<int4> checkid;
709 #endif
710  EmitXml *lowlevel;
711  vector<int4> indentstack;
712  int4 spaceremain;
713  int4 maxlinesize;
714  int4 leftotal;
715  int4 rightotal;
716  bool needbreak;
717  bool commentmode;
718  string commentfill;
719  circularqueue<int4> scanqueue;
720  circularqueue<TokenSplit> tokqueue;
721  void expand(void);
722  void checkstart(void);
723  void checkend(void);
724  void checkstring(void);
725  void checkbreak(void);
726  void overflow(void);
727  void print(const TokenSplit &tok);
728  void advanceleft(void);
729  void scan(void);
730  void resetDefaultsPrettyPrint(void) { setMaxLineSize(100); }
731 public:
732  EmitPrettyPrint(void);
733  virtual ~EmitPrettyPrint(void);
734  virtual int4 beginDocument(void);
735  virtual void endDocument(int4 id);
736  virtual int4 beginFunction(const Funcdata *fd);
737  virtual void endFunction(int4 id);
738  virtual int4 beginBlock(const FlowBlock *bl);
739  virtual void endBlock(int4 id);
740  virtual void tagLine(void);
741  virtual void tagLine(int4 indent);
742  virtual int4 beginReturnType(const Varnode *vn);
743  virtual void endReturnType(int4 id);
744  virtual int4 beginVarDecl(const Symbol *sym);
745  virtual void endVarDecl(int4 id);
746  virtual int4 beginStatement(const PcodeOp *op);
747  virtual void endStatement(int4 id);
748  virtual int4 beginFuncProto(void);
749  virtual void endFuncProto(int4 id);
750  virtual void tagVariable(const char *ptr,syntax_highlight hl,
751  const Varnode *vn,const PcodeOp *op);
752  virtual void tagOp(const char *ptr,syntax_highlight hl,const PcodeOp *op);
753  virtual void tagFuncName(const char *ptr,syntax_highlight hl,const Funcdata *fd,const PcodeOp *op);
754  virtual void tagType(const char *ptr,syntax_highlight hl,const Datatype *ct);
755  virtual void tagField(const char *ptr,syntax_highlight hl,const Datatype *ct,int4 off);
756  virtual void tagComment(const char *ptr,syntax_highlight hl,
757  const AddrSpace *spc,uintb off);
758  virtual void tagLabel(const char *ptr,syntax_highlight hl,
759  const AddrSpace *spc,uintb off);
760  virtual void print(const char *str,syntax_highlight hl=no_color);
761  virtual int4 openParen(char o,int4 id=0);
762  virtual void closeParen(char c,int4 id);
763  virtual int4 openGroup(void);
764  virtual void closeGroup(int4 id);
765  virtual void clear(void);
766  virtual void setOutputStream(ostream *t) { lowlevel->setOutputStream(t); }
767  virtual ostream *getOutputStream(void) const { return lowlevel->getOutputStream(); }
768  virtual void spaces(int4 num,int4 bump=0);
769  virtual int4 startIndent(void);
770  virtual void stopIndent(int4 id);
771  virtual int4 startComment(void);
772  virtual void stopComment(int4 id);
773  virtual void flush(void);
774  virtual void setMaxLineSize(int4 val);
775  virtual int4 getMaxLineSize(void) const { return maxlinesize; }
776  virtual void setCommentFill(const string &fill) { commentfill = fill; }
777  virtual bool emitsXml(void) const { return lowlevel->emitsXml(); }
778  virtual void resetDefaults(void);
779  void setXML(bool val);
780 };
781 
782 #endif
TokenSplit::bloc_e
@ bloc_e
End of a control-flow section.
Definition: prettyprint.hh:304
EmitPrettyPrint::endDocument
virtual void endDocument(int4 id)
End a whole document of output.
Definition: prettyprint.cc:872
EmitNoXml::endVarDecl
virtual void endVarDecl(int4 id)
End a variable declaration.
Definition: prettyprint.hh:238
circularqueue
A circular buffer template.
Definition: prettyprint.hh:609
TokenSplit::tokenstring
@ tokenstring
A token representing actual content.
Definition: prettyprint.hh:288
EmitPrettyPrint::stopComment
virtual void stopComment(int4 id)
End a comment block.
Definition: prettyprint.cc:1137
EmitXml::beginStatement
virtual int4 beginStatement(const PcodeOp *op)
Begin a source code statement.
Definition: prettyprint.cc:122
EmitPrettyPrint::tagType
virtual void tagType(const char *ptr, syntax_highlight hl, const Datatype *ct)
Emit a data-type identifier.
Definition: prettyprint.cc:1042
TokenSplit::cinv_t
@ cinv_t
End of an arbitrary (invisible) grouping.
Definition: prettyprint.hh:324
EmitPrettyPrint::spaces
virtual void spaces(int4 num, int4 bump=0)
Emit a sequence of space characters as part of source code.
Definition: prettyprint.cc:1161
EmitPrettyPrint::tagOp
virtual void tagOp(const char *ptr, syntax_highlight hl, const PcodeOp *op)
Emit an operation token.
Definition: prettyprint.cc:1024
TokenSplit::field_t
@ field_t
A field name for a structured data-type.
Definition: prettyprint.hh:317
TokenSplit::tagField
void tagField(const char *ptr, EmitXml::syntax_highlight h, const Datatype *ct, int4 o)
Create an identifier for a field within a structured data-type.
Definition: prettyprint.hh:486
EmitXml::endVarDecl
virtual void endVarDecl(int4 id)
End a variable declaration.
Definition: prettyprint.cc:115
EmitPrettyPrint::tagLabel
virtual void tagLabel(const char *ptr, syntax_highlight hl, const AddrSpace *spc, uintb off)
Emit a code label identifier.
Definition: prettyprint.cc:1069
AddrSpace
A region where processor data is stored.
Definition: space.hh:73
EmitXml::getMaxLineSize
virtual int4 getMaxLineSize(void) const
Get the current maximum line size.
Definition: prettyprint.hh:186
FlowBlock
Description of a control-flow block containing PcodeOps.
Definition: block.hh:60
TokenSplit::docu_b
@ docu_b
Start of a document.
Definition: prettyprint.hh:299
TokenSplit::synt_t
@ synt_t
Other unspecified syntax.
Definition: prettyprint.hh:320
TokenSplit::opar_t
@ opar_t
Open parenthesis.
Definition: prettyprint.hh:321
EmitNoXml::endReturnType
virtual void endReturnType(int4 id)
End a return type declaration.
Definition: prettyprint.hh:236
EmitPrettyPrint::startIndent
virtual int4 startIndent(void)
Start a new indent level.
Definition: prettyprint.cc:1170
EmitPrettyPrint::getMaxLineSize
virtual int4 getMaxLineSize(void) const
Get the current maximum line size.
Definition: prettyprint.hh:775
EmitXml::tagComment
virtual void tagComment(const char *ptr, syntax_highlight hl, const AddrSpace *spc, uintb off)
Emit a comment string as part of the generated source code.
Definition: prettyprint.cc:259
TokenSplit::tagLine
void tagLine(int4 indent)
Create a line break token with special indentation.
Definition: prettyprint.hh:586
EmitNoXml::closeParen
virtual void closeParen(char c, int4 id)
Emit a close parenthesis.
Definition: prettyprint.hh:264
TokenSplit::ignore
@ ignore
Mark-up that doesn't affect pretty printing.
Definition: prettyprint.hh:294
EmitXml::resetDefaults
virtual void resetDefaults(void)
(Re)set the default emitting options
Definition: prettyprint.cc:347
EmitNoXml::emitsXml
virtual bool emitsXml(void) const
Determine if this is an XML markup emitter.
Definition: prettyprint.hh:266
EmitPrettyPrint::beginFuncProto
virtual int4 beginFuncProto(void)
Begin a function prototype declaration.
Definition: prettyprint.cc:996
EmitPrettyPrint::tagVariable
virtual void tagVariable(const char *ptr, syntax_highlight hl, const Varnode *vn, const PcodeOp *op)
Emit a variable token.
Definition: prettyprint.cc:1015
EmitXml::param_color
@ param_color
Function parameters.
Definition: prettyprint.hh:95
TokenSplit::endDocument
void endDocument(int4 id)
Create an "end document" command.
Definition: prettyprint.hh:362
EmitPrettyPrint::closeGroup
virtual void closeGroup(int4 id)
End a group of things that are printed together.
Definition: prettyprint.cc:1118
EmitXml::stopIndent
virtual void stopIndent(int4 id)
End an indent level.
Definition: prettyprint.hh:155
EmitPrettyPrint::tagComment
virtual void tagComment(const char *ptr, syntax_highlight hl, const AddrSpace *spc, uintb off)
Emit a comment string as part of the generated source code.
Definition: prettyprint.cc:1060
EmitXml::syntax_highlight
syntax_highlight
Possible types of syntax highlighting.
Definition: prettyprint.hh:88
TokenSplit::beginDocument
int4 beginDocument(void)
Create a "begin document" command.
Definition: prettyprint.hh:356
TokenSplit::end_comment
@ end_comment
End of a comment block.
Definition: prettyprint.hh:293
EmitPrettyPrint::beginBlock
virtual int4 beginBlock(const FlowBlock *bl)
Begin a control-flow element.
Definition: prettyprint.cc:904
TokenSplit::startIndent
int4 startIndent(int4 bump)
Create a "start a new indent level" command.
Definition: prettyprint.hh:552
TokenSplit::stat_e
@ stat_e
End of a statement.
Definition: prettyprint.hh:310
TokenSplit::tagType
void tagType(const char *ptr, EmitXml::syntax_highlight h, const Datatype *ct)
Create a data-type identifier token.
Definition: prettyprint.hh:476
EmitXml::tagField
virtual void tagField(const char *ptr, syntax_highlight hl, const Datatype *ct, int4 off)
Emit an identifier for a field within a structured data-type.
Definition: prettyprint.cc:234
EmitPrettyPrint::openParen
virtual int4 openParen(char o, int4 id=0)
Emit an open parenthesis.
Definition: prettyprint.cc:1087
TokenSplit::bloc_b
@ bloc_b
Start of a control-flow section.
Definition: prettyprint.hh:303
EmitPrettyPrint::beginVarDecl
virtual int4 beginVarDecl(const Symbol *sym)
Begin a variable declaration.
Definition: prettyprint.cc:958
TokenSplit::endVarDecl
void endVarDecl(int4 id)
Create an "end variable declaration" command.
Definition: prettyprint.hh:413
TokenSplit::vari_t
@ vari_t
A variable identifier.
Definition: prettyprint.hh:313
TokenSplit::openParen
void openParen(char o, int4 id)
Create an open parenthesis.
Definition: prettyprint.hh:524
EmitNoXml
A trivial emitter that outputs syntax straight to the stream.
Definition: prettyprint.hh:224
EmitPrettyPrint::setCommentFill
virtual void setCommentFill(const string &fill)
Set the comment fill characters for when line breaks are forced.
Definition: prettyprint.hh:776
TokenSplit::stat_b
@ stat_b
Start of a statement.
Definition: prettyprint.hh:309
EmitNoXml::beginVarDecl
virtual int4 beginVarDecl(const Symbol *sym)
Begin a variable declaration.
Definition: prettyprint.hh:237
EmitPrettyPrint::endBlock
virtual void endBlock(int4 id)
End a control-flow element.
Definition: prettyprint.cc:913
EmitXml::stopComment
virtual void stopComment(int4 id)
End a comment block.
Definition: prettyprint.hh:167
TokenSplit::endFunction
void endFunction(int4 id)
Create an "end function body" command.
Definition: prettyprint.hh:374
EmitXml::openParen
virtual int4 openParen(char o, int4 id=0)
Emit an open parenthesis.
Definition: prettyprint.cc:304
EmitNoXml::tagVariable
virtual void tagVariable(const char *ptr, syntax_highlight hl, const Varnode *vn, const PcodeOp *op)
Emit a variable token.
Definition: prettyprint.hh:243
EmitPrettyPrint::resetDefaults
virtual void resetDefaults(void)
(Re)set the default emitting options
Definition: prettyprint.cc:1233
EmitNoXml::endBlock
virtual void endBlock(int4 id)
End a control-flow element.
Definition: prettyprint.hh:232
EmitXml::setCommentFill
virtual void setCommentFill(const string &fill)
Set the comment fill characters for when line breaks are forced.
Definition: prettyprint.hh:193
EmitNoXml::beginReturnType
virtual int4 beginReturnType(const Varnode *vn)
Begin a return type declaration.
Definition: prettyprint.hh:235
EmitXml::tagLabel
virtual void tagLabel(const char *ptr, syntax_highlight hl, const AddrSpace *spc, uintb off)
Emit a code label identifier.
Definition: prettyprint.cc:276
TokenSplit::tagComment
void tagComment(const char *ptr, EmitXml::syntax_highlight h, const AddrSpace *s, uintb o)
Create a comment string in the generated source code.
Definition: prettyprint.hh:496
EmitPrettyPrint::setXML
void setXML(bool val)
Toggle whether the low-level emitter emits XML markup or not.
Definition: prettyprint.cc:1209
EmitPrettyPrint::endReturnType
virtual void endReturnType(int4 id)
End a return type declaration.
Definition: prettyprint.cc:949
EmitNoXml::print
virtual void print(const char *str, syntax_highlight hl=no_color)
Emit other (more unusual) syntax as part of source code generation.
Definition: prettyprint.hh:260
circularqueue::expand
void expand(int4 amount)
Expand the (maximum) size of the queue.
Definition: prettyprint.hh:671
TokenSplit::stopIndent
void stopIndent(int4 id)
Create an "end an indent level" command.
Definition: prettyprint.hh:559
EmitNoXml::tagField
virtual void tagField(const char *ptr, syntax_highlight hl, const Datatype *ct, int4 off)
Emit an identifier for a field within a structured data-type.
Definition: prettyprint.hh:252
TokenSplit::end
@ end
A token that ends a printing group.
Definition: prettyprint.hh:287
TokenSplit::endReturnType
void endReturnType(int4 id)
Create an "end return type declaration" command.
Definition: prettyprint.hh:400
PcodeOp
Lowest level operation of the p-code language.
Definition: op.hh:58
EmitNoXml::tagType
virtual void tagType(const char *ptr, syntax_highlight hl, const Datatype *ct)
Emit a data-type identifier.
Definition: prettyprint.hh:250
EmitXml::setMaxLineSize
virtual void setMaxLineSize(int4 mls)
Provide a maximum line size to the pretty printer.
Definition: prettyprint.hh:180
TokenSplit::comm_t
@ comm_t
Part of a comment block.
Definition: prettyprint.hh:318
EmitXml::global_color
@ global_color
Global variable identifiers.
Definition: prettyprint.hh:96
TokenSplit::openGroup
int4 openGroup(void)
Create a "start a printing group" command.
Definition: prettyprint.hh:539
EmitXml::parenlevel
int4 parenlevel
Current depth of parentheses.
Definition: prettyprint.hh:81
EmitXml::const_color
@ const_color
Constant values.
Definition: prettyprint.hh:94
EmitPrettyPrint::beginDocument
virtual int4 beginDocument(void)
Begin a whole document of output.
Definition: prettyprint.cc:862
TokenSplit::beginVarDecl
int4 beginVarDecl(const Symbol *sym)
Create a "begin variable declaration" command.
Definition: prettyprint.hh:407
TokenSplit::begin_comment
@ begin_comment
Start of a comment block.
Definition: prettyprint.hh:292
EmitNoXml::tagFuncName
virtual void tagFuncName(const char *ptr, syntax_highlight hl, const Funcdata *fd, const PcodeOp *op)
Emit a function identifier.
Definition: prettyprint.hh:248
EmitPrettyPrint::endFuncProto
virtual void endFuncProto(int4 id)
End a function prototype declaration.
Definition: prettyprint.cc:1006
TokenSplit::end_indent
@ end_indent
End of a nesting level.
Definition: prettyprint.hh:291
EmitNoXml::tagLabel
virtual void tagLabel(const char *ptr, syntax_highlight hl, const AddrSpace *spc, uintb off)
Emit a code label identifier.
Definition: prettyprint.hh:257
EmitXml::funcname_color
@ funcname_color
Function identifiers.
Definition: prettyprint.hh:92
EmitXml::tagType
virtual void tagType(const char *ptr, syntax_highlight hl, const Datatype *ct)
Emit a data-type identifier.
Definition: prettyprint.cc:216
EmitXml::setIndentIncrement
void setIndentIncrement(int4 val)
Set the number of characters indented per level of nesting.
Definition: prettyprint.hh:216
EmitXml::startIndent
virtual int4 startIndent(void)
Start a new indent level.
Definition: prettyprint.hh:148
EmitPrettyPrint::tagField
virtual void tagField(const char *ptr, syntax_highlight hl, const Datatype *ct, int4 off)
Emit an identifier for a field within a structured data-type.
Definition: prettyprint.cc:1051
EmitNoXml::tagComment
virtual void tagComment(const char *ptr, syntax_highlight hl, const AddrSpace *spc, uintb off)
Emit a comment string as part of the generated source code.
Definition: prettyprint.hh:254
TokenSplit::tagVariable
void tagVariable(const char *ptr, EmitXml::syntax_highlight h, const Varnode *v, const PcodeOp *o)
Create a variable identifier token.
Definition: prettyprint.hh:447
EmitNoXml::endFunction
virtual void endFunction(int4 id)
End a whole declaration and body of a function.
Definition: prettyprint.hh:230
TokenSplit::tagLine
void tagLine(void)
Create a line break token.
Definition: prettyprint.hh:582
Varnode
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
EmitXml::endFunction
virtual void endFunction(int4 id)
End a whole declaration and body of a function.
Definition: prettyprint.cc:52
TokenSplit::bump_t
@ bump_t
Required line break.
Definition: prettyprint.hh:326
EmitXml::indentlevel
int4 indentlevel
Current indent level (in fixed width characters)
Definition: prettyprint.hh:80
TokenSplit::closeParen
void closeParen(char c, int4 id)
Create a close parenthesis.
Definition: prettyprint.hh:532
TokenSplit::label_t
@ label_t
A code label.
Definition: prettyprint.hh:319
TokenSplit::begin
@ begin
A token that starts a printing group.
Definition: prettyprint.hh:286
EmitPrettyPrint::endVarDecl
virtual void endVarDecl(int4 id)
End a variable declaration.
Definition: prettyprint.cc:968
EmitNoXml::beginStatement
virtual int4 beginStatement(const PcodeOp *op)
Begin a source code statement.
Definition: prettyprint.hh:239
TokenSplit::spaces
void spaces(int4 num, int4 bump)
Create a whitespace token.
Definition: prettyprint.hh:578
TokenSplit::bl
const FlowBlock * bl
Associated Control-flow.
Definition: prettyprint.hh:338
EmitXml::emitsXml
virtual bool emitsXml(void) const
Determine if this is an XML markup emitter.
Definition: prettyprint.hh:198
EmitPrettyPrint::emitsXml
virtual bool emitsXml(void) const
Determine if this is an XML markup emitter.
Definition: prettyprint.hh:777
EmitPrettyPrint::setMaxLineSize
virtual void setMaxLineSize(int4 val)
Provide a maximum line size to the pretty printer.
Definition: prettyprint.cc:1221
TokenSplit::docu_e
@ docu_e
End of a document.
Definition: prettyprint.hh:300
circularqueue::circularqueue
circularqueue(int4 sz)
Construct queue of a given size.
Definition: prettyprint.hh:634
EmitXml::endFuncProto
virtual void endFuncProto(int4 id)
End a function prototype declaration.
Definition: prettyprint.cc:146
EmitXml::closeGroup
virtual void closeGroup(int4 id)
End a group of things that are printed together.
Definition: prettyprint.hh:138
TokenSplit::startComment
int4 startComment(void)
Create a "start a comment block" command.
Definition: prettyprint.hh:565
TokenSplit::tag_type
tag_type
The exhaustive list of possible token types.
Definition: prettyprint.hh:298
EmitNoXml::endFuncProto
virtual void endFuncProto(int4 id)
End a function prototype declaration.
Definition: prettyprint.hh:242
circularqueue::setMax
void setMax(int4 sz)
Establish a new maximum queue size.
Definition: prettyprint.hh:653
EmitPrettyPrint::stopIndent
virtual void stopIndent(int4 id)
End an indent level.
Definition: prettyprint.cc:1179
EmitXml::endStatement
virtual void endStatement(int4 id)
End a source code statement.
Definition: prettyprint.cc:133
EmitPrettyPrint::startComment
virtual int4 startComment(void)
Start a comment block within the emitted source code.
Definition: prettyprint.cc:1127
TokenSplit::endStatement
void endStatement(int4 id)
Create an "end source code statement" command.
Definition: prettyprint.hh:426
EmitNoXml::openParen
virtual int4 openParen(char o, int4 id=0)
Emit an open parenthesis.
Definition: prettyprint.hh:262
Funcdata
Container for data structures associated with a single function.
Definition: funcdata.hh:45
Datatype
The base datatype class for the decompiler.
Definition: type.hh:62
EmitXml::tagFuncName
virtual void tagFuncName(const char *ptr, syntax_highlight hl, const Funcdata *fd, const PcodeOp *op)
Emit a function identifier.
Definition: prettyprint.cc:197
EmitXml::indentincrement
int4 indentincrement
Change in indentlevel per level of nesting.
Definition: prettyprint.hh:82
EmitXml::getParenLevel
int4 getParenLevel(void) const
Get the current parentheses depth.
Definition: prettyprint.hh:206
TokenSplit::endFuncProto
void endFuncProto(int4 id)
Create an "end function prototype declaration" command.
Definition: prettyprint.hh:438
TokenSplit::line_t
@ line_t
Required line break with one-time indent level.
Definition: prettyprint.hh:327
TokenSplit::fd
const Funcdata * fd
Associated Function.
Definition: prettyprint.hh:339
TokenSplit::beginBlock
int4 beginBlock(const FlowBlock *b)
Create a "begin control-flow element" command.
Definition: prettyprint.hh:381
TokenSplit::rtyp_b
@ rtyp_b
Start of a return type declaration.
Definition: prettyprint.hh:305
EmitXml::keyword_color
@ keyword_color
Keyword in the high-level language.
Definition: prettyprint.hh:89
EmitXml::beginFunction
virtual int4 beginFunction(const Funcdata *fd)
Begin a whole declaration and body of a function.
Definition: prettyprint.cc:44
TokenSplit::type_t
@ type_t
A data-type identifier.
Definition: prettyprint.hh:316
EmitNoXml::beginFuncProto
virtual int4 beginFuncProto(void)
Begin a function prototype declaration.
Definition: prettyprint.hh:241
TokenSplit::spac_t
@ spac_t
White space.
Definition: prettyprint.hh:325
TokenSplit::tagLabel
void tagLabel(const char *ptr, EmitXml::syntax_highlight h, const AddrSpace *s, uintb o)
Create a code label identifier token.
Definition: prettyprint.hh:507
TokenSplit::rtyp_e
@ rtyp_e
End of a return type declaration.
Definition: prettyprint.hh:306
TokenSplit::printclass
printclass
An enumeration denoting the general class of a token.
Definition: prettyprint.hh:285
TokenSplit::fnam_t
@ fnam_t
A function identifier.
Definition: prettyprint.hh:315
EmitXml::s
ostream * s
Stream being emitted to.
Definition: prettyprint.hh:79
EmitXml::tagVariable
virtual void tagVariable(const char *ptr, syntax_highlight hl, const Varnode *vn, const PcodeOp *op)
Emit a variable token.
Definition: prettyprint.cc:157
EmitPrettyPrint::closeParen
virtual void closeParen(char c, int4 id)
Emit a close parenthesis.
Definition: prettyprint.cc:1098
EmitNoXml::tagOp
virtual void tagOp(const char *ptr, syntax_highlight hl, const PcodeOp *op)
Emit an operation token.
Definition: prettyprint.hh:246
TokenSplit::tagFuncName
void tagFuncName(const char *ptr, EmitXml::syntax_highlight h, const Funcdata *f, const PcodeOp *o)
Create a function identifier token.
Definition: prettyprint.hh:467
EmitPrettyPrint::beginStatement
virtual int4 beginStatement(const PcodeOp *op)
Begin a source code statement.
Definition: prettyprint.cc:977
EmitXml::beginDocument
virtual int4 beginDocument(void)
Begin a whole document of output.
Definition: prettyprint.cc:31
EmitPrettyPrint::tagFuncName
virtual void tagFuncName(const char *ptr, syntax_highlight hl, const Funcdata *fd, const PcodeOp *op)
Emit a function identifier.
Definition: prettyprint.cc:1033
EmitPrettyPrint::beginFunction
virtual int4 beginFunction(const Funcdata *fd)
Begin a whole declaration and body of a function.
Definition: prettyprint.cc:881
EmitXml
Base class (and interface) for pretty printing and XML markup of tokens.
Definition: prettyprint.hh:76
EmitXml::spaces
virtual void spaces(int4 num, int4 bump=0)
Emit a sequence of space characters as part of source code.
Definition: prettyprint.cc:333
EmitXml::endReturnType
virtual void endReturnType(int4 id)
End a return type declaration.
Definition: prettyprint.cc:100
TokenSplit
A token/command object in the pretty printing stream.
Definition: prettyprint.hh:282
EmitXml::endBlock
virtual void endBlock(int4 id)
End a control-flow element.
Definition: prettyprint.cc:68
type.hh
Classes for describing and printing data-types.
TokenSplit::prot_e
@ prot_e
End of a function prototype.
Definition: prettyprint.hh:312
EmitXml::no_color
@ no_color
Un-highlighted.
Definition: prettyprint.hh:97
EmitXml::beginVarDecl
virtual int4 beginVarDecl(const Symbol *sym)
Begin a variable declaration.
Definition: prettyprint.cc:107
EmitPrettyPrint::tagLine
virtual void tagLine(void)
Force a line break.
Definition: prettyprint.cc:921
TokenSplit::tagOp
void tagOp(const char *ptr, EmitXml::syntax_highlight h, const PcodeOp *o)
Create an operator token.
Definition: prettyprint.hh:457
TokenSplit::begin_indent
@ begin_indent
Start of a new nesting level.
Definition: prettyprint.hh:290
EmitXml::endDocument
virtual void endDocument(int4 id)
End a whole document of output.
Definition: prettyprint.cc:38
EmitXml::print
virtual void print(const char *str, syntax_highlight hl=no_color)
Emit other (more unusual) syntax as part of source code generation.
Definition: prettyprint.cc:291
circularqueue::~circularqueue
~circularqueue(void)
Destructor.
Definition: prettyprint.hh:644
EmitXml::type_color
@ type_color
Data-type identifiers.
Definition: prettyprint.hh:91
TokenSplit::print
void print(const char *str, EmitXml::syntax_highlight h)
Create a token for other (more unusual) syntax in source code.
Definition: prettyprint.hh:516
EmitPrettyPrint::flush
virtual void flush(void)
Flush any remaining character data.
Definition: prettyprint.cc:1187
EmitXml::beginReturnType
virtual int4 beginReturnType(const Varnode *vn)
Begin a return type declaration.
Definition: prettyprint.cc:89
EmitXml::closeParen
virtual void closeParen(char c, int4 id)
Emit a close parenthesis.
Definition: prettyprint.cc:319
TokenSplit::func_b
@ func_b
Start of a function body.
Definition: prettyprint.hh:301
EmitXml::flush
virtual void flush(void)
Flush any remaining character data.
Definition: prettyprint.hh:174
TokenSplit::oinv_t
@ oinv_t
Start of an arbitrary (invisible) grouping.
Definition: prettyprint.hh:323
EmitPrettyPrint
A generic source code pretty printer.
Definition: prettyprint.hh:706
TokenSplit::vard_e
@ vard_e
End of a variable declaration.
Definition: prettyprint.hh:308
TokenSplit::symbol
const Symbol * symbol
Associated Symbol being displayed.
Definition: prettyprint.hh:342
EmitXml::beginFuncProto
virtual int4 beginFuncProto(void)
Begin a function prototype declaration.
Definition: prettyprint.cc:139
EmitNoXml::beginBlock
virtual int4 beginBlock(const FlowBlock *bl)
Begin a control-flow element.
Definition: prettyprint.hh:231
TokenSplit::spc
const AddrSpace * spc
Associated Address.
Definition: prettyprint.hh:341
EmitXml::tagLine
virtual void tagLine(void)
Force a line break.
Definition: prettyprint.cc:73
TokenSplit::beginFuncProto
int4 beginFuncProto(void)
Create a "begin function prototype declaration" command.
Definition: prettyprint.hh:432
EmitXml::comment_color
@ comment_color
Comments.
Definition: prettyprint.hh:90
TokenSplit::stopComment
void stopComment(int4 id)
Create an "end a comment block" command.
Definition: prettyprint.hh:571
EmitNoXml::tagLine
virtual void tagLine(int4 indent)
Force a line break and indent level.
Definition: prettyprint.hh:233
EmitXml::tagOp
virtual void tagOp(const char *ptr, syntax_highlight hl, const PcodeOp *op)
Emit an operation token.
Definition: prettyprint.cc:177
TokenSplit::endBlock
void endBlock(int4 id)
Create an "end control-flow element" command.
Definition: prettyprint.hh:387
TokenSplit::beginStatement
int4 beginStatement(const PcodeOp *o)
Create a "begin source code statement" command.
Definition: prettyprint.hh:420
TokenSplit::vn
const Varnode * vn
Associated Varnode.
Definition: prettyprint.hh:337
TokenSplit::closeGroup
void closeGroup(int4 id)
Create an "end a printing group" command.
Definition: prettyprint.hh:545
EmitPrettyPrint::openGroup
virtual int4 openGroup(void)
Start a group of things that are printed together.
Definition: prettyprint.cc:1108
EmitNoXml::endDocument
virtual void endDocument(int4 id)
End a whole document of output.
Definition: prettyprint.hh:228
EmitXml::getIndentIncrement
int4 getIndentIncrement(void) const
Get the number of characters indented per level of nesting.
Definition: prettyprint.hh:211
EmitNoXml::endStatement
virtual void endStatement(int4 id)
End a source code statement.
Definition: prettyprint.hh:240
EmitPrettyPrint::endFunction
virtual void endFunction(int4 id)
End a whole declaration and body of a function.
Definition: prettyprint.cc:895
Symbol
The base class for a symbol in a symbol table or scope.
Definition: database.hh:152
TokenSplit::vard_b
@ vard_b
Start of a variable declaration.
Definition: prettyprint.hh:307
EmitXml::var_color
@ var_color
Local variable identifiers.
Definition: prettyprint.hh:93
TokenSplit::func_e
@ func_e
End of a function body.
Definition: prettyprint.hh:302
EmitPrettyPrint::endStatement
virtual void endStatement(int4 id)
End a source code statement.
Definition: prettyprint.cc:987
EmitXml::openGroup
virtual int4 openGroup(void)
Start a group of things that are printed together.
Definition: prettyprint.hh:132
TokenSplit::op_t
@ op_t
An operator.
Definition: prettyprint.hh:314
EmitNoXml::beginFunction
virtual int4 beginFunction(const Funcdata *fd)
Begin a whole declaration and body of a function.
Definition: prettyprint.hh:229
TokenSplit::ct
const Datatype * ct
Associated Data-type.
Definition: prettyprint.hh:340
TokenSplit::cpar_t
@ cpar_t
Close parenthesis.
Definition: prettyprint.hh:322
TokenSplit::beginReturnType
int4 beginReturnType(const Varnode *v)
Create a "begin return type declaration" command.
Definition: prettyprint.hh:394
TokenSplit::beginFunction
int4 beginFunction(const Funcdata *f)
Create a "begin function body" command.
Definition: prettyprint.hh:368
TokenSplit::tokenbreak
@ tokenbreak
White space (where line breaks can be inserted)
Definition: prettyprint.hh:289
TokenSplit::prot_b
@ prot_b
Start of a function prototype.
Definition: prettyprint.hh:311
EmitPrettyPrint::beginReturnType
virtual int4 beginReturnType(const Varnode *vn)
Begin a return type declaration.
Definition: prettyprint.cc:939
EmitPrettyPrint::EmitPrettyPrint
EmitPrettyPrint(void)
Construct with an initial maximum line size.
Definition: prettyprint.cc:545
EmitXml::beginBlock
virtual int4 beginBlock(const FlowBlock *bl)
Begin a control-flow element.
Definition: prettyprint.cc:60
EmitXml::startComment
virtual int4 startComment(void)
Start a comment block within the emitted source code.
Definition: prettyprint.hh:161
EmitNoXml::beginDocument
virtual int4 beginDocument(void)
Begin a whole document of output.
Definition: prettyprint.hh:227