vrq
cbackend.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 1997-2007, Mark Hummel
3  * This file is part of Vrq.
4  *
5  * Vrq is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * Vrq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301 USA
19  *****************************************************************************
20  */
21 /******************************************************************************
22  *
23  *
24  * cbackend.hpp
25  * - abstract class definition for code generators
26  *
27  ******************************************************************************
28  */
29 
30 #ifndef CBACKEND_HPP
31 #define CBACKEND_HPP
32 
33 #include <stdio.h>
34 #include "glue.h"
35 #include <list>
36 #include <map>
37 #include <string>
38 
39 using namespace std;
40 
41 class CNode;
42 class CModule;
43 class CInstance;
44 class CObstack;
45 
178 class CElement
179 {
180 private:
181  string filename; // Optional filename for compilation unit
182  int filenameValid; // non-zero to indicate filename is valid
183  CNode* code; // parse tree pointer for compilation unit
184 public:
191  CElement( const char* filename, int filenameValid, CNode* code ) :
192  filename(filename),
193  filenameValid( filenameValid ),
194  code(code ) {}
200  const char* Filename() { return filenameValid ? filename.c_str() : NULL; }
205  CNode* Code() { return code; }
210  void Code( CNode* code ) { this->code = code; }
211 };
212 
232 
249 class CBackend
250 {
251 protected:
252  list<string> switches;
253  map<string,string> switchDescription;
254 public:
259  virtual char* GetToolName( void ) = 0;
264  virtual char* GetToolDescription( void ) = 0;
271  virtual int AcceptAllPlusArgs( void ) { return FALSE; }
277  virtual list<string>& GetSwitches( void ) {return switches;}
284  virtual const char* GetSwitchDescription( const char* sw )
285  {
286  MASSERT( switchDescription.find(sw) !=
287  switchDescription.end() );
288  return switchDescription[sw].c_str();
289  }
296  virtual void RegisterSwitch( const char* switchName,
297  const char* description )
298  {
299  switches.push_back( switchName );
300  switchDescription[switchName] = description;
301  }
308  virtual int RequireModuleResolution() { return TRUE; }
315  virtual int ResolveModules() = 0;
323  virtual int ResolveInstance( CModule* module, CInstance* inst ) = 0;
332  virtual int HideTool() { return FALSE; }
343  virtual int IgnoreVrqComments() { return FALSE; }
348  virtual void Activate() = 0;
352  virtual void Logfile( FILE* logfile ) {}
365  virtual void Process( list<CElement>& inputList,
366  list<CElement>& outputList ) = 0;
367 };
368 
369 #endif // CBACKEND_HPP
virtual const char * GetSwitchDescription(const char *sw)
Method to get the help text for a switch using the switch name as a key.
Definition: cbackend.h:284
Exception thrown by CBackend::Process when plugin aborts due to an internal error.
Definition: cbackend.h:221
const char * Filename()
Access method for filename tagging this compilation unit.
Definition: cbackend.h:200
Exception thrown by CBackend::Process when plugin terminates early with an error. ...
Definition: cbackend.h:231
Exception thrown by CBackend::Process when plugin terminates early without an error.
Definition: cbackend.h:226
map< string, string > switchDescription
list of plugin command line switches
Definition: cbackend.h:253
void Code(CNode *code)
Method to set parse tree for this compilation unit.
Definition: cbackend.h:210
virtual void Logfile(FILE *logfile)
Pass current open logfile to plugin.
Definition: cbackend.h:352
list< string > switches
Definition: cbackend.h:252
CElement(const char *filename, int filenameValid, CNode *code)
Constructor for class.
Definition: cbackend.h:191
Bulk object allocation object.
Definition: cobstack.h:46
Primary data structure representing parse tree nodes.
Definition: cnode.h:188
Declaration object for module and gate instances.
Definition: cinstance.h:45
virtual int IgnoreVrqComments()
Method to control how parser handles vrq comment based pragmas: ie // vrq translate_on/off Note: the ...
Definition: cbackend.h:343
This is the abstract class to overload to create new backend tools.
Definition: cbackend.h:249
Definition: cmodule.h:54
virtual int AcceptAllPlusArgs(void)
Override this method if the plugin accepts arbitrary plusargs: ie +argName[=argValue] or +argName[+ar...
Definition: cbackend.h:271
virtual int RequireModuleResolution()
Method to control if plugin requires all module definitions to be resolved.
Definition: cbackend.h:308
virtual void RegisterSwitch(const char *switchName, const char *description)
Method shortcut to register tool switches with vrq's help system.
Definition: cbackend.h:296
CNode * Code()
Access method for parse tree for this compilation unit.
Definition: cbackend.h:205
virtual int HideTool()
Method to control if plugin should be hidden, in this case it will not appear in the help but will it...
Definition: cbackend.h:332
virtual list< string > & GetSwitches(void)
Access method for list of switches.
Definition: cbackend.h:277
Base class for exceptions that can be thrown by backend plugins.
Definition: cbackend.h:216
FILE * logfile
Definition: main.cc:232
An element of compilation passed to and from plugins.
Definition: cbackend.h:178