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  

arch_info_parser.h

Go to the documentation of this file.
00001 // $Id: arch_info_parser.h,v 1.6 2003/08/11 17:38:51 abrown Exp $
00002 // ----------------------------------------------------------------------
00003 //
00004 //  C-Breeze
00005 //  C Compiler Framework
00006 // 
00007 //  Copyright (c) 2002 University of Texas at Austin
00008 // 
00009 //  Charles Nevill
00010 //  Paul Arthur Navratil
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 #ifndef _arch_info_parser_H
00039 #define _arch_info_parser_H
00040 
00041 #include "arch_info.h"
00042 
00043 class arch_info_parser
00044 {
00045 public:
00047 // object management
00048 
00049         // ctor/dtor
00050         arch_info_parser();
00051         ~arch_info_parser();
00052 
00053 public:
00055 // persistence methods
00056 
00057         // load architecture information from the specified file
00058         bool parse( const char * pFile, arch_info * pArchInfo );
00059 
00060 
00061 private:
00063 // parsing helpers
00064 
00065         // initialize various things before parsing
00066         void init_parser();
00067 
00068         // get the next input character from the file
00069         // this basically preprocesses the file so the parser is more simple
00070         char get_char( bool skipWhitespace = false );
00071         char peek_char( bool skipWhitespace = false );
00072 
00073         // low-level character getter/ungetter routines
00074         char do_getc();
00075         void do_ungetc( char );
00076 
00077         // read a string from a file, returns false if none could be
00078         // read readAnyChars: if true, all characters are read until
00079         // end of line // if false, only alphanumerics are read
00080         bool read_string( string & stringOut, bool readAnyChars = false, 
00081                           bool skipLeadingNewlines = false );
00082 
00083         // types of things we need to be able to load
00084         enum parse_type
00085         {
00086                 type__unknown,
00087                 type_reg,               // single register
00088                 type_reg_list,  // list of registers
00089                 type_string,    // string
00090                 type_integer,   // integer
00091                 type_boolean,   // boolean true/false
00092                 type_vartype,   // typeNode * value
00093                 type_Lir2Asm,   // Lir2Asm record
00094         };
00095 
00096         // pointer-to-member typedefs for load types
00097         typedef arch_info::register_info* arch_info::* reg_info_ptr;
00098         typedef arch_info::register_info_list arch_info::* reg_info_list_ptr;
00099         typedef string arch_info::* string_ptr;
00100         typedef int arch_info::* int_ptr;
00101         typedef bool arch_info::* bool_ptr;
00102         typedef typeNode * arch_info::* vartype_ptr;
00103         typedef arch_info::Lir2Asm_list arch_info::* Lir2Asm_list_ptr;
00104 
00105         // subroutines for parsing various things
00106         bool parse_reg_item( string keyName, reg_info_ptr toRead );
00107         bool parse_reg_list_item( string keyName, reg_info_list_ptr toRead, 
00108                                   bool isMasterList = false, 
00109                                   bool allowTokens = false );
00110         bool parse_string_item( string keyName, string_ptr toRead );
00111         bool parse_integer_item( string keyName, int_ptr toRead );
00112         bool parse_bool_item( string keyName, bool_ptr toRead );
00113         bool parse_vartype_item( string keyName, vartype_ptr toRead );
00114         bool parse_Lir2Asm_item( string keyName, Lir2Asm_list_ptr toAppend );
00115 
00116         // structure defining something that we might need to parse
00117         struct thing_to_parse
00118         {
00119                 thing_to_parse() : _parseType( type__unknown )
00120                 {
00121                 }
00122 
00123                 // constructors for various types
00124                 thing_to_parse( string keyName, reg_info_ptr toRead ) 
00125                         : _keyName( keyName ), _parseType( type_reg )
00126                 {
00127                         cbz_util::string_to_lower( _keyName );
00128                         _data._reg = toRead;
00129                 }
00130                 thing_to_parse( string keyName, reg_info_list_ptr toRead, 
00131                                 bool isMasterList = false ) 
00132                         : _keyName( keyName ), _parseType( type_reg_list )
00133                 {
00134                         cbz_util::string_to_lower( _keyName );
00135                         _data._regList = toRead;
00136                         _regIsMasterList = isMasterList;
00137                 }
00138                 thing_to_parse( string keyName, string_ptr toRead ) 
00139                         : _keyName( keyName ), _parseType( type_string )
00140                 {
00141                         cbz_util::string_to_lower( _keyName );
00142                         _data._string = toRead;
00143                 }
00144                 thing_to_parse( string keyName, int_ptr toRead ) 
00145                         : _keyName( keyName ), _parseType( type_integer )
00146                 {
00147                         cbz_util::string_to_lower( _keyName );
00148                         _data._int = toRead;
00149                 }
00150                 thing_to_parse( string keyName, bool_ptr toRead ) 
00151                         : _keyName( keyName ), _parseType( type_boolean )
00152                 {
00153                         cbz_util::string_to_lower( _keyName );
00154                         _data._bool = toRead;
00155                 }
00156                 thing_to_parse( string keyName, vartype_ptr toRead ) 
00157                         : _keyName( keyName ), _parseType( type_vartype )
00158                 {
00159                         cbz_util::string_to_lower( _keyName );
00160                         _data._vartype = toRead;
00161                 }
00162                 thing_to_parse( string keyName, Lir2Asm_list_ptr toAppend ) 
00163                         : _keyName( keyName ), _parseType( type_Lir2Asm )
00164                 {
00165                         cbz_util::string_to_lower( _keyName );
00166                         _data._Lir2AsmList = toAppend;
00167                 }
00168 
00169                 // the name that identifies this information in the config file
00170                 // e.g. RegsGprInt or Lir2Asm
00171                 string          _keyName;
00172 
00173                 // the function that should be used to parse this thing
00174                 // e.g. parse_reg_list() or parse_Lir2Asm()
00175                 parse_type      _parseType;
00176 
00177                 // if we are parsing a register list, is it the master list?
00178                 bool            _regIsMasterList;
00179 
00180                 // pointer to the data that should be filled out by the
00181                 // parse function
00182                 union 
00183                 {
00184                         reg_info_ptr            _reg;
00185                         reg_info_list_ptr       _regList;
00186                         string_ptr                      _string;
00187                         int_ptr                         _int;
00188                         bool_ptr                        _bool;
00189                         vartype_ptr                     _vartype;
00190                         Lir2Asm_list_ptr        _Lir2AsmList;
00191                 } _data;
00192         };
00193 
00194         // a list of things that may need to be parsed
00195         typedef vector<thing_to_parse> thing_to_parse_array;
00196 
00197         // top-level things to parse
00198         thing_to_parse_array    _thingsToParse;
00199 
00200 
00201 private:
00203 // member data
00204 
00205         // whether or not we are initialized
00206         bool                            _initialized;
00207 
00208         // the architecture info object we are currently setting up
00209         arch_info *                     _pArchInfo;
00210 
00211         // the file we are parsing to load the arch info
00212         FILE *                          _pSpecFile;
00213         int                                     _currentLine;
00214 
00215         // used for getchar/peekchar stuff
00216 #define NO_CHAR -2
00217         int                                     _lastChar;
00218         bool                            _wasNewLine;
00219 
00220         // character classes
00221         enum char_class { WS, LINEBREAK, ALPHANUM, SPECIAL };
00222         char_class                      _charClass[256];
00223 
00224         // map from mnemonic str to mnemonic
00225         typedef map<string, mnemonic> mnemonic_map;
00226         mnemonic_map            _mnemonicMap;
00227 
00228         // map from data type str to typeNode *
00229         typedef map<string, typeNode *> vartype_map;
00230         vartype_map                     _varTypeMap;
00231 
00232 };
00233 
00234 #endif
00235 

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