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.h

Go to the documentation of this file.
00001 // $Id: LIR.h,v 1.12 2003/08/11 17:38:50 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 //  Adam C. Brown
00014 // 
00015 //  Permission is hereby granted, free of charge, to any person
00016 //  obtaining a copy of this software and associated documentation
00017 //  files (the "Software"), to deal in the Software without
00018 //  restriction, including without limitation the rights to use, copy,
00019 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00020 //  of the Software, and to permit persons to whom the Software is
00021 //  furnished to do so, subject to the following conditions:
00022 //  
00023 //  The above copyright notice and this permission notice shall be
00024 //  included in all copies or substantial portions of the Software.
00025 //  
00026 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00030 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00031 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00032 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00033 //  THE SOFTWARE.
00034 //
00035 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00036 //  Computer Science for inspiring parts of the C-Breeze design.
00037 //
00038 // ----------------------------------------------------------------------
00039 
00040 #ifndef LIR_H
00041 #define LIR_H
00042 
00043 #include "instruction.h"
00044 using namespace std;
00045 
00046 typedef LirInst * (*BinaryInstProc)(typeNode *, Register &, declNode *, 
00047                                     Register, declNode *, reg_or_const, 
00048                                     declNode *);
00049 typedef LirInst * (*UnaryInstProc)(typeNode *, Register &, declNode *, 
00050                                    Register, declNode *);
00051 
00052 class LIR
00053 {
00054 public:
00055 
00056   // simple no-op instruction
00057   static LirInst *NOP ();
00058 
00059   // handle type conversions
00060   static LirInst *ConvertType (typeNode * sourceType, Register source,
00061                                declNode * pDeclSource, typeNode * destType,
00062                                Register & dest, declNode * pDeclDest);
00063 
00064   // TODO: allow Load to specify two registers, in place of offset
00065   // handle load/store/move/etc
00066   static LirInst *Load (typeNode * typeToLoad, Register & dest_register,
00067                         declNode * pDeclDest, Register base_reg,
00068                         declNode * pDeclBase, constant offset,
00069                         declNode * pDeclOffset);
00070   static LirInst *LoadImmediate (typeNode * typeToLoad,
00071                                  Register & dest_register,
00072                                  declNode * pDeclDest, constant con);
00073   // TODO: allow LoadStatic to specify a register, in place of offset
00074   static LirInst *LoadStatic (typeNode * typeToLoad, Register & dest, 
00075                               declNode * pDeclDest, string staticLabel, 
00076                               declNode * declStatic, constant offset, 
00077                               declNode * pDeclOffset);
00078   static LirInst *Store (typeNode * typeToStore, Register source_register,
00079                          declNode * pDeclSrc, Register base_reg,
00080                          declNode * pDeclBase, constant offset,
00081                          declNode * pDeclOffset);
00082   static LirInst *StoreStatic(typeNode * typeToStore, 
00083                               Register source_register, declNode * pDeclSrc,
00084                               string staticLabel, declNode * staticDecl,
00085                               constant offset, declNode * pDeclOffset);
00086   static LirInst *GetEffectiveAddress (Register & dest_register,
00087                                        declNode * pDeclDest,
00088                                        Register base_reg,
00089                                        declNode * pDeclBase, constant offset,
00090                                        declNode * pDeclOffset);
00091   static LirInst *GetGlobalAddress (Register & dest_register,
00092                                     declNode * pDeclDest,
00093                                     string staticLabel, declNode * staticDecl,
00094                                     constant offset, declNode * pDeclOffset);
00095   static LirInst *Move (Register dest, declNode * pDeclDest, Register source,
00096                         declNode * pDeclSrc);
00097 
00098   // handle arithmetic
00099   static LirInst *Add (typeNode * destType, Register & dest_reg,
00100                        declNode * pDeclDest, Register opnd1,
00101                        declNode * pDeclOp1, reg_or_const opnd2,
00102                        declNode * pDeclOp2);
00103   static LirInst *Sub (typeNode * destType, Register & dest_reg,
00104                        declNode * pDeclDest, Register opnd1,
00105                        declNode * pDeclOp1, reg_or_const opnd2,
00106                        declNode * pDeclOp2);
00107   static LirInst *Mul (typeNode * destType, Register & dest_reg,
00108                        declNode * pDeclDest, Register opnd1,
00109                        declNode * pDeclOp1, reg_or_const opnd2,
00110                        declNode * pDeclOp2);
00111   static LirInst *Div (typeNode * destType, Register & dest_reg,
00112                        declNode * pDeclDest, Register opnd1,
00113                        declNode * pDeclOp1, reg_or_const opnd2,
00114                        declNode * pDeclOp2);
00115   static LirInst *Mod (typeNode * destType, Register & dest_reg,
00116                        declNode * pDeclDest, Register opnd1,
00117                        declNode * pDeclOp1, reg_or_const opnd2,
00118                        declNode * pDeclOp2);
00119   static LirInst *Neg (typeNode * destType, Register & dest_reg,
00120                        declNode * pDeclDest, Register opnd1,
00121                        declNode * pDeclOp1);
00122 
00123   // boolean operations
00124   static LirInst *BitwiseOR (typeNode * destType, Register & dest_reg,
00125                              declNode * pDeclDest, Register opnd1,
00126                              declNode * pDeclOp1, reg_or_const opnd2,
00127                              declNode * pDeclOp2);
00128   static LirInst *BitwiseAND (typeNode * destType, Register & dest_reg,
00129                               declNode * pDeclDest, Register opnd1,
00130                               declNode * pDeclOp1, reg_or_const opnd2,
00131                               declNode * pDeclOp2);
00132   static LirInst *BitwiseXOR (typeNode * destType, Register & dest_reg,
00133                               declNode * pDeclDest, Register opnd1,
00134                               declNode * pDeclOp1, reg_or_const opnd2,
00135                               declNode * pDeclOp2);
00136   static LirInst *BitwiseNOT (typeNode * destType, Register & dest_reg,
00137                               declNode * pDeclDest, Register opnd1,
00138                               declNode * pDeclOp1);
00139   static LirInst *BitwiseShiftLeft (typeNode * destType, Register & dest_reg,
00140                                     declNode * pDeclDest, Register opnd1,
00141                                     declNode * pDeclOp1, reg_or_const bitCnt,
00142                                     declNode * pDeclBitCnt);
00143   static LirInst *BitwiseShiftRight (typeNode * destType, Register & dest_reg,
00144                                      declNode * pDeclDest, Register opnd1,
00145                                      declNode * pDeclOp1, reg_or_const bitCnt,
00146                                      declNode * pDeclBitCnt);
00147   static LirInst *BitwiseRotateRight (typeNode * destType,
00148                                       Register & dest_reg,
00149                                       declNode * pDeclDest, Register opnd1,
00150                                       declNode * pDeclOp1,
00151                                       reg_or_const bitCnt,
00152                                       declNode * pDeclBitCnt);
00153   static LirInst *BitwiseRotateLeft (typeNode * destType, Register & dest_reg,
00154                                      declNode * pDeclDest, Register opnd1,
00155                                      declNode * pDeclOp1, reg_or_const bitCnt,
00156                                      declNode * pDeclBitCnt);
00157 
00158   // control flow stuff
00159   static LirInst *Compare (Register opnd1, declNode * pDeclOp1,
00160                            reg_or_const opnd2, declNode * pDeclOp2);
00161   static LirInst *Branch (Compare_type cmp_type, string label);
00162   static LirInst *Jmp (string label);
00163   static LirInst *Call(threeAddrNode * the_call, int stack_arg_bytes);
00164   // TODO:  static LirInst *IndirectCall(
00165   static LirInst *CallPre(void);
00166   static LirInst *Return (procNode * current_proc);
00167   static LirInst *Label (string label);
00168 
00169   // static data stuff
00170 /*   static LirInst *StaticDataString (constant str); */
00171   static LirInst *StaticDataString (constant str);
00172   static LirInst *StaticDataLong (constant value);
00173   static LirInst *StaticDataInt (constant value);
00174   static LirInst *StaticDataShort (constant value);
00175   static LirInst *StaticDataChar (constant value);
00176   static LirInst *StaticDataSingle (constant value);
00177   static LirInst *StaticDataDouble (constant value);
00178   static LirInst *StaticDataZero (int size);
00179   static LirInst *StaticDataUninit (string name, int size);
00180 
00181   // other stuff
00182   static LirInst *DeclareLocal (declNode * the_decl);
00183   static LirInst *DeclareGlobal (declNode * the_decl);
00184   static LirInst *BeginProc (procNode * the_proc);
00185   static LirInst *EndProc (procNode * the_proc);
00186   static LirInst *BeginUnit (unitNode * the_unit);
00187   static LirInst *EndUnit (unitNode * the_unit);
00188 
00189 private:
00190 
00191   // do a simple 2-operand instruction (add, subtract, bitwise stuff, etc.)
00192   static LirInst *make_simple (mnemonic inst, typeNode * destType,
00193                                Register & dest_reg, declNode * pDeclDest,
00194                                Register opnd1, declNode * pDeclOp1,
00195                                reg_or_const opnd2, declNode * pDeclOp2);
00196   static LirInst *make_data(mnemonic inst, constant value);
00197 };
00198 #endif // LIR_H

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