[qfcc] Hide details about instruction type

At this stage, I doubt emit.c will need to know the details of the
target (v6, v6p, ruamoko) since the instruction formats are identical,
just different meanings for the opcode itself.
This commit is contained in:
Bill Currie 2022-01-07 19:05:26 +09:00
parent d9ccf3a394
commit 7e303a1151
3 changed files with 24 additions and 17 deletions

View File

@ -31,13 +31,14 @@
#ifndef __opcodes_h
#define __opcodes_h
#include "QF/pr_comp.h"
typedef struct instruction_s instruction_t;
struct operand_s;
extern struct v6p_opcode_s *opcode_map;
struct v6p_opcode_s *opcode_find (const char *name, struct operand_s *op_a,
struct operand_s *op_b,
struct operand_s *op_c);
pr_ushort_t opcode_get (instruction_t *inst);
instruction_t *opcode_find (const char *name, struct operand_s *op_a,
struct operand_s *op_b, struct operand_s *op_c);
void opcode_init (void);
#endif//__opcodes_h

View File

@ -185,7 +185,7 @@ emit_statement (statement_t *statement)
{
const char *opcode = statement->opcode;
def_t *def_a, *def_b, *def_c;
v6p_opcode_t *op;
instruction_t *inst;
dstatement_t *s;
def_a = get_operand_def (statement->expr, statement->opa);
@ -194,9 +194,9 @@ emit_statement (statement_t *statement)
use_tempop (statement->opb, statement->expr);
def_c = get_operand_def (statement->expr, statement->opc);
use_tempop (statement->opc, statement->expr);
op = opcode_find (opcode, statement->opa, statement->opb, statement->opc);
inst = opcode_find (opcode, statement->opa, statement->opb, statement->opc);
if (!op) {
if (!inst) {
print_expr (statement->expr);
print_statement (statement);
internal_error (statement->expr, "ice ice baby");
@ -213,7 +213,7 @@ emit_statement (statement_t *statement)
}
}
s = codespace_newstatement (pr.code);
s->op = op - opcode_map;
s->op = opcode_get (inst);
s->a = def_a ? def_a->offset : 0;
s->b = def_b ? def_b->offset : 0;
s->c = def_c ? def_c->offset : 0;

View File

@ -47,9 +47,9 @@
#include "tools/qfcc/include/statements.h"
#include "tools/qfcc/include/type.h"
hashtab_t *opcode_type_table;
hashtab_t *opcode_void_table;
v6p_opcode_t *opcode_map;
static hashtab_t *opcode_type_table;
static hashtab_t *opcode_void_table;
static v6p_opcode_t *opcode_map;
#define ROTL(x,n) ((((unsigned)(x))<<(n))|((unsigned)(x))>>(32-n))
@ -92,7 +92,13 @@ check_operand_type (etype_t ot1, etype_t ot2)
return 0;
}
v6p_opcode_t *
pr_ushort_t
opcode_get (instruction_t *op)
{
return (v6p_opcode_t *) op - opcode_map;
}
instruction_t *
opcode_find (const char *name, operand_t *op_a, operand_t *op_b,
operand_t *op_c)
{
@ -108,10 +114,10 @@ opcode_find (const char *name, operand_t *op_a, operand_t *op_b,
search_op.type_c = op_c ? low_level_type (op_c->type) : ev_invalid;
op = Hash_FindElement (opcode_type_table, &search_op);
if (op)
return op;
return (instruction_t *) op;
op_list = Hash_FindList (opcode_void_table, name);
if (!op_list)
return op;
return (instruction_t *) op;
for (i = 0; !op && op_list[i]; i++) {
sop = op_list[i];
if (check_operand_type (sop->type_a, search_op.type_a)
@ -120,7 +126,7 @@ opcode_find (const char *name, operand_t *op_a, operand_t *op_b,
op = sop;
}
free (op_list);
return op;
return (instruction_t *) op;
}
void