|
||
storage_alloc.ccGo to the documentation of this file.00001 // $Id: storage_alloc.cc,v 1.11 2003/08/11 17:38:53 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 #include "c_breeze.h" 00040 #include "LIR.h" 00041 #include "storage_alloc.h" 00042 #include "lirutil.h" 00043 00044 storage_alloc::storage_alloc (void) 00045 { 00046 // reset us to init vars 00047 reset (); 00048 } 00049 00050 void 00051 storage_alloc::reset () 00052 { 00053 // start registers after maximum valid real register number 00054 _next_reg = CBZ::ArchInfo.get_all_regs ().size (); 00055 00056 // start with input register zero 00057 _next_reg_formal_fixed = 0; 00058 _next_reg_formal_float = 0; 00059 00060 // stack formals start at an arch-specific offset from frame pointer 00061 _next_stack_formal = CBZ::ArchInfo.get_stack_formals_offset (); 00062 } 00063 00064 void 00065 storage_alloc::get_temp_var (typeNode * intendedType, Register & reg, 00066 declNode * &pDecl) 00067 { 00068 // allocate a new register 00069 reg = _next_reg++; 00070 00071 // make a declaration for it 00072 pDecl = LirUtil::new_auto_decl (intendedType); 00073 pDecl->storage_location()._type = 00074 declNode::Storage_location::storageloc_register; 00075 pDecl->storage_location()._register = reg; 00076 } 00077 00078 void storage_alloc::get_temp_ptr(Register & reg, declNode *& pDecl) { 00079 get_temp_var(LirUtil::newVoidPtr(), reg, pDecl); 00080 } 00081 00082 void storage_alloc::assign_register(declNode * the_decl) { 00083 declNode::Storage_location & loc = the_decl->storage_location(); 00084 loc._type = declNode::Storage_location::storageloc_register; 00085 // allocate a virtual register 00086 loc._register = _next_reg++; 00087 loc._register.setType(the_decl->type()); 00088 } 00089 00090 bool storage_alloc::assign_arg_register(typeNode * type, Register & reg) { 00091 const arch_info::register_info_list & fixedRegs = 00092 CBZ::ArchInfo.get_regs_param_fixed(); 00093 const arch_info::register_info_list & floatRegs = 00094 CBZ::ArchInfo.get_regs_param_float(); 00095 bool isFloat = type->is_float(); 00096 bool isFixed = ( type->is_integer() || type->is_pointer() ); 00097 if ( isFloat && _next_reg_formal_float < floatRegs.size() ) { 00098 reg = *(floatRegs[_next_reg_formal_float]); 00099 reg.type(reg_fpr); 00100 _next_reg_formal_float++; 00101 return true; 00102 } else if ( isFixed && _next_reg_formal_fixed < fixedRegs.size() ) { 00103 reg = *(fixedRegs[_next_reg_formal_fixed]); 00104 reg.type(reg_gpr); 00105 _next_reg_formal_fixed++; 00106 return true; 00107 } 00108 return false; 00109 } 00110 00111 int storage_alloc::assign_arg_stack(typeNode * type) { 00112 int align = type->alloc_align(); 00113 int size = type->alloc_size(); 00114 _next_stack_formal = (( _next_stack_formal + align - 1 ) / align ) * align; 00115 int returnLoc = _next_stack_formal; 00116 _next_stack_formal += size; 00117 return returnLoc; 00118 } |
Generated on August 27, 2003
Back to the C-Breeze home page