summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schleef <ds@ginger.bigkitten.com>2008-05-15 14:15:46 -0700
committerDavid Schleef <ds@ginger.bigkitten.com>2008-05-15 14:15:46 -0700
commit8fd8ff30977f0317d819f0a551b3b7f922afb055 (patch)
treeea228e04d9cb540dd79347caa2a7f794bacff6fb
parentd7ff7a39fd9dda3af266158244dc800ee16000c2 (diff)
downloadliboil-8fd8ff30977f0317d819f0a551b3b7f922afb055.tar.gz
[orc] Splitting C files
-rw-r--r--configure.ac6
-rw-r--r--examples/orc/Makefile.am8
-rw-r--r--examples/orc/jit.c (renamed from orc/jit.c)2
-rw-r--r--orc/Makefile.am13
-rw-r--r--orc/ojprogram.c178
-rw-r--r--orc/orcexecutor.c102
-rw-r--r--orc/orcrule.c62
-rw-r--r--orc/orctype.c45
8 files changed, 232 insertions, 184 deletions
diff --git a/configure.ac b/configure.ac
index 11312ce..7272749 100644
--- a/configure.ac
+++ b/configure.ac
@@ -249,6 +249,12 @@ AC_SUBST(LIBOIL_CFLAGS)
LIBOIL_LIBS="\$(top_builddir)/liboil/liboil-$LIBOIL_MAJORMINOR.la $LIBM $LIBRT"
AC_SUBST(LIBOIL_LIBS)
+ORC_CFLAGS="$LIBOIL_CFLAGS"
+AC_SUBST(ORC_CFLAGS)
+
+ORC_LIBS="\$(top_builddir)/orc/liborc-$LIBOIL_MAJORMINOR.la $LIBOIL_LIBS"
+AC_SUBST(ORC_LIBS)
+
pkgconfigdir="\$(libdir)/pkgconfig"
AC_SUBST(pkgconfigdir)
diff --git a/examples/orc/Makefile.am b/examples/orc/Makefile.am
index e69de29..7d3bfc0 100644
--- a/examples/orc/Makefile.am
+++ b/examples/orc/Makefile.am
@@ -0,0 +1,8 @@
+
+noinst_PROGRAMS = jit
+
+AM_LDFLAGS = $(ORC_LIBS) $(GLIB_LIBS)
+AM_CFLAGS = $(ORC_CFLAGS) $(GLIB_CFLAGS)
+
+jit_SOURCES = jit.c
+
diff --git a/orc/jit.c b/examples/orc/jit.c
index 900f05a..6d3a9de 100644
--- a/orc/jit.c
+++ b/examples/orc/jit.c
@@ -6,7 +6,7 @@
#include <string.h>
#include <stdlib.h>
-#include "ojprogram.h"
+#include <orc/ojprogram.h>
#define N 10
diff --git a/orc/Makefile.am b/orc/Makefile.am
index c2b9972..4fbc528 100644
--- a/orc/Makefile.am
+++ b/orc/Makefile.am
@@ -1,12 +1,15 @@
+includedir = $(includedir)/orc-@LIBOIL_MAJORMINOR@/orc
-noinst_PROGRAMS = jit
+lib_LTLIBRARIES = liborc-@LIBOIL_MAJORMINOR@.la
+liborc_@LIBOIL_MAJORMINOR@_la_LIBS = $(LIBOIL_LIBS) $(GLIB_LIBS)
+liborc_@LIBOIL_MAJORMINOR@_la_CFLAGS = $(LIBOIL_CFLAGS) $(GLIB_CFLAGS)
-AM_LDFLAGS = $(LIBOIL_LIBS) $(GLIB_LIBS)
-AM_CFLAGS = $(LIBOIL_CFLAGS) $(GLIB_CFLAGS)
-
-jit_SOURCES = jit.c \
+liborc_@LIBOIL_MAJORMINOR@_la_SOURCES = \
+ orcexecutor.c \
+ orcrule.c \
+ orctype.c \
ojprogram.c \
ojprogram-x86.c \
ojprogram.h \
diff --git a/orc/ojprogram.c b/orc/ojprogram.c
index 688d44a..ea9a5ef 100644
--- a/orc/ojprogram.c
+++ b/orc/ojprogram.c
@@ -111,184 +111,6 @@ oj_program_append (OJProgram *program, const char *name, int arg0,
}
-
-OJType *types;
-static int n_types;
-static int n_alloc_types;
-
-OJType *
-oj_type_get (const char *name)
-{
- int i;
- for(i=0;i<n_types;i++){
- if (!strcmp (types[i].name, name)) {
- return types + i;
- }
- }
- return NULL;
-}
-
-void
-oj_type_register (const char *name, int size)
-{
- OJType *type;
-
- if (n_types == n_alloc_types) {
- n_alloc_types += 100;
- types = realloc (types, sizeof(OJType) * n_alloc_types);
- }
-
- type = types + n_types;
- type->name = strdup (name);
- type->size = size;
-
- n_types++;
-}
-
-
-
-OJExecutor *
-oj_executor_new (OJProgram *program)
-{
- OJExecutor *ex;
-
- ex = g_malloc0(sizeof(OJExecutor));
-
- ex->program = program;
-
- memcpy (ex->vars, program->vars, 10*sizeof(OJVariable));
-
- return ex;
-}
-
-void
-oj_executor_free (OJExecutor *ex)
-{
- g_free (ex);
-}
-
-void
-oj_executor_run (OJExecutor *ex)
-{
-
-
-}
-
-void
-oj_executor_set_array (OJExecutor *ex, int var, void *ptr)
-{
- ex->arrays[var] = ptr;
-}
-
-void
-oj_executor_set_n (OJExecutor *ex, int n)
-{
- ex->n = n;
-}
-
-void
-oj_executor_emulate (OJExecutor *ex)
-{
- int i;
- int j;
- int k;
- OJProgram *program = ex->program;
- OJInstruction *insn;
- OJOpcode *opcode;
-
- printf("n %d\n", ex->n);
- printf("n_insns %d\n", program->n_insns);
-
- for(i=0;i<ex->n;i++){
- for(j=0;j<program->n_insns;j++){
- insn = program->insns + j;
- opcode = insn->opcode;
-
- printf("%d: %s\n", j, insn->opcode->name);
-
- /* set up args */
- for(k=0;k<opcode->n_src + opcode->n_dest;k++){
- ex->args[k] = ex->vars + insn->args[k];
-
- printf("setting up arg %d as var %d vartype %d\n",
- k, insn->args[k], ex->args[k]->vartype);
-
- if (ex->args[k]->vartype == OJ_VAR_TYPE_SRC) {
- void *ptr = ex->arrays[insn->args[k]] + 2*i;
-
- printf("load %p\n", ptr);
- ex->args[k]->s16 = *(int16_t *)ptr;
- }
- }
-
- opcode->emulate (ex, opcode->emulate_user);
- printf("emulate: %d %d %d\n", ex->args[0]->s16,
- ex->args[1]->s16, ex->args[2]->s16);
-
- for(k=0;k<opcode->n_src + opcode->n_dest;k++){
- if (ex->args[k]->vartype == OJ_VAR_TYPE_DEST) {
- void *ptr = ex->arrays[insn->args[k]] + 2*i;
-
- printf("store %p\n", ptr);
- *(int16_t *)ptr = ex->args[k]->s16;
- }
- }
- }
- }
-}
-
-/* rule list */
-
-OJRuleList *
-oj_rule_list_new (void)
-{
- OJRuleList *rule_list;
-
- rule_list = malloc (sizeof(OJRuleList));
- memset (rule_list, 0, sizeof(OJRuleList));
-
- return rule_list;
-}
-
-void
-oj_rule_list_free (OJRuleList *rule_list)
-{
- free (rule_list->rules);
- free (rule_list);
-}
-
-void
-oj_rule_list_register (OJRuleList *rule_list, const char *opcode_name,
- OJRuleEmitFunc emit, void *emit_user, unsigned int flags)
-{
- int i;
-
- if (rule_list->n_rules == rule_list->n_alloc) {
- rule_list->n_alloc += 100;
- rule_list->rules = realloc (rule_list, sizeof(OJRule) * rule_list->n_alloc);
- }
-
- i = rule_list->n_rules;
- rule_list->rules[i].opcode = oj_opcode_find_by_name (opcode_name);
- rule_list->rules[i].emit = emit;
- rule_list->rules[i].emit_user = emit_user;
- rule_list->rules[i].flags = flags;
-
- rule_list->n_rules++;
-}
-
-OJRule *
-oj_rule_list_get (OJRuleList *rule_list, OJOpcode *opcode)
-{
- int i;
- for (i=0;i<rule_list->n_rules;i++){
- if (rule_list->rules[i].opcode == opcode) {
- return rule_list->rules + i;
- }
- }
- return NULL;
-}
-
void
oj_program_rewrite_vars (OJProgram *program)
{
diff --git a/orc/orcexecutor.c b/orc/orcexecutor.c
new file mode 100644
index 0000000..bd8874d
--- /dev/null
+++ b/orc/orcexecutor.c
@@ -0,0 +1,102 @@
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "ojprogram.h"
+
+
+OJExecutor *
+oj_executor_new (OJProgram *program)
+{
+ OJExecutor *ex;
+
+ ex = g_malloc0(sizeof(OJExecutor));
+
+ ex->program = program;
+
+ memcpy (ex->vars, program->vars, 10*sizeof(OJVariable));
+
+ return ex;
+}
+
+void
+oj_executor_free (OJExecutor *ex)
+{
+ g_free (ex);
+}
+
+void
+oj_executor_run (OJExecutor *ex)
+{
+
+
+}
+
+void
+oj_executor_set_array (OJExecutor *ex, int var, void *ptr)
+{
+ ex->arrays[var] = ptr;
+}
+
+void
+oj_executor_set_n (OJExecutor *ex, int n)
+{
+ ex->n = n;
+}
+
+void
+oj_executor_emulate (OJExecutor *ex)
+{
+ int i;
+ int j;
+ int k;
+ OJProgram *program = ex->program;
+ OJInstruction *insn;
+ OJOpcode *opcode;
+
+ printf("n %d\n", ex->n);
+ printf("n_insns %d\n", program->n_insns);
+
+ for(i=0;i<ex->n;i++){
+ for(j=0;j<program->n_insns;j++){
+ insn = program->insns + j;
+ opcode = insn->opcode;
+
+ printf("%d: %s\n", j, insn->opcode->name);
+
+ /* set up args */
+ for(k=0;k<opcode->n_src + opcode->n_dest;k++){
+ ex->args[k] = ex->vars + insn->args[k];
+
+ printf("setting up arg %d as var %d vartype %d\n",
+ k, insn->args[k], ex->args[k]->vartype);
+
+ if (ex->args[k]->vartype == OJ_VAR_TYPE_SRC) {
+ void *ptr = ex->arrays[insn->args[k]] + 2*i;
+
+ printf("load %p\n", ptr);
+ ex->args[k]->s16 = *(int16_t *)ptr;
+ }
+ }
+
+ opcode->emulate (ex, opcode->emulate_user);
+ printf("emulate: %d %d %d\n", ex->args[0]->s16,
+ ex->args[1]->s16, ex->args[2]->s16);
+
+ for(k=0;k<opcode->n_src + opcode->n_dest;k++){
+ if (ex->args[k]->vartype == OJ_VAR_TYPE_DEST) {
+ void *ptr = ex->arrays[insn->args[k]] + 2*i;
+
+ printf("store %p\n", ptr);
+ *(int16_t *)ptr = ex->args[k]->s16;
+ }
+ }
+ }
+ }
+}
+
+
diff --git a/orc/orcrule.c b/orc/orcrule.c
new file mode 100644
index 0000000..6ee5229
--- /dev/null
+++ b/orc/orcrule.c
@@ -0,0 +1,62 @@
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "ojprogram.h"
+
+
+OJRuleList *
+oj_rule_list_new (void)
+{
+ OJRuleList *rule_list;
+
+ rule_list = malloc (sizeof(OJRuleList));
+ memset (rule_list, 0, sizeof(OJRuleList));
+
+ return rule_list;
+}
+
+void
+oj_rule_list_free (OJRuleList *rule_list)
+{
+ free (rule_list->rules);
+ free (rule_list);
+}
+
+void
+oj_rule_list_register (OJRuleList *rule_list, const char *opcode_name,
+ OJRuleEmitFunc emit, void *emit_user, unsigned int flags)
+{
+ int i;
+
+ if (rule_list->n_rules == rule_list->n_alloc) {
+ rule_list->n_alloc += 100;
+ rule_list->rules = realloc (rule_list, sizeof(OJRule) * rule_list->n_alloc);
+ }
+
+ i = rule_list->n_rules;
+ rule_list->rules[i].opcode = oj_opcode_find_by_name (opcode_name);
+ rule_list->rules[i].emit = emit;
+ rule_list->rules[i].emit_user = emit_user;
+ rule_list->rules[i].flags = flags;
+
+ rule_list->n_rules++;
+}
+
+OJRule *
+oj_rule_list_get (OJRuleList *rule_list, OJOpcode *opcode)
+{
+ int i;
+ for (i=0;i<rule_list->n_rules;i++){
+ if (rule_list->rules[i].opcode == opcode) {
+ return rule_list->rules + i;
+ }
+ }
+ return NULL;
+}
+
+
diff --git a/orc/orctype.c b/orc/orctype.c
new file mode 100644
index 0000000..4ec497e
--- /dev/null
+++ b/orc/orctype.c
@@ -0,0 +1,45 @@
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "ojprogram.h"
+
+OJType *types;
+static int n_types;
+static int n_alloc_types;
+
+OJType *
+oj_type_get (const char *name)
+{
+ int i;
+ for(i=0;i<n_types;i++){
+ if (!strcmp (types[i].name, name)) {
+ return types + i;
+ }
+ }
+ return NULL;
+}
+
+void
+oj_type_register (const char *name, int size)
+{
+ OJType *type;
+
+ if (n_types == n_alloc_types) {
+ n_alloc_types += 100;
+ types = realloc (types, sizeof(OJType) * n_alloc_types);
+ }
+
+ type = types + n_types;
+ type->name = strdup (name);
+ type->size = size;
+
+ n_types++;
+}
+
+
+