My Project
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 public:
84  EmitXml(void) { s = (ostream *)0; indentlevel=0; parenlevel=0; indentincrement=2; }
85 
90  type_color = 2,
92  var_color = 4,
96  no_color = 8
97  };
98  virtual ~EmitXml(void) {}
99  virtual int4 beginDocument(void);
100  virtual void endDocument(int4 id);
101  virtual int4 beginFunction(const Funcdata *fd);
102  virtual void endFunction(int4 id);
103  virtual int4 beginBlock(const FlowBlock *bl);
104  virtual void endBlock(int4 id);
105  virtual void tagLine(void);
106  virtual void tagLine(int4 indent);
107  virtual int4 beginReturnType(const Varnode *vn);
108  virtual void endReturnType(int4 id);
109  virtual int4 beginVarDecl(const Symbol *sym);
110  virtual void endVarDecl(int4 id);
111  virtual int4 beginStatement(const PcodeOp *op);
112  virtual void endStatement(int4 id);
113  virtual int4 beginFuncProto(void);
114  virtual void endFuncProto(int4 id);
115  virtual void tagVariable(const char *ptr,syntax_highlight hl,
116  const Varnode *vn,const PcodeOp *op);
117  virtual void tagOp(const char *ptr,syntax_highlight hl,const PcodeOp *op);
118  virtual void tagFuncName(const char *ptr,syntax_highlight hl,const Funcdata *fd,const PcodeOp *op);
119  virtual void tagType(const char *ptr,syntax_highlight hl,const Datatype *ct);
120  virtual void tagField(const char *ptr,syntax_highlight hl,const Datatype *ct,int4 off);
121  virtual void tagComment(const char *ptr,syntax_highlight hl,const AddrSpace *spc,uintb off);
122  virtual void tagLabel(const char *ptr,syntax_highlight hl,const AddrSpace *spc,uintb off);
123  virtual void print(const char *str,syntax_highlight hl=no_color);
124  virtual int4 openParen(char o,int4 id=0);
125  virtual void closeParen(char c,int4 id);
126 
131  virtual int4 openGroup(void) { return 0; }
132 
137  virtual void closeGroup(int4 id) {}
138  virtual void clear(void) { parenlevel = 0; indentlevel=0; }
139  virtual void setOutputStream(ostream *t) { s = t; }
140  virtual ostream *getOutputStream(void) const { return s; }
141  virtual void spaces(int4 num,int4 bump=0);
142 
147  virtual int4 startIndent(void) { indentlevel+=indentincrement; return 0; }
148 
154  virtual void stopIndent(int4 id) { indentlevel-=indentincrement; }
155 
160  virtual int4 startComment(void) { return 0; }
161 
166  virtual void stopComment(int4 id) {}
167 
173  virtual void flush(void) {}
174 
179  virtual void setMaxLineSize(int4 mls) {}
180 
185  virtual int4 getMaxLineSize(void) const { return -1; }
186 
192  virtual void setCommentFill(const string &fill) {}
193 
197  virtual bool emitsXml(void) const { return true; }
198 
202  int4 getParenLevel(void) const { return parenlevel; }
203 
207  int4 getIndentIncrement(void) const { return indentincrement; }
208 
212  void setIndentIncrement(int4 val) { indentincrement = val; }
213 };
214 
220 class EmitNoXml : public EmitXml {
221 public:
222  EmitNoXml(void) : EmitXml() {}
223  virtual int4 beginDocument(void) { return 0; }
224  virtual void endDocument(int4 id) {}
225  virtual int4 beginFunction(const Funcdata *fd) { return 0; }
226  virtual void endFunction(int4 id) {}
227  virtual int4 beginBlock(const FlowBlock *bl) { return 0; }
228  virtual void endBlock(int4 id) {}
229  virtual void tagLine(int4 indent) {
230  *s << endl; for(int4 i=indent;i>0;--i) *s << ' '; }
231  virtual int4 beginReturnType(const Varnode *vn) { return 0; }
232  virtual void endReturnType(int4 id) {}
233  virtual int4 beginVarDecl(const Symbol *sym) { return 0; }
234  virtual void endVarDecl(int4 id) {}
235  virtual int4 beginStatement(const PcodeOp *op) { return 0; }
236  virtual void endStatement(int4 id) {}
237  virtual int4 beginFuncProto(void) { return 0; }
238  virtual void endFuncProto(int4 id) {}
239  virtual void tagVariable(const char *ptr,syntax_highlight hl,
240  const Varnode *vn,const PcodeOp *op) {
241  *s << ptr; }
242  virtual void tagOp(const char *ptr,syntax_highlight hl,const PcodeOp *op) {
243  *s << ptr; }
244  virtual void tagFuncName(const char *ptr,syntax_highlight hl,const Funcdata *fd,const PcodeOp *op) {
245  *s << ptr; }
246  virtual void tagType(const char *ptr,syntax_highlight hl,const Datatype *ct) {
247  *s << ptr; }
248  virtual void tagField(const char *ptr,syntax_highlight hl,const Datatype *ct,int4 off) {
249  *s << ptr; }
250  virtual void tagComment(const char *ptr,syntax_highlight hl,
251  const AddrSpace *spc,uintb off) {
252  *s << ptr; }
253  virtual void tagLabel(const char *ptr,syntax_highlight hl,
254  const AddrSpace *spc,uintb off) {
255  *s << ptr; }
256  virtual void print(const char *str,syntax_highlight hl=no_color) {
257  *s << str; }
258  virtual int4 openParen(char o,int4 id=0) {
259  *s << o; parenlevel += 1; return id; }
260  virtual void closeParen(char c,int4 id) {
261  *s << c; parenlevel -= 1; }
262  virtual bool emitsXml(void) const { return false; }
263 };
264 
278 class TokenSplit {
279 public:
281  enum printclass {
283  end,
290  ignore
291  };
292 
294  enum tag_type {
323  line_t
324  };
325 private:
326  tag_type tagtype;
327  printclass delimtype;
328  string tok;
330  // Additional markup elements for token
331  const PcodeOp *op;
332  union {
333  const Varnode *vn;
334  const FlowBlock *bl;
335  const Funcdata *fd;
336  const Datatype *ct;
337  const AddrSpace *spc;
338  const Symbol *symbol;
339  } ptr_second;
340  uintb off;
341  int4 indentbump;
342  int4 numspaces;
343  int4 size;
344  int4 count;
345  static int4 countbase;
346 public:
347  TokenSplit(void) { }
348 
352  int4 beginDocument(void) {
353  tagtype=docu_b; delimtype=begin; size=0; count=countbase++; return count; }
354 
358  void endDocument(int4 id) {
359  tagtype=docu_e; delimtype=end; size=0; count=id; }
360 
364  int4 beginFunction(const Funcdata *f) {
365  tagtype=func_b; delimtype=begin; size=0; ptr_second.fd=f; count=countbase++; return count; }
366 
370  void endFunction(int4 id) {
371  tagtype=func_e; delimtype=end; size=0; count=id; }
372 
377  int4 beginBlock(const FlowBlock *b) {
378  tagtype=bloc_b; delimtype=ignore; ptr_second.bl=b; count=countbase++; return count; }
379 
383  void endBlock(int4 id) {
384  tagtype=bloc_e; delimtype=ignore; count=id; }
385 
390  int4 beginReturnType(const Varnode *v) {
391  tagtype=rtyp_b; delimtype=begin; ptr_second.vn=v; count=countbase++; return count; }
392 
396  void endReturnType(int4 id) {
397  tagtype=rtyp_e; delimtype=end; count=id; }
398 
403  int4 beginVarDecl(const Symbol *sym) {
404  tagtype=vard_b; delimtype=begin; ptr_second.symbol=sym; count = countbase++; return count; }
405 
409  void endVarDecl(int4 id) {
410  tagtype=vard_e; delimtype=end; count=id; }
411 
416  int4 beginStatement(const PcodeOp *o) {
417  tagtype=stat_b; delimtype=begin; op=o; count=countbase++; return count; }
418 
422  void endStatement(int4 id) {
423  tagtype=stat_e; delimtype=end; count=id; }
424 
428  int4 beginFuncProto(void) {
429  tagtype=prot_b; delimtype=begin; count=countbase++; return count; }
430 
434  void endFuncProto(int4 id) {
435  tagtype=prot_e; delimtype=end; count=id; }
436 
443  void tagVariable(const char *ptr,EmitXml::syntax_highlight h,
444  const Varnode *v,const PcodeOp *o) {
445  tok = ptr; size = tok.size();
446  tagtype=vari_t; delimtype=tokenstring; hl=h; ptr_second.vn=v; op=o; }
447 
453  void tagOp(const char *ptr,EmitXml::syntax_highlight h,const PcodeOp *o) {
454  tok = ptr; size = tok.size();
455  tagtype=op_t; delimtype=tokenstring; hl=h; op=o; }
456 
463  void tagFuncName(const char *ptr,EmitXml::syntax_highlight h,const Funcdata *f,const PcodeOp *o) {
464  tok = ptr; size = tok.size();
465  tagtype=fnam_t; delimtype=tokenstring; hl=h; ptr_second.fd=f; op=o; }
466 
472  void tagType(const char *ptr,EmitXml::syntax_highlight h,const Datatype *ct) {
473  tok = ptr; size = tok.size();
474  tagtype=type_t; delimtype=tokenstring; hl=h; ptr_second.ct=ct; }
475 
482  void tagField(const char *ptr,EmitXml::syntax_highlight h,const Datatype *ct,int4 o) {
483  tok = ptr; size = tok.size();
484  tagtype=field_t; delimtype=tokenstring; hl=h; ptr_second.ct=ct; off=(uintb)o; }
485 
492  void tagComment(const char *ptr,EmitXml::syntax_highlight h,
493  const AddrSpace *s,uintb o) {
494  tok = ptr; size = tok.size(); ptr_second.spc=s; off=o;
495  tagtype=comm_t; delimtype=tokenstring; hl=h; }
496 
503  void tagLabel(const char *ptr,EmitXml::syntax_highlight h,
504  const AddrSpace *s,uintb o) {
505  tok = ptr; size = tok.size(); ptr_second.spc=s; off=o;
506  tagtype=label_t; delimtype=tokenstring; hl=h; }
507 
512  void print(const char *str,EmitXml::syntax_highlight h) {
513  tok = str; size=tok.size();
514  tagtype=synt_t; delimtype=tokenstring; hl=h; }
515 
520  void openParen(char o,int4 id) {
521  tok = o; size = 1;
522  tagtype=opar_t; delimtype=tokenstring; count=id; }
523 
528  void closeParen(char c,int4 id) {
529  tok = c; size = 1;
530  tagtype=cpar_t; delimtype=tokenstring; count=id; }
531 
535  int4 openGroup(void) {
536  tagtype=oinv_t; delimtype=begin; count=countbase++; return count; }
537 
541  void closeGroup(int4 id) {
542  tagtype=cinv_t; delimtype=end; count=id; }
543 
548  int4 startIndent(int4 bump) {
549  tagtype=bump_t; delimtype=begin_indent; indentbump=bump; size=0;
550  count=countbase++; return count; }
551 
555  void stopIndent(int4 id) {
556  tagtype=bump_t; delimtype=end_indent; size=0; count=id; }
557 
561  int4 startComment(void) {
562  tagtype=oinv_t; delimtype=begin_comment; count=countbase++; return count; }
563 
567  void stopComment(int4 id) {
568  tagtype=cinv_t; delimtype=end_comment; count=id; }
569 
574  void spaces(int4 num,int4 bump) {
575  tagtype=spac_t; delimtype=tokenbreak; numspaces=num; indentbump=bump; }
576 
578  void tagLine(void) {
579  tagtype=bump_t; delimtype=tokenbreak; numspaces=999999; indentbump=0; }
580 
582  void tagLine(int4 indent) {
583  tagtype=line_t; delimtype=tokenbreak; numspaces=999999; indentbump=indent; }
584 
585  void print(EmitXml *emit) const;
586  int4 getIndentBump(void) const { return indentbump; }
587  int4 getNumSpaces(void) const { return numspaces; }
588  int4 getSize(void) const { return size; }
589  void setSize(int4 sz) { size = sz; }
590  printclass getClass(void) const { return delimtype; }
591  tag_type getTag(void) const { return tagtype; }
592 #ifdef PRETTY_DEBUG
593  int4 getCount(void) const { return count; }
594  void printDebug(ostream &s) const;
595 #endif
596 };
597 
604 template<typename _type>
606  _type *cache;
607  int4 left;
608  int4 right;
609  int4 max;
610 public:
611  circularqueue(int4 sz);
612  ~circularqueue(void);
613  void setMax(int4 sz);
614  int4 getMax(void) const { return max; }
615  void expand(int4 amount);
616  void clear(void) { left=1; right=0; }
617  bool empty(void) const { return (left == (right+1)%max); }
618  int4 topref(void) const { return right; }
619  int4 bottomref(void) const { return left; }
620  _type &ref(int4 r) { return cache[r]; }
621  _type &top(void) { return cache[right]; }
622  _type &bottom(void) { return cache[left]; }
623  _type &push(void) { right=(right+1)%max; return cache[right]; }
624  _type &pop(void) { int4 tmp=right; right=(right+max-1)%max; return cache[tmp]; }
625  _type &popbottom(void) { int4 tmp=left; left=(left+1)%max; return cache[tmp]; }
626 };
627 
629 template<typename _type>
631 
632 {
633  max = sz;
634  left = 1; // Set queue to be empty
635  right = 0;
636  cache = new _type [ sz ];
637 }
638 
639 template<typename _type>
641 
642 {
643  delete [] cache;
644 }
645 
648 template<typename _type>
650 
651 {
652  delete [] cache;
653  max = sz;
654  cache = new _type [ sz ];
655  left = 1; // This operation empties queue
656  right = 0;
657 }
658 
664 template<typename _type>
666 
667 {
668  _type *newcache = new _type [ max + amount ];
669 
670  int4 i=left;
671  int4 j=0;
672 
673  // Assume there is at least one element in queue
674  while(i != right) {
675  newcache[j++] = cache[i];
676  i = (i+1)%max;
677  }
678  newcache[j] = cache[i]; // Copy rightmost
679  left=0;
680  right = j;
681 
682  delete [] cache;
683  cache = newcache;
684  max += amount;
685 }
686 
700 class EmitPrettyPrint : public EmitXml {
701 #ifdef PRETTY_DEBUG
702  vector<int4> checkid;
703 #endif
704  EmitXml *lowlevel;
705  vector<int4> indentstack;
706  int4 spaceremain;
707  int4 maxlinesize;
708  int4 leftotal;
709  int4 rightotal;
710  bool needbreak;
711  bool commentmode;
712  string commentfill;
713  circularqueue<int4> scanqueue;
714  circularqueue<TokenSplit> tokqueue;
715  void expand(void);
716  void checkstart(void);
717  void checkend(void);
718  void checkstring(void);
719  void checkbreak(void);
720  void overflow(void);
721  void print(const TokenSplit &tok);
722  void advanceleft(void);
723  void scan(void);
724 public:
725  EmitPrettyPrint(int4 mls);
726  virtual ~EmitPrettyPrint(void);
727  virtual int4 beginDocument(void);
728  virtual void endDocument(int4 id);
729  virtual int4 beginFunction(const Funcdata *fd);
730  virtual void endFunction(int4 id);
731  virtual int4 beginBlock(const FlowBlock *bl);
732  virtual void endBlock(int4 id);
733  virtual void tagLine(void);
734  virtual void tagLine(int4 indent);
735  virtual int4 beginReturnType(const Varnode *vn);
736  virtual void endReturnType(int4 id);
737  virtual int4 beginVarDecl(const Symbol *sym);
738  virtual void endVarDecl(int4 id);
739  virtual int4 beginStatement(const PcodeOp *op);
740  virtual void endStatement(int4 id);
741  virtual int4 beginFuncProto(void);
742  virtual void endFuncProto(int4 id);
743  virtual void tagVariable(const char *ptr,syntax_highlight hl,
744  const Varnode *vn,const PcodeOp *op);
745  virtual void tagOp(const char *ptr,syntax_highlight hl,const PcodeOp *op);
746  virtual void tagFuncName(const char *ptr,syntax_highlight hl,const Funcdata *fd,const PcodeOp *op);
747  virtual void tagType(const char *ptr,syntax_highlight hl,const Datatype *ct);
748  virtual void tagField(const char *ptr,syntax_highlight hl,const Datatype *ct,int4 off);
749  virtual void tagComment(const char *ptr,syntax_highlight hl,
750  const AddrSpace *spc,uintb off);
751  virtual void tagLabel(const char *ptr,syntax_highlight hl,
752  const AddrSpace *spc,uintb off);
753  virtual void print(const char *str,syntax_highlight hl=no_color);
754  virtual int4 openParen(char o,int4 id=0);
755  virtual void closeParen(char c,int4 id);
756  virtual int4 openGroup(void);
757  virtual void closeGroup(int4 id);
758  virtual void clear(void);
759  virtual void setOutputStream(ostream *t) { lowlevel->setOutputStream(t); }
760  virtual ostream *getOutputStream(void) const { return lowlevel->getOutputStream(); }
761  virtual void spaces(int4 num,int4 bump=0);
762  virtual int4 startIndent(void);
763  virtual void stopIndent(int4 id);
764  virtual int4 startComment(void);
765  virtual void stopComment(int4 id);
766  virtual void flush(void);
767  virtual void setMaxLineSize(int4 val);
768  virtual int4 getMaxLineSize(void) const { return maxlinesize; }
769  virtual void setCommentFill(const string &fill) { commentfill = fill; }
770  virtual bool emitsXml(void) const { return lowlevel->emitsXml(); }
771  void setXML(bool val);
772 };
773 
774 #endif
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:248
virtual ostream * getOutputStream(void) const
Get the current output stream.
Definition: prettyprint.hh:760
A function identifier.
Definition: prettyprint.hh:311
virtual void endStatement(int4 id)
End a source code statement.
Definition: prettyprint.hh:236
White space.
Definition: prettyprint.hh:321
A region where processor data is stored.
Definition: space.hh:73
A token that ends a printing group.
Definition: prettyprint.hh:283
Start of a document.
Definition: prettyprint.hh:295
int4 getMax(void) const
Get the maximum queue size.
Definition: prettyprint.hh:614
Description of a control-flow block containing PcodeOps.
Definition: block.hh:60
virtual void endVarDecl(int4 id)
End a variable declaration.
Definition: prettyprint.hh:234
virtual int4 beginReturnType(const Varnode *vn)
Begin a return type declaration.
Definition: prettyprint.cc:89
ostream * s
Stream being emitted to.
Definition: prettyprint.hh:79
printclass
An enumeration denoting the general class of a token.
Definition: prettyprint.hh:281
virtual void setOutputStream(ostream *t)
Set the output stream for the emitter.
Definition: prettyprint.hh:139
_type & ref(int4 r)
Retrieve an object by its reference.
Definition: prettyprint.hh:620
virtual void tagLabel(const char *ptr, syntax_highlight hl, const AddrSpace *spc, uintb off)
Emit a code label identifier.
Definition: prettyprint.cc:276
The base datatype class for the decompiler.
Definition: type.hh:62
virtual void endBlock(int4 id)
End a control-flow element.
Definition: prettyprint.hh:228
tag_type getTag(void) const
Get this tag type.
Definition: prettyprint.hh:591
A trivial emitter that outputs syntax straight to the stream.
Definition: prettyprint.hh:220
End of a function body.
Definition: prettyprint.hh:298
Start of a function body.
Definition: prettyprint.hh:297
virtual int4 beginBlock(const FlowBlock *bl)
Begin a control-flow element.
Definition: prettyprint.cc:60
void endReturnType(int4 id)
Create an "end return type declaration" command.
Definition: prettyprint.hh:396
_type & push(void)
Push a new object onto the queue/stack.
Definition: prettyprint.hh:623
virtual void tagLine(void)
Force a line break.
Definition: prettyprint.cc:73
_type & bottom(void)
Get the first object on the queue/stack.
Definition: prettyprint.hh:622
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
A field name for a structured data-type.
Definition: prettyprint.hh:313
Start of a statement.
Definition: prettyprint.hh:305
virtual int4 beginReturnType(const Varnode *vn)
Begin a return type declaration.
Definition: prettyprint.hh:231
Container for data structures associated with a single function.
Definition: funcdata.hh:45
Open parenthesis.
Definition: prettyprint.hh:317
virtual ostream * getOutputStream(void) const
Get the current output stream.
Definition: prettyprint.hh:140
void endBlock(int4 id)
Create an "end control-flow element" command.
Definition: prettyprint.hh:383
Base class (and interface) for pretty printing and XML markup of tokens.
Definition: prettyprint.hh:76
virtual void endStatement(int4 id)
End a source code statement.
Definition: prettyprint.cc:133
End of a document.
Definition: prettyprint.hh:296
const AddrSpace * spc
Associated Address.
Definition: prettyprint.hh:337
int4 startComment(void)
Create a "start a comment block" command.
Definition: prettyprint.hh:561
virtual ~EmitXml(void)
Destructor.
Definition: prettyprint.hh:98
int4 beginFunction(const Funcdata *f)
Create a "begin function body" command.
Definition: prettyprint.hh:364
const Datatype * ct
Associated Data-type.
Definition: prettyprint.hh:336
virtual void tagFuncName(const char *ptr, syntax_highlight hl, const Funcdata *fd, const PcodeOp *op)
Emit a function identifier.
Definition: prettyprint.cc:197
int4 getSize(void) const
Get the number of content characters.
Definition: prettyprint.hh:588
virtual int4 beginDocument(void)
Begin a whole document of output.
Definition: prettyprint.cc:31
virtual void closeGroup(int4 id)
End a group of things that are printed together.
Definition: prettyprint.hh:137
virtual bool emitsXml(void) const
Determine if this is an XML markup emitter.
Definition: prettyprint.hh:770
virtual bool emitsXml(void) const
Determine if this is an XML markup emitter.
Definition: prettyprint.hh:197
int4 beginBlock(const FlowBlock *b)
Create a "begin control-flow element" command.
Definition: prettyprint.hh:377
virtual int4 beginVarDecl(const Symbol *sym)
Begin a variable declaration.
Definition: prettyprint.hh:233
virtual int4 beginFuncProto(void)
Begin a function prototype declaration.
Definition: prettyprint.cc:139
virtual int4 beginVarDecl(const Symbol *sym)
Begin a variable declaration.
Definition: prettyprint.cc:107
White space (where line breaks can be inserted)
Definition: prettyprint.hh:285
virtual int4 openGroup(void)
Start a group of things that are printed together.
Definition: prettyprint.hh:131
Function identifiers.
Definition: prettyprint.hh:91
End of a statement.
Definition: prettyprint.hh:306
End of a variable declaration.
Definition: prettyprint.hh:304
Start of a control-flow section.
Definition: prettyprint.hh:299
Other unspecified syntax.
Definition: prettyprint.hh:316
Part of a comment block.
Definition: prettyprint.hh:314
virtual int4 beginDocument(void)
Begin a whole document of output.
Definition: prettyprint.hh:223
printclass getClass(void) const
Get the print class of this.
Definition: prettyprint.hh:590
virtual void setOutputStream(ostream *t)
Set the output stream for the emitter.
Definition: prettyprint.hh:759
void tagFuncName(const char *ptr, EmitXml::syntax_highlight h, const Funcdata *f, const PcodeOp *o)
Create a function identifier token.
Definition: prettyprint.hh:463
virtual void tagVariable(const char *ptr, syntax_highlight hl, const Varnode *vn, const PcodeOp *op)
Emit a variable token.
Definition: prettyprint.hh:239
~circularqueue(void)
Destructor.
Definition: prettyprint.hh:640
virtual void stopComment(int4 id)
End a comment block.
Definition: prettyprint.hh:166
End of an arbitrary (invisible) grouping.
Definition: prettyprint.hh:320
void endFuncProto(int4 id)
Create an "end function prototype declaration" command.
Definition: prettyprint.hh:434
virtual void setMaxLineSize(int4 mls)
Provide a maximum line size to the pretty printer.
Definition: prettyprint.hh:179
virtual void tagType(const char *ptr, syntax_highlight hl, const Datatype *ct)
Emit a data-type identifier.
Definition: prettyprint.hh:246
Global variable identifiers.
Definition: prettyprint.hh:95
virtual int4 beginFunction(const Funcdata *fd)
Begin a whole declaration and body of a function.
Definition: prettyprint.cc:44
void tagLabel(const char *ptr, EmitXml::syntax_highlight h, const AddrSpace *s, uintb o)
Create a code label identifier token.
Definition: prettyprint.hh:503
void setMax(int4 sz)
Establish a new maximum queue size.
Definition: prettyprint.hh:649
int4 indentlevel
Current indent level (in fixed width characters)
Definition: prettyprint.hh:80
A data-type identifier.
Definition: prettyprint.hh:312
virtual void endVarDecl(int4 id)
End a variable declaration.
Definition: prettyprint.cc:115
Constant values.
Definition: prettyprint.hh:93
A code label.
Definition: prettyprint.hh:315
virtual void spaces(int4 num, int4 bump=0)
Emit a sequence of space characters as part of source code.
Definition: prettyprint.cc:333
void tagLine(int4 indent)
Create a line break token with special indentation.
Definition: prettyprint.hh:582
int4 indentincrement
Change in indentlevel per level of nesting.
Definition: prettyprint.hh:82
virtual void tagOp(const char *ptr, syntax_highlight hl, const PcodeOp *op)
Emit an operation token.
Definition: prettyprint.cc:177
Lowest level operation of the p-code language.
Definition: op.hh:58
virtual void flush(void)
Flush any remaining character data.
Definition: prettyprint.hh:173
int4 bottomref(void) const
Get a reference to the first object on the queue/stack.
Definition: prettyprint.hh:619
int4 topref(void) const
Get a reference to the last object on the queue/stack.
Definition: prettyprint.hh:618
void endVarDecl(int4 id)
Create an "end variable declaration" command.
Definition: prettyprint.hh:409
TokenSplit(void)
Constructor.
Definition: prettyprint.hh:347
Function parameters.
Definition: prettyprint.hh:94
A token representing actual content.
Definition: prettyprint.hh:284
virtual void clear(void)
Reset the emitter to its initial state.
Definition: prettyprint.hh:138
virtual void endDocument(int4 id)
End a whole document of output.
Definition: prettyprint.hh:224
int4 beginFuncProto(void)
Create a "begin function prototype declaration" command.
Definition: prettyprint.hh:428
Comments.
Definition: prettyprint.hh:89
const Symbol * symbol
Associated Symbol being displayed.
Definition: prettyprint.hh:338
virtual void endBlock(int4 id)
End a control-flow element.
Definition: prettyprint.cc:68
virtual int4 beginBlock(const FlowBlock *bl)
Begin a control-flow element.
Definition: prettyprint.hh:227
int4 getParenLevel(void) const
Get the current parentheses depth.
Definition: prettyprint.hh:202
void tagOp(const char *ptr, EmitXml::syntax_highlight h, const PcodeOp *o)
Create an operator token.
Definition: prettyprint.hh:453
syntax_highlight
Possible types of syntax highlighting.
Definition: prettyprint.hh:87
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:256
int4 beginDocument(void)
Create a "begin document" command.
Definition: prettyprint.hh:352
void tagType(const char *ptr, EmitXml::syntax_highlight h, const Datatype *ct)
Create a data-type identifier token.
Definition: prettyprint.hh:472
A variable identifier.
Definition: prettyprint.hh:309
void print(const char *str, EmitXml::syntax_highlight h)
Create a token for other (more unusual) syntax in source code.
Definition: prettyprint.hh:512
void closeGroup(int4 id)
Create an "end a printing group" command.
Definition: prettyprint.hh:541
virtual int4 beginFuncProto(void)
Begin a function prototype declaration.
Definition: prettyprint.hh:237
End of a nesting level.
Definition: prettyprint.hh:287
virtual bool emitsXml(void) const
Determine if this is an XML markup emitter.
Definition: prettyprint.hh:262
A low-level variable or contiguous set of bytes described by an Address and a size.
Definition: varnode.hh:65
virtual int4 getMaxLineSize(void) const
Get the current maximum line size.
Definition: prettyprint.hh:185
void openParen(char o, int4 id)
Create an open parenthesis.
Definition: prettyprint.hh:520
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
Classes for describing and printing data-types.
int4 beginStatement(const PcodeOp *o)
Create a "begin source code statement" command.
Definition: prettyprint.hh:416
void setIndentIncrement(int4 val)
Set the number of characters indented per level of nesting.
Definition: prettyprint.hh:212
void stopComment(int4 id)
Create an "end a comment block" command.
Definition: prettyprint.hh:567
Required line break.
Definition: prettyprint.hh:322
An operator.
Definition: prettyprint.hh:310
End of a function prototype.
Definition: prettyprint.hh:308
virtual void endReturnType(int4 id)
End a return type declaration.
Definition: prettyprint.cc:100
const Varnode * vn
Associated Varnode.
Definition: prettyprint.hh:333
virtual int4 startComment(void)
Start a comment block within the emitted source code.
Definition: prettyprint.hh:160
virtual void stopIndent(int4 id)
End an indent level.
Definition: prettyprint.hh:154
A token/command object in the pretty printing stream.
Definition: prettyprint.hh:278
virtual int4 getMaxLineSize(void) const
Get the current maximum line size.
Definition: prettyprint.hh:768
EmitXml(void)
Constructor.
Definition: prettyprint.hh:84
A token that starts a printing group.
Definition: prettyprint.hh:282
virtual void tagFuncName(const char *ptr, syntax_highlight hl, const Funcdata *fd, const PcodeOp *op)
Emit a function identifier.
Definition: prettyprint.hh:244
int4 openGroup(void)
Create a "start a printing group" command.
Definition: prettyprint.hh:535
End of a comment block.
Definition: prettyprint.hh:289
virtual void endFunction(int4 id)
End a whole declaration and body of a function.
Definition: prettyprint.hh:226
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:250
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:492
virtual void tagOp(const char *ptr, syntax_highlight hl, const PcodeOp *op)
Emit an operation token.
Definition: prettyprint.hh:242
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:482
Keyword in the high-level language.
Definition: prettyprint.hh:88
virtual void tagVariable(const char *ptr, syntax_highlight hl, const Varnode *vn, const PcodeOp *op)
Emit a variable token.
Definition: prettyprint.cc:157
int4 parenlevel
Current depth of parentheses.
Definition: prettyprint.hh:81
Start of a return type declaration.
Definition: prettyprint.hh:301
int4 beginReturnType(const Varnode *v)
Create a "begin return type declaration" command.
Definition: prettyprint.hh:390
bool empty(void) const
Is the queue empty.
Definition: prettyprint.hh:617
int4 getNumSpaces(void) const
Get the number of characters of whitespace.
Definition: prettyprint.hh:587
void tagVariable(const char *ptr, EmitXml::syntax_highlight h, const Varnode *v, const PcodeOp *o)
Create a variable identifier token.
Definition: prettyprint.hh:443
virtual int4 beginStatement(const PcodeOp *op)
Begin a source code statement.
Definition: prettyprint.hh:235
Start of a function prototype.
Definition: prettyprint.hh:307
virtual void tagLine(int4 indent)
Force a line break and indent level.
Definition: prettyprint.hh:229
A circular buffer template.
Definition: prettyprint.hh:605
virtual int4 beginFunction(const Funcdata *fd)
Begin a whole declaration and body of a function.
Definition: prettyprint.hh:225
void spaces(int4 num, int4 bump)
Create a whitespace token.
Definition: prettyprint.hh:574
virtual void endFunction(int4 id)
End a whole declaration and body of a function.
Definition: prettyprint.cc:52
Start of a comment block.
Definition: prettyprint.hh:288
void closeParen(char c, int4 id)
Create a close parenthesis.
Definition: prettyprint.hh:528
virtual void endDocument(int4 id)
End a whole document of output.
Definition: prettyprint.cc:38
virtual void tagLabel(const char *ptr, syntax_highlight hl, const AddrSpace *spc, uintb off)
Emit a code label identifier.
Definition: prettyprint.hh:253
void endDocument(int4 id)
Create an "end document" command.
Definition: prettyprint.hh:358
The base class for a symbol in a symbol table or scope.
Definition: database.hh:153
const FlowBlock * bl
Associated Control-flow.
Definition: prettyprint.hh:334
Start of an arbitrary (invisible) grouping.
Definition: prettyprint.hh:319
int4 beginVarDecl(const Symbol *sym)
Create a "begin variable declaration" command.
Definition: prettyprint.hh:403
virtual void endFuncProto(int4 id)
End a function prototype declaration.
Definition: prettyprint.cc:146
int4 getIndentBump(void) const
Get the extra indent after a line break.
Definition: prettyprint.hh:586
void clear(void)
Clear the queue.
Definition: prettyprint.hh:616
virtual void setCommentFill(const string &fill)
Set the comment fill characters for when line breaks are forced.
Definition: prettyprint.hh:192
int4 getIndentIncrement(void) const
Get the number of characters indented per level of nesting.
Definition: prettyprint.hh:207
virtual int4 openParen(char o, int4 id=0)
Emit an open parenthesis.
Definition: prettyprint.hh:258
_type & top(void)
Get the last object on the queue/stack.
Definition: prettyprint.hh:621
Data-type identifiers.
Definition: prettyprint.hh:90
Start of a new nesting level.
Definition: prettyprint.hh:286
void tagLine(void)
Create a line break token.
Definition: prettyprint.hh:578
tag_type
The exhaustive list of possible token types.
Definition: prettyprint.hh:294
virtual int4 beginStatement(const PcodeOp *op)
Begin a source code statement.
Definition: prettyprint.cc:122
Local variable identifiers.
Definition: prettyprint.hh:92
int4 startIndent(int4 bump)
Create a "start a new indent level" command.
Definition: prettyprint.hh:548
Close parenthesis.
Definition: prettyprint.hh:318
virtual int4 openParen(char o, int4 id=0)
Emit an open parenthesis.
Definition: prettyprint.cc:304
void endStatement(int4 id)
Create an "end source code statement" command.
Definition: prettyprint.hh:422
Un-highlighted.
Definition: prettyprint.hh:96
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
void expand(int4 amount)
Expand the (maximum) size of the queue.
Definition: prettyprint.hh:665
Start of a variable declaration.
Definition: prettyprint.hh:303
virtual void closeParen(char c, int4 id)
Emit a close parenthesis.
Definition: prettyprint.hh:260
EmitNoXml(void)
Constructor.
Definition: prettyprint.hh:222
A generic source code pretty printer.
Definition: prettyprint.hh:700
_type & popbottom(void)
Get the (next) object in the queue.
Definition: prettyprint.hh:625
void endFunction(int4 id)
Create an "end function body" command.
Definition: prettyprint.hh:370
End of a return type declaration.
Definition: prettyprint.hh:302
circularqueue(int4 sz)
Construct queue of a given size.
Definition: prettyprint.hh:630
virtual void endFuncProto(int4 id)
End a function prototype declaration.
Definition: prettyprint.hh:238
End of a control-flow section.
Definition: prettyprint.hh:300
virtual void closeParen(char c, int4 id)
Emit a close parenthesis.
Definition: prettyprint.cc:319
void stopIndent(int4 id)
Create an "end an indent level" command.
Definition: prettyprint.hh:555
virtual void tagType(const char *ptr, syntax_highlight hl, const Datatype *ct)
Emit a data-type identifier.
Definition: prettyprint.cc:216
virtual void endReturnType(int4 id)
End a return type declaration.
Definition: prettyprint.hh:232
void setSize(int4 sz)
Set the number of content characters.
Definition: prettyprint.hh:589
virtual int4 startIndent(void)
Start a new indent level.
Definition: prettyprint.hh:147
virtual void setCommentFill(const string &fill)
Set the comment fill characters for when line breaks are forced.
Definition: prettyprint.hh:769
const Funcdata * fd
Associated Function.
Definition: prettyprint.hh:335
_type & pop(void)
Pop the (last) object on the stack.
Definition: prettyprint.hh:624