![]() |
![]() |
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 class CObstack; 00045 00173 class CElement 00174 { 00175 private: 00176 string filename; // Optional filename for compilation unit 00177 int filenameValid; // non-zero to indicate filename is valid 00178 CNode* code; // parse tree pointer for compilation unit 00179 public: 00186 CElement( const char* filename, int filenameValid, CNode* code ) : 00187 filename(filename), 00188 filenameValid( filenameValid ), 00189 code(code ) {} 00195 const char* Filename() { return filenameValid ? filename.c_str() : NULL; } 00200 CNode* Code() { return code; } 00205 void Code( CNode* code ) { this->code = code; } 00206 }; 00207 00211 class CBackendException {}; 00216 class CBackendAbort : CBackendException {}; 00221 class CBackendExit : CBackendException {}; 00226 class CBackendFail : CBackendException {}; 00227 00244 class CBackend 00245 { 00246 protected: 00247 list<string> switches; 00248 map<string,string> switchDescription; 00249 public: 00254 virtual char* GetToolName( void ) = 0; 00259 virtual char* GetToolDescription( void ) = 0; 00266 virtual int AcceptAllPlusArgs( void ) { return FALSE; } 00272 virtual list<string>& GetSwitches( void ) {return switches;} 00279 virtual const char* GetSwitchDescription( const char* sw ) 00280 { 00281 MASSERT( switchDescription.find(sw) != 00282 switchDescription.end() ); 00283 return switchDescription[sw].c_str(); 00284 } 00291 virtual void RegisterSwitch( const char* switchName, 00292 const char* description ) 00293 { 00294 switches.push_back( switchName ); 00295 switchDescription[switchName] = description; 00296 } 00303 virtual int ResolveModules() = 0; 00311 virtual int ResolveInstance( CModule* module, CInstance* inst ) = 0; 00320 virtual int HideTool() { return FALSE; } 00331 virtual int IgnoreVrqComments() { return FALSE; } 00336 virtual void Activate() = 0; 00349 virtual void Process( list<CElement>& inputList, 00350 list<CElement>& outputList ) = 0; 00351 }; 00352 00353 #endif // CBACKEND_HPP