Line 1... |
Line 1... |
/* generate.c -- generates file execgen.c from instruction set
|
/* generate.c -- generates file execgen.c from instruction set
|
Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
|
Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
|
|
Copyright (C) 2005 György `nog' Jeney, nog@sdf.lonestar.org
|
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
|
|
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
Line 24... |
Line 25... |
#include <ctype.h>
|
#include <ctype.h>
|
|
|
#include "config.h"
|
#include "config.h"
|
#include "opcode/or32.h"
|
#include "opcode/or32.h"
|
#include "abstract.h"
|
#include "abstract.h"
|
#include "labels.h"
|
|
#include "parse.h"
|
|
#include "execute.h"
|
|
|
|
#define LEAF_FLAG (0x80000000)
|
|
#define SHIFT {int i; for (i = 0; i < level; i++) fprintf (fo, " ");}
|
|
|
|
extern unsigned long *automata;
|
|
extern struct temp_insn_struct {
|
|
unsigned long insn;
|
|
unsigned long insn_mask;
|
|
int in_pass;
|
|
} *ti;
|
|
|
|
static char *in_file;
|
static char *in_file;
|
unsigned long op[MAX_OPERANDS];
|
static char *out_file;
|
int num_op;
|
static unsigned long op[MAX_OPERANDS];
|
|
|
|
/* Whether this instruction stores something in register */
|
|
static int write_to_reg;
|
|
|
|
static int out_lines = 0;
|
|
|
inline void debug(int level, const char *format, ...)
|
void debug(int level, const char *format, ...)
|
{
|
{
|
#if DEBUG
|
#if DEBUG
|
char *p;
|
char *p;
|
va_list ap;
|
va_list ap;
|
|
|
Line 59... |
Line 52... |
fflush(stdout);
|
fflush(stdout);
|
free(p);
|
free(p);
|
#endif
|
#endif
|
}
|
}
|
|
|
/* Whether this instruction stores something in register */
|
static int shift_fprintf(int level, FILE *f, const char *fmt, ...)
|
static int write_to_reg = 0;
|
{
|
|
va_list ap;
|
|
int i;
|
|
|
static int olevel;
|
va_start(ap, fmt);
|
|
for(i = 0; i < level; i++)
|
|
fprintf(f, " ");
|
|
|
/* Following functions recursivelly searches for substrings eval_operand and
|
i = vfprintf(f, fmt, ap);
|
set_operand (see functions with the same name in execute.c) and replaces
|
va_end(ap);
|
them with optimized code. */
|
|
char *replace_operands (FILE *fo, char *str) {
|
out_lines++;
|
int replace = 0;
|
return i + (level * 2);
|
if (*str == '}') {olevel--;}
|
|
else if (*str == '{') {olevel++;}
|
|
else if (strncmp ("eval_operand", str, 12) == 0) {
|
|
replace = 1; str += 12;
|
|
} else if (strncmp ("set_operand", str, 11) == 0) {
|
|
replace = 2; str += 11;
|
|
} else if (strncmp ("get_operand", str, 11) == 0) {
|
|
replace = 10; str += 11;
|
|
}
|
|
if (replace) {
|
|
int width, oper;
|
|
if (replace < 10) {
|
|
sscanf (str, "%i(%i", &width, &oper);
|
|
while (*str && *str != '(') str++;
|
|
while (*str && *str != ',') str++;
|
|
str++;
|
|
} else {
|
|
sscanf (str, "(%i)", &oper);
|
|
while (*str && *str != ')') str++;
|
|
}
|
|
if (replace == 1) {
|
|
if (op[oper] & OPTYPE_DIS) {
|
|
fprintf (fo, "eval_mem%i (%c", width, 'a' + oper);
|
|
} else {
|
|
if (op[oper] & OPTYPE_REG) {
|
|
fprintf (fo, "(reg[%c]", 'a' + oper);
|
|
} else {
|
|
fprintf (fo, "(%c", 'a' + oper);
|
|
}
|
|
}
|
|
} else if (replace == 2) {
|
|
op[oper] |= OPTYPE_DST;
|
|
if (op[oper] & OPTYPE_DIS) {
|
|
fprintf (fo, "set_mem%i(%c,", width, 'a' + oper);
|
|
} else if (op[oper] & OPTYPE_REG) {
|
|
fprintf (fo, "reg[%c] = (", 'a' + oper);
|
|
write_to_reg = 1;
|
|
} else {
|
|
fprintf (stderr, "Invalid operand type.\n");
|
|
exit (1);
|
|
}
|
|
while (*str != ',') str = replace_operands (fo, str) + 1;
|
|
} else {
|
|
fprintf (fo, "%c", 'a' + oper);
|
|
}
|
|
if (replace < 10) {
|
|
while (*str && *str != ')') str++;
|
|
if (op[oper] & OPTYPE_DIS) fprintf (fo, ", &breakpoint)");
|
|
else fprintf (fo, ")");
|
|
}
|
|
} else {
|
|
fputc (*str, fo);
|
|
}
|
|
return str;
|
|
}
|
}
|
|
|
/* Generates a execute sequence for one instruction */
|
/* Generates a execute sequence for one instruction */
|
int output_function (FILE *fo, const char *func_name, int level)
|
int output_function (FILE *fo, const char *func_name, int level)
|
{
|
{
|
FILE *fi;
|
FILE *fi;
|
|
int olevel;
|
|
int line_num = 0;
|
|
|
if ((fi = fopen (in_file, "rt")) == NULL) {
|
if ((fi = fopen (in_file, "rt")) == NULL) {
|
printf("could not open file\n");
|
printf("could not open file\n");
|
return 1;
|
return 1;
|
};
|
}
|
|
|
while (!feof (fi)) {
|
while (!feof (fi)) {
|
char line[10000], *str = line;
|
char line[10000], *str = line;
|
fgets (str, sizeof (line), fi);
|
fgets (str, sizeof (line), fi);
|
line[sizeof(line) - 1] = 0;
|
line[sizeof(line) - 1] = 0;
|
|
line_num++;
|
if (strncmp (str, "INSTRUCTION (", 13) == 0) {
|
if (strncmp (str, "INSTRUCTION (", 13) == 0) {
|
char *s;
|
char *s;
|
str += 13;
|
str += 13;
|
while (isspace (*str)) str++;
|
while (isspace (*str)) str++;
|
s = str;
|
s = str;
|
Line 155... |
Line 103... |
s = str;
|
s = str;
|
while (*s && *s != '\n' && *s != '\r') s++;
|
while (*s && *s != '\n' && *s != '\r') s++;
|
*s = 0;
|
*s = 0;
|
while (isspace(*(s - 1))) s--;
|
while (isspace(*(s - 1))) s--;
|
*s = 0;
|
*s = 0;
|
fprintf (fo, "%s", str);
|
/*shift_fprintf (level, fo, "#line %i \"%s\"\n", line_num, in_file);*/
|
fprintf (fo, " /* \"%s\" */\n", func_name);
|
shift_fprintf (level, fo, "%s", str);
|
SHIFT;
|
shift_fprintf (level, fo, " /* \"%s\" */\n", func_name);
|
do {
|
do {
|
fgets (line, sizeof (line), fi);
|
fgets (line, sizeof (line), fi);
|
line[sizeof(line) - 1] = 0;
|
line[sizeof(line) - 1] = 0;
|
for (str = line; *str; str++) {
|
for (str = line; *str; str++) {
|
str = replace_operands (fo, str);
|
if (*str == '{') olevel++;
|
|
else if (*str == '}') olevel--;
|
}
|
}
|
SHIFT;
|
shift_fprintf (level, fo, "%s", line);
|
} while (olevel);
|
} while (olevel);
|
fclose(fi);
|
fclose(fi);
|
|
/*shift_fprintf (level, fo, "#line %i \"%s\"\n", out_lines, out_file);*/
|
return 0;
|
return 0;
|
}
|
}
|
}
|
}
|
}
|
}
|
fprintf (fo, "{\n");
|
shift_fprintf (level, fo, "%s ();\n", func_name);
|
level++;
|
|
SHIFT; fprintf (fo, "%s ();\n", func_name);
|
|
level--;
|
|
SHIFT; fprintf (fo, "}");
|
|
|
|
fclose(fi);
|
fclose(fi);
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/* Parses and puts operands into op[] structure.
|
/* Parses and puts operands into op[] structure.
|
Replacement for eval_operands routine. */
|
Replacement for eval_operands routine. */
|
|
|
static void
|
static int
|
gen_eval_operands (FILE *fo, int insn_index, int level)
|
gen_eval_operands (FILE *fo, int insn_index, int level)
|
{
|
{
|
struct insn_op_struct *opd = op_start[insn_index];
|
struct insn_op_struct *opd = op_start[insn_index];
|
|
int i;
|
|
int num_ops;
|
|
int nbits = 0;
|
|
int set_param = 0;
|
int dis = 0;
|
int dis = 0;
|
int no = 0;
|
int sbit;
|
int firstd = 1;
|
|
|
|
while (1)
|
write_to_reg = 0;
|
{
|
|
int nbits = 0, first = 1;
|
shift_fprintf (level, fo, "unsigned long ");
|
while (1)
|
|
{
|
/* Count number of operands */
|
SHIFT;
|
for (i = 0, num_ops = 0;; i++) {
|
fprintf (fo, "tmp %s= ((insn >> %li) & 0x%08x) << %i;\n",
|
if (!(opd[i].type & OPTYPE_OP))
|
first ? "" : "|", opd->type & OPTYPE_SHR,
|
continue;
|
(1 << opd->data) - 1, nbits);
|
if (opd[i].type & OPTYPE_DIS)
|
nbits += opd->data;
|
continue;
|
if (opd->type & OPTYPE_OP)
|
if (num_ops)
|
|
fprintf(fo, ", ");
|
|
fprintf(fo, "%c", 'a' + num_ops);
|
|
num_ops++;
|
|
if (opd[i].type & OPTYPE_LAST)
|
break;
|
break;
|
opd++;
|
|
first = 0;
|
|
}
|
}
|
|
|
/* Do we have to sign extend? */
|
fprintf (fo, ";\n");
|
if (opd->type & OPTYPE_SIG)
|
|
{
|
shift_fprintf (level, fo, "/* Number of operands: %i */\n", num_ops);
|
int sbit = (opd->type & OPTYPE_SBIT) >> OPTYPE_SBIT_SHR;
|
|
SHIFT; fprintf (fo, "if (tmp & (1 << %i)) tmp |= 0xFFFFFFFF << %i; /* Sign extend */\n", sbit, sbit);
|
i = 0;
|
}
|
num_ops = 0;
|
|
do {
|
|
/*
|
|
printf("opd[%i].type<last> = %c\n", i, opd->type & OPTYPE_LAST ? '1' : '0'); printf("opd[%i].type<op> = %c\n", i, opd->type & OPTYPE_OP ? '1' : '0');
|
|
printf("opd[%i].type<reg> = %c\n", i, opd->type & OPTYPE_REG ? '1' : '0');
|
|
printf("opd[%i].type<sig> = %c\n", i, opd->type & OPTYPE_SIG ? '1' : '0');
|
|
printf("opd[%i].type<dis> = %c\n", i, opd->type & OPTYPE_DIS ? '1' : '0');
|
|
printf("opd[%i].type<shr> = %i\n", i, opd->type & OPTYPE_SHR);
|
|
printf("opd[%i].type<sbit> = %i\n", i, (opd->type & OPTYPE_SBIT) >> OPTYPE_SBIT_SHR);
|
|
printf("opd[%i].data = %i\n", i, opd->data);
|
|
*/
|
|
|
|
if (!nbits)
|
|
shift_fprintf (level, fo, "%c = (insn >> %i) & 0x%x;\n", 'a' + num_ops,
|
|
opd->type & OPTYPE_SHR, (1 << opd->data) - 1);
|
|
else
|
|
shift_fprintf (level, fo, "%c |= ((insn >> %i) & 0x%x) << %i;\n",
|
|
'a' + num_ops, opd->type & OPTYPE_SHR,
|
|
(1 << opd->data) - 1, nbits);
|
|
|
|
nbits += opd->data;
|
|
|
if (opd->type & OPTYPE_DIS) {
|
if (opd->type & OPTYPE_DIS) {
|
/* We have to read register later. */
|
sbit = (opd->type & OPTYPE_SBIT) >> OPTYPE_SBIT_SHR;
|
SHIFT; fprintf (fo, "data %s= tmp;\n", firstd ? "" : "+");
|
if (opd->type & OPTYPE_SIG)
|
firstd = 0;
|
shift_fprintf (level, fo, "if(%c & 0x%08x) %c |= 0x%x;\n",
|
|
'a' + num_ops, 1 << sbit, 'a' + num_ops,
|
|
0xffffffff << sbit);
|
|
opd++;
|
|
shift_fprintf (level, fo, "(signed)%c += (signed)reg[(insn >> %i) & 0x%x];\n",
|
|
'a' + num_ops, opd->type & OPTYPE_SHR,
|
|
(1 << opd->data) - 1);
|
dis = 1;
|
dis = 1;
|
} else
|
|
{
|
|
if (dis && (opd->type & OPTYPE_REG)) {
|
|
if (MAX_GPRS == (1 << nbits)) {
|
|
SHIFT; fprintf (fo, "%c = data + reg [tmp];\n", 'a' + no);
|
|
} else {
|
|
SHIFT; fprintf (fo, "%c = data + eval_reg32 (tmp);\n", 'a' + no);
|
|
}
|
}
|
|
|
|
if (opd->type & OPTYPE_OP) {
|
|
sbit = (opd->type & OPTYPE_SBIT) >> OPTYPE_SBIT_SHR;
|
|
if (opd->type & OPTYPE_SIG)
|
|
shift_fprintf (level, fo, "if(%c & 0x%08x) %c |= 0x%x;\n",
|
|
'a' + num_ops, 1 << sbit, 'a' + num_ops,
|
|
0xffffffff << sbit);
|
|
if ((opd->type & OPTYPE_REG) && !dis) {
|
|
if(!i) {
|
|
shift_fprintf (level, fo, "#define SET_PARAM0(val) reg[a] = val\n");
|
|
set_param = 1;
|
|
}
|
|
shift_fprintf (level, fo, "#define PARAM%i reg[%c]\n", num_ops,
|
|
'a' + num_ops);
|
|
if(opd->type & OPTYPE_DST)
|
|
write_to_reg = 1;
|
} else {
|
} else {
|
SHIFT; fprintf (fo, "%c = tmp;\n", 'a' + no);
|
shift_fprintf (level, fo, "#define PARAM%i %c\n", num_ops,
|
|
'a' + num_ops);
|
}
|
}
|
op[no] = opd->type | (dis ? OPTYPE_DIS : 0);
|
|
no++;
|
op[num_ops] = opd->type;
|
firstd = 1;
|
if(dis)
|
|
op[num_ops] |= OPTYPE_DIS;
|
|
num_ops++;
|
|
nbits = 0;
|
dis = 0;
|
dis = 0;
|
}
|
}
|
if(opd->type & OPTYPE_LAST) goto last;
|
|
|
if ((opd->type & OPTYPE_LAST))
|
|
break;
|
opd++;
|
opd++;
|
}
|
i++;
|
|
} while (1);
|
|
|
|
output_function (fo, or32_opcodes[insn_index].function_name, level);
|
|
|
|
if (set_param)
|
|
shift_fprintf (level, fo, "#undef SET_PARAM\n");
|
|
|
|
for (i = 0; i < num_ops; i++)
|
|
shift_fprintf (level, fo, "#undef PARAM%i\n", i);
|
|
|
last:
|
return num_ops;
|
num_op = no;
|
|
}
|
}
|
|
|
/* Generates decode and execute for one instruction instance */
|
/* Generates decode and execute for one instruction instance */
|
int output_call (FILE *fo, int index, int level)
|
static int output_call (FILE *fo, int index, int level)
|
{
|
{
|
int i;
|
int i;
|
printf ("%i:%s\n", index, insn_name (index));
|
int num_op;
|
fprintf (fo, "{\n");
|
|
level++;
|
/*printf ("%i:%s\n", index, insn_name (index));*/
|
if (index >= 0) {
|
|
SHIFT; fprintf (fo, "unsigned long data, tmp;\n");
|
shift_fprintf (level++, fo, "{\n");
|
SHIFT; fprintf (fo, "unsigned long a, b, c, d, e; /* operands */\n");
|
|
}
|
|
write_to_reg = 0;
|
|
if (index >= 0)
|
if (index >= 0)
|
gen_eval_operands (fo, index, level);
|
num_op = gen_eval_operands (fo, index, level);
|
else
|
else
|
num_op = 0;
|
num_op = 0;
|
SHIFT;
|
|
if (index < 0) output_function (fo, "l_invalid", level);
|
if (index < 0) output_function (fo, "l_invalid", level);
|
else output_function (fo, or32_opcodes[index].function_name, level);
|
|
fprintf (fo, "\n");
|
fprintf (fo, "\n");
|
|
|
SHIFT; fprintf (fo, "if (do_stats) {\n");
|
shift_fprintf (level++, fo, "if (do_stats) {\n");
|
level++;
|
shift_fprintf (level, fo, "num_op = %i;\n", num_op);
|
SHIFT; fprintf (fo, "num_op = %i;\n", num_op);
|
|
if (num_op) {SHIFT; fprintf (fo, " op = ¤t->op[0];\n");}
|
if (num_op) shift_fprintf (level, fo, "op = ¤t->op[0];\n");
|
SHIFT; fprintf (fo, "current->insn_index = %i; /* \"%s\" */\n", index, insn_name (index));
|
shift_fprintf (level, fo, "current->insn_index = %i; /* \"%s\" */\n", index,
|
|
insn_name (index));
|
|
|
for (i = 0; i < num_op; i++) {
|
for (i = 0; i < num_op; i++) {
|
SHIFT; fprintf (fo, "op[%i] = %c;\n", i, 'a' + i);
|
shift_fprintf (level, fo, "op[%i] = %c;\n", i, 'a' + i);
|
SHIFT; fprintf (fo, "op[%i + MAX_OPERANDS] = 0x%08x;\n", i, op[i]);
|
shift_fprintf (level, fo, "op[%i + MAX_OPERANDS] = 0x%08x;\n", i, op[i]);
|
}
|
|
SHIFT; fprintf (fo, "analysis(current);\n");
|
|
level--;
|
|
SHIFT; fprintf (fo, "}\n");
|
|
if (write_to_reg) {
|
|
SHIFT; fprintf (fo, "reg[0] = 0; /* Repair in case we changed it */\n");
|
|
}
|
}
|
level--;
|
shift_fprintf (level, fo, "analysis(current);\n");
|
SHIFT; fprintf (fo, "}");
|
shift_fprintf (--level, fo, "}\n");
|
|
if (write_to_reg)
|
|
shift_fprintf (level, fo, "reg[0] = 0; /* Repair in case we changed it */\n");
|
|
shift_fprintf (--level, fo, "}\n");
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/* Generates .c file header */
|
/* Generates .c file header */
|
int generate_header (FILE *fo)
|
static int generate_header (FILE *fo)
|
{
|
{
|
fprintf (fo, "/* This file was automatically generated by generate (see cpu/or32/generate.c) */\n\n");
|
fprintf (fo, "/* This file was automatically generated by generate (see cpu/or32/generate.c) */\n\n");
|
fprintf (fo, "static inline void decode_execute (struct iqueue_entry *current)\n{\n");
|
fprintf (fo, "static inline void decode_execute (struct iqueue_entry *current)\n{\n");
|
fprintf (fo, " unsigned long insn = current->insn;\n");
|
fprintf (fo, " unsigned long insn = current->insn;\n");
|
|
out_lines = 5;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/* Generates .c file footer */
|
/* Generates .c file footer */
|
int generate_footer (FILE *fo)
|
static int generate_footer (FILE *fo)
|
{
|
{
|
fprintf (fo, "}\n");
|
fprintf (fo, "}\n");
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/* Decodes all instructions and generates code for that. This function
|
/* Decodes all instructions and generates code for that. This function
|
is similar to insn_decode, except it decodes all instructions. */
|
is similar to insn_decode, except it decodes all instructions. */
|
static int generate_body (FILE *fo, unsigned long *a, unsigned long cur_mask, int level)
|
static int generate_body (FILE *fo, unsigned long *a, unsigned long cur_mask, int level)
|
{
|
{
|
|
unsigned long shift = *a;
|
|
unsigned long mask;
|
int i;
|
int i;
|
if (!(*a & LEAF_FLAG)) {
|
int prev_inv = 0;
|
unsigned int shift = *a++;
|
|
unsigned int mask = *a++;
|
|
int prev_invalid = 0;
|
|
fprintf (fo, "\n");
|
|
SHIFT; fprintf (fo, "/* (insn >> %i) & 0x%x */\n", shift, mask);
|
|
SHIFT; fprintf (fo, "switch ((insn >> %i) & 0x%x) {\n", shift, mask);
|
|
level++;
|
|
|
|
/* Print each case recursively */
|
if (!(*a & LEAF_FLAG)) {
|
|
shift = *a++;
|
|
mask = *a++;
|
|
shift_fprintf (level, fo, "switch((insn >> %i) & 0x%x) {\n", shift,
|
|
mask);
|
for (i = 0; i <= mask; i++, a++) {
|
for (i = 0; i <= mask; i++, a++) {
|
/* Group invalid instruction decodes together */
|
|
if (!*a) {
|
if (!*a) {
|
if (prev_invalid) fprintf (fo, "\n");
|
shift_fprintf (level, fo, "case 0x%x:\n", i);
|
prev_invalid = 1;
|
prev_inv = 1;
|
SHIFT; fprintf (fo, "case 0x%02x: ", i);
|
|
} else {
|
} else {
|
if (prev_invalid) {
|
if(prev_inv) {
|
if (output_call (fo, -1, level)) return 1;
|
shift_fprintf (++level, fo, "/* Invalid instruction(s) */\n");
|
fprintf (fo, " break;\n");
|
shift_fprintf (level--, fo, "break;\n");
|
}
|
}
|
SHIFT; fprintf (fo, "case 0x%02x: ", i);
|
shift_fprintf (level, fo, "case 0x%x:\n", i);
|
if (generate_body (fo, automata + *a, cur_mask | (mask << shift), level + 1)) return 1;
|
generate_body (fo, automata + *a, cur_mask | (mask << shift), ++level);
|
prev_invalid = 0;
|
shift_fprintf (level--, fo, "break;\n");
|
}
|
prev_inv = 0;
|
}
|
}
|
if (prev_invalid) {
|
}
|
if (output_call (fo, -1, level)) return 1;
|
if (prev_inv) {
|
fprintf (fo, " break;\n");
|
shift_fprintf (++level, fo, "/* Invalid instruction(s) */\n");
|
}
|
shift_fprintf (level--, fo, "break;\n");
|
level--;
|
}
|
if (level > 1)
|
shift_fprintf (level, fo, "}\n");
|
fprintf (fo, "} break;\n");
|
|
else
|
|
fprintf (fo, "}\n");
|
|
} else {
|
} else {
|
i = *a & ~LEAF_FLAG;
|
i = *a & ~LEAF_FLAG;
|
|
|
/* Final check - do we have direct match?
|
/* Final check - do we have direct match?
|
(based on or32_opcodes this should be the only possibility,
|
(based on or32_opcodes this should be the only possibility,
|
but in case of invalid/missing instruction we must perform a check) */
|
but in case of invalid/missing instruction we must perform a check) */
|
|
|
if (ti[i].insn_mask != cur_mask) {
|
if (ti[i].insn_mask != cur_mask) {
|
fprintf (fo, "\n");
|
shift_fprintf (level, fo, "/* Not unique: real mask %08lx and current mask %08lx differ - do final check */\n", ti[i].insn_mask, cur_mask);
|
SHIFT;
|
shift_fprintf (level++, fo, "if((insn & 0x%x) == 0x%x) {\n",
|
fprintf (fo, "/* Not unique: real mask %08lx and current mask %08lx differ - do final check */\n", ti[i].insn_mask, cur_mask);
|
ti[i].insn_mask, ti[i].insn);
|
SHIFT; fprintf (fo, "if ((insn & 0x%08lx) == 0x%08lx) ", ti[i].insn_mask, ti[i].insn);
|
}
|
if (output_call (fo, i, level)) return 1; // Fail
|
shift_fprintf (level, fo, "/* Instruction: %s */\n", or32_opcodes[i].name);
|
fprintf (fo, " else ");
|
|
if (output_call (fo, -1, level)) return 1; // Fail
|
output_call (fo, i, level);
|
} else {
|
|
if (output_call (fo, i, level - 1)) return 1; // Fail
|
if (ti[i].insn_mask != cur_mask) {
|
|
shift_fprintf (--level, fo, "} else {\n");
|
|
shift_fprintf (++level, fo, "/* Invalid insn */\n");
|
|
output_call (fo, -1, level);
|
|
shift_fprintf (--level, fo, "}\n");
|
}
|
}
|
fprintf (fo, " break;\n");
|
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/* Main function; it takes two parameters:
|
/* Main function; it takes two parameters:
|
Line 374... |
Line 371... |
fprintf (stderr, "USAGE: generate input_file(possibly insnset.c) output_file(possibly execgen.c)\n");
|
fprintf (stderr, "USAGE: generate input_file(possibly insnset.c) output_file(possibly execgen.c)\n");
|
exit (-1);
|
exit (-1);
|
}
|
}
|
|
|
in_file = argv[1];
|
in_file = argv[1];
|
|
out_file = argv[2];
|
if (!(fo = fopen (argv[2], "wt+"))) {
|
if (!(fo = fopen (argv[2], "wt+"))) {
|
fprintf (stderr, "Cannot create '%s'.\n", argv[2]);
|
fprintf (stderr, "Cannot create '%s'.\n", argv[2]);
|
exit (1);
|
exit (1);
|
}
|
}
|
|
|
build_automata ();
|
build_automata ();
|
if (generate_header (fo)) {fprintf (stderr, "generate_header\n"); return 1;}
|
if (generate_header (fo)) {
|
if (generate_body (fo, automata, 0, 1)) {fprintf (stderr, "generate_body\n"); return 1;}
|
fprintf (stderr, "generate_header\n");
|
if (generate_footer (fo)) {fprintf (stderr, "generate_footer\n"); return 1;}
|
return 1;
|
|
}
|
|
|
|
if (generate_body (fo, automata, 0, 1)) {
|
|
fprintf (stderr, "generate_body\n");
|
|
return 1;
|
|
}
|
|
|
|
if (generate_footer (fo)) {
|
|
fprintf (stderr, "generate_footer\n");
|
|
return 1;
|
|
}
|
|
|
fclose (fo);
|
fclose (fo);
|
destruct_automata ();
|
destruct_automata ();
|
return 0;
|
return 0;
|
}
|
}
|
|
|