Use the new syntax in the mips, pdp, powerpc tables to declare functions before calling them. These declarations prevent compiler warnings about implicitly declaring functions. They also provide prototypes of the function parameters. Also fix a warning in the powerpc table: use `bsearch(...) != NULL` to avoid converting the pointer from bsearch() to an int. The syntax for topgen is a block `{...}` among the parameters in the top table. It looks like the syntax of LLgen, but topgen doesn't allow nested blocks, so declarations like `struct whatever {...};` don't work. The token OPEN_BRACKET that begins a declaration_block doesn't conflict with the LETTER that begins a parameter_line or the '%' that begins a separator. Because a block writes a #line command to gen.h, a parameter line now also writes a #line command to gen.h, so it doesn't get a wrong line number from a previous block.
51 lines
1 KiB
Text
51 lines
1 KiB
Text
|
|
/* MIPS table for ACK target optimizer */
|
|
|
|
MAXOP 5;
|
|
LABEL_STARTER '.';
|
|
|
|
{
|
|
int plus(const char *, const char *, const char *);
|
|
}
|
|
|
|
%%;
|
|
|
|
X, Y, Z { TRUE };
|
|
R { TRUE };
|
|
|
|
%%;
|
|
|
|
/* Whitespace is significant here! */
|
|
|
|
addiu R, R, X : addiu R, R, Y { plus(X, Y, Z) } -> addiu R, R, Z ;
|
|
|
|
addiu X, X, 0 -> ;
|
|
|
|
b X : nop : labdef X -> labdef X ;
|
|
|
|
%%;
|
|
|
|
/* Does it fit a signed 16-bit integer? */
|
|
static int fits16(long l) {
|
|
return l >= -32768 && l <= 32767;
|
|
}
|
|
|
|
/* Tries sum = a + b with signed 16-bit integers. */
|
|
int plus(const char *a, const char *b, const char *sum)
|
|
{
|
|
long la, lb, lsum;
|
|
char *end;
|
|
|
|
la = strtol(a, &end, 10);
|
|
if (*a == '\0' || *end != '\0' || !fits16(la))
|
|
return 0;
|
|
lb = strtol(b, &end, 10);
|
|
if (*b == '\0' || *end != '\0' || !fits16(lb))
|
|
return 0;
|
|
|
|
lsum = la + lb;
|
|
if (!fits16(lsum))
|
|
return 0;
|
|
snprintf(sum, 7, "%ld", lsum);
|
|
return 1;
|
|
}
|