it helps if one understands /why/ something is done. I think this
	might be it for the reference count tweeks
switch.c:
	o	better control over whether case ranges are built
	o	/always/ append the temp = test expression and use temp instead of
		test for the != check
	o	only ever build case ranges if the switch expression is integer
This commit is contained in:
Bill Currie 2001-11-14 06:45:31 +00:00
parent dc80f51d89
commit 3fe67eecd2
2 changed files with 7 additions and 11 deletions

View file

@ -888,13 +888,11 @@ binary_expr (int op, expr_t *e1, expr_t *e2)
if (op == '=' && e1->type == ex_def) if (op == '=' && e1->type == ex_def)
PR_DefInitialized (e1->e.def); PR_DefInitialized (e1->e.def);
if (op == '=')
inc_users (e1);
if (e1->type == ex_block && e1->e.block.is_call if (e1->type == ex_block && e1->e.block.is_call
&& e2->type == ex_block && e2->e.block.is_call && e2->type == ex_block && e2->e.block.is_call
&& e1->e.block.result) { && e1->e.block.result) {
e = new_temp_def_expr (e1->e.block.result->e.def->type); e = new_temp_def_expr (e1->e.block.result->e.def->type);
inc_users (e); // for the block itself
e1 = binary_expr ('=', e, e1); e1 = binary_expr ('=', e, e1);
} }
@ -1365,7 +1363,7 @@ incop_expr (int op, expr_t *e, int postop)
{ {
expr_t *one = new_expr (); expr_t *one = new_expr ();
expr_t *incop; expr_t *incop;
one->type = ex_integer; // integer constants get auto-cast to float one->type = ex_integer; // integer constants get auto-cast to float
one->e.integer_val = 1; one->e.integer_val = 1;
incop = asx_expr (op, e, one); incop = asx_expr (op, e, one);
@ -1376,7 +1374,6 @@ incop_expr (int op, expr_t *e, int postop)
temp = new_temp_def_expr (type); temp = new_temp_def_expr (type);
append_expr (block, binary_expr ('=', temp, e)); append_expr (block, binary_expr ('=', temp, e));
temp->e.temp.users = 1;
append_expr (block, incop); append_expr (block, incop);
block->e.block.result = temp; block->e.block.result = temp;
return block; return block;

View file

@ -181,7 +181,7 @@ balance_case_tree (case_node_t **nodes, int base, int count)
} }
static case_node_t * static case_node_t *
build_case_tree (case_label_t **labels, int count) build_case_tree (case_label_t **labels, int count, int range)
{ {
case_node_t **nodes; case_node_t **nodes;
int i, j, k; int i, j, k;
@ -193,7 +193,7 @@ build_case_tree (case_label_t **labels, int count)
if (!nodes) if (!nodes)
Sys_Error ("out of memory"); Sys_Error ("out of memory");
if (labels[0]->value->type == ex_integer) { if (range && labels[0]->value->type == ex_integer) {
for (i = 0; i < count - 1; i = j, num_nodes++) { for (i = 0; i < count - 1; i = j, num_nodes++) {
for (j = i + 1; j < count; j++) { for (j = i + 1; j < count; j++) {
if (labels[j]->value->e.integer_val if (labels[j]->value->e.integer_val
@ -258,9 +258,10 @@ build_switch (expr_t *sw, case_node_t *tree, int op, expr_t *sw_val,
test = binary_expr ('=', temp, test); test = binary_expr ('=', temp, test);
test->line = sw_val->line; test->line = sw_val->line;
test->file = sw_val->file; test->file = sw_val->file;
append_expr (sw, test);
if (tree->low == tree->high) { if (tree->low == tree->high) {
branch = new_binary_expr ('n', test, tree->labels[0]); branch = new_binary_expr ('n', temp, tree->labels[0]);
branch->line = sw_val->line; branch->line = sw_val->line;
branch->file = sw_val->file; branch->file = sw_val->file;
append_expr (sw, branch); append_expr (sw, branch);
@ -296,8 +297,6 @@ build_switch (expr_t *sw, case_node_t *tree, int op, expr_t *sw_val,
table->type = ex_def; table->type = ex_def;
table->e.def = def; table->e.def = def;
append_expr (sw, test);
if (tree->left) { if (tree->left) {
branch = new_binary_expr (IFB, temp, low_label); branch = new_binary_expr (IFB, temp, low_label);
branch->line = sw_val->line; branch->line = sw_val->line;
@ -391,7 +390,7 @@ switch_expr (switch_block_t *switch_block, expr_t *break_label,
temp = new_temp_def_expr (&type_integer); temp = new_temp_def_expr (&type_integer);
else else
temp = new_temp_def_expr (type); temp = new_temp_def_expr (type);
case_tree = build_case_tree (labels, num_labels); case_tree = build_case_tree (labels, num_labels, type == &type_integer);
switch (type->type) { switch (type->type) {
case ev_string: case ev_string:
op = NE; op = NE;