![]() |
![]() |
00001 /***************************************************************************** 00002 * Copyright (C) 1997-2007, Mark Hummel 00003 * This file is part of Vrq. 00004 * 00005 * Vrq is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * Vrq is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301 USA 00019 ***************************************************************************** 00020 */ 00021 /****************************************************************************** 00022 * 00023 * 00024 * cbackend.hpp 00025 * - abstract class definition for code generators 00026 * 00027 ****************************************************************************** 00028 */ 00029 00030 #ifndef CBACKEND_HPP 00031 #define CBACKEND_HPP 00032 00033 #include <stdio.h> 00034 #include "glue.h" 00035 #include <list> 00036 #include <map> 00037 #include <string> 00038 00039 using namespace std; 00040 00041 class CNode; 00042 class CModule; 00043 class CInstance; 00044 00172 class CElement 00173 { 00174 private: 00175 string filename; // Optional filename for compilation unit 00176 int filenameValid; // non-zero to indicate filename is valid 00177 CNode* code; // parse tree pointer for compilation unit 00178 public: 00185 CElement( const char* filename, int filenameValid, CNode* code ) : 00186 filename(filename), 00187 filenameValid( filenameValid ), 00188 code(code ) {} 00194 const char* Filename() { return filenameValid ? filename.c_str() : NULL; } 00199 CNode* Code() { return code; } 00204 void Code( CNode* code ) { this->code = code; } 00205 }; 00206 00210 class CBackendException {}; 00215 class CBackendAbort : CBackendException {}; 00220 class CBackendExit : CBackendException {}; 00225 class CBackendFail : CBackendException {}; 00226 00243 class CBackend 00244 { 00245 protected: 00246 list<string> switches; 00247 map<string,string> switchDescription; 00248 public: 00253 virtual char* GetToolName( void ) = 0; 00258 virtual char* GetToolDescription( void ) = 0; 00265 virtual int AcceptAllPlusArgs( void ) { return FALSE; } 00271 virtual list<string>& GetSwitches( void ) {return switches;} 00278 virtual const char* GetSwitchDescription( const char* sw ) 00279 { 00280 MASSERT( switchDescription.find(sw) != 00281 switchDescription.end() ); 00282 return switchDescription[sw].c_str(); 00283 } 00290 virtual void RegisterSwitch( const char* switchName, 00291 const char* description ) 00292 { 00293 switches.push_back( switchName ); 00294 switchDescription[switchName] = description; 00295 } 00302 virtual int ResolveModules() = 0; 00310 virtual int ResolveInstance( CModule* module, CInstance* inst ) = 0; 00319 virtual int HideTool() { return FALSE; } 00330 virtual int IgnoreVrqComments() { return FALSE; } 00335 virtual void Activate() = 0; 00348 virtual void Process( list<CElement>& inputList, 00349 list<CElement>& outputList ) = 0; 00350 }; 00351 00352 #endif // CBACKEND_HPP