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  

lir_gen_walker.h

Go to the documentation of this file.
00001 // $Id: lir_gen_walker.h,v 1.8 2003/08/11 17:38:52 abrown Exp $
00002 // ----------------------------------------------------------------------
00003 //
00004 //  C-Breeze
00005 //  C Compiler Framework
00006 // 
00007 //  Copyright (c) 2002 University of Texas at Austin
00008 // 
00009 //  Chuck Tsen
00010 //  Charles Nevill
00011 //  Paul Arthur Navratil
00012 //  Calvin Lin
00013 // 
00014 //  Permission is hereby granted, free of charge, to any person
00015 //  obtaining a copy of this software and associated documentation
00016 //  files (the "Software"), to deal in the Software without
00017 //  restriction, including without limitation the rights to use, copy,
00018 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00019 //  of the Software, and to permit persons to whom the Software is
00020 //  furnished to do so, subject to the following conditions:
00021 //  
00022 //  The above copyright notice and this permission notice shall be
00023 //  included in all copies or substantial portions of the Software.
00024 //  
00025 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00026 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00027 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00028 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00029 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00030 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00031 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00032 //  THE SOFTWARE.
00033 //
00034 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00035 //  Computer Science for inspiring parts of the C-Breeze design.
00036 //
00037 // ----------------------------------------------------------------------
00038 
00039 #ifndef __LIR_GEN_WALKER_H
00040 #define __LIR_GEN_WALKER_H
00041 
00042 #include <utility>
00043 #include <stack>
00044 #include "c_breeze.h"
00045 #include "LIR.h"
00046 #include "instruction.h"
00047 #include "arch_info.h"
00048 #include "storage_alloc.h"
00049 
00050 // class declarations
00051 class AllocToMemWalker;
00052 
00053 class lir_gen_walker : public Walker {
00054  public:
00055   // constructor
00056   lir_gen_walker();
00057 
00059 // walker interface
00060 
00061   virtual void at_unit(unitNode * the_unit, Order ord);
00062   virtual void at_proc(procNode * the_proc, Order ord);
00063   virtual void at_threeAddr(threeAddrNode * the_3addr, Order ord);
00064   virtual void at_goto(gotoNode *the_goto, Order ord);
00065   virtual void at_label(labelNode *the_label, Order ord);
00066   virtual void at_conditiongoto(conditiongotoNode * the_condgoto, Order ord);
00067   virtual void at_return(returnNode *the_return, Walker::Order ord);
00068 
00069  private:
00071   // Initialization
00072   static void init_maps(void);
00073 
00075   // Handling initializers
00076   expr_list * flatten_init(exprNode *);
00077 
00079   // LIR generation methods
00080 
00081   virtual void gen_global_decl(defNode *);
00082   virtual void gen_arg_decl(declNode *, AllocToMemWalker &);
00083   virtual void gen_local_decl(declNode *, AllocToMemWalker &);
00084 
00085   virtual void gen_assignment(threeAddrNode *);
00086   virtual void gen_simple_assignment(threeAddrNode *);
00087   virtual void gen_unary_assignment(threeAddrNode *);
00088   virtual void gen_binary_assignment(threeAddrNode *);
00089   virtual void gen_call_assignment(threeAddrNode *);
00090 
00091   virtual void gen_conditional_branch(conditiongotoNode *);
00092   virtual void gen_goto(gotoNode *);
00093   virtual void gen_label(labelNode *);
00094   virtual void gen_return(returnNode *);
00095   virtual void gen_call(threeAddrNode *);
00096 
00097   virtual pair<Register, declNode *> gen_load(indexNode *);
00098   virtual pair<Register, declNode *> gen_load(operandNode *);
00099   virtual int field_offset(operandNode *);
00100   virtual pair<reg_or_const, declNode *> index_offset(operandNode *);
00101 
00102   virtual pair<Register, declNode *> load_global(operandNode *);
00103   virtual pair<Register, declNode *> load_global_ea(operandNode *);
00104   virtual pair<Register, declNode *> load_global_value(operandNode *);
00105   virtual pair<Register, declNode *> load_global_var(idNode *);
00106   virtual pair<Register, declNode *> load_global_addr(idNode *);
00107 
00108   virtual pair<Register, declNode *> load_stack(operandNode *);
00109   virtual pair<Register, declNode *> load_stack_ea(operandNode *);
00110   virtual pair<Register, declNode *> load_stack_value(operandNode *);
00111   virtual pair<Register, declNode *> load_stack_var(idNode *);
00112   virtual pair<Register, declNode *> load_stack_addr(idNode *);
00113 
00114   virtual pair<Register, declNode *> load_const(constNode * the_const);
00115 
00116   virtual void gen_store(operandNode *, Register, declNode *);
00117   virtual void store_global(operandNode *, Register, declNode *);
00118   virtual void store_stack(operandNode *, Register, declNode *);
00119 
00120   virtual void gen_move(Register dest, declNode *, Register src, declNode *);
00121 
00122   bool needs_conversion(typeNode *, typeNode *);
00123   virtual pair<Register, declNode *> gen_conversion(typeNode *, Register,
00124                                                     declNode *);
00125 
00127 // data members
00128 
00129   // translation unit being processed
00130   unitNode * _unit;
00131 
00132   // procedure being processed
00133   procNode * _proc;
00134 
00135   // storage allocator for initial LIR generation phase
00136   storage_alloc _alloc;
00137 
00138   // maps from an Operators id() to the Lir:: method that generates
00139   // the proper LirInst
00140   static map<unsigned int, BinaryInstProc> binary_map;
00141 
00142   // maps from an Operators id() to the Lir:: method that generate
00143   // the proper LirInst
00144   static map<unsigned int, UnaryInstProc> unary_map;
00145 
00146   // maps from an Operators id() to the Compare_type necessary to
00147   // generate a LIR::Branch()
00148   static map<unsigned int, Compare_type> opid_cmptype_map;
00149 };
00150 
00154 class AllocSizeChanger : public Changer {
00155  public:
00156   AllocSizeChanger(void);
00157 
00158   static void size(Node * the_node) {
00159     AllocSizeChanger asw;
00160     the_node->change(asw);
00161   }
00162 
00163   virtual Node * at_prim(primNode *, Order);
00164   virtual Node * at_decl(declNode *, Order);
00165   virtual Node * at_array(arrayNode *, Order);
00166   virtual Node * at_ptr(ptrNode *, Order);
00167   virtual Node * at_enum(enumNode *, Order);
00168   virtual Node * at_union(unionNode *, Order);
00169   virtual Node * at_struct(structNode *, Order);
00170   virtual Node * at_tdef(tdefNode *, Order);
00171   virtual Node * at_unary(unaryNode *, Order);
00172 
00173  private:
00174   stack<declNode *> _decls;
00175 };
00176 
00184 class SizeofChanger : public Changer {
00185  public:
00186   SizeofChanger(void);
00187 
00188   virtual Node * at_threeAddr(threeAddrNode * the_3addr, Order ord);
00189 };
00190 
00198 class AllocToMemWalker : public Walker {
00199  public:
00200   AllocToMemWalker(void);
00201 
00204   bool needsMem(declNode * the_decl);
00205   
00206   virtual void at_decl(declNode *, Order);
00207   virtual void at_operand(operandNode *, Order);
00208  private:
00209   list<declNode *> _decls;
00210 };
00211 
00212 #endif //  __LIR_GEN_WALKER_H
00213 

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