mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
split the emit stuf out of expr.h into emit.h
This commit is contained in:
parent
e815669b7a
commit
c1894db59f
5 changed files with 70 additions and 36 deletions
|
@ -1,5 +1,5 @@
|
||||||
AUTOMAKE_OPTIONS= foreign
|
AUTOMAKE_OPTIONS= foreign
|
||||||
|
|
||||||
EXTRA_DIST= class.h cmdlib.h cpp.h debug.h def.h expr.h function.h idstuff.h \
|
EXTRA_DIST= class.h cmdlib.h cpp.h debug.h def.h emit.h expr.h function.h \
|
||||||
immediate.h linker.h method.h obj_file.h opcodes.h options.h \
|
idstuff.h immediate.h linker.h method.h obj_file.h opcodes.h \
|
||||||
qfcc.h reloc.h strpool.h struct.h switch.h type.h
|
options.h qfcc.h reloc.h strpool.h struct.h switch.h type.h
|
||||||
|
|
39
tools/qfcc/include/emit.h
Normal file
39
tools/qfcc/include/emit.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
#FILENAME#
|
||||||
|
|
||||||
|
#DESCRIPTION#
|
||||||
|
|
||||||
|
Copyright (C) 2001 #AUTHOR#
|
||||||
|
|
||||||
|
Author: #AUTHOR#
|
||||||
|
Date: #DATE#
|
||||||
|
|
||||||
|
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 the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __emit_h
|
||||||
|
#define __emit_h
|
||||||
|
|
||||||
|
struct expr_s;
|
||||||
|
struct def_s *emit_statement (struct expr_s *e, opcode_t *op, struct def_s *var_a, struct def_s *var_b, struct def_s *var_c);
|
||||||
|
void emit_expr (struct expr_s *e);
|
||||||
|
|
||||||
|
#endif//__emit_h
|
|
@ -163,9 +163,6 @@ expr_t *cast_expr (struct type_s *t, expr_t *e);
|
||||||
|
|
||||||
void init_elements (struct def_s *def, expr_t *eles);
|
void init_elements (struct def_s *def, expr_t *eles);
|
||||||
|
|
||||||
struct def_s *emit_statement (int line, opcode_t *op, struct def_s *var_a, struct def_s *var_b, struct def_s *var_c);
|
|
||||||
void emit_expr (expr_t *e);
|
|
||||||
|
|
||||||
expr_t *error (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
|
expr_t *error (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
|
||||||
void warning (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
|
void warning (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
|
||||||
void notice (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
|
void notice (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3)));
|
||||||
|
|
|
@ -46,6 +46,7 @@ static const char rcsid[] =
|
||||||
|
|
||||||
#include "def.h"
|
#include "def.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "emit.h"
|
||||||
#include "expr.h"
|
#include "expr.h"
|
||||||
#include "immediate.h"
|
#include "immediate.h"
|
||||||
#include "opcodes.h"
|
#include "opcodes.h"
|
||||||
|
@ -74,22 +75,18 @@ add_statement_ref (def_t *def, dstatement_t *st, reloc_type type)
|
||||||
}
|
}
|
||||||
|
|
||||||
def_t *
|
def_t *
|
||||||
emit_statement (int sline, opcode_t *op, def_t *var_a, def_t *var_b,
|
emit_statement (expr_t *e, opcode_t *op, def_t *var_a, def_t *var_b,
|
||||||
def_t *var_c)
|
def_t *var_c)
|
||||||
{
|
{
|
||||||
dstatement_t *statement;
|
dstatement_t *statement;
|
||||||
def_t *ret;
|
def_t *ret;
|
||||||
|
|
||||||
if (!op) {
|
if (!op) {
|
||||||
expr_t e;
|
error (e, "ice ice baby\n");
|
||||||
|
|
||||||
e.line = sline;
|
|
||||||
e.file = pr.source_file;
|
|
||||||
error (&e, "ice ice baby\n");
|
|
||||||
abort ();
|
abort ();
|
||||||
}
|
}
|
||||||
if (options.code.debug) {
|
if (options.code.debug) {
|
||||||
int line = sline - lineno_base;
|
int line = e->line - lineno_base;
|
||||||
|
|
||||||
if (line != linenos[num_linenos - 1].line) {
|
if (line != linenos[num_linenos - 1].line) {
|
||||||
pr_lineno_t *lineno = new_lineno ();
|
pr_lineno_t *lineno = new_lineno ();
|
||||||
|
@ -142,7 +139,7 @@ emit_statement (int sline, opcode_t *op, def_t *var_a, def_t *var_b,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
emit_branch (int line, opcode_t *op, expr_t *e, expr_t *l)
|
emit_branch (expr_t *_e, opcode_t *op, expr_t *e, expr_t *l)
|
||||||
{
|
{
|
||||||
dstatement_t *st;
|
dstatement_t *st;
|
||||||
reloc_t *ref;
|
reloc_t *ref;
|
||||||
|
@ -152,7 +149,7 @@ emit_branch (int line, opcode_t *op, expr_t *e, expr_t *l)
|
||||||
if (e)
|
if (e)
|
||||||
def = emit_sub_expr (e, 0);
|
def = emit_sub_expr (e, 0);
|
||||||
st = &pr.statements[ofs = pr.num_statements];
|
st = &pr.statements[ofs = pr.num_statements];
|
||||||
emit_statement (line, op, def, 0, 0);
|
emit_statement (_e, op, def, 0, 0);
|
||||||
if (l->e.label.ofs) {
|
if (l->e.label.ofs) {
|
||||||
if (op == op_goto)
|
if (op == op_goto)
|
||||||
st->a = l->e.label.ofs - ofs;
|
st->a = l->e.label.ofs - ofs;
|
||||||
|
@ -185,17 +182,17 @@ emit_function_call (expr_t *e, def_t *dest)
|
||||||
arg = emit_sub_expr (earg, &parm);
|
arg = emit_sub_expr (earg, &parm);
|
||||||
if (earg->type != ex_expr && earg->type != ex_uexpr) {
|
if (earg->type != ex_expr && earg->type != ex_uexpr) {
|
||||||
op = opcode_find ("=", arg, &parm, &def_void);
|
op = opcode_find ("=", arg, &parm, &def_void);
|
||||||
emit_statement (e->line, op, arg, &parm, 0);
|
emit_statement (e, op, arg, &parm, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
op = opcode_find (va ("<CALL%d>", count), &def_function, &def_void,
|
op = opcode_find (va ("<CALL%d>", count), &def_function, &def_void,
|
||||||
&def_void);
|
&def_void);
|
||||||
emit_statement (e->line, op, func, 0, 0);
|
emit_statement (e, op, func, 0, 0);
|
||||||
|
|
||||||
def_ret.type = func->type->aux_type;
|
def_ret.type = func->type->aux_type;
|
||||||
if (dest) {
|
if (dest) {
|
||||||
op = opcode_find ("=", dest, &def_ret, &def_void);
|
op = opcode_find ("=", dest, &def_ret, &def_void);
|
||||||
emit_statement (e->line, op, &def_ret, dest, 0);
|
emit_statement (e, op, &def_ret, dest, 0);
|
||||||
return dest;
|
return dest;
|
||||||
} else {
|
} else {
|
||||||
return &def_ret;
|
return &def_ret;
|
||||||
|
@ -239,7 +236,7 @@ emit_assign_expr (int oper, expr_t *e)
|
||||||
def_b = emit_sub_expr (e2, def_a);
|
def_b = emit_sub_expr (e2, def_a);
|
||||||
if (def_b != def_a) {
|
if (def_b != def_a) {
|
||||||
op = opcode_find (operator, def_b, def_a, &def_void);
|
op = opcode_find (operator, def_b, def_a, &def_void);
|
||||||
emit_statement (e->line, op, def_b, def_a, 0);
|
emit_statement (e, op, def_b, def_a, 0);
|
||||||
}
|
}
|
||||||
return def_a;
|
return def_a;
|
||||||
} else {
|
} else {
|
||||||
|
@ -256,7 +253,7 @@ emit_assign_expr (int oper, expr_t *e)
|
||||||
def_c = 0;
|
def_c = 0;
|
||||||
op = opcode_find (operator, def_b, def_a, &def_void);
|
op = opcode_find (operator, def_b, def_a, &def_void);
|
||||||
}
|
}
|
||||||
emit_statement (e->line, op, def_b, def_a, def_c);
|
emit_statement (e, op, def_b, def_a, def_c);
|
||||||
return def_b;
|
return def_b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -294,7 +291,7 @@ emit_address_expr (expr_t *e)
|
||||||
def_a = emit_sub_expr (e->e.expr.e1, 0);
|
def_a = emit_sub_expr (e->e.expr.e1, 0);
|
||||||
def_b = emit_sub_expr (e->e.expr.e2, 0);
|
def_b = emit_sub_expr (e->e.expr.e2, 0);
|
||||||
op = opcode_find ("&", def_a, def_b, 0);
|
op = opcode_find ("&", def_a, def_b, 0);
|
||||||
d = emit_statement (e->line, op, def_a, def_b, 0);
|
d = emit_statement (e, op, def_a, def_b, 0);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +314,7 @@ emit_deref_expr (expr_t *e, def_t *dest)
|
||||||
zero.type = ex_short;
|
zero.type = ex_short;
|
||||||
z = emit_sub_expr (&zero, 0);
|
z = emit_sub_expr (&zero, 0);
|
||||||
op = opcode_find (".", d, z, dest);
|
op = opcode_find (".", d, z, dest);
|
||||||
d = emit_statement (e->line, op, d, z, dest);
|
d = emit_statement (e, op, d, z, dest);
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
@ -338,7 +335,7 @@ emit_deref_expr (expr_t *e, def_t *dest)
|
||||||
zero.type = ex_short;
|
zero.type = ex_short;
|
||||||
z = emit_sub_expr (&zero, 0);
|
z = emit_sub_expr (&zero, 0);
|
||||||
op = opcode_find (".", d, z, dest);
|
op = opcode_find (".", d, z, dest);
|
||||||
d = emit_statement (e->line, op, d, z, dest);
|
d = emit_statement (e, op, d, z, dest);
|
||||||
} else {
|
} else {
|
||||||
if (!d->name)
|
if (!d->name)
|
||||||
d->type = type;
|
d->type = type;
|
||||||
|
@ -397,7 +394,7 @@ emit_sub_expr (expr_t *e, def_t *dest)
|
||||||
dest->users += 2;
|
dest->users += 2;
|
||||||
}
|
}
|
||||||
op = opcode_find (operator, def_a, def_b, dest);
|
op = opcode_find (operator, def_a, def_b, dest);
|
||||||
d = emit_statement (e->line, op, def_a, def_b, dest);
|
d = emit_statement (e, op, def_a, def_b, dest);
|
||||||
break;
|
break;
|
||||||
case ex_uexpr:
|
case ex_uexpr:
|
||||||
switch (e->e.expr.op) {
|
switch (e->e.expr.op) {
|
||||||
|
@ -459,7 +456,7 @@ emit_sub_expr (expr_t *e, def_t *dest)
|
||||||
abort ();
|
abort ();
|
||||||
}
|
}
|
||||||
op = opcode_find (operator, def_a, def_b, dest);
|
op = opcode_find (operator, def_a, def_b, dest);
|
||||||
d = emit_statement (e->line, op, def_a, def_b, dest);
|
d = emit_statement (e, op, def_a, def_b, dest);
|
||||||
break;
|
break;
|
||||||
case ex_def:
|
case ex_def:
|
||||||
d = e->e.def;
|
d = e->e.def;
|
||||||
|
@ -528,22 +525,22 @@ emit_expr (expr_t *e)
|
||||||
emit_assign_expr (e->e.expr.op, e);
|
emit_assign_expr (e->e.expr.op, e);
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
emit_branch (e->line, op_ifnot, e->e.expr.e1, e->e.expr.e2);
|
emit_branch (e, op_ifnot, e->e.expr.e1, e->e.expr.e2);
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
emit_branch (e->line, op_if, e->e.expr.e1, e->e.expr.e2);
|
emit_branch (e, op_if, e->e.expr.e1, e->e.expr.e2);
|
||||||
break;
|
break;
|
||||||
case IFBE:
|
case IFBE:
|
||||||
emit_branch (e->line, op_ifbe, e->e.expr.e1, e->e.expr.e2);
|
emit_branch (e, op_ifbe, e->e.expr.e1, e->e.expr.e2);
|
||||||
break;
|
break;
|
||||||
case IFB:
|
case IFB:
|
||||||
emit_branch (e->line, op_ifb, e->e.expr.e1, e->e.expr.e2);
|
emit_branch (e, op_ifb, e->e.expr.e1, e->e.expr.e2);
|
||||||
break;
|
break;
|
||||||
case IFAE:
|
case IFAE:
|
||||||
emit_branch (e->line, op_ifae, e->e.expr.e1, e->e.expr.e2);
|
emit_branch (e, op_ifae, e->e.expr.e1, e->e.expr.e2);
|
||||||
break;
|
break;
|
||||||
case IFA:
|
case IFA:
|
||||||
emit_branch (e->line, op_ifa, e->e.expr.e1, e->e.expr.e2);
|
emit_branch (e, op_ifa, e->e.expr.e1, e->e.expr.e2);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
emit_function_call (e, 0);
|
emit_function_call (e, 0);
|
||||||
|
@ -551,7 +548,7 @@ emit_expr (expr_t *e)
|
||||||
case 's':
|
case 's':
|
||||||
def_a = emit_sub_expr (e->e.expr.e1, 0);
|
def_a = emit_sub_expr (e->e.expr.e1, 0);
|
||||||
def_b = emit_sub_expr (e->e.expr.e2, 0);
|
def_b = emit_sub_expr (e->e.expr.e2, 0);
|
||||||
emit_statement (e->line, op_state, def_a, def_b, 0);
|
emit_statement (e, op_state, def_a, def_b, 0);
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
emit_bind_expr (e->e.expr.e1, e->e.expr.e2);
|
emit_bind_expr (e->e.expr.e1, e->e.expr.e2);
|
||||||
|
@ -559,7 +556,7 @@ emit_expr (expr_t *e)
|
||||||
case 'g':
|
case 'g':
|
||||||
def_a = emit_sub_expr (e->e.expr.e1, 0);
|
def_a = emit_sub_expr (e->e.expr.e1, 0);
|
||||||
def_b = emit_sub_expr (e->e.expr.e2, 0);
|
def_b = emit_sub_expr (e->e.expr.e2, 0);
|
||||||
emit_statement (e->line, op_jumpb, def_a, def_b, 0);
|
emit_statement (e, op_jumpb, def_a, def_b, 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
warning (e, "Ignoring useless expression");
|
warning (e, "Ignoring useless expression");
|
||||||
|
@ -572,10 +569,10 @@ emit_expr (expr_t *e)
|
||||||
def = 0;
|
def = 0;
|
||||||
if (e->e.expr.e1)
|
if (e->e.expr.e1)
|
||||||
def = emit_sub_expr (e->e.expr.e1, 0);
|
def = emit_sub_expr (e->e.expr.e1, 0);
|
||||||
emit_statement (e->line, op_return, def, 0, 0);
|
emit_statement (e, op_return, def, 0, 0);
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
emit_branch (e->line, op_goto, 0, e->e.expr.e1);
|
emit_branch (e, op_goto, 0, e->e.expr.e1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
warning (e, "useless expression");
|
warning (e, "useless expression");
|
||||||
|
|
|
@ -47,6 +47,7 @@ static const char rcsid[] =
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "def.h"
|
#include "def.h"
|
||||||
|
#include "emit.h"
|
||||||
#include "expr.h"
|
#include "expr.h"
|
||||||
#include "function.h"
|
#include "function.h"
|
||||||
#include "immediate.h"
|
#include "immediate.h"
|
||||||
|
@ -253,7 +254,7 @@ emit_function (function_t *f, expr_t *e)
|
||||||
emit_expr (e);
|
emit_expr (e);
|
||||||
e = e->next;
|
e = e->next;
|
||||||
}
|
}
|
||||||
emit_statement (pr.source_line, op_done, 0, 0, 0);
|
emit_statement (0, op_done, 0, 0, 0);
|
||||||
flush_scope (current_scope, 0);
|
flush_scope (current_scope, 0);
|
||||||
current_scope = pr.scope;
|
current_scope = pr.scope;
|
||||||
reset_tempdefs ();
|
reset_tempdefs ();
|
||||||
|
|
Loading…
Reference in a new issue