From: Mike D. Lowis Date: Thu, 10 Oct 2013 01:25:49 +0000 (-0400) Subject: added file reading and writing infrastructure X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=a6f29b748eee1127960dc3380656df31480b8020;p=proto%2Fsclpl.git added file reading and writing infrastructure --- diff --git a/SConstruct b/SConstruct index b3dd088..9f45013 100644 --- a/SConstruct +++ b/SConstruct @@ -23,7 +23,7 @@ c_cpp = Environment( ENV = os.environ, CCFLAGS = [ '-Wall', '-Werror', '-std=c99' ], LDFLAGS = [], - TOOLS = [ 'mingw' ]) + TOOLS = [ 'mingw' ]) # Chicken Scheme Environment #--------------------------- diff --git a/source/slas/main.c b/source/slas/main.c index 5a883f1..ebb6f0d 100644 --- a/source/slas/main.c +++ b/source/slas/main.c @@ -1,7 +1,61 @@ #include +static int assemble_file(char* infile, char* outfile); +static int generate_bytecode(FILE* ifh, FILE* ofh); + +static char usage[] = + "\nUsage: slas \n\n" + "Assemble to SCLPL bytecode and write the result to .\n" ; + +static char buffer[1024] = { 0 }; + int main(int argc, char** argv) { - puts("Hello, World!"); - return 0; + int ret = 0; + if (argc == 3) + { + ret = assemble_file(argv[1],argv[2]); + } + else + { + puts(usage); + } + return ret; +} + +static int assemble_file(char* infile, char* outfile) +{ + int ret = 1; + FILE* ifh = fopen(infile, "r"); + FILE* ofh = fopen(outfile, "w"); + if (ifh && ofh) + { + ret = generate_bytecode(ifh,ofh); + } + fclose(ifh); + fclose(ofh); + fclose(NULL); + return ret; } + +static int generate_bytecode(FILE* ifh, FILE* ofh) +{ + int ret = 0; + //asm_ctx_t context; + //asm_init(&context); + while(!feof(ifh)) + { + if (fgets(buffer,1023,ifh)) + { + puts(buffer); + } + else + { + ret = 1; + break; + } + } + return ret; +} + +