]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
added file reading and writing infrastructure
authorMike D. Lowis <mike@mdlowis.com>
Thu, 10 Oct 2013 01:25:49 +0000 (21:25 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Thu, 10 Oct 2013 01:25:49 +0000 (21:25 -0400)
SConstruct
source/slas/main.c

index b3dd088c92ce0c13cc90f9d197beb3d128fea84d..9f4501377df4e38651e18b6379e48fdbbe89a86b 100644 (file)
@@ -23,7 +23,7 @@ c_cpp = Environment(
         ENV      = os.environ,
         CCFLAGS  = [ '-Wall', '-Werror', '-std=c99' ],
         LDFLAGS  = [],
-        TOOLS = [ 'mingw' ])
+        TOOLS    = [ 'mingw' ])
 
 # Chicken Scheme Environment
 #---------------------------
index 5a883f1803845eed06d1e240d44b7b1d09de76e8..ebb6f0d21597675c4c82a30ae0490fa2f608d0bc 100644 (file)
@@ -1,7 +1,61 @@
 #include <stdio.h>
 
+static int assemble_file(char* infile, char* outfile);
+static int generate_bytecode(FILE* ifh, FILE* ofh);
+
+static char usage[] =
+    "\nUsage: slas <INFILE> <OUTFILE>\n\n"
+    "Assemble <INFILE> to SCLPL bytecode and write the result to <OUTFILE>.\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;
+}
+
+