diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-07-06 20:30:50 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-07-06 20:30:50 +0000 |
commit | dbd7082d205410deecfacb5a7cd5336fc360c242 (patch) | |
tree | 40747585594a98a29f7b35866b7876d8c723039d | |
parent | 2d58f0bae4d1e0b69cb0106acbd4b4a48831bbb6 (diff) | |
download | libgats-dbd7082d205410deecfacb5a7cd5336fc360c242.tar.gz libgats-dbd7082d205410deecfacb5a7cd5336fc360c242.tar.bz2 libgats-dbd7082d205410deecfacb5a7cd5336fc360c242.tar.xz libgats-dbd7082d205410deecfacb5a7cd5336fc360c242.zip |
Added the gats compiler. It can only compile from gats-text to gats-binary
right now.
-rw-r--r-- | default.bld | 13 | ||||
-rw-r--r-- | src/gatsc/main.cpp | 73 |
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 | ||
4 | action "default" | 4 | action "default" |
5 | { | 5 | { |
6 | build: [targets("header-links"), "libgats.a"]; | 6 | build: [targets("header-links"), "libgats.a", "gatsc"]; |
7 | } | 7 | } |
8 | 8 | ||
9 | action "all" | 9 | action "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 | ||
14 | action "gatscon" | 15 | action "gatscon" |
@@ -47,6 +48,14 @@ target "libgats.a" | |||
47 | CXXFLAGS += "-I. -Ilibbu++ -fPIC"; | 48 | CXXFLAGS += "-I. -Ilibbu++ -fPIC"; |
48 | } | 49 | } |
49 | 50 | ||
51 | target "gatsc" | ||
52 | { | ||
53 | rule "exe"; | ||
54 | input files("src/gatsc/*.cpp"); | ||
55 | CXXFLAGS += "-I. -Ilibbu++"; | ||
56 | LDFLAGS += "-L. -lgats -lbu++"; | ||
57 | } | ||
58 | |||
50 | target files("src/tests/*.cpp").replace("src/","").replace(".cpp","") | 59 | target 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 | |||
9 | using namespace Bu; | ||
10 | |||
11 | class Options : public OptParser | ||
12 | { | ||
13 | public: | ||
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 | |||
45 | int 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 | |||