diff options
author | David Schleef <ds@schleef.org> | 2011-10-08 23:17:10 -0700 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2011-10-08 23:17:10 -0700 |
commit | 9dee20aa3ba22342c83638d6402c4ef1edcde916 (patch) | |
tree | e6f96ecec4650d7977ee7b957598ea4ff221d4b5 /testsuite | |
parent | 401ed9227093ac66d38950bdb931dc04b5208ff5 (diff) | |
download | orc-9dee20aa3ba22342c83638d6402c4ef1edcde916.tar.gz |
bytecode: Add bytecode
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/Makefile.am | 1 | ||||
-rw-r--r-- | testsuite/bytecode_parse.c | 100 |
2 files changed, 101 insertions, 0 deletions
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index fdae171..4926454 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -18,6 +18,7 @@ noinst_PROGRAMS = $(TESTS) generate_xml_table generate_xml_table2 \ generate_opcodes_sys compile_parse compile_parse_c memcpy_speed \ perf_opcodes_sys_compare perf_parse_compare \ exec_parse \ + bytecode_parse \ compile_opcodes_sys_c \ compile_opcodes_sys \ show_parse diff --git a/testsuite/bytecode_parse.c b/testsuite/bytecode_parse.c new file mode 100644 index 0000000..fb1e587 --- /dev/null +++ b/testsuite/bytecode_parse.c @@ -0,0 +1,100 @@ + +#define ORC_ENABLE_UNSTABLE_API +#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); +void output_code (OrcProgram *p, FILE *output); +void output_code_header (OrcProgram *p, FILE *output); +void output_code_test (OrcProgram *p, FILE *output); + +int error = FALSE; + +int +main (int argc, char *argv[]) +{ + char *code; + int n; + int i; + int j; + OrcProgram **programs; + const char *filename = NULL; + + orc_init (); + orc_test_init (); + + if (argc >= 2) { + filename = argv[1]; + } + if (filename == NULL) { + filename = getenv ("testfile"); + } + if (filename == NULL) { + filename = "test.orc"; + } + code = read_file (filename); + if (!code) { + printf("compile_parse_test <file.orc>\n"); + exit(1); + } + + n = orc_parse (code, &programs); + + for(i=0;i<n;i++){ + OrcBytecode *bytecode; + + printf("%s:\n", programs[i]->name); + bytecode = orc_bytecode_from_program (programs[i]); + + for(j=0;j<bytecode->length;j++) { + printf("%d, ", bytecode->bytecode[j]); + } + printf("\n"); + } + + if (error) return 1; + 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; +} + |