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  

gotonode.cc

Go to the documentation of this file.
00001 // $Id: gotonode.cc,v 1.7 2003/08/07 23:13:05 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 // --------------------------------------------------------------------
00041 // Constructors
00042 // --------------------------------------------------------------------
00043 
00044 gotoNode::gotoNode(labelNode * label, const Coord coord, NodeType typ)
00045   : jumpNode(typ, coord),
00046     _name(),
00047     _label(NULL)
00048 {
00049   if (label) {
00050     this->label(label);
00051   }
00052 }
00053 
00054 // -- Was ResolveGoto in procedure.c
00055 
00056 gotoNode::gotoNode(idNode * ident, const Coord coord)
00057   : jumpNode(Goto, coord),
00058     _label(0),
00059     _name()
00060 {
00061   /* --- NOTE: This is all made obsolete by goto_label_walker...
00062 
00063   // -- Try to find a matching label
00064 
00065   labelNode * the_label = Symbols::Labels->lookup(ident->text());
00066 
00067   // -- If not there, create an undeclared label. It will be
00068   // found later when we actually encounter the label.
00069 
00070   if (! the_label)
00071     the_label = new labelNode(ident);
00072 
00073   assert(the_label);
00074 
00075   // -- Set the label field and add this "goto" to it's references
00076 
00077   label(the_label);
00078   the_label->add_reference(this);
00079 
00080   */
00081 
00082   name(ident->name());
00083   //delete ident;
00084 }
00085 
00086 void gotoNode::label(labelNode * label) {
00087   labelNode * old_label = _label;
00088   _label = label;
00089   if ( old_label )
00090     old_label->references().remove(this);
00091   if ( label ) {
00092     label->references().push_back(this);
00093     label->references().sort();
00094     label->references().unique();
00095     _name = label->name();
00096   }
00097 }
00098 
00099 // ------------------------------------------------------------
00100 //  Walker
00101 // ------------------------------------------------------------
00102 
00103 void gotoNode::visit(Visitor * the_visitor) 
00104 {
00105   the_visitor->at_goto(this);
00106 }
00107 
00108 void gotoNode::walk(Walker & the_walker)
00109 {
00110   Walker::Order ord = the_walker.order(); 
00111 
00112   if (ord == Walker::Preorder || ord == Walker::Both)
00113     the_walker.at_goto(this, Walker::Preorder);
00114 
00115   if (ord == Walker::Postorder || ord == Walker::Both)
00116     the_walker.at_goto(this, Walker::Postorder);
00117 }
00118 
00119 // ------------------------------------------------------------
00120 //  Dataflow
00121 // ------------------------------------------------------------
00122 
00123 void gotoNode::dataflow(FlowVal * v, FlowProblem & fp)
00124 {
00125   if (fp.forward()) {
00126     fp.flow_goto(v, this, FlowProblem::Entry);
00127 
00128     // -- Push current values to the label and then reset to "top"
00129 
00130     if (label())
00131       label()->at_entry()->meet_and_diff(v, fp);
00132 
00133     v->to_top();
00134 
00135     fp.flow_goto(v, this, FlowProblem::Exit);
00136   }
00137   else {
00138     fp.flow_goto(v, this, FlowProblem::Exit);
00139 
00140     // -- Get the current values from the label
00141 
00142     v->to_top();
00143 
00144     if (label())
00145       v->meet(label()->at_entry());
00146 
00147     fp.flow_goto(v, this, FlowProblem::Entry);
00148   }
00149 }
00150 
00151 // ------------------------------------------------------------
00152 // Output
00153 // ------------------------------------------------------------
00154 
00155 void gotoNode::output_stmt(output_context & ct, Node * parent)
00156 {
00157   ct << "goto " << name() << ';' ;
00158 }
00159 
00160 // ------------------------------------------------------------
00161 //  Changer
00162 // ------------------------------------------------------------
00163 
00164 Node * gotoNode::change(Changer & the_changer, bool redispatch)
00165 {
00166   Changer::Order ord = the_changer.order(); 
00167   gotoNode * the_goto = this;
00168 
00169   if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch)
00170     the_goto = (gotoNode *) the_changer.at_goto(the_goto, Changer::Preorder);
00171 
00172   if (the_goto) {
00173 
00174     if (the_goto != this)
00175       return the_goto->change(the_changer, true);
00176 
00177   }
00178 
00179   if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch)
00180     the_goto = (gotoNode *) the_changer.at_goto(the_goto, Changer::Postorder);
00181 
00182   return the_goto;
00183 }
00184 
00185 
00186 // ------------------------------------------------------------
00187 // Destructor
00188 // ------------------------------------------------------------
00189 
00190 gotoNode::~gotoNode()
00191 {
00192 }

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