C-Breeze
C Compiler Infrastructure

[ Project home page]
Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

phase.cc

Go to the documentation of this file.
00001 // $Id: phase.cc,v 1.5 2003/08/07 23:14:03 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 #include "c_breeze.h"
00039 
00040 // -- The registry..
00041 
00042 int Phases::_count = 0;
00043 int Phases::_cur_order = 1;
00044 phase_vec * Phases::_phases = 0;
00045 
00046 // ------------------------------------------------------------
00047 // Constructor
00048 // ------------------------------------------------------------
00049 
00050 Phases::Phases(const char * name, Phase * new_phase, const char * desc)
00051 {
00052   if (! _count++)
00053     _phases = new phase_vec();
00054   
00055   string nm = string(name);
00056   phase_vec_p p = find_if(_phases->begin(), _phases->end(), Equal_phases(nm));
00057   if ( p != _phases->end() )
00058     cerr << "Phase name \"" << name << "\" is already registered." << endl;
00059   else
00060     _phases->push_back(new Phase_entry(name, new_phase, desc));
00061 }
00062 
00063 // ------------------------------------------------------------
00064 // Destructor
00065 // ------------------------------------------------------------
00066 
00067 Phases::~Phases()
00068 {
00069   if (! --_count) {
00070     for (phase_vec_p p = _phases->begin();
00071          p != _phases->end();
00072          ++p)
00073       delete (*p);
00074 
00075     delete _phases;
00076   }
00077 }
00078 
00079 // ------------------------------------------------------------
00080 // Phase operations...
00081 // ------------------------------------------------------------
00082 
00083 // phase_flag checks the current command-line argument to see if
00084 // it refers to one of the registered phases. If so, it gives
00085 // the phase a chance to get any extra arguments needed.
00086 
00087 bool Phases::phase_flag(str_list_p & arg_p)
00088 {
00089   string arg = (*arg_p);
00090   bool dis = false;
00091   str_list_p next;
00092   bool was_phase_flag = false;
00093 
00094   if (arg[0] == '-') {
00095 
00096     // Remove the leading "-"
00097 
00098     arg.erase(0,1);
00099 
00100 #if 0
00101     // Check for disabling argument
00102 
00103     if (arg.compare("no-",3) == 0) {
00104       dis = true;
00105       arg.erase(0,3);
00106     }
00107 #endif
00108 
00109     // Find the phase by name
00110 
00111     phase_vec_p p = find_if(_phases->begin(), _phases->end(),
00112                             Equal_phases(arg));
00113 
00114     if (p != _phases->end()) {
00115 
00116       was_phase_flag = true;
00117       ++arg_p;
00118 
00119       if (dis)
00120         (*p)->disable();
00121       else {
00122         (*p)->order(++_cur_order);
00123         (*p)->phase()->get_flags(arg_p);
00124       }
00125     }
00126   }
00127 
00128   return was_phase_flag;
00129 }
00130 
00131 void Phases::run_all()
00132 {
00133   stable_sort(_phases->begin(), _phases->end(), Less_phases());
00134 
00135   for (phase_vec_p p = _phases->begin();
00136        p != _phases->end();
00137        ++p) {
00138     if ((*p)->is_enabled())
00139       (*p)->phase()->run();
00140   }
00141 }
00142 
00143 void Phases::next_phase(string & the_name)
00144 {
00145   phase_vec_p p = find_if(_phases->begin(), _phases->end(),
00146                           Equal_phases(the_name));
00147 
00148   if (p != _phases->end())
00149     (*p)->order(++_cur_order);
00150 }
00151 
00152 void Phases::disable_phase(string & the_name)
00153 {
00154   phase_vec_p p = find_if(_phases->begin(), _phases->end(),
00155                           Equal_phases(the_name));
00156 
00157   if (p != _phases->end())
00158     (*p)->disable();
00159 }

Generated on August 27, 2003
Back to the C-Breeze home page