Add OrcCode structure
authorDavid Schleef <ds@schleef.org>
Thu, 5 Aug 2010 21:10:19 +0000 (14:10 -0700)
committerDavid Schleef <ds@schleef.org>
Thu, 5 Aug 2010 21:10:19 +0000 (14:10 -0700)
orc/Makefile.am
orc/orccode.c [new file with mode: 0644]
orc/orccompiler.c
orc/orcprogram.h

index 7b6f832..4ed83e8 100644 (file)
@@ -24,7 +24,8 @@ liborc_@ORC_MAJORMINOR@_la_SOURCES = \
        orcopcodes.c \
        orcparse.c \
        orconce.c \
-       orcdebug.c
+       orcdebug.c \
+       orccode.c
 
 if ENABLE_BACKEND_SSE
 liborc_@ORC_MAJORMINOR@_la_SOURCES += orcsse.c orcrules-sse.c orcprogram-sse.c
diff --git a/orc/orccode.c b/orc/orccode.c
new file mode 100644 (file)
index 0000000..2c644ed
--- /dev/null
@@ -0,0 +1,32 @@
+
+#include "config.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <orc/orcprogram.h>
+#include <orc/orcdebug.h>
+
+
+OrcCode *
+orc_code_new (void)
+{
+  OrcCode *code;
+  code = malloc(sizeof(OrcCode));
+  memset (code, 0, sizeof(OrcCode));
+  return code;
+}
+
+void
+orc_code_free (OrcCode *code)
+{
+  if (code->insns) {
+    free (code->insns);
+  }
+
+  free (code);
+}
+
+
+
index c5a6855..e11f6d2 100644 (file)
@@ -296,6 +296,23 @@ orc_program_compile_full (OrcProgram *program, OrcTarget *target,
   compiler->target->compile (compiler);
   if (compiler->error) goto error;
 
+  program->orccode = orc_code_new ();
+  program->orccode->exec = program->code_exec;
+  program->orccode->code = program->code;
+  program->orccode->code_size = compiler->codeptr - program->code;
+  program->orccode->is_2d = program->is_2d;
+  program->orccode->constant_n = program->constant_n;
+  program->orccode->constant_m = program->constant_m;
+
+  program->orccode->n_insns = compiler->n_insns;
+  program->orccode->insns = malloc(sizeof(OrcInstruction) * compiler->n_insns);
+  memcpy (program->orccode->insns, compiler->insns,
+      sizeof(OrcInstruction) * compiler->n_insns);
+
+  program->orccode->vars = malloc (sizeof(OrcVariable) * ORC_N_COMPILER_VARIABLES);
+  memcpy (program->orccode->vars, compiler->vars,
+      sizeof(OrcVariable) * ORC_N_COMPILER_VARIABLES);
+
   program->asm_code = compiler->asm_code;
   program->code_size = compiler->codeptr - program->code;
 
index 6a1a357..32577e9 100644 (file)
@@ -18,6 +18,7 @@ typedef struct _OrcRuleSet OrcRuleSet;
 typedef struct _OrcConstant OrcConstant;
 typedef struct _OrcFixup OrcFixup;
 typedef struct _OrcTarget OrcTarget;
+typedef struct _OrcCode OrcCode;
 
 typedef void (*OrcOpcodeEmulateFunc)(OrcOpcodeExecutor *ex, void *user);
 typedef void (*OrcOpcodeEmulateNFunc)(OrcOpcodeExecutor *ex, int n);
@@ -349,6 +350,8 @@ struct _OrcProgram {
   int is_2d;
   int constant_n;
   int constant_m;
+
+  OrcCode *orccode;
 };
 
 /**
@@ -489,6 +492,25 @@ struct _OrcExecutorAlt {
 #define ORC_EXECUTOR_M_INDEX(ex) ((ex)->params[ORC_VAR_A2])
 #define ORC_EXECUTOR_TIME(ex) ((ex)->params[ORC_VAR_A3])
 
+struct _OrcCode {
+  /*< private >*/
+  OrcCompileResult result;
+  char *name;
+
+  /* for execution */
+  OrcExecutorFunc exec;
+  unsigned char *code;
+  int code_size;
+
+  /* for emulation */
+  int n_insns;
+  OrcInstruction *insns;
+  OrcVariable *vars;
+  int is_2d;
+  int constant_n;
+  int constant_m;
+};
+
 /**
  * OrcTarget:
  *
@@ -621,6 +643,10 @@ int orc_program_get_max_accumulator_size (OrcProgram *program);
 
 void orc_get_data_cache_sizes (int *level1, int *level2, int *level3);
 
+OrcCode * orc_code_new (void);
+void orc_code_free (OrcCode *code);
+
+
 #ifdef ORC_ENABLE_UNSTABLE_API
 
 int orc_compiler_flag_check (const char *flag);