/******************************************************* * * DESCRIPTION: CD++ compiler for Modelica specifications * * AUTHOR: Mariana C. D'Abreu * * EMAIL: mdabreu@dc.uba.ar * ********************************************************/ #include #include "modelica_compiler.h" #define endl "\n" /******************************************************************* * Function Name: *******************************************************************/ Modelica2CDPPCompiler::Modelica2CDPPCompiler( int argc, const char *argv[] ) :simParamsFile( "" ) , outDir( "" ) , gQuantum( 0.01 ) , gHystWind( 0.01 ) { while( --argc ) { if( argv[ argc ][ 0 ] == '-' ) { switch( argv[ argc ][ 1 ] ) { case 'f': // file de parametros de simulacion para componentes especificos simParamsFile = argv[ argc ] + 2 ; break; case 'o': // output directory outDir = argv[ argc ] + 2; break; case 'q': // quantum aplicable a todos los componentes gQuantum = atof( argv[ argc ] + 2 ); break; case 'y': // histeresis window aplicable a todos los componentes gHystWind = atof( argv[ argc ] + 2 ); break; case 'h': // help printUsage( argv[0] ); exit(0); default: cout << "Invalid parameter " << argv[ argc ] << "!" << endl; printUsage( argv[0] ); exit(-1); } } else { cout << "Invalid parameter " << argv[ argc ] << "!" << endl; printUsage( argv[0] ); exit(-1); } } mapper = new EC_BG_Mapper(); assert( mapper != NULL ); compiler = new BG_CDPP_Compiler(); assert( compiler != NULL ); setCDPPCompilerParams(); } /******************************************************************* * Function Name: *******************************************************************/ Modelica2CDPPCompiler::~Modelica2CDPPCompiler() { if( mapper != NULL ) delete mapper; if( compiler != NULL ) delete compiler; } /******************************************************************* * Function Name: *******************************************************************/ Modelica2CDPPCompiler &Modelica2CDPPCompiler::setCDPPCompilerParams() { QuantizerParams aqparams; aqparams.quantum = gQuantum; aqparams.hystWindow = gHystWind; compiler->setOutputDirectory( outDir ); compiler->setQuantizerParamsForAll( aqparams ); compiler->setQuantizerParamsFile( simParamsFile ); return *this; } /******************************************************************* * Function Name: *******************************************************************/ void Modelica2CDPPCompiler::printUsage( const string &pgm ) const { cout << "\nUsage : " << pgm << " [-o simoutdir] [-q simgenquantum] [-y simgenhyswind] [-f file] [-h]" << endl; cout << "\nOptions:" << endl; cout << "\t o: Components output directory (default: no output)" << endl; cout << "\t q: Components general quantum (default: 0.01)" << endl; cout << "\t y: Components general hysteresis window (default: 0.01)" << endl; cout << "\t f: File with simulation parameters for specific components (default: none)" << endl; cout << "\t h: Shows this help" << endl; } /******************************************************************* * Function Name: *******************************************************************/ int Modelica2CDPPCompiler::compile() { ECircuit *circuit = NULL; BondGraph *bg = NULL; int error = -1; try { //------------------------------------------------------------ // Construyo el circuito a partir del codigo fuente Modelica //------------------------------------------------------------ ModelicaParser modparser; circuit = modparser.parseAndExecute(); assert( circuit != NULL ); //------------------------------------------------------------ // Mapeo el circuito a un grafo Bond Graph //------------------------------------------------------------ bg = mapper->mappToBondGraph( *circuit ); assert( bg != NULL ); //------------------------------------------------------------ // Genero el codigo CD++ correspondiente al Bond Graph //------------------------------------------------------------ compiler->generateMA( *bg, cout ); error = 0; } catch ( ModelicaParserException &e ) { e.print( cerr ); } catch ( ECircuitException &e1 ) { e1.print( cerr ); } catch ( ECompException &e2 ) { e2.print( cerr ); } catch ( EC_BG_MapperException &e ) { e.print( cerr ); } catch ( BondGraphException &e ) { e.print( cerr ); } catch ( BGCompException &e ) { e.print( cerr ); } if( circuit != NULL ) delete circuit; if( bg != NULL ) delete bg; return error; } /******************************************************************* * Main *******************************************************************/ int main( int argc, const char *argv[] ) { Modelica2CDPPCompiler *compiler = new Modelica2CDPPCompiler( argc, argv ); assert( compiler != NULL ); int aret = compiler->compile(); if( compiler ) delete compiler; return aret; }