aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--default.bld13
-rw-r--r--src/gatsc/main.cpp73
2 files changed, 84 insertions, 2 deletions
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");
3 3
4action "default" 4action "default"
5{ 5{
6 build: [targets("header-links"), "libgats.a"]; 6 build: [targets("header-links"), "libgats.a", "gatsc"];
7} 7}
8 8
9action "all" 9action "all"
10{ 10{
11 build: [targets("header-links"), "libgats.a", targets()]; 11 build: [targets("header-links"), "libgats.a", targets("headers"),
12 targets()];
12} 13}
13 14
14action "gatscon" 15action "gatscon"
@@ -47,6 +48,14 @@ target "libgats.a"
47 CXXFLAGS += "-I. -Ilibbu++ -fPIC"; 48 CXXFLAGS += "-I. -Ilibbu++ -fPIC";
48} 49}
49 50
51target "gatsc"
52{
53 rule "exe";
54 input files("src/gatsc/*.cpp");
55 CXXFLAGS += "-I. -Ilibbu++";
56 LDFLAGS += "-L. -lgats -lbu++";
57}
58
50target files("src/tests/*.cpp").replace("src/","").replace(".cpp","") 59target files("src/tests/*.cpp").replace("src/","").replace(".cpp","")
51{ 60{
52 input "src/${OUTPUT}.cpp"; 61 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 @@
1#include <bu/optparser.h>
2#include <bu/string.h>
3#include <bu/file.h>
4#include <bu/sio.h>
5
6#include "gats/types.h"
7#include "gats/gatsstream.h"
8
9using namespace Bu;
10
11class Options : public OptParser
12{
13public:
14 Options( int argc, char *argv[] ) :
15 bCompile( true )
16 {
17 addHelpBanner("Gats Compiler\nUsage: gatsc [options] [input]\n");
18
19 addOption( sInput, 'i', "input", "Specify input file.");
20 addOption( sOutput, 'o', "output", "Specify output file.");
21
22 addOption( bCompile, 'd', "decompile",
23 "Convert binary gats to text gats.");
24
25 addHelpOption('h', "help", "This Help");
26
27 setNonOption( slot( this, &Options::setInput ) );
28
29 setOverride("decompile", false );
30
31 parse( argc, argv );
32 }
33
34 int setInput( StrArray aParam )
35 {
36 sInput = aParam[0];
37 return 0;
38 }
39
40 bool bCompile;
41 String sInput;
42 String sOutput;
43};
44
45int main( int argc, char *argv[] )
46{
47 Options opt( argc, argv );
48
49 if( opt.sInput.isEmpty() )
50 {
51 sio << "You must specify an input." << sio.nl << sio.nl;
52 return 1;
53 }
54
55 if( opt.sOutput.isEmpty() )
56 {
57 opt.sOutput.set( opt.sInput.begin(), opt.sInput.find('.') );
58 opt.sOutput += ".gats";
59 }
60
61 if( opt.bCompile )
62 {
63 File fIn( opt.sInput, File::Read );
64 File fOut( opt.sOutput, File::WriteNew );
65 Gats::GatsStream gs( fOut );
66 Gats::Object *pObj = Gats::Object::strToGats( fIn.readAll() );
67 gs.writeObject( pObj );
68 delete pObj;
69 }
70
71 return 0;
72}
73