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
|
|
|
|
|
|
|
|
*/
|
2002-06-01 04:41:25 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2002-06-01 04:41:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2001-10-25 06:41:52 +00:00
|
|
|
#include <QF/hash.h>
|
|
|
|
#include <QF/sys.h>
|
|
|
|
|
2002-06-04 21:23:39 +00:00
|
|
|
#include "def.h"
|
2011-01-24 12:54:57 +00:00
|
|
|
#include "diagnostic.h"
|
2002-06-01 05:30:16 +00:00
|
|
|
#include "expr.h"
|
2002-06-04 21:23:39 +00:00
|
|
|
#include "opcodes.h"
|
2002-06-04 18:44:03 +00:00
|
|
|
#include "options.h"
|
2002-06-07 17:29:30 +00:00
|
|
|
#include "qfcc.h"
|
|
|
|
#include "reloc.h"
|
2001-10-25 06:41:52 +00:00
|
|
|
#include "switch.h"
|
2011-01-18 23:41:24 +00:00
|
|
|
#include "symtab.h"
|
2002-06-07 17:29:30 +00:00
|
|
|
#include "type.h"
|
|
|
|
|
2001-10-25 06:41:52 +00:00
|
|
|
#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;
|
|
|
|
|
2011-03-03 05:02:18 +00:00
|
|
|
static ex_value_t *
|
2011-01-18 23:41:24 +00:00
|
|
|
get_value (expr_t *e)
|
|
|
|
{
|
2011-03-03 05:02:18 +00:00
|
|
|
if (e->type == ex_symbol)
|
2012-07-18 14:01:09 +00:00
|
|
|
return e->e.symbol->s.value;
|
|
|
|
return e->e.value;
|
2011-01-18 23:41:24 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 11:22:48 +00:00
|
|
|
static uintptr_t
|
2012-07-18 13:34:37 +00:00
|
|
|
get_hash (const void *_cl, void *unused)
|
2001-10-25 06:41:52 +00:00
|
|
|
{
|
2001-12-06 19:49:40 +00:00
|
|
|
case_label_t *cl = (case_label_t *) _cl;
|
2011-03-03 05:02:18 +00:00
|
|
|
ex_value_t *val;
|
2001-10-25 06:41:52 +00:00
|
|
|
|
2004-05-15 01:00:47 +00:00
|
|
|
if (!cl->value)
|
|
|
|
return 0;
|
2011-03-03 05:02:18 +00:00
|
|
|
val = get_value (cl->value);
|
|
|
|
return Hash_Buffer (val, sizeof (*val));
|
2001-10-25 06:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-07-18 13:34:37 +00:00
|
|
|
compare (const void *_cla, const void *_clb, void *unused)
|
2001-10-25 06:41:52 +00:00
|
|
|
{
|
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;
|
2011-03-03 05:02:18 +00:00
|
|
|
ex_value_t *val1, *val2;
|
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;
|
2011-01-18 23:41:24 +00:00
|
|
|
if (extract_type (v1) != extract_type (v2))
|
2004-05-15 01:00:47 +00:00
|
|
|
return 0;
|
2011-01-18 23:41:24 +00:00
|
|
|
val1 = get_value (v1);
|
|
|
|
val2 = get_value (v1);
|
2011-03-03 05:02:18 +00:00
|
|
|
return memcmp (val1, val2, sizeof (*val1));
|
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
|
|
|
|
2011-02-05 13:32:23 +00:00
|
|
|
if (value)
|
|
|
|
convert_name (value);
|
2011-01-19 13:19:26 +00:00
|
|
|
if (value && !is_constant (value)) {
|
2001-10-25 06:41:52 +00:00
|
|
|
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;
|
|
|
|
}
|
2011-03-05 15:29:29 +00:00
|
|
|
if (!switch_block->test)
|
|
|
|
internal_error (value, "broken switch block");
|
|
|
|
if (value) {
|
|
|
|
type_t *type = get_type (switch_block->test);
|
|
|
|
type_t *val_type = get_type (value);
|
2012-05-04 09:13:11 +00:00
|
|
|
if (!type)
|
|
|
|
return 0;
|
2011-03-05 15:29:29 +00:00
|
|
|
if (!type_assignable (type, get_type (value)))
|
|
|
|
return error (value, "type mismatch in case label");
|
2011-03-06 02:41:01 +00:00
|
|
|
if (is_integral (type) && is_integral (val_type)) {
|
2011-03-30 10:58:09 +00:00
|
|
|
value = new_integer_expr (expr_integer (value));
|
2011-03-06 02:41:01 +00:00
|
|
|
debug (value, "integeral label used in integral switch");
|
|
|
|
} else if (is_integral (type) && is_float (val_type)) {
|
|
|
|
warning (value, "float label used in integral switch");
|
|
|
|
value = new_integer_expr (expr_float (value));
|
|
|
|
} else if (is_float (type) && is_integral (val_type)) {
|
|
|
|
debug (value, "integeral label used in float switch");
|
|
|
|
value = new_float_expr (expr_integer (value));
|
|
|
|
} else if (is_float (type) && is_float (val_type)) {
|
2011-03-30 10:58:09 +00:00
|
|
|
value = new_float_expr (expr_float (value));
|
2011-03-06 02:41:01 +00:00
|
|
|
debug (value, "float label used in float switch");
|
2011-03-05 15:29:29 +00:00
|
|
|
}
|
|
|
|
}
|
2001-10-25 06:41:52 +00:00
|
|
|
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;
|
|
|
|
|
2011-01-18 23:41:24 +00:00
|
|
|
if (is_string_val ((*a)->value)) {
|
|
|
|
s1 = expr_string ((*a)->value);
|
|
|
|
if (!s1)
|
|
|
|
s1 = "";
|
|
|
|
s2 = expr_string ((*b)->value);
|
|
|
|
if (!s2)
|
|
|
|
s2 = "";
|
|
|
|
return strcmp (s1, s2);
|
|
|
|
} else if (is_float_val ((*a)->value)) {
|
|
|
|
return expr_float ((*a)->value) - expr_float ((*b)->value);
|
|
|
|
} else if (is_integer_val ((*a)->value)) {
|
|
|
|
return expr_integer ((*a)->value) - expr_integer ((*b)->value);
|
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
|
|
|
}
|
2011-01-18 23:41:24 +00:00
|
|
|
internal_error (0, "in switch");
|
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
|
|
|
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
|
|
|
|
2012-10-26 10:02:02 +00:00
|
|
|
if (!is_integer_val (low))
|
|
|
|
internal_error (low, "switch");
|
2011-01-18 23:41:24 +00:00
|
|
|
size = expr_integer (high) - expr_integer (low) + 1;
|
2001-11-13 08:58:54 +00:00
|
|
|
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");
|
|
|
|
|
2011-01-18 23:41:24 +00:00
|
|
|
if (range && is_integer_val (labels[0]->value)) {
|
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++) {
|
2011-01-18 23:41:24 +00:00
|
|
|
if (expr_integer (labels[j]->value)
|
|
|
|
- expr_integer (labels[j - 1]->value) > 1)
|
2001-11-13 08:58:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
nodes[num_nodes] = new_case_node (labels[i]->value,
|
|
|
|
labels[j - 1]->value);
|
|
|
|
for (k = i; k < j; k++)
|
2011-01-18 23:41:24 +00:00
|
|
|
nodes[num_nodes]->labels[expr_integer (labels[k]->value)
|
|
|
|
- expr_integer (labels[i]->value)]
|
2001-11-13 08:58:54 +00:00
|
|
|
= 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) {
|
2011-03-03 06:28:49 +00:00
|
|
|
branch = goto_expr (default_label);
|
2001-11-13 20:27:05 +00:00
|
|
|
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) {
|
2011-03-05 15:29:29 +00:00
|
|
|
branch = branch_expr ('n', new_alias_expr (&type_integer, 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) {
|
2011-03-05 15:29:29 +00:00
|
|
|
branch = branch_expr (IFA, new_alias_expr (&type_integer, temp),
|
|
|
|
high_label);
|
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
|
|
|
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 {
|
2011-01-18 23:41:24 +00:00
|
|
|
int low = expr_integer (tree->low);
|
|
|
|
int high = expr_integer (tree->high);
|
2012-11-03 09:08:32 +00:00
|
|
|
symbol_t *table_sym;
|
|
|
|
expr_t *table_expr;
|
|
|
|
expr_t *table_init;
|
|
|
|
const char *table_name = new_label_name ();
|
2001-11-13 08:58:54 +00:00
|
|
|
int i;
|
|
|
|
expr_t *range = binary_expr ('-', tree->high, tree->low);
|
|
|
|
|
2011-01-18 23:41:24 +00:00
|
|
|
range = fold_constants (range);
|
2001-11-13 08:58:54 +00:00
|
|
|
|
2012-11-03 09:08:32 +00:00
|
|
|
table_init = new_block_expr ();
|
|
|
|
for (i = 0; i <= high - low; i++) {
|
|
|
|
tree->labels[i]->e.label.used++;
|
|
|
|
append_expr (table_init, address_expr (tree->labels[i], 0, 0));
|
|
|
|
}
|
|
|
|
table_sym = new_symbol (table_name);
|
|
|
|
initialize_def (table_sym, array_type (&type_integer, high - low + 1),
|
2012-12-02 01:11:30 +00:00
|
|
|
table_init, pr.near_data, sc_static);
|
2012-11-03 09:08:32 +00:00
|
|
|
table_expr = new_symbol_expr (table_sym);
|
|
|
|
table_expr = new_alias_expr (&type_integer, table_expr);
|
2001-11-13 08:58:54 +00:00
|
|
|
|
|
|
|
if (tree->left) {
|
2011-03-03 08:33:53 +00:00
|
|
|
branch = branch_expr (IFB, temp, low_label);
|
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
|
|
|
}
|
2011-04-09 01:07:47 +00:00
|
|
|
test = binary_expr (GT, cast_expr (&type_uinteger, temp),
|
|
|
|
cast_expr (&type_uinteger, range));
|
2011-03-03 06:28:49 +00:00
|
|
|
branch = branch_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);
|
2012-11-03 09:08:32 +00:00
|
|
|
branch = new_binary_expr ('g', table_expr, temp);
|
2001-11-13 08:58:54 +00:00
|
|
|
append_expr (sw, branch);
|
2012-11-24 08:55:57 +00:00
|
|
|
debug (sw, "switch using jump table");
|
2001-11-13 08:58:54 +00:00
|
|
|
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);
|
|
|
|
}
|
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;
|
2002-07-03 21:32:03 +00:00
|
|
|
int saved_line = pr.source_line;
|
|
|
|
string_t saved_file = pr.source_file;
|
2001-11-05 19:12:33 +00:00
|
|
|
|
2002-07-03 21:32:03 +00:00
|
|
|
pr.source_line = sw_val->line = switch_block->test->line;
|
|
|
|
pr.source_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;
|
|
|
|
}
|
|
|
|
|
2011-01-21 10:07:58 +00:00
|
|
|
append_expr (sw, assign_expr (sw_val, 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
|
|
|
|
|
|
|
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);
|
2011-03-03 06:28:49 +00:00
|
|
|
expr_t *test = branch_expr ('i', test_expr (cmp),
|
|
|
|
(*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);
|
|
|
|
}
|
2012-11-24 12:53:00 +00:00
|
|
|
default_expr = goto_expr (default_label->label);
|
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:
|
2012-10-26 10:02:02 +00:00
|
|
|
internal_error (0, "in switch");
|
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, case_tree, op, sw_val, temp, default_label->label);
|
2001-10-25 06:41:52 +00:00
|
|
|
}
|
2002-07-03 21:32:03 +00:00
|
|
|
pr.source_line = saved_line;
|
|
|
|
pr.source_file = saved_file;
|
2001-10-25 06:41:52 +00:00
|
|
|
append_expr (sw, statements);
|
|
|
|
append_expr (sw, break_label);
|
|
|
|
return sw;
|
|
|
|
}
|