2001-10-25 06:41:52 +00:00
|
|
|
/*
|
|
|
|
switch.c
|
|
|
|
|
|
|
|
qc switch statement support
|
|
|
|
|
|
|
|
Copyright (C) 2001 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2001/10/24
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
2001-12-06 19:49:40 +00:00
|
|
|
static const char rcsid[] =
|
2001-10-25 06:41:52 +00:00
|
|
|
"$Id$";
|
|
|
|
|
|
|
|
#include <QF/hash.h>
|
|
|
|
#include <QF/sys.h>
|
|
|
|
|
|
|
|
#include "qfcc.h"
|
2002-05-09 17:11:14 +00:00
|
|
|
#include "type.h"
|
2001-10-25 06:41:52 +00:00
|
|
|
#include "switch.h"
|
|
|
|
#include "qc-parse.h"
|
|
|
|
|
2001-11-13 08:58:54 +00:00
|
|
|
typedef struct case_node_s {
|
|
|
|
expr_t *low;
|
|
|
|
expr_t *high;
|
|
|
|
expr_t **labels;
|
|
|
|
expr_t *_label;
|
|
|
|
struct case_node_s *left, *right;
|
|
|
|
} case_node_t;
|
|
|
|
|
2001-10-25 06:41:52 +00:00
|
|
|
static unsigned long
|
|
|
|
get_hash (void *_cl, void *unused)
|
|
|
|
{
|
2001-12-06 19:49:40 +00:00
|
|
|
case_label_t *cl = (case_label_t *) _cl;
|
2001-10-25 06:41:52 +00:00
|
|
|
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
return cl->value ? cl->value->e.integer_val : 0;
|
2001-10-25 06:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compare (void *_cla, void *_clb, void *unused)
|
|
|
|
{
|
2001-12-06 19:49:40 +00:00
|
|
|
case_label_t *cla = (case_label_t *) _cla;
|
|
|
|
case_label_t *clb = (case_label_t *) _clb;
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
expr_t *v1 = cla->value;
|
|
|
|
expr_t *v2 = clb->value;
|
2001-10-25 06:41:52 +00:00
|
|
|
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
if (v1 == v2)
|
|
|
|
return 1;
|
|
|
|
if ((v1 && !v2) || (!v1 && v2))
|
|
|
|
return 0;
|
|
|
|
return v1->e.integer_val == v2->e.integer_val;
|
2001-10-25 06:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct expr_s *
|
|
|
|
case_label_expr (switch_block_t *switch_block, expr_t *value)
|
|
|
|
{
|
|
|
|
case_label_t *cl = malloc (sizeof (case_label_t));
|
|
|
|
|
2002-05-14 06:37:28 +00:00
|
|
|
SYS_CHECKMEM (cl);
|
2001-10-25 06:41:52 +00:00
|
|
|
|
2002-01-21 19:18:41 +00:00
|
|
|
if (value)
|
|
|
|
convert_name (value);
|
2001-10-25 06:41:52 +00:00
|
|
|
if (value && value->type < ex_string) {
|
|
|
|
error (value, "non-constant case value");
|
|
|
|
free (cl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!switch_block) {
|
|
|
|
error (value, "%s outside of switch", value ? "case" : "default");
|
|
|
|
free (cl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
cl->value = value;
|
|
|
|
if (Hash_FindElement (switch_block->labels, cl)) {
|
|
|
|
error (value, "duplicate %s", value ? "case" : "default");
|
|
|
|
free (cl);
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
return 0;
|
2001-10-25 06:41:52 +00:00
|
|
|
}
|
|
|
|
cl->label = new_label_expr ();
|
|
|
|
Hash_AddElement (switch_block->labels, cl);
|
|
|
|
return cl->label;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_block_t *
|
|
|
|
new_switch_block (void)
|
|
|
|
{
|
|
|
|
switch_block_t *switch_block = malloc (sizeof (switch_block_t));
|
2001-12-06 19:49:40 +00:00
|
|
|
|
2002-05-14 06:37:28 +00:00
|
|
|
SYS_CHECKMEM (switch_block);
|
2001-10-25 06:41:52 +00:00
|
|
|
switch_block->labels = Hash_NewTable (127, 0, 0, 0);
|
|
|
|
Hash_SetHashCompare (switch_block->labels, get_hash, compare);
|
|
|
|
switch_block->test = 0;
|
|
|
|
return switch_block;
|
|
|
|
}
|
|
|
|
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
static int
|
|
|
|
label_compare (const void *_a, const void *_b)
|
|
|
|
{
|
2001-12-06 19:49:40 +00:00
|
|
|
const case_label_t **a = (const case_label_t **) _a;
|
|
|
|
const case_label_t **b = (const case_label_t **) _b;
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
const char *s1, *s2;
|
|
|
|
|
|
|
|
switch ((*a)->value->type) {
|
|
|
|
case ex_string:
|
|
|
|
s1 = (*a)->value->e.string_val ? (*a)->value->e.string_val : "";
|
|
|
|
s2 = (*b)->value->e.string_val ? (*b)->value->e.string_val : "";
|
|
|
|
return strcmp (s1, s2);
|
|
|
|
break;
|
|
|
|
case ex_float:
|
|
|
|
return (*a)->value->e.float_val - (*b)->value->e.float_val;
|
|
|
|
break;
|
|
|
|
case ex_integer:
|
|
|
|
return (*a)->value->e.integer_val - (*b)->value->e.integer_val;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error (0, "internal compiler error in switch");
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-13 08:58:54 +00:00
|
|
|
static case_node_t *
|
|
|
|
new_case_node (expr_t *low, expr_t *high)
|
|
|
|
{
|
|
|
|
case_node_t *node = malloc (sizeof (case_node_t));
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
Sys_Error ("out of memory");
|
|
|
|
node->low = low;
|
|
|
|
node->high = high;
|
|
|
|
if (low == high) {
|
|
|
|
node->labels = &node->_label;
|
|
|
|
node->_label = 0;
|
|
|
|
} else {
|
|
|
|
int size;
|
2001-12-06 19:49:40 +00:00
|
|
|
|
2001-11-13 08:58:54 +00:00
|
|
|
if (low->type != ex_integer) {
|
|
|
|
error (low, "switch: internal error");
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
size = high->e.integer_val - low->e.integer_val + 1;
|
|
|
|
node->labels = calloc (size, sizeof (case_node_t *));
|
|
|
|
}
|
|
|
|
node->left = node->right = 0;
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static case_node_t *
|
|
|
|
balance_case_tree (case_node_t **nodes, int base, int count)
|
|
|
|
{
|
|
|
|
case_node_t *node;
|
|
|
|
int index = count / 2;
|
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
node = nodes[base + index];
|
|
|
|
|
|
|
|
node->left = balance_case_tree (nodes, base, index);
|
|
|
|
|
|
|
|
base += index + 1;
|
|
|
|
count -= index + 1;
|
|
|
|
node->right = balance_case_tree (nodes, base, count);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static case_node_t *
|
2001-11-14 06:45:31 +00:00
|
|
|
build_case_tree (case_label_t **labels, int count, int range)
|
2001-11-13 08:58:54 +00:00
|
|
|
{
|
|
|
|
case_node_t **nodes;
|
|
|
|
int i, j, k;
|
2001-12-06 19:49:40 +00:00
|
|
|
int num_nodes = 0;
|
2001-11-13 08:58:54 +00:00
|
|
|
|
|
|
|
qsort (labels, count, sizeof (*labels), label_compare);
|
|
|
|
|
2001-12-06 19:49:40 +00:00
|
|
|
nodes = (case_node_t **) malloc (count * sizeof (case_node_t *));
|
|
|
|
|
2001-11-13 08:58:54 +00:00
|
|
|
if (!nodes)
|
|
|
|
Sys_Error ("out of memory");
|
|
|
|
|
2001-11-14 06:45:31 +00:00
|
|
|
if (range && labels[0]->value->type == ex_integer) {
|
2001-11-13 08:58:54 +00:00
|
|
|
for (i = 0; i < count - 1; i = j, num_nodes++) {
|
|
|
|
for (j = i + 1; j < count; j++) {
|
|
|
|
if (labels[j]->value->e.integer_val
|
|
|
|
- labels[j - 1]->value->e.integer_val > 1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nodes[num_nodes] = new_case_node (labels[i]->value,
|
|
|
|
labels[j - 1]->value);
|
|
|
|
for (k = i; k < j; k++)
|
|
|
|
nodes[num_nodes]->labels[labels[k]->value->e.integer_val
|
|
|
|
- labels[i]->value->e.integer_val]
|
|
|
|
= labels[k]->label;
|
|
|
|
}
|
|
|
|
if (i < count) {
|
|
|
|
nodes[num_nodes] = new_case_node (labels[i]->value,
|
|
|
|
labels[i]->value);
|
|
|
|
nodes[num_nodes]->labels[0] = labels[i]->label;
|
|
|
|
num_nodes++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < count; i++, num_nodes++) {
|
|
|
|
nodes[num_nodes] = new_case_node (labels[i]->value,
|
|
|
|
labels[i]->value);
|
|
|
|
nodes[num_nodes]->labels[0] = labels[i]->label;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return balance_case_tree (nodes, 0, num_nodes);
|
|
|
|
}
|
|
|
|
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
static void
|
2001-12-06 19:49:40 +00:00
|
|
|
build_switch (expr_t *sw, case_node_t *tree, int op, expr_t *sw_val,
|
2001-11-13 08:58:54 +00:00
|
|
|
expr_t *temp, expr_t *default_label)
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
{
|
|
|
|
expr_t *test;
|
|
|
|
expr_t *branch;
|
2001-11-13 08:58:54 +00:00
|
|
|
expr_t *high_label = default_label;
|
|
|
|
expr_t *low_label = default_label;
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
|
2001-11-13 20:27:05 +00:00
|
|
|
if (!tree) {
|
|
|
|
branch = new_unary_expr ('g', default_label);
|
|
|
|
append_expr (sw, branch);
|
2001-11-13 08:58:54 +00:00
|
|
|
return;
|
2001-11-13 20:27:05 +00:00
|
|
|
}
|
2001-11-13 08:58:54 +00:00
|
|
|
|
|
|
|
if (tree->right) {
|
|
|
|
high_label = new_label_expr ();
|
|
|
|
}
|
|
|
|
if (tree->left) {
|
|
|
|
low_label = new_label_expr ();
|
|
|
|
}
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
|
2001-11-13 08:58:54 +00:00
|
|
|
test = binary_expr (op, sw_val, tree->low);
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
|
2001-12-12 08:39:47 +00:00
|
|
|
test = assign_expr (temp, test);
|
2001-11-14 06:45:31 +00:00
|
|
|
append_expr (sw, test);
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
|
2001-11-13 08:58:54 +00:00
|
|
|
if (tree->low == tree->high) {
|
2001-11-14 06:45:31 +00:00
|
|
|
branch = new_binary_expr ('n', temp, tree->labels[0]);
|
2001-11-13 08:58:54 +00:00
|
|
|
append_expr (sw, branch);
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
|
2001-11-13 08:58:54 +00:00
|
|
|
if (tree->left) {
|
|
|
|
branch = new_binary_expr (IFA, temp, high_label);
|
|
|
|
append_expr (sw, branch);
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
|
2001-11-13 08:58:54 +00:00
|
|
|
build_switch (sw, tree->left, op, sw_val, temp, default_label);
|
|
|
|
|
|
|
|
if (tree->right)
|
|
|
|
append_expr (sw, high_label);
|
|
|
|
}
|
2001-11-13 22:11:45 +00:00
|
|
|
if (tree->right || !tree->left) {
|
|
|
|
build_switch (sw, tree->right, op, sw_val, temp, default_label);
|
|
|
|
}
|
2001-11-13 08:58:54 +00:00
|
|
|
} else {
|
|
|
|
expr_t *utemp = new_temp_def_expr (&type_uinteger);
|
|
|
|
int low = tree->low->e.integer_val;
|
|
|
|
int high = tree->high->e.integer_val;
|
|
|
|
def_t *def;
|
|
|
|
expr_t *table = new_expr ();
|
|
|
|
const char *name = new_label_name ();
|
|
|
|
int i;
|
|
|
|
expr_t *range = binary_expr ('-', tree->high, tree->low);
|
|
|
|
|
2001-11-13 18:11:19 +00:00
|
|
|
range->type = ex_uinteger;
|
2001-11-13 08:58:54 +00:00
|
|
|
|
|
|
|
def = PR_GetArray (&type_uinteger, name, high - low + 1, 0,
|
|
|
|
&numpr_globals);
|
|
|
|
table->type = ex_def;
|
|
|
|
table->e.def = def;
|
|
|
|
|
|
|
|
if (tree->left) {
|
|
|
|
branch = new_binary_expr (IFB, temp, low_label);
|
|
|
|
append_expr (sw, branch);
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
}
|
2001-11-13 18:49:27 +00:00
|
|
|
append_expr (sw, new_bind_expr (temp, utemp));
|
2001-11-13 08:58:54 +00:00
|
|
|
test = binary_expr (GT, utemp, range);
|
|
|
|
branch = new_binary_expr ('i', test, high_label);
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
append_expr (sw, branch);
|
2001-11-13 08:58:54 +00:00
|
|
|
branch = new_binary_expr ('g', table, temp);
|
|
|
|
append_expr (sw, branch);
|
|
|
|
if (tree->left) {
|
|
|
|
append_expr (sw, low_label);
|
|
|
|
build_switch (sw, tree->left, op, sw_val, temp, default_label);
|
|
|
|
}
|
|
|
|
if (tree->right) {
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
append_expr (sw, high_label);
|
2001-11-13 08:58:54 +00:00
|
|
|
build_switch (sw, tree->right, op, sw_val, temp, default_label);
|
|
|
|
}
|
|
|
|
for (i = 0; i <= high - low; i++) {
|
|
|
|
dstatement_t *st;
|
|
|
|
statref_t *ref;
|
2001-12-06 19:49:40 +00:00
|
|
|
|
2001-11-13 08:58:54 +00:00
|
|
|
st = (dstatement_t *) &pr_globals[G_INT (def->ofs) + i];
|
|
|
|
ref = PR_NewStatref (st, 3);
|
|
|
|
ref->next = tree->labels[i]->e.label.refs;
|
|
|
|
tree->labels[i]->e.label.refs = ref;
|
|
|
|
}
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-25 06:41:52 +00:00
|
|
|
struct expr_s *
|
2001-12-06 19:49:40 +00:00
|
|
|
switch_expr (switch_block_t *switch_block, expr_t *break_label,
|
2001-10-25 06:41:52 +00:00
|
|
|
expr_t *statements)
|
|
|
|
{
|
|
|
|
case_label_t **labels, **l;
|
|
|
|
case_label_t _default_label;
|
|
|
|
case_label_t *default_label = &_default_label;
|
|
|
|
expr_t *sw = new_block_expr ();
|
|
|
|
type_t *type = get_type (switch_block->test);
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
expr_t *sw_val = new_temp_def_expr (type);
|
2001-11-05 19:12:33 +00:00
|
|
|
expr_t *default_expr;
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
int num_labels = 0;
|
2001-12-12 21:50:11 +00:00
|
|
|
int saved_line = pr_source_line;
|
|
|
|
string_t saved_file = s_file;
|
2001-11-05 19:12:33 +00:00
|
|
|
|
2001-12-12 21:50:11 +00:00
|
|
|
pr_source_line = sw_val->line = switch_block->test->line;
|
|
|
|
s_file = sw_val->file = switch_block->test->file;
|
2001-12-06 19:49:40 +00:00
|
|
|
|
2001-10-25 06:41:52 +00:00
|
|
|
default_label->value = 0;
|
2001-11-06 20:39:42 +00:00
|
|
|
default_label = Hash_DelElement (switch_block->labels, default_label);
|
2001-12-06 19:49:40 +00:00
|
|
|
labels = (case_label_t **) Hash_GetList (switch_block->labels);
|
2001-10-25 06:41:52 +00:00
|
|
|
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
if (!default_label) {
|
|
|
|
default_label = &_default_label;
|
|
|
|
default_label->label = break_label;
|
|
|
|
}
|
|
|
|
default_expr = new_unary_expr ('g', default_label->label);
|
|
|
|
|
2001-11-13 18:49:27 +00:00
|
|
|
append_expr (sw, new_bind_expr (switch_block->test, sw_val));
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
|
|
|
|
for (l = labels; *l; l++)
|
|
|
|
num_labels++;
|
|
|
|
if (options.code.progsversion == PROG_ID_VERSION
|
2001-11-12 21:13:55 +00:00
|
|
|
|| (type != &type_string
|
2001-12-06 19:49:40 +00:00
|
|
|
&& type != &type_float && type != &type_integer)
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
|| num_labels < 8) {
|
|
|
|
for (l = labels; *l; l++) {
|
|
|
|
expr_t *cmp = binary_expr (EQ, sw_val, (*l)->value);
|
|
|
|
expr_t *test = new_binary_expr ('i',
|
|
|
|
test_expr (cmp, 1),
|
|
|
|
(*l)->label);
|
2001-12-06 19:49:40 +00:00
|
|
|
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
append_expr (sw, test);
|
|
|
|
}
|
2001-11-13 20:27:05 +00:00
|
|
|
append_expr (sw, default_expr);
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
} else {
|
2001-11-12 21:13:55 +00:00
|
|
|
expr_t *temp;
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
int op;
|
2001-11-13 08:58:54 +00:00
|
|
|
case_node_t *case_tree;
|
2001-11-12 21:13:55 +00:00
|
|
|
|
|
|
|
if (type == &type_string)
|
|
|
|
temp = new_temp_def_expr (&type_integer);
|
|
|
|
else
|
|
|
|
temp = new_temp_def_expr (type);
|
2001-11-14 06:45:31 +00:00
|
|
|
case_tree = build_case_tree (labels, num_labels, type == &type_integer);
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
switch (type->type) {
|
|
|
|
case ev_string:
|
|
|
|
op = NE;
|
|
|
|
break;
|
|
|
|
case ev_float:
|
|
|
|
op = '-';
|
|
|
|
break;
|
|
|
|
case ev_integer:
|
|
|
|
op = '-';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error (0, "internal compiler error in switch");
|
|
|
|
abort ();
|
|
|
|
}
|
2001-11-13 08:58:54 +00:00
|
|
|
build_switch (sw, case_tree, op, sw_val, temp, default_label->label);
|
2001-10-25 06:41:52 +00:00
|
|
|
}
|
2001-12-12 21:50:11 +00:00
|
|
|
pr_source_line = saved_line;
|
|
|
|
s_file = saved_file;
|
2001-10-25 06:41:52 +00:00
|
|
|
append_expr (sw, statements);
|
|
|
|
append_expr (sw, break_label);
|
|
|
|
return sw;
|
|
|
|
}
|