From dbd7082d205410deecfacb5a7cd5336fc360c242 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 6 Jul 2012 20:30:50 +0000 Subject: Added the gats compiler. It can only compile from gats-text to gats-binary right now. --- default.bld | 13 ++++++++-- src/gatsc/main.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 src/gatsc/main.cpp diff --git a/default.bld b/default.bld index b3a9020..676c63e 100644 --- a/default.bld +++ b/default.bld @@ -3,12 +3,13 @@ execute("mkdir -p tmp"); action "default" { - build: [targets("header-links"), "libgats.a"]; + build: [targets("header-links"), "libgats.a", "gatsc"]; } action "all" { - build: [targets("header-links"), "libgats.a", targets()]; + build: [targets("header-links"), "libgats.a", targets("headers"), + targets()]; } action "gatscon" @@ -47,6 +48,14 @@ target "libgats.a" CXXFLAGS += "-I. -Ilibbu++ -fPIC"; } +target "gatsc" +{ + rule "exe"; + input files("src/gatsc/*.cpp"); + CXXFLAGS += "-I. -Ilibbu++"; + LDFLAGS += "-L. -lgats -lbu++"; +} + target files("src/tests/*.cpp").replace("src/","").replace(".cpp","") { input "src/${OUTPUT}.cpp"; diff --git a/src/gatsc/main.cpp b/src/gatsc/main.cpp new file mode 100644 index 0000000..2bac3fd --- /dev/null +++ b/src/gatsc/main.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +#include + +#include "gats/types.h" +#include "gats/gatsstream.h" + +using namespace Bu; + +class Options : public OptParser +{ +public: + Options( int argc, char *argv[] ) : + bCompile( true ) + { + addHelpBanner("Gats Compiler\nUsage: gatsc [options] [input]\n"); + + addOption( sInput, 'i', "input", "Specify input file."); + addOption( sOutput, 'o', "output", "Specify output file."); + + addOption( bCompile, 'd', "decompile", + "Convert binary gats to text gats."); + + addHelpOption('h', "help", "This Help"); + + setNonOption( slot( this, &Options::setInput ) ); + + setOverride("decompile", false ); + + parse( argc, argv ); + } + + int setInput( StrArray aParam ) + { + sInput = aParam[0]; + return 0; + } + + bool bCompile; + String sInput; + String sOutput; +}; + +int main( int argc, char *argv[] ) +{ + Options opt( argc, argv ); + + if( opt.sInput.isEmpty() ) + { + sio << "You must specify an input." << sio.nl << sio.nl; + return 1; + } + + if( opt.sOutput.isEmpty() ) + { + opt.sOutput.set( opt.sInput.begin(), opt.sInput.find('.') ); + opt.sOutput += ".gats"; + } + + if( opt.bCompile ) + { + File fIn( opt.sInput, File::Read ); + File fOut( opt.sOutput, File::WriteNew ); + Gats::GatsStream gs( fOut ); + Gats::Object *pObj = Gats::Object::strToGats( fIn.readAll() ); + gs.writeObject( pObj ); + delete pObj; + } + + return 0; +} + -- cgit v1.2.3