Commit 90e0112f authored by David Schleef's avatar David Schleef

Split OrcProgram into Program and Compiler

parent 1688c5f7
......@@ -604,6 +604,8 @@ test9(void)
}
}
printf("%s", orc_program_get_asm_code (p));
orc_executor_free (ex);
orc_program_free (p);
}
......
......@@ -40,63 +40,63 @@ arm_reg_name (int reg)
}
void
arm_emit (OrcProgram *program, uint32_t insn)
arm_emit (OrcCompiler *compiler, uint32_t insn)
{
ORC_WRITE_UINT32_LE (program->codeptr, insn);
program->codeptr+=4;
ORC_WRITE_UINT32_LE (compiler->codeptr, insn);
compiler->codeptr+=4;
}
void
arm_emit_bx_lr (OrcProgram *program)
arm_emit_bx_lr (OrcCompiler *compiler)
{
ORC_ASM_CODE(program," bx lr\n");
arm_emit (program, 0xe12fff1e);
ORC_ASM_CODE(compiler," bx lr\n");
arm_emit (compiler, 0xe12fff1e);
}
void
arm_emit_push (OrcProgram *program, int regs)
arm_emit_push (OrcCompiler *compiler, int regs)
{
int i;
int x = 0;
ORC_ASM_CODE(program," push {");
ORC_ASM_CODE(compiler," push {");
for(i=0;i<16;i++){
if (regs & (1<<i)) {
x |= (1<<i);
ORC_ASM_CODE(program,"r%d", i);
ORC_ASM_CODE(compiler,"r%d", i);
if (x != regs) {
ORC_ASM_CODE(program,", ");
ORC_ASM_CODE(compiler,", ");
}
}
}
ORC_ASM_CODE(program,"}\n");
ORC_ASM_CODE(compiler,"}\n");
arm_emit (program, 0xe92d0000 | regs);
arm_emit (compiler, 0xe92d0000 | regs);
}
void
arm_emit_pop (OrcProgram *program, int regs)
arm_emit_pop (OrcCompiler *compiler, int regs)
{
int i;
int x = 0;
ORC_ASM_CODE(program," pop {");
ORC_ASM_CODE(compiler," pop {");
for(i=0;i<16;i++){
if (regs & (1<<i)) {
x |= (1<<i);
ORC_ASM_CODE(program,"r%d", i);
ORC_ASM_CODE(compiler,"r%d", i);
if (x != regs) {
ORC_ASM_CODE(program,", ");
ORC_ASM_CODE(compiler,", ");
}
}
}
ORC_ASM_CODE(program,"}\n");
ORC_ASM_CODE(compiler,"}\n");
arm_emit (program, 0xe8bd0000 | regs);
arm_emit (compiler, 0xe8bd0000 | regs);
}
void
arm_emit_mov (OrcProgram *program, int dest, int src)
arm_emit_mov (OrcCompiler *compiler, int dest, int src)
{
uint32_t code;
......@@ -104,35 +104,35 @@ arm_emit_mov (OrcProgram *program, int dest, int src)
code |= (src&0xf) << 0;
code |= (dest&0xf) << 12;
ORC_ASM_CODE(program," mov %s, %s\n", arm_reg_name (dest), arm_reg_name (src));
ORC_ASM_CODE(compiler," mov %s, %s\n", arm_reg_name (dest), arm_reg_name (src));
arm_emit (program, code);
arm_emit (compiler, code);
}
void
arm_emit_label (OrcProgram *program, int label)
arm_emit_label (OrcCompiler *compiler, int label)
{
ORC_ASM_CODE(program,".L%d:\n", label);
ORC_ASM_CODE(compiler,".L%d:\n", label);
program->labels[label] = program->codeptr;
compiler->labels[label] = compiler->codeptr;
}
void
arm_add_fixup (OrcProgram *program, int label, int type)
arm_add_fixup (OrcCompiler *compiler, int label, int type)
{
program->fixups[program->n_fixups].ptr = program->codeptr;
program->fixups[program->n_fixups].label = label;
program->fixups[program->n_fixups].type = type;
program->n_fixups++;
compiler->fixups[compiler->n_fixups].ptr = compiler->codeptr;
compiler->fixups[compiler->n_fixups].label = label;
compiler->fixups[compiler->n_fixups].type = type;
compiler->n_fixups++;
}
void
arm_do_fixups (OrcProgram *program)
arm_do_fixups (OrcCompiler *compiler)
{
int i;
for(i=0;i<program->n_fixups;i++){
unsigned char *label = program->labels[program->fixups[i].label];
unsigned char *ptr = program->fixups[i].ptr;
for(i=0;i<compiler->n_fixups;i++){
unsigned char *label = compiler->labels[compiler->fixups[i].label];
unsigned char *ptr = compiler->fixups[i].ptr;
uint32_t code;
int diff;
......@@ -144,7 +144,7 @@ arm_do_fixups (OrcProgram *program)
}
void
arm_emit_branch (OrcProgram *program, int cond, int label)
arm_emit_branch (OrcCompiler *compiler, int cond, int label)
{
static const char *cond_names[] = {
"eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
......@@ -153,14 +153,14 @@ arm_emit_branch (OrcProgram *program, int cond, int label)
code = 0x0afffffe;
code |= (cond&0xf) << 28;
arm_add_fixup (program, label, 0);
arm_emit (program, code);
arm_add_fixup (compiler, label, 0);
arm_emit (compiler, code);
ORC_ASM_CODE(program," b%s .L%d\n", cond_names[cond], label);
ORC_ASM_CODE(compiler," b%s .L%d\n", cond_names[cond], label);
}
void
arm_emit_loadimm (OrcProgram *program, int dest, int imm)
arm_emit_loadimm (OrcCompiler *compiler, int dest, int imm)
{
uint32_t code;
int shift2;
......@@ -176,12 +176,12 @@ arm_emit_loadimm (OrcProgram *program, int dest, int imm)
code |= (((16-shift2)&0xf) << 8);
code |= (imm&0xff);
ORC_ASM_CODE(program," mov %s, #0x%08x\n", arm_reg_name (dest), imm << (shift2*2));
arm_emit (program, code);
ORC_ASM_CODE(compiler," mov %s, #0x%08x\n", arm_reg_name (dest), imm << (shift2*2));
arm_emit (compiler, code);
}
void
arm_emit_add (OrcProgram *program, int dest, int src1, int src2)
arm_emit_add (OrcCompiler *compiler, int dest, int src1, int src2)
{
uint32_t code;
......@@ -190,15 +190,15 @@ arm_emit_add (OrcProgram *program, int dest, int src1, int src2)
code |= (dest&0xf) << 12;
code |= (src2&0xf) << 0;
ORC_ASM_CODE(program," add %s, %s, %s\n",
ORC_ASM_CODE(compiler," add %s, %s, %s\n",
arm_reg_name (dest),
arm_reg_name (src1),
arm_reg_name (src2));
arm_emit (program, code);
arm_emit (compiler, code);
}
void
arm_emit_sub (OrcProgram *program, int dest, int src1, int src2)
arm_emit_sub (OrcCompiler *compiler, int dest, int src1, int src2)
{
uint32_t code;
......@@ -207,15 +207,15 @@ arm_emit_sub (OrcProgram *program, int dest, int src1, int src2)
code |= (dest&0xf) << 12;
code |= (src2&0xf) << 0;
ORC_ASM_CODE(program," sub %s, %s, %s\n",
ORC_ASM_CODE(compiler," sub %s, %s, %s\n",
arm_reg_name (dest),
arm_reg_name (src1),
arm_reg_name (src2));
arm_emit (program, code);
arm_emit (compiler, code);
}
void
arm_emit_sub_imm (OrcProgram *program, int dest, int src1, int value)
arm_emit_sub_imm (OrcCompiler *compiler, int dest, int src1, int value)
{
uint32_t code;
......@@ -224,15 +224,15 @@ arm_emit_sub_imm (OrcProgram *program, int dest, int src1, int value)
code |= (dest&0xf) << 12;
code |= (value) << 0;
ORC_ASM_CODE(program," subs %s, %s, #%d\n",
ORC_ASM_CODE(compiler," subs %s, %s, #%d\n",
arm_reg_name (dest),
arm_reg_name (src1),
value);
arm_emit (program, code);
arm_emit (compiler, code);
}
void
arm_emit_cmp_imm (OrcProgram *program, int src1, int value)
arm_emit_cmp_imm (OrcCompiler *compiler, int src1, int value)
{
uint32_t code;
......@@ -240,14 +240,14 @@ arm_emit_cmp_imm (OrcProgram *program, int src1, int value)
code |= (src1&0xf) << 16;
code |= (value) << 0;
ORC_ASM_CODE(program," cmp %s, #%d\n",
ORC_ASM_CODE(compiler," cmp %s, #%d\n",
arm_reg_name (src1),
value);
arm_emit (program, code);
arm_emit (compiler, code);
}
void
arm_emit_load_reg (OrcProgram *program, int dest, int src1, int offset)
arm_emit_load_reg (OrcCompiler *compiler, int dest, int src1, int offset)
{
uint32_t code;
......@@ -256,16 +256,16 @@ arm_emit_load_reg (OrcProgram *program, int dest, int src1, int offset)
code |= (dest&0xf) << 12;
code |= offset&0xfff;
ORC_ASM_CODE(program," ldr %s, [%s, #%d]\n",
ORC_ASM_CODE(compiler," ldr %s, [%s, #%d]\n",
arm_reg_name (dest),
arm_reg_name (src1), offset);
arm_emit (program, code);
arm_emit (compiler, code);
}
void
arm_emit_dp_reg (OrcProgram *program, int cond, int opcode, int dest,
arm_emit_dp_reg (OrcCompiler *compiler, int cond, int opcode, int dest,
int src1, int src2)
{
static const char *dp_insn_names[] = {
......@@ -290,19 +290,19 @@ arm_emit_dp_reg (OrcProgram *program, int cond, int opcode, int dest,
code |= (src2&0xf) << 0;
if (shift_expn[opcode]) {
ORC_ASM_CODE(program," %s%s %s, %s\n",
ORC_ASM_CODE(compiler," %s%s %s, %s\n",
dp_insn_names[opcode],
update ? "s" : "",
arm_reg_name (src1),
arm_reg_name (src2));
} else {
ORC_ASM_CODE(program," %s%s %s, %s, %s\n",
ORC_ASM_CODE(compiler," %s%s %s, %s, %s\n",
dp_insn_names[opcode],
update ? "s" : "",
arm_reg_name (dest),
arm_reg_name (src1),
arm_reg_name (src2));
}
arm_emit (program, code);
arm_emit (compiler, code);
}
......@@ -60,31 +60,31 @@ enum {
ARM_COND_AL,
};
void arm_emit (OrcProgram *program, uint32_t insn);
void arm_emit_bx_lr (OrcProgram *program);
void arm_emit (OrcCompiler *compiler, uint32_t insn);
void arm_emit_bx_lr (OrcCompiler *compiler);
const char * arm_reg_name (int reg);
void arm_emit_loadimm (OrcProgram *program, int dest, int imm);
void arm_emit_loadimm (OrcCompiler *compiler, int dest, int imm);
void arm_emit_add (OrcProgram *program, int dest, int src1, int src2);
void arm_emit_sub (OrcProgram *program, int dest, int src1, int src2);
void arm_emit_sub_imm (OrcProgram *program, int dest, int src1, int value);
void arm_emit_cmp_imm (OrcProgram *program, int src1, int value);
void arm_emit_add (OrcCompiler *compiler, int dest, int src1, int src2);
void arm_emit_sub (OrcCompiler *compiler, int dest, int src1, int src2);
void arm_emit_sub_imm (OrcCompiler *compiler, int dest, int src1, int value);
void arm_emit_cmp_imm (OrcCompiler *compiler, int src1, int value);
void arm_emit_label (OrcProgram *program, int label);
void arm_emit_push (OrcProgram *program, int regs);
void arm_emit_pop (OrcProgram *program, int regs);
void arm_emit_mov (OrcProgram *program, int dest, int src);
void arm_emit_branch (OrcProgram *program, int cond, int label);
void arm_emit_label (OrcCompiler *compiler, int label);
void arm_emit_push (OrcCompiler *compiler, int regs);
void arm_emit_pop (OrcCompiler *compiler, int regs);
void arm_emit_mov (OrcCompiler *compiler, int dest, int src);
void arm_emit_branch (OrcCompiler *compiler, int cond, int label);
void arm_emit_dp_reg (OrcProgram *program, int cond, int opcode, int dest,
void arm_emit_dp_reg (OrcCompiler *compiler, int cond, int opcode, int dest,
int src1, int src2);
void arm_loadw (OrcProgram *program, int dest, int src1, int offset);
void arm_storew (OrcProgram *program, int dest, int offset, int src1);
void arm_loadw (OrcCompiler *compiler, int dest, int src1, int offset);
void arm_storew (OrcCompiler *compiler, int dest, int offset, int src1);
void arm_emit_load_reg (OrcProgram *program, int dest, int src1, int offset);
void arm_emit_load_reg (OrcCompiler *compiler, int dest, int src1, int offset);
void arm_do_fixups (OrcProgram *program);
void arm_do_fixups (OrcCompiler *compiler);
#endif
......
UNARY_SB(absb, "ORC_ABS(%s)")
BINARY_SB(addb, "%s + %s")
BINARY_SB(addssb, "ORC_CLAMP_SB(%s + %s)")
BINARY_UB(addusb, "ORC_CLAMP_UB(%s + %s)")
BINARY_SB(andb, "%s & %s")
BINARY_SB(andnb, "%s & (~%s)")
BINARY_SB(avgsb, "(%s + %s + 1)>>1")
BINARY_UB(avgub, "(%s + %s + 1)>>1")
BINARY_SB(cmpeqb, "(%s == %s) ? (~0) : 0")
BINARY_SB(cmpgtsb, "(%s > %s) ? (~0) : 0")
UNARY_SB(copyb, "%s")
BINARY_SB(maxsb, "ORC_MAX(%s, %s)")
BINARY_UB(maxub, "ORC_MAX(%s, %s)")
BINARY_SB(minsb, "ORC_MIN(%s, %s)")
BINARY_UB(minub, "ORC_MIN(%s, %s)")
BINARY_SB(mullb, "(%s * %s) & 0xff")
BINARY_SB(mulhsb, "(%s * %s) >> 8")
BINARY_UB(mulhub, "(%s * %s) >> 8")
BINARY_SB(orb, "%s | %s")
BINARY_SB(shlb, "%s << %s")
BINARY_SB(shrsb, "%s >> %s")
BINARY_UB(shrub, "((uint8_t)%s) >> %s")
UNARY_SB(signb, "ORC_CLAMP(%s,-1,1)")
BINARY_SB(subb, "%s - %s")
BINARY_SB(subssb, "ORC_CLAMP_SB(%s - %s)")
BINARY_UB(subusb, "ORC_CLAMP_UB((uint8_t)%s - (uint8_t)%s)")
BINARY_SB(xorb, "%s ^ %s")
UNARY_SW(absw, "ORC_ABS(%s)")
BINARY_SW(addw, "%s + %s")
BINARY_SW(addssw, "ORC_CLAMP_SW(%s + %s)")
BINARY_UW(addusw, "ORC_CLAMP_UW(%s + %s)")
BINARY_SW(andw, "%s & %s")
BINARY_SW(andnw, "%s & (~%s)")
BINARY_SW(avgsw, "(%s + %s + 1)>>1")
BINARY_UW(avguw, "(%s + %s + 1)>>1")
BINARY_SW(cmpeqw, "(%s == %s) ? (~0) : 0")
BINARY_SW(cmpgtsw, "(%s > %s) ? (~0) : 0")
UNARY_SW(copyw, "%s")
BINARY_SW(maxsw, "ORC_MAX(%s, %s)")
BINARY_UW(maxuw, "ORC_MAX(%s, %s)")
BINARY_SW(minsw, "ORC_MIN(%s, %s)")
BINARY_UW(minuw, "ORC_MIN(%s, %s)")
BINARY_SW(mullw, "(%s * %s) & 0xffff")
BINARY_SW(mulhsw, "(%s * %s) >> 16")
BINARY_UW(mulhuw, "(%s * %s) >> 16")
BINARY_SW(orw, "%s | %s")
BINARY_SW(shlw, "%s << %s")
BINARY_SW(shrsw, "%s >> %s")
BINARY_UW(shruw, "%s >> %s")
UNARY_SW(signw, "ORC_CLAMP(%s,-1,1)")
BINARY_SW(subw, "%s - %s")
BINARY_SW(subssw, "ORC_CLAMP_SW(%s - %s)")
BINARY_UW(subusw, "ORC_CLAMP_UW(%s - %s)")
BINARY_SW(xorw, "%s ^ %s")
UNARY_SL(absl, "ORC_ABS(%s)")
BINARY_SL(addl, "%s + %s")
BINARY_SL(addssl, "ORC_CLAMP_SL((int64_t)%s + (int64_t)%s)")
BINARY_UL(addusl, "ORC_CLAMP_UL((uint64_t)%s + (uint64_t)%s)")
BINARY_SL(andl, "%s & %s")
BINARY_SL(andnl, "%s & (~%s)")
BINARY_SL(avgsl, "(%s + %s + 1)>>1")
BINARY_UL(avgul, "(%s + %s + 1)>>1")
BINARY_SL(cmpeql, "(%s == %s) ? (~0) : 0")
BINARY_SL(cmpgtsl, "(%s > %s) ? (~0) : 0")
UNARY_SL(copyl, "%s")
BINARY_SL(maxsl, "ORC_MAX(%s, %s)")
BINARY_UL(maxul, "ORC_MAX(%s, %s)")
BINARY_SL(minsl, "ORC_MIN(%s, %s)")
BINARY_UL(minul, "ORC_MIN(%s, %s)")
BINARY_SL(mulll, "(%s * %s) & 0xffffffff")
BINARY_SL(mulhsl, "((int64_t)%s * (int64_t)%s) >> 32")
BINARY_UL(mulhul, "((uint64_t)%s * (uint64_t)%s) >> 32")
BINARY_SL(orl, "%s | %s")
BINARY_SL(shll, "%s << %s")
BINARY_SL(shrsl, "%s >> %s")
BINARY_UL(shrul, "%s >> %s")
UNARY_SL(signl, "ORC_CLAMP(%s,-1,1)")
BINARY_SL(subl, "%s - %s")
BINARY_SL(subssl, "ORC_CLAMP_SL((int64_t)%s - (int64_t)%s)")
BINARY_UL(subusl, "ORC_CLAMP_UL((uint64_t)%s - (uint64_t)%s)")
BINARY_SL(xorl, "%s ^ %s")
BINARY_BW(convsbw, "%s")
BINARY_BW(convubw, "(uint8_t)%s")
BINARY_WL(convswl, "%s")
BINARY_WL(convuwl, "(uint16_t)%s")
BINARY_WB(convwb, "%s")
BINARY_WB(convssswb, "ORC_CLAMP_SB(%s)")
BINARY_WB(convsuswb, "ORC_CLAMP_UB(%s)")
BINARY_WB(convusswb, "ORC_CLAMP_SB(%s)")
BINARY_WB(convuuswb, "ORC_CLAMP_UB(%s)")
BINARY_LW(convlw, "%s")
BINARY_LW(convssslw, "ORC_CLAMP_SW(%s)")
BINARY_LW(convsuslw, "ORC_CLAMP_UW(%s)")
BINARY_LW(convusslw, "ORC_CLAMP_SW(%s)")
BINARY_LW(convuuslw, "ORC_CLAMP_UW(%s)")
BINARY_BW(mulsbw, "%s * %s")
BINARY_BW(mulubw, "%s * %s")
BINARY_WL(mulswl, "%s * %s")
BINARY_WL(muluwl, "%s * %s")
......@@ -17,7 +17,7 @@
#ifdef HAVE_CODEMEM_MMAP
void
orc_program_allocate_codemem (OrcProgram *program)
orc_compiler_allocate_codemem (OrcCompiler *compiler)
{
char filename[32] = "/tmp/orcexecXXXXXX";
int fd;
......@@ -27,45 +27,41 @@ orc_program_allocate_codemem (OrcProgram *program)
if (fd == -1) {
/* FIXME oh crap */
ORC_ERROR ("failed to create temp file");
program->error = TRUE;
compiler->error = TRUE;
return;
}
unlink (filename);
n = ftruncate (fd, SIZE);
program->code = mmap (NULL, SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (program->code == MAP_FAILED) {
/* FIXME oh crap */
ORC_ERROR ("failed to create write map");
program->error = TRUE;
compiler->program->code = mmap (NULL, SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (compiler->program->code == MAP_FAILED) {
ORC_PROGRAM_ERROR(compiler, "failed to create write map");
return;
}
program->code_exec = mmap (NULL, SIZE, PROT_READ|PROT_EXEC, MAP_SHARED, fd, 0);
if (program->code_exec == MAP_FAILED) {
/* FIXME oh crap */
ORC_ERROR ("failed to create exec map");
program->error = TRUE;
compiler->program->code_exec = mmap (NULL, SIZE, PROT_READ|PROT_EXEC, MAP_SHARED, fd, 0);
if (compiler->program->code_exec == MAP_FAILED) {
ORC_PROGRAM_ERROR(compiler, "failed to create exec map");
return;
}
close (fd);
program->code_size = SIZE;
program->codeptr = program->code;
compiler->program->code_size = SIZE;
compiler->codeptr = compiler->program->code;
}
#endif
#ifdef HAVE_CODEMEM_MALLOC
void
orc_program_allocate_codemem (OrcProgram *program)
orc_compiler_allocate_codemem (OrcCompiler *compiler)
{
/* Now you know why Windows has viruses */
program->code = malloc(SIZE);
program->code_exec = program->code;
program->code_size = SIZE;
program->codeptr = program->code;
compiler->program->code = malloc(SIZE);
compiler->program->code_exec = compiler->code;
compiler->program->code_size = SIZE;
compiler->codeptr = compiler->program->code;
}
#endif
This diff is collapsed.
This diff is collapsed.
......@@ -13,14 +13,14 @@ static const char *c_get_type_name (int size);
void orc_c_init (void);
void
orc_program_c_init (OrcProgram *program)
orc_compiler_c_init (OrcCompiler *compiler)
{
int i;
for(i=ORC_GP_REG_BASE;i<ORC_GP_REG_BASE+16;i++){
program->valid_regs[i] = 1;
compiler->valid_regs[i] = 1;
}
program->loop_shift = 0;
compiler->loop_shift = 0;
}
const char *
......@@ -71,7 +71,7 @@ orc_target_get_asm_preamble (int target)
}
void
orc_program_assemble_c (OrcProgram *program)
orc_compiler_assemble_c (OrcCompiler *compiler)
{
int i;
int j;
......@@ -79,28 +79,28 @@ orc_program_assemble_c (OrcProgram *program)
OrcOpcode *opcode;
OrcRule *rule;
ORC_ASM_CODE(program,"void\n");
ORC_ASM_CODE(program,"%s (OrcExecutor *ex)\n", program->name);
ORC_ASM_CODE(program,"{\n");
ORC_ASM_CODE(program," int i;\n");
ORC_ASM_CODE(compiler,"void\n");
ORC_ASM_CODE(compiler,"%s (OrcExecutor *ex)\n", compiler->program->name);
ORC_ASM_CODE(compiler,"{\n");
ORC_ASM_CODE(compiler," int i;\n");
for(i=0;i<program->n_vars;i++){
OrcVariable *var = program->vars + i;
for(i=0;i<compiler->n_vars;i++){
OrcVariable *var = compiler->vars + i;
switch (var->vartype) {
case ORC_VAR_TYPE_CONST:
ORC_ASM_CODE(program," %s var%d = %d;\n",
ORC_ASM_CODE(compiler," %s var%d = %d;\n",
c_get_type_name(var->size), i, var->value);
break;
case ORC_VAR_TYPE_TEMP:
ORC_ASM_CODE(program," %s var%d;\n", c_get_type_name(var->size), i);
ORC_ASM_CODE(compiler," %s var%d;\n", c_get_type_name(var->size), i);
break;
case ORC_VAR_TYPE_SRC:
case ORC_VAR_TYPE_DEST:
ORC_ASM_CODE(program," %s *var%d = ex->arrays[%d];\n",
ORC_ASM_CODE(compiler," %s *var%d = ex->arrays[%d];\n",
c_get_type_name (var->size), i, i);
break;
case ORC_VAR_TYPE_PARAM:
ORC_ASM_CODE(program," %s var%d = ex->arrays[%d];\n",
ORC_ASM_CODE(compiler," %s var%d = ex->arrays[%d];\n",
c_get_type_name (var->size), i, i);
break;
default:
......@@ -109,34 +109,34 @@ orc_program_assemble_c (OrcProgram *program)
}
ORC_ASM_CODE(program,"\n");
ORC_ASM_CODE(program," for (i = 0; i < ex->n; i++) {\n");
ORC_ASM_CODE(compiler,"\n");
ORC_ASM_CODE(compiler," for (i = 0; i < ex->n; i++) {\n");
for(j=0;j<program->n_insns;j++){
insn = program->insns + j;
for(j=0;j<compiler->n_insns;j++){
insn = compiler->insns + j;
opcode = insn->opcode;
ORC_ASM_CODE(program," /* %d: %s */\n", j, insn->opcode->name);
ORC_ASM_CODE(compiler," /* %d: %s */\n", j, insn->opcode->name);
rule = insn->rule;
if (rule) {
rule->emit (program, rule->emit_user, insn);
rule->emit (compiler, rule->emit_user, insn);
} else {
ORC_PROGRAM_ERROR(program,"No rule for: %s\n", opcode->name);
program->error = TRUE;
ORC_PROGRAM_ERROR(compiler,"No rule for: %s\n", opcode->name);
compiler->error = TRUE;
}
}
ORC_ASM_CODE(program," }\n");
ORC_ASM_CODE(program,"}\n");
ORC_ASM_CODE(program,"\n");
ORC_ASM_CODE(compiler," }\n");
ORC_ASM_CODE(compiler,"}\n");
ORC_ASM_CODE(compiler,"\n");
}
/* rules */
static void
c_get_name (char *name, OrcProgram *p, int var)
c_get_name (char *name, OrcCompiler *p, int var)
{
switch (p->vars[var].vartype) {
case ORC_VAR_TYPE_CONST:
......@@ -172,7 +172,7 @@ c_get_type_name (int size)
#if 0
static void
c_rule_copyw (OrcProgram *p, void *user, OrcInstruction *insn)
c_rule_copyw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
char dest[20], src1[20];
......@@ -185,7 +185,7 @@ c_rule_copyw (OrcProgram *p, void *user, OrcInstruction *insn)
#define BINARY(name,op) \
static void \
c_rule_ ## name (OrcProgram *p, void *user, OrcInstruction *insn) \
c_rule_ ## name (OrcCompiler *p, void *user, OrcInstruction *insn) \
{ \
char dest[20], src1[20], src2[20]; \
\
......@@ -247,7 +247,7 @@ BINARY(shrsw, src1 >> src2)
#if 0
static void
c_rule_addw (OrcProgram *p, void *user, OrcInstruction *insn)
c_rule_addw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
char dest[20], src1[20], src2[20];
......@@ -259,7 +259,7 @@ c_rule_addw (OrcProgram *p, void *user, OrcInstruction *insn)
}
static void
c_rule_subw (OrcProgram *p, void *user, OrcInstruction *insn)
c_rule_subw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
char dest[20], src1[20], src2[20];
......@@ -271,7 +271,7 @@ c_rule_subw (OrcProgram *p, void *user, OrcInstruction *insn)
}
static void
c_rule_mullw (OrcProgram *p, void *user, OrcInstruction *insn)
c_rule_mullw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
char dest[20], src1[20], src2[20];
......@@ -283,7 +283,7 @@ c_rule_mullw (OrcProgram *p, void *user, OrcInstruction *insn)
}
static void
c_rule_shlw (OrcProgram *p, void *user, OrcInstruction *insn)
c_rule_shlw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
char dest[20], src1[20], src2[20];
......@@ -295,7 +295,7 @@ c_rule_shlw (OrcProgram *p, void *user, OrcInstruction *insn)
}
static void
c_rule_shrsw (OrcProgram *p, void *user, OrcInstruction *insn)
c_rule_shrsw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
char dest[20], src1[20], src2[20];
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -211,17 +211,17 @@ orc_program_find_var_by_name (OrcProgram *program, const char *name)
}
int
orc_program_get_dest (OrcProgram *program)
orc_compiler_get_dest (OrcCompiler *compiler)
{
int k;
for(k=0;k<program->n_vars;k++){
if (program->vars[k].vartype == ORC_VAR_TYPE_DEST) {
for(k=0;k<compiler->n_vars;k++){
if (compiler->vars[k].vartype == ORC_VAR_TYPE_DEST) {
return k;
}
}
ORC_PROGRAM_ERROR(program, "failed to find destination array");
ORC_PROGRAM_ERROR(compiler, "failed to find destination array");
return -1;
}
......@@ -262,3 +262,9 @@ orc_program_append_ds_str (OrcProgram *program, const char *name,
program->n_insns++;