Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

phase.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 //  C-Breeze
00004 //  C Compiler Framework
00005 // 
00006 //  Copyright (c) 2000 University of Texas at Austin
00007 // 
00008 //  Samuel Z. Guyer
00009 //  Daniel A. Jimenez
00010 //  Calvin Lin
00011 // 
00012 //  Permission is hereby granted, free of charge, to any person
00013 //  obtaining a copy of this software and associated documentation
00014 //  files (the "Software"), to deal in the Software without
00015 //  restriction, including without limitation the rights to use, copy,
00016 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00017 //  of the Software, and to permit persons to whom the Software is
00018 //  furnished to do so, subject to the following conditions:
00019 //  
00020 //  The above copyright notice and this permission notice shall be
00021 //  included in all copies or substantial portions of the Software.
00022 //  
00023 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00024 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00025 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00026 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00027 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00028 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00029 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00030 //  THE SOFTWARE.
00031 //
00032 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00033 //  Computer Science for inspiring parts of the C-Breeze design.
00034 //
00035 // ----------------------------------------------------------------------
00036 
00037 #ifndef CBZ_PHASE_H
00038 #define CBZ_PHASE_H
00039 
00040 
00041 
00042 // ------------------------------------------------------------
00043 // Phase: override the run() method
00044 // ------------------------------------------------------------
00045 
00046 class Phase
00047 {
00048 public:
00049 
00050   virtual void run() =0;
00051 
00052   virtual void get_flags(str_list_p & arg) { };
00053 };
00054 
00055 // ------------------------------------------------------------
00056 // Phase Registry
00057 // ------------------------------------------------------------
00058 
00059 // -- Phase entry
00060 
00061 class Phase_entry
00062 {
00063 private:
00064 
00065   string _name;
00066   int _order;
00067   Phase * _phase;
00068 
00069 public:
00070 
00071   Phase_entry(const char * name, Phase * phase)
00072     : _name(string(name)),
00073       _order(0),
00074       _phase(phase)
00075   {}
00076 
00077   ~Phase_entry() { delete _phase; }
00078 
00079   inline int order() const { return _order; }
00080   inline void order(int order) { _order = order; }
00081 
00082   inline void disable() { _order = 0; }
00083   inline bool is_enabled() const { return _order != 0; }
00084 
00085   inline string & name() { return _name; }
00086   inline const string & name() const { return _name; }
00087   inline void name(string & name) { _name = name; }
00088 
00089   inline Phase * phase() const { return _phase; }
00090 };
00091 
00092 typedef vector< Phase_entry * > phase_vec;
00093 typedef phase_vec::iterator phase_vec_p;
00094 
00095 // -- Phase_entry comparator for sorting
00096 
00097 class Less_phases
00098 {
00099 public:
00100   int operator()(const Phase_entry * ph1, const Phase_entry * ph2)
00101   { return ph1->order() < ph2->order(); }
00102 };
00103 
00104 class Equal_phases
00105 {
00106 private:
00107 
00108   string & _name;
00109 
00110 public:
00111 
00112   Equal_phases(string & name)
00113     : _name(name)
00114   {}
00115 
00116   bool operator()(const Phase_entry * ph)
00117   { return ph->name() == _name; }
00118 };
00119 
00120 // -- Registry class
00121 // Each use of the constructor puts a new entry into the registry.
00122 
00123 class Phases
00124 {
00125 
00126 private:
00127 
00128   // -- The registry..
00129 
00130   static int _count;
00131   static int _cur_order;
00132   static phase_vec * _phases;
00133 
00134 public:
00135 
00136   // -- Constructor registers a new phase
00137 
00138   Phases(const char * name, Phase * new_phase);
00139 
00140   ~Phases();
00141 
00142   // -- Call the phases
00143 
00144   static void run_all();
00145 
00146   // -- Handle command line argument
00147 
00148   static bool phase_flag(str_list_p & arg);
00149 
00150   // -- Set priority
00151 
00152   static void next_phase(string & name);
00153   static void disable_phase(string & name);
00154   
00155 };
00156 
00157 
00158 
00159 #endif // CBZ_PHASE_H

Generated on Thu Jan 10 12:06:20 2002 for C-Breeze by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001