[51587aa] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[a08ba92] | 7 | // LabelFixer.h -- |
---|
[51587aa] | 8 | // |
---|
[843054c2] | 9 | // Author : Rodolfo G. Esteves |
---|
[51587aa] | 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[be5aa1b] | 11 | // Last Modified By : Rob Schluntz |
---|
| 12 | // Last Modified On : Tue May 26 12:55:10 2015 |
---|
| 13 | // Update Count : 4 |
---|
[51587aa] | 14 | // |
---|
[a08ba92] | 15 | |
---|
[51b7345] | 16 | #ifndef LABEL_FIXER_H |
---|
| 17 | #define LABEL_FIXER_H |
---|
| 18 | |
---|
| 19 | #include "utility.h" |
---|
| 20 | #include "SynTree/SynTree.h" |
---|
| 21 | #include "SynTree/Visitor.h" |
---|
| 22 | #include "LabelGenerator.h" |
---|
| 23 | |
---|
| 24 | #include <map> |
---|
| 25 | |
---|
| 26 | namespace ControlStruct { |
---|
[a08ba92] | 27 | class LabelFixer : public Visitor { |
---|
| 28 | typedef Visitor Parent; |
---|
[d9a0e76] | 29 | public: |
---|
[a08ba92] | 30 | LabelFixer( LabelGenerator *gen = 0 ); |
---|
| 31 | |
---|
| 32 | std::map < Label, Statement * > *resolveJumps() throw ( SemanticError ); |
---|
| 33 | |
---|
| 34 | // Declarations |
---|
| 35 | virtual void visit( FunctionDecl *functionDecl ); |
---|
| 36 | |
---|
| 37 | // Statements |
---|
| 38 | void visit( Statement *stmt ); |
---|
| 39 | |
---|
| 40 | virtual void visit( CompoundStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
| 41 | virtual void visit( NullStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
| 42 | virtual void visit( ExprStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
| 43 | virtual void visit( IfStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
| 44 | virtual void visit( WhileStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
| 45 | virtual void visit( ForStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
| 46 | virtual void visit( SwitchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
| 47 | virtual void visit( ChooseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
| 48 | virtual void visit( FallthruStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
| 49 | virtual void visit( CaseStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
| 50 | virtual void visit( ReturnStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
| 51 | virtual void visit( TryStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
| 52 | virtual void visit( CatchStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
| 53 | virtual void visit( DeclStmt *stmt ) { visit( (Statement *)stmt ); return Parent::visit( stmt ); } |
---|
| 54 | virtual void visit( BranchStmt *branchStmt ); |
---|
| 55 | |
---|
| 56 | Label setLabelsDef( std::list< Label > &, Statement *definition ); |
---|
| 57 | Label setLabelsUsg( Label, Statement *usage = 0 ); |
---|
[d9a0e76] | 58 | |
---|
| 59 | private: |
---|
[a08ba92] | 60 | class Entry { |
---|
| 61 | public: |
---|
| 62 | Entry( Statement *to = 0, Statement *from = 0 ); |
---|
| 63 | bool used() { return ( usage.empty() ); } |
---|
| 64 | bool defined() { return ( definition != 0 ); } |
---|
| 65 | bool insideLoop(); |
---|
| 66 | |
---|
| 67 | Label get_label() const { return label; } |
---|
[be5aa1b] | 68 | void set_label( Label lab ) { label = lab; } |
---|
| 69 | |
---|
[a08ba92] | 70 | Statement *get_definition() const { return definition; } |
---|
[be5aa1b] | 71 | void set_definition( Statement *def ) { definition = def; } |
---|
[a08ba92] | 72 | |
---|
[be5aa1b] | 73 | std::list< Statement *> &get_uses() { return usage; } |
---|
[a08ba92] | 74 | void add_use ( Statement *use ) { usage.push_back( use ); } |
---|
| 75 | void add_uses ( std::list<Statement *> uses ) { usage.insert( usage.end(), uses.begin(), uses.end() ); } |
---|
| 76 | private: |
---|
| 77 | Label label; |
---|
| 78 | Statement *definition; |
---|
| 79 | std::list<Statement *> usage; |
---|
| 80 | }; |
---|
| 81 | |
---|
| 82 | std::map < Label, Entry *> labelTable; |
---|
| 83 | LabelGenerator *generator; |
---|
[d9a0e76] | 84 | }; |
---|
[51b7345] | 85 | } // namespace ControlStruct |
---|
| 86 | |
---|
[d9a0e76] | 87 | #endif // LABEL_FIXER_H |
---|
[51b7345] | 88 | |
---|
[51587aa] | 89 | // Local Variables: // |
---|
| 90 | // tab-width: 4 // |
---|
| 91 | // mode: c++ // |
---|
| 92 | // compile-command: "make install" // |
---|
| 93 | // End: // |
---|