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>
|
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "tools/qfcc/include/def.h"
|
|
|
|
#include "tools/qfcc/include/diagnostic.h"
|
|
|
|
#include "tools/qfcc/include/expr.h"
|
|
|
|
#include "tools/qfcc/include/opcodes.h"
|
|
|
|
#include "tools/qfcc/include/options.h"
|
|
|
|
#include "tools/qfcc/include/qfcc.h"
|
|
|
|
#include "tools/qfcc/include/reloc.h"
|
2022-01-24 03:48:02 +00:00
|
|
|
#include "tools/qfcc/include/shared.h"
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "tools/qfcc/include/switch.h"
|
|
|
|
#include "tools/qfcc/include/symtab.h"
|
|
|
|
#include "tools/qfcc/include/type.h"
|
|
|
|
|
|
|
|
#include "tools/qfcc/source/qc-parse.h"
|
2001-10-25 06:41:52 +00:00
|
|
|
|
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;
|
|
|
|
|
2018-10-09 03:35:01 +00:00
|
|
|
static __attribute__((pure)) 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;
|
2013-06-25 23:40:25 +00:00
|
|
|
if (e->type != ex_value)
|
|
|
|
internal_error (e, "bogus case label");
|
2012-07-18 14:01:09 +00:00
|
|
|
return e->e.value;
|
2011-01-18 23:41:24 +00:00
|
|
|
}
|
|
|
|
|
2018-10-09 03:35:01 +00:00
|
|
|
static __attribute__((pure)) 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);
|
2018-10-12 13:05:17 +00:00
|
|
|
return Hash_Buffer (&val->v, sizeof (val->v)) + val->lltype;
|
2001-10-25 06:41:52 +00:00
|
|
|
}
|
|
|
|
|
2020-03-13 10:58:07 +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);
|
2013-06-25 23:40:25 +00:00
|
|
|
val2 = get_value (v2);
|
|
|
|
if (val1->type != val2->type)
|
|
|
|
return 0;
|
|
|
|
return memcmp (&val1->v, &val2->v, sizeof (val1->v)) == 0;
|
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)) {
|
2022-01-18 04:21:06 +00:00
|
|
|
value = new_int_expr (expr_int (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");
|
2022-01-18 04:21:06 +00:00
|
|
|
value = new_int_expr (expr_float (value));
|
2011-03-06 02:41:01 +00:00
|
|
|
} else if (is_float (type) && is_integral (val_type)) {
|
|
|
|
debug (value, "integeral label used in float switch");
|
2022-01-18 04:21:06 +00:00
|
|
|
value = new_float_expr (expr_int (value));
|
2011-03-06 02:41:01 +00:00
|
|
|
} 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);
|
2020-03-25 06:43:16 +00:00
|
|
|
switch_block->labels = Hash_NewTable (127, 0, 0, 0, 0);
|
2001-10-25 06:41:52 +00:00
|
|
|
Hash_SetHashCompare (switch_block->labels, get_hash, compare);
|
|
|
|
switch_block->test = 0;
|
|
|
|
return switch_block;
|
|
|
|
}
|
|
|
|
|
2018-10-09 03:35:01 +00:00
|
|
|
static __attribute__((pure)) int
|
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
|
|
|
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);
|
2022-01-18 04:21:06 +00:00
|
|
|
} else if (is_int_val ((*a)->value)) {
|
|
|
|
return expr_int ((*a)->value) - expr_int ((*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
|
|
|
|
2022-01-18 04:21:06 +00:00
|
|
|
if (!is_int_val (low))
|
2012-10-26 10:02:02 +00:00
|
|
|
internal_error (low, "switch");
|
2022-01-18 04:21:06 +00:00
|
|
|
size = expr_int (high) - expr_int (low) + 1;
|
2018-09-07 11:00:57 +00:00
|
|
|
node->labels = calloc (size, sizeof (expr_t *));
|
2001-11-13 08:58:54 +00:00
|
|
|
}
|
|
|
|
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");
|
|
|
|
|
2022-01-18 04:21:06 +00:00
|
|
|
if (range && is_int_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++) {
|
2022-01-18 04:21:06 +00:00
|
|
|
if (expr_int (labels[j]->value)
|
|
|
|
- expr_int (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++)
|
2022-01-18 04:21:06 +00:00
|
|
|
nodes[num_nodes]->labels[expr_int (labels[k]->value)
|
|
|
|
- expr_int (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) {
|
2022-01-18 04:21:06 +00:00
|
|
|
branch = branch_expr (EQ, new_alias_expr (&type_int, temp),
|
2011-03-05 15:29:29 +00:00
|
|
|
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) {
|
2022-01-18 04:21:06 +00:00
|
|
|
branch = branch_expr (GT, new_alias_expr (&type_int, temp),
|
2011-03-05 15:29:29 +00:00
|
|
|
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 {
|
2022-01-18 04:21:06 +00:00
|
|
|
int low = expr_int (tree->low);
|
|
|
|
int high = expr_int (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);
|
2020-03-11 14:52:12 +00:00
|
|
|
expr_t *label;
|
2001-11-13 08:58:54 +00:00
|
|
|
|
2020-03-11 14:52:12 +00:00
|
|
|
table_init = new_compound_init ();
|
2012-11-03 09:08:32 +00:00
|
|
|
for (i = 0; i <= high - low; i++) {
|
|
|
|
tree->labels[i]->e.label.used++;
|
2020-03-11 14:52:12 +00:00
|
|
|
label = address_expr (tree->labels[i], 0, 0);
|
|
|
|
append_element (table_init, new_element (label, 0));
|
2012-11-03 09:08:32 +00:00
|
|
|
}
|
2018-10-15 13:11:20 +00:00
|
|
|
table_sym = new_symbol_type (table_name,
|
2022-01-18 04:21:06 +00:00
|
|
|
array_type (&type_int,
|
2018-10-15 13:11:20 +00:00
|
|
|
high - low + 1));
|
2022-01-24 03:48:02 +00:00
|
|
|
initialize_def (table_sym, table_init, pr.near_data, sc_static,
|
|
|
|
current_symtab);
|
2012-11-03 09:08:32 +00:00
|
|
|
table_expr = new_symbol_expr (table_sym);
|
2001-11-13 08:58:54 +00:00
|
|
|
|
|
|
|
if (tree->left) {
|
2022-01-09 05:02:16 +00:00
|
|
|
branch = branch_expr (LT, 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
|
|
|
}
|
2022-01-18 04:21:06 +00:00
|
|
|
test = binary_expr (GT, cast_expr (&type_uint, temp),
|
|
|
|
cast_expr (&type_uint, range));
|
2022-01-09 05:02:16 +00:00
|
|
|
branch = branch_expr (NE, 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);
|
2022-01-09 05:02:16 +00:00
|
|
|
branch = jump_table_expr (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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-25 05:21:43 +00:00
|
|
|
static void
|
|
|
|
check_enum_switch (switch_block_t *switch_block)
|
|
|
|
{
|
|
|
|
case_label_t cl;
|
|
|
|
symbol_t *enum_val;
|
|
|
|
type_t *type = get_type (switch_block->test);
|
|
|
|
|
|
|
|
for (enum_val = type->t.symtab->symbols; enum_val;
|
|
|
|
enum_val = enum_val->next) {
|
2022-01-18 04:21:06 +00:00
|
|
|
cl.value = new_int_expr (enum_val->s.value->v.int_val);
|
2013-06-25 05:21:43 +00:00
|
|
|
if (!Hash_FindElement (switch_block->labels, &cl)) {
|
|
|
|
warning (switch_block->test,
|
|
|
|
"enumeration value `%s' not handled in switch",
|
|
|
|
enum_val->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2021-12-26 15:47:35 +00:00
|
|
|
if (switch_block->test->type == ex_error) {
|
|
|
|
return switch_block->test;
|
|
|
|
}
|
|
|
|
|
2001-10-25 06:41:52 +00:00
|
|
|
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;
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_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;
|
2013-06-26 00:08:51 +00:00
|
|
|
if (options.warnings.enum_switch && is_enum (type))
|
2013-06-25 05:21:43 +00:00
|
|
|
check_enum_switch (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
|
|
|
}
|
|
|
|
|
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
|
2020-03-27 06:16:41 +00:00
|
|
|
|| (!is_string(type) && !is_float(type) && !is_integral (type))
|
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);
|
2022-01-09 05:02:16 +00:00
|
|
|
expr_t *test = branch_expr (NE, test_expr (cmp),
|
2011-03-03 06:28:49 +00:00
|
|
|
(*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
|
|
|
|
2020-03-27 06:16:41 +00:00
|
|
|
if (is_string(type))
|
2022-01-18 04:21:06 +00:00
|
|
|
temp = new_temp_def_expr (&type_int);
|
2001-11-12 21:13:55 +00:00
|
|
|
else
|
|
|
|
temp = new_temp_def_expr (type);
|
2013-06-25 03:09:13 +00:00
|
|
|
case_tree = build_case_tree (labels, num_labels, is_integral (type));
|
|
|
|
op = '-';
|
|
|
|
if (type->type == ev_string)
|
|
|
|
op = NE;
|
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;
|
|
|
|
}
|