#include "libfaudes.h"
using namespace faudes;
void usage_exit(const std::string& message="") {
if(message!="") {
std::cout << "compiledes: " << message << std::endl;
std::cout << "" << std::endl;
exit(-1);
}
std::cout << "" << std::endl;
std::cout << "compiledes: usage: " << std::endl;
std::cout << "compiledes [-q][-v] -t <target> -o <outfile> <srcfile>"<< std::endl;
std::cout << "where " << std::endl;
std::cout << " <scrfile>: code generator source file, typically \"*.cgc\"" << std::endl;
std::cout << "" << std::endl;
std::cout << " -q: less console output " << std::endl;
std::cout << " -qq: absolutely no console output " << std::endl;
std::cout << " -v: more console output" << std::endl;
std::cout << " -vv: even more console output" << std::endl;
std::cout << "" << std::endl;
std::cout << " -t <target>: target platform, see also below " << std::endl;
std::cout << " -o <outfile>: (base)name of output file(s), defaults to console output" << std::endl;
std::cout << "" << std::endl;
std::cout << "compiledes: target platforms: ";
for(size_t i=0; i<registry.size(); ++i)
std::cout << registry[i] << " ";
std::cout << "" << std::endl;
std::cout << "" << std::endl;
exit(-1);
}
int main(int argc, char* argv[]) {
std::string mMark="% compiledes: ========================================= ";
int mConsoleOut=0;
std::string mSrcFile="";
std::string mOutFile="std::cout";
std::string mTarget="";
for(int i=1; i<argc; i++) {
std::string option(argv[i]);
if((option=="-q") || (option=="--quiet")) {
mConsoleOut=-1;
continue;
}
if(option=="-qq"){
mConsoleOut=-2;
continue;
}
if((option=="-v") || (option=="--verbose")) {
mConsoleOut=1;
continue;
}
if(option=="-vv") {
mConsoleOut=2;
continue;
}
if((option=="-o") || (option=="--out")) {
i++; if(i>=argc) usage_exit();
mOutFile=argv[i];
continue;
}
if((option=="-t") || (option=="--target")) {
i++; if(i>=argc) usage_exit();
mTarget=argv[i];
continue;
}
if((option=="-?") || (option=="--help")) {
usage_exit();
continue;
}
if(option.c_str()[0]=='-') {
usage_exit("unknown option "+ option);
continue;
}
if(mSrcFile!="")
usage_exit("more than one source file specified" );
mSrcFile=option;
}
if(mSrcFile=="")
usage_exit("you must specify a source file" );
if(!mpCodeGenerator)
usage_exit("unknown target platform");
mpCodeGenerator->
Verbose(mConsoleOut);
try{
mpCodeGenerator->Read(mSrcFile);
}
catch(const Exception& fe) {
std::cout << std::flush;
std::cerr << fe.Message() << std::endl;
std::cerr << "CompileDES: caught libFAUDES exception --- missing/missformed configuration file" << std::endl;
return 1;
}
try{
}
catch(const Exception& fe) {
std::cout << std::flush;
std::cerr << fe.Message() << std::endl;
std::cerr << "CompileDES: caught libFAUDES exception --- failed to setup output file/console or output filters" << std::endl;
return 1;
}
try{
}
catch(const Exception& fe) {
std::cout << std::flush;
std::cerr << fe.Message() << std::endl;
std::cerr << "CompileDES: caught libFAUDES exception --- failed to compile configuration data to internal representation" << std::endl;
return 1;
}
try{
}
catch(const Exception& fe) {
std::cout << std::flush;
std::cerr << fe.Message() << std::endl;
std::cerr << "CompileDES: caught libFAUDES exception --- failed to generate target code for specified options" << std::endl;
return 1;
}
return 0;
}
Code-generator common base class.
Code-generation common base.
static std::vector< std::string > Registry(void)
Access registry contents.
virtual void OutputMode(const std::string &mode)
Set code output mode.
static CodeGenerator * New(const std::string &type)
Instantiate by identifier (returns 0 on unknown class)
void Verbose(int level, std::ostream *altout=0)
Set verbosity level.
static std::string VersionString(void)
Version (refers to macro COMPILEDES_VERSION, defined in cgp_codegenerator.h)
virtual void Compile(void)
Compile input data for alternative representation.
virtual void Generate(void)
Generate code.