C-Breeze
C Compiler Infrastructure

[ Project home page]

phase.h

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

Generated on February 1, 2006
Back to the C-Breeze home page