diff options
| author | Franklin Wei <git@fwei.tk> | 2015-11-26 15:36:59 -0500 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2015-11-26 15:36:59 -0500 |
| commit | 4ac525349f7997aaf090edae932c14972c77d385 (patch) | |
| tree | b9ea3037365778077122770f9378eea80ea12c0c /target | |
| parent | f9bd70a047c357d7f4ebfadbfe34c30becb380db (diff) | |
| download | ducky-4ac525349f7997aaf090edae932c14972c77d385.zip ducky-4ac525349f7997aaf090edae932c14972c77d385.tar.gz ducky-4ac525349f7997aaf090edae932c14972c77d385.tar.bz2 ducky-4ac525349f7997aaf090edae932c14972c77d385.tar.xz | |
support one-command compilation, replace jump table with switch statement
Diffstat (limited to 'target')
| -rw-r--r-- | target/unix/main.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/target/unix/main.c b/target/unix/main.c index d7f49bf..e5dc4a3 100644 --- a/target/unix/main.c +++ b/target/unix/main.c @@ -12,6 +12,12 @@ char *progname; void arg_error(void) { printf("Usage: %s [-aceit] FILE\n", progname); + printf(" -a: compile to machine code\n"); + printf(" -c: compile to bytecode\n"); + printf(" -e: execute bytecode (not needed)\n"); + printf(" -i: interpret directly (default action)\n"); + printf(" -t: transcompile to C\n"); + printf("Default action is to interpret or execute bytecode.\n"); exit(EXIT_FAILURE); } @@ -24,7 +30,9 @@ int main(int argc, char *argv[]) { for(int i = 1; i < argc; ++i) { - if(!strcmp(argv[i], "-c")) + if(!strcmp(argv[i], "-a")) + action = EVERYTHING; + else if(!strcmp(argv[i], "-c")) action = COMPILE; else if(!strcmp(argv[i], "-i")) action = INTERP; @@ -79,6 +87,35 @@ int main(int argc, char *argv[]) return 1; } break; + case EVERYTHING: + { + char bytecode[L_tmpnam]; + tmpnam(bytecode); + out_fd = open(bytecode, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if(ducky_compile(fd, false, out_fd)) + { + printf("Compiler error.\n"); + return 1; + } + + close(fd); + close(out_fd); + + char c_code[L_tmpnam]; + tmpnam(c_code); + fd = open(bytecode, O_RDONLY); + out_fd = open(c_code, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if(ducky_to_c(fd, out_fd)) + { + printf("Transcompiler error.\n"); + return 1; + } + close(fd); + close(out_fd); + char cmd[256]; + snprintf(cmd, sizeof(cmd), "cc -O3 -lm -x c %s", c_code); + system(cmd); + } default: break; } |