add a compiler tool
authorDavid Schleef <ds@schleef.org>
Sat, 28 Mar 2009 07:00:00 +0000 (00:00 -0700)
committerDavid Schleef <ds@schleef.org>
Sat, 28 Mar 2009 07:07:03 +0000 (00:07 -0700)
tools/Makefile.am
tools/orcc.c

index 8b5906e..88297a0 100644 (file)
@@ -1,4 +1,6 @@
 
 bin_PROGRAMS = orcc
 
+AM_CFLAGS = $(ORC_CFLAGS)
+LDADD = $(ORC_LIBS) ../orc-test/liborc-test-0.3.la
 
index 442020a..8c8324f 100644 (file)
@@ -1,10 +1,71 @@
 
+#include <orc/orc.h>
+#include <orc-test/orctest.h>
+#include <orc/orcparse.h>
+
 #include <stdio.h>
+#include <stdlib.h>
+
+static char * read_file (const char *filename);
 
 int
 main (int argc, char *argv[])
 {
+  char *code;
+  int n;
+  int i;
+  OrcProgram **programs;
+
+  orc_init ();
+  orc_test_init ();
+
+  code = read_file ("test.orc");
+
+  n = orc_parse (code, &programs);
+
+  for(i=0;i<n;i++){
+    printf("%s\n", programs[i]->name);
+    orc_test_gcc_compile (programs[i]);
+  }
 
   return 0;
 }
 
+
+static char *
+read_file (const char *filename)
+{
+  FILE *file = NULL;
+  char *contents = NULL;
+  long size;
+  int ret;
+
+  file = fopen (filename, "r");
+  if (file == NULL) return NULL;
+
+  ret = fseek (file, 0, SEEK_END);
+  if (ret < 0) goto bail;
+
+  size = ftell (file);
+  if (size < 0) goto bail;
+
+  ret = fseek (file, 0, SEEK_SET);
+  if (ret < 0) goto bail;
+
+  contents = malloc (size + 1);
+  if (contents == NULL) goto bail;
+
+  ret = fread (contents, size, 1, file);
+  if (ret < 0) goto bail;
+
+  contents[size] = 0;
+
+  return contents;
+bail:
+  /* something failed */
+  if (file) fclose (file);
+  if (contents) free (contents);
+
+  return NULL;
+}
+