#define GENSEL_PATT_CLOBBER 12
#define GENSEL_PATT_IF 13
#define GENSEL_PATT_SPACE 14
+#define GENSEL_PATT_ANY 15
/*
* Register flags.
int other_regs_mask;
int imms, max_imms;
int have_local;
- int scratch, max_scratch;
+ int scratch, others;
int have_clobber;
- int others;
max_regs = 0;
other_regs_mask = 0;
max_imms = 0;
have_local = 0;
- max_scratch = 0;
have_clobber = 0;
while(clauses != 0)
{
{
switch(pattern->option)
{
+ case GENSEL_PATT_ANY:
+ ++others;
+ break;
+
case GENSEL_PATT_REG:
case GENSEL_PATT_FREG:
++regs;
clauses->linenum,
"too many scratch args in the pattern");
}
- if(max_regs < regs)
+ if(max_regs < (regs + scratch))
{
- max_regs = regs;
+ max_regs = regs + scratch;
}
if(max_imms < imms)
{
max_imms = imms;
}
- if(max_scratch < scratch)
- {
- max_scratch = scratch;
- }
clauses = clauses->next;
}
- switch(max_regs)
+ if(max_regs > 0)
{
- case 1:
- printf("\tint reg;\n");
- break;
- case 2:
- printf("\tint reg, reg2;\n");
- break;
- case 3:
- printf("\tint reg, reg2, reg3;\n");
- break;
+ printf("\tint reg");
+ for(scratch = 1; scratch < max_regs; scratch++)
+ {
+ printf(", reg%d", scratch + 1);
+ }
+ printf(";\n");
}
if(other_regs_mask)
{
printf("\tint other_reg3;\n");
break;
case 5:
- printf("\tint other_reg, othre_reg3;\n");
+ printf("\tint other_reg, other_reg3;\n");
break;
case 6:
- printf("\tint other_reg2, othre_reg3;\n");
+ printf("\tint other_reg2, other_reg3;\n");
break;
case 7:
- printf("\tint other_reg, other_reg2, othre_reg3;\n");
+ printf("\tint other_reg, other_reg2, other_reg3;\n");
break;
}
}
printf("\tjit_nint imm_value, imm_value2, imm_value3;\n");
break;
}
- for(scratch = 0; scratch < max_scratch; scratch++)
- {
- if((scratch + max_regs) == 0)
- {
- printf("\tint reg;\n");
- }
- else
- {
- printf("\tint reg%d;\n", scratch + max_regs + 1);
- }
- }
if(have_local)
{
printf("\tjit_nint local_offset;\n");
{
switch(pattern->option)
{
+ case GENSEL_PATT_ANY:
+ ++index;
+ break;
+
case GENSEL_PATT_REG:
case GENSEL_PATT_FREG:
names[index] = gensel_reg_names[regs];
* Output the code.
*/
static void
-gensel_output_code(gensel_option_t pattern, char *code)
+gensel_output_code(gensel_option_t pattern, char *code, int in_line)
{
char *names[9];
char *other_names[9];
gensel_build_index(pattern, names, other_names);
/* Output the clause code */
- printf("\t\t");
+ if(!in_line)
+ {
+ printf("\t\t");
+ }
while(*code != '\0')
{
if(*code == '$' && code[1] >= '1' && code[1] <= '9')
++code;
}
}
- printf("\n");
+ if(!in_line)
+ {
+ printf("\n");
+ }
}
/*
/* Output the line number information from the original file */
printf("#line %ld \"%s\"\n", clause->linenum, clause->filename);
- gensel_output_code(clause->pattern, clause->code);
+ gensel_output_code(clause->pattern, clause->code, 0);
}
/*
if(space && space->values && space->values->value)
{
printf("(");
- gensel_output_code(clause->pattern, space->values->value);
+ gensel_output_code(clause->pattern, space->values->value, 1);
printf(")");
}
else
index = 0;
seen_option = 0;
pattern = clause->pattern;
- while(pattern && index < MAX_INPUT)
+ while(pattern)
{
switch(pattern->option)
{
+ case GENSEL_PATT_ANY:
+ ++index;
+ break;
+
case GENSEL_PATT_REG:
case GENSEL_PATT_LREG:
case GENSEL_PATT_FREG:
printf(" && ");
}
printf("(");
- gensel_output_code(clause->pattern, pattern->values->value);
+ gensel_output_code(clause->pattern, pattern->values->value, 1);
printf(")");
seen_option = 1;
break;
regs = 0;
index = 0;
pattern = clause->pattern;
- while(pattern && index < MAX_INPUT)
+ while(pattern)
{
switch(pattern->option)
{
+ case GENSEL_PATT_ANY:
+ ++index;
+ break;
+
case GENSEL_PATT_REG:
case GENSEL_PATT_FREG:
if(pattern->values && pattern->values->value)
{
printf("\t\t%s = _jit_regs_lookup(\"%s\")];\n",
gensel_reg_names[regs],
- pattern->values->value);
- printf("\t\t_jit_regs_set_scratch(®s, clobber);\n");
+ values->value);
+ printf("\t\t_jit_regs_set_scratch(®s, %s);\n",
+ gensel_reg_names[regs]);
}
else
{
{
if(values->value && strcmp(values->value, "*") != 0)
{
- printf("\t\tclobber = _jit_regs_lookup(\"%s\")];\n",
- pattern->values->value);
+ printf("\t\tclobber = _jit_regs_lookup(\"%s\");\n",
+ values->value);
printf("\t\t_jit_regs_set_clobber(®s, clobber);\n");
}
values = values->next;
index = 0;
scratch = 0;
pattern = clause->pattern;
- while(pattern && index < MAX_INPUT)
+ while(pattern)
{
switch(pattern->option)
{
+ case GENSEL_PATT_ANY:
+ ++index;
+ break;
+
case GENSEL_PATT_REG:
case GENSEL_PATT_FREG:
printf("\t\t%s = _jit_reg_info[_jit_regs_%s(®s)].cpu_reg;\n",
%token CODE_BLOCK "a code block"
%token LITERAL "literal string"
%token K_PTR "`->'"
+%token K_ANY "any variable"
%token K_REG "word register"
%token K_LREG "long register"
%token K_FREG "float register"
| K_IMMS16 { $$ = GENSEL_PATT_IMMS16; }
| K_IMMU16 { $$ = GENSEL_PATT_IMMU16; }
| K_LOCAL { $$ = GENSEL_PATT_LOCAL; }
+ | K_ANY { $$ = GENSEL_PATT_ANY; }
;
RegTag