| 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 | //
|
|---|
| 7 | // LabelFixer.h --
|
|---|
| 8 | //
|
|---|
| 9 | // Author : Rodolfo G. Esteves
|
|---|
| 10 | // Created On : Mon May 18 07:44:20 2015
|
|---|
| 11 | // Last Modified By : Peter A. Buhr
|
|---|
| 12 | // Last Modified On : Mon Jan 31 22:28:04 2022
|
|---|
| 13 | // Update Count : 35
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #pragma once
|
|---|
| 17 |
|
|---|
| 18 | #include <list> // for list
|
|---|
| 19 | #include <map> // for map
|
|---|
| 20 |
|
|---|
| 21 | #include "Common/PassVisitor.h"
|
|---|
| 22 | #include "Common/SemanticError.h" // for SemanticError
|
|---|
| 23 | #include "SynTree/Label.h" // for Label
|
|---|
| 24 | #include "SynTree/Visitor.h" // for Visitor
|
|---|
| 25 | #include "SynTree/SynTree.h" // for Visitor Nodes
|
|---|
| 26 |
|
|---|
| 27 | namespace ControlStruct {
|
|---|
| 28 | // normalizes label definitions and generates multi-level exit labels
|
|---|
| 29 | class LabelGenerator;
|
|---|
| 30 |
|
|---|
| 31 | class LabelFixer final : public WithGuards {
|
|---|
| 32 | public:
|
|---|
| 33 | LabelFixer( LabelGenerator *gen = 0 );
|
|---|
| 34 |
|
|---|
| 35 | std::map < Label, Statement * > *resolveJumps();
|
|---|
| 36 |
|
|---|
| 37 | // Declarations
|
|---|
| 38 | void previsit( FunctionDecl *functionDecl );
|
|---|
| 39 | void postvisit( FunctionDecl *functionDecl );
|
|---|
| 40 |
|
|---|
| 41 | // Statements
|
|---|
| 42 | void previsit( Statement *stmt );
|
|---|
| 43 | void previsit( BranchStmt *branchStmt );
|
|---|
| 44 |
|
|---|
| 45 | // Expressions
|
|---|
| 46 | void previsit( LabelAddressExpr *addrExpr );
|
|---|
| 47 |
|
|---|
| 48 | Label setLabelsDef( std::list< Label > &, Statement *definition );
|
|---|
| 49 | template< typename UsageNode >
|
|---|
| 50 | void setLabelsUsg( Label, UsageNode *usage = 0 );
|
|---|
| 51 |
|
|---|
| 52 | private:
|
|---|
| 53 | class Entry {
|
|---|
| 54 | public:
|
|---|
| 55 | Entry( Statement *to ) : definition( to ) {}
|
|---|
| 56 | bool defined() { return ( definition != 0 ); }
|
|---|
| 57 | bool insideLoop();
|
|---|
| 58 |
|
|---|
| 59 | Label get_label() const { return label; }
|
|---|
| 60 | void set_label( Label lab ) { label = lab; }
|
|---|
| 61 |
|
|---|
| 62 | Statement *get_definition() const { return definition; }
|
|---|
| 63 | void set_definition( Statement *def ) { definition = def; }
|
|---|
| 64 |
|
|---|
| 65 | private:
|
|---|
| 66 | Label label;
|
|---|
| 67 | Statement *definition;
|
|---|
| 68 | };
|
|---|
| 69 |
|
|---|
| 70 | std::map < Label, Entry *> labelTable;
|
|---|
| 71 | LabelGenerator *generator;
|
|---|
| 72 | };
|
|---|
| 73 | } // namespace ControlStruct
|
|---|
| 74 |
|
|---|
| 75 | // Local Variables: //
|
|---|
| 76 | // tab-width: 4 //
|
|---|
| 77 | // mode: c++ //
|
|---|
| 78 | // compile-command: "make install" //
|
|---|
| 79 | // End: //
|
|---|