3 #include <orc-test/orctest.h>
4 #include <orc/orcparse.h>
9 static char * read_file (const char *filename);
10 void output_code (OrcProgram *p, FILE *output);
11 void output_code_header (OrcProgram *p, FILE *output);
12 void output_code_test (OrcProgram *p, FILE *output);
17 main (int argc, char *argv[])
22 OrcProgram **programs;
23 const char *filename = "test.orc";
31 code = read_file (filename);
33 printf("compile_parse_test <file.orc>\n");
37 n = orc_parse (code, &programs);
42 printf("%s:\n", programs[i]->name);
43 ret = orc_test_gcc_compile (programs[i]);
44 if (ret == ORC_TEST_FAILED) {
55 read_file (const char *filename)
58 char *contents = NULL;
62 file = fopen (filename, "r");
63 if (file == NULL) return NULL;
65 ret = fseek (file, 0, SEEK_END);
66 if (ret < 0) goto bail;
69 if (size < 0) goto bail;
71 ret = fseek (file, 0, SEEK_SET);
72 if (ret < 0) goto bail;
74 contents = malloc (size + 1);
75 if (contents == NULL) goto bail;
77 ret = fread (contents, size, 1, file);
78 if (ret < 0) goto bail;
84 /* something failed */
85 if (file) fclose (file);
86 if (contents) free (contents);