1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1987-03-09 19:15:41 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1985-04-12 16:56:43 +00:00
|
|
|
/* @(#)comm2.y 1.7 */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* delay inclusion of machine dependent stuff (see comm0.h)
|
|
|
|
*/
|
|
|
|
#define _include #include
|
|
|
|
|
|
|
|
%{
|
|
|
|
#include "comm0.h"
|
|
|
|
#include "comm1.h"
|
1990-07-30 09:43:45 +00:00
|
|
|
|
|
|
|
static item_t *last_it, *o_it;
|
1985-04-12 16:56:43 +00:00
|
|
|
%}
|
|
|
|
|
|
|
|
/* ========== Machine independent Yacc definitions ========== */
|
|
|
|
|
|
|
|
%union {
|
|
|
|
word_t y_word;
|
|
|
|
valu_t y_valu;
|
|
|
|
expr_t y_expr;
|
|
|
|
item_t *y_item;
|
|
|
|
#ifdef ASLD
|
|
|
|
char *y_strp;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef ASLD
|
|
|
|
%token <y_strp> MODULE
|
|
|
|
#endif
|
|
|
|
%token STRING
|
|
|
|
%token <y_item> IDENT
|
|
|
|
%token <y_item> FBSYM
|
|
|
|
%token <y_valu> CODE1
|
|
|
|
%token <y_valu> CODE2
|
|
|
|
%token <y_valu> CODE4
|
2019-08-13 15:47:44 +00:00
|
|
|
%token NUMBER0 /* keep NUMBER[0-4] in this order */
|
1985-04-12 16:56:43 +00:00
|
|
|
%token NUMBER1
|
|
|
|
%token NUMBER2
|
|
|
|
%token NUMBER3
|
2019-08-13 15:47:44 +00:00
|
|
|
%token NUMBER4
|
2019-10-04 22:58:56 +00:00
|
|
|
%token <y_valu> NUMBER8
|
2018-09-10 20:56:18 +00:00
|
|
|
%token NUMBERF
|
1985-04-12 16:56:43 +00:00
|
|
|
%token DOT
|
|
|
|
%token EXTERN
|
|
|
|
%token <y_word> DATA
|
2019-08-13 15:47:44 +00:00
|
|
|
%token DATA8
|
2018-09-10 20:56:18 +00:00
|
|
|
%token <y_word> DATAF
|
1985-04-12 16:56:43 +00:00
|
|
|
%token <y_word> ASCII
|
|
|
|
%token SECTION
|
|
|
|
%token COMMON
|
|
|
|
%token BASE
|
|
|
|
%token SYMB
|
1990-07-30 09:43:45 +00:00
|
|
|
%token SYMD
|
1985-04-12 16:56:43 +00:00
|
|
|
%token ALIGN
|
|
|
|
%token ASSERT
|
|
|
|
%token SPACE
|
|
|
|
%token <y_word> LINE
|
|
|
|
%token FILe
|
|
|
|
%token <y_word> LIST
|
|
|
|
|
|
|
|
%left OP_OO
|
|
|
|
%left OP_AA
|
|
|
|
%left '|'
|
|
|
|
%left '^'
|
|
|
|
%left '&'
|
|
|
|
%left OP_EQ OP_NE
|
|
|
|
%left '<' '>' OP_LE OP_GE
|
|
|
|
%left OP_LL OP_RR
|
|
|
|
%left '+' '-'
|
2019-08-13 15:47:44 +00:00
|
|
|
%left '*' '/' '%'
|
1985-04-12 16:56:43 +00:00
|
|
|
%nonassoc '~'
|
|
|
|
|
|
|
|
%type <y_valu> absexp optabs1 optabs2
|
|
|
|
%type <y_expr> expr
|
|
|
|
%type <y_item> id_fb
|
|
|
|
|
|
|
|
/* ========== Machine dependent Yacc definitions ========== */
|
|
|
|
|
|
|
|
#include "mach2.c"
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
/* ========== Machine independent rules ========== */
|
|
|
|
|
|
|
|
#ifdef LISTING
|
1991-01-11 14:20:59 +00:00
|
|
|
#define LISTLINE(n) if (listflag) listline(n); \
|
|
|
|
else if (listtemp) { listflag = listtemp; listeoln = 1; }
|
1985-04-12 16:56:43 +00:00
|
|
|
#else
|
|
|
|
#define LISTLINE(n) /* empty */
|
1991-12-17 15:05:43 +00:00
|
|
|
#endif /* LISTING */
|
1985-04-12 16:56:43 +00:00
|
|
|
|
|
|
|
#ifdef ASLD
|
|
|
|
#define RELODONE /* empty */
|
|
|
|
#else
|
|
|
|
#define RELODONE assert(relonami == 0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
program : /* empty */
|
|
|
|
#ifdef ASLD
|
|
|
|
| program MODULE /* not in PASS_1 */
|
|
|
|
{ newmodule($2);}
|
|
|
|
#endif
|
|
|
|
| program IDENT ':'
|
|
|
|
{ newident($2, DOTTYP); newlabel($2);}
|
2019-08-13 15:47:44 +00:00
|
|
|
| program NUMBER8 ':'
|
1985-04-12 16:56:43 +00:00
|
|
|
{ if ($2 < 0 || $2 > 9) {
|
|
|
|
serror("bad f/b label");
|
|
|
|
$2 = 0;
|
|
|
|
}
|
|
|
|
newlabel(fb_shift((int)$2));
|
|
|
|
}
|
|
|
|
| program CODE1
|
1989-01-19 13:48:09 +00:00
|
|
|
{ emit1((int)$2); LISTLINE(0);}
|
1985-04-12 16:56:43 +00:00
|
|
|
| program CODE2
|
1989-01-19 13:48:09 +00:00
|
|
|
{ emit2((int)$2); LISTLINE(0);}
|
1985-04-12 16:56:43 +00:00
|
|
|
| program CODE4
|
|
|
|
{ emit4((long)$2); LISTLINE(0);}
|
|
|
|
| program operation ';'
|
|
|
|
| program operation '\n'
|
|
|
|
{ lineno++; LISTLINE(1); RELODONE;}
|
2019-08-13 15:47:44 +00:00
|
|
|
| program '#' NUMBER8 STRING '\n'
|
|
|
|
{ lineno = $3; /* long = int64_t */
|
1990-08-01 14:30:45 +00:00
|
|
|
if (modulename) strncpy(modulename, stringbuf, STRINGMAX-1);
|
1989-01-19 13:48:09 +00:00
|
|
|
LISTLINE(1); RELODONE;
|
|
|
|
}
|
1985-04-12 16:56:43 +00:00
|
|
|
| program error '\n'
|
|
|
|
{ serror("syntax error"); yyerrok;
|
|
|
|
lineno++; LISTLINE(1); RELODONE;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
#undef LISTLINE
|
|
|
|
#undef RELODONE
|
|
|
|
operation
|
|
|
|
: /* empty */
|
|
|
|
| IDENT '=' expr
|
|
|
|
{
|
|
|
|
#ifdef LISTING
|
|
|
|
if (listflag & 1)
|
|
|
|
listcolm += printx(VALWIDTH, $3.val);
|
|
|
|
#endif
|
|
|
|
newequate($1, $3.typ);
|
|
|
|
store($1, $3.val);
|
|
|
|
}
|
|
|
|
#ifdef LISTING
|
|
|
|
| LIST
|
|
|
|
{ if ($1)
|
|
|
|
listtemp = listmode;
|
|
|
|
else if ((dflag & 01000) == 0)
|
|
|
|
listtemp = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
| SECTION IDENT
|
|
|
|
{ newsect($2);}
|
|
|
|
| COMMON IDENT ',' absexp
|
|
|
|
{ newcomm($2, $4);}
|
|
|
|
| BASE absexp
|
|
|
|
{ if (pass == PASS_1) newbase($2);}
|
|
|
|
| ASSERT expr
|
|
|
|
{ if ($2.val == 0 && pass == PASS_3)
|
|
|
|
warning("assertion failed");
|
|
|
|
}
|
1990-07-30 09:43:45 +00:00
|
|
|
| SYMB STRING ',' expr { o_it = last_it; }
|
|
|
|
optabs2 optabs2
|
1985-04-12 16:56:43 +00:00
|
|
|
{ if ((sflag & SYM_SMB) && PASS_SYMB) {
|
|
|
|
#ifndef ASLD
|
|
|
|
if (
|
|
|
|
pass == PASS_3
|
|
|
|
&&
|
|
|
|
($4.typ & S_TYP) == S_UND
|
|
|
|
) {
|
|
|
|
serror("expression undefined");
|
|
|
|
relonami = -1;
|
|
|
|
}
|
1990-07-30 09:43:45 +00:00
|
|
|
if (
|
|
|
|
PASS_SYMB
|
|
|
|
&&
|
|
|
|
($4.typ & S_COM)
|
|
|
|
) {
|
|
|
|
/* No value is known at
|
|
|
|
assembler time.
|
|
|
|
Generate reference to other
|
|
|
|
entry in name table
|
|
|
|
*/
|
|
|
|
$4.typ = S_CRS;
|
|
|
|
$4.val = new_string(o_it->i_name);
|
|
|
|
relonami = 0;
|
|
|
|
}
|
1985-04-12 16:56:43 +00:00
|
|
|
#endif
|
1990-07-30 09:43:45 +00:00
|
|
|
|
1985-04-12 16:56:43 +00:00
|
|
|
newsymb(
|
1990-08-01 14:30:45 +00:00
|
|
|
*stringbuf ? stringbuf : (char *) 0,
|
1985-04-12 16:56:43 +00:00
|
|
|
(short)(
|
|
|
|
($4.typ & (S_EXT|S_TYP))
|
|
|
|
|
|
1991-12-16 15:24:24 +00:00
|
|
|
((unsigned short)$6<<8)
|
1985-04-12 16:56:43 +00:00
|
|
|
),
|
1990-07-30 09:43:45 +00:00
|
|
|
(short)$7,
|
1985-04-12 16:56:43 +00:00
|
|
|
$4.val
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
1990-07-30 09:43:45 +00:00
|
|
|
| SYMD STRING ',' absexp ',' absexp
|
|
|
|
{ if ((sflag & SYM_SMB) && PASS_SYMB) {
|
|
|
|
newsymb(
|
1990-08-01 14:30:45 +00:00
|
|
|
*stringbuf ? stringbuf : (char *) 0,
|
1990-07-30 09:43:45 +00:00
|
|
|
(short)(
|
|
|
|
(DOTTYP & (S_EXT|S_TYP))
|
|
|
|
|
|
1991-12-16 15:24:24 +00:00
|
|
|
((unsigned short)$4<<8)
|
1990-07-30 09:43:45 +00:00
|
|
|
),
|
|
|
|
(short)$6,
|
|
|
|
(valu_t)DOTVAL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
1985-04-12 16:56:43 +00:00
|
|
|
| LINE optabs1
|
|
|
|
{ if ((sflag & SYM_LIN) && PASS_SYMB) {
|
|
|
|
if ($2)
|
|
|
|
hllino = (short)$2;
|
|
|
|
else
|
|
|
|
hllino++;
|
|
|
|
newsymb(
|
|
|
|
(char *)0,
|
1991-01-11 14:20:59 +00:00
|
|
|
(DOTTYP | S_LIN),
|
|
|
|
hllino,
|
1985-04-12 16:56:43 +00:00
|
|
|
(valu_t)DOTVAL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
| FILe STRING
|
|
|
|
{ if ((sflag & SYM_LIN) && PASS_SYMB) {
|
|
|
|
hllino = 0;
|
|
|
|
newsymb(
|
1990-08-01 14:30:45 +00:00
|
|
|
stringbuf,
|
1991-01-11 14:20:59 +00:00
|
|
|
(DOTTYP | S_FIL),
|
|
|
|
0,
|
1985-04-12 16:56:43 +00:00
|
|
|
(valu_t)DOTVAL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
| EXTERN externlist
|
|
|
|
| ALIGN optabs1
|
|
|
|
{ align($2);}
|
|
|
|
| SPACE absexp
|
|
|
|
{ if (DOTSCT == NULL)
|
|
|
|
nosect();
|
|
|
|
DOTVAL += $2;
|
|
|
|
DOTSCT->s_zero += $2;
|
|
|
|
}
|
|
|
|
| DATA datalist
|
2019-08-13 15:47:44 +00:00
|
|
|
| DATA8 data8list
|
|
|
|
| DATAF dataflist
|
1985-04-12 16:56:43 +00:00
|
|
|
| ASCII STRING
|
|
|
|
{ emitstr($1);}
|
|
|
|
;
|
|
|
|
externlist
|
|
|
|
: IDENT
|
|
|
|
{ $1->i_type |= S_EXT;}
|
|
|
|
| externlist ',' IDENT
|
|
|
|
{ $3->i_type |= S_EXT;}
|
|
|
|
;
|
|
|
|
datalist
|
|
|
|
: expr
|
|
|
|
{
|
|
|
|
#ifdef RELOCATION
|
|
|
|
if (rflag != 0 && PASS_RELO)
|
1986-12-01 15:41:29 +00:00
|
|
|
newrelo($1.typ, (int)$<y_word>0|MACHREL_BWR);
|
1985-04-12 16:56:43 +00:00
|
|
|
#endif
|
|
|
|
emitx($1.val, (int)$<y_word>0);
|
|
|
|
}
|
|
|
|
| datalist ',' expr
|
|
|
|
{
|
|
|
|
#ifdef RELOCATION
|
|
|
|
if (rflag != 0 && PASS_RELO)
|
1986-12-01 15:41:29 +00:00
|
|
|
newrelo($3.typ, (int)$<y_word>0|MACHREL_BWR);
|
1985-04-12 16:56:43 +00:00
|
|
|
#endif
|
|
|
|
emitx($3.val, (int)$<y_word>0);
|
|
|
|
}
|
|
|
|
;
|
2018-09-10 20:56:18 +00:00
|
|
|
|
2019-08-13 15:47:44 +00:00
|
|
|
data8list
|
2019-10-04 22:58:56 +00:00
|
|
|
: absexp
|
2019-08-13 15:47:44 +00:00
|
|
|
{ emit8($1);}
|
2019-10-04 22:58:56 +00:00
|
|
|
| data8list ',' absexp
|
2019-08-13 15:47:44 +00:00
|
|
|
{ emit8($3);}
|
|
|
|
;
|
|
|
|
|
2018-09-12 21:19:32 +00:00
|
|
|
numberf
|
|
|
|
: NUMBERF
|
2018-09-10 20:56:18 +00:00
|
|
|
{
|
2018-09-12 21:19:32 +00:00
|
|
|
emitf((int)$<y_word>-1, 0);
|
2018-09-10 20:56:18 +00:00
|
|
|
}
|
2018-09-12 21:19:32 +00:00
|
|
|
| '-' NUMBERF
|
2018-09-10 20:56:18 +00:00
|
|
|
{
|
2018-09-12 21:19:32 +00:00
|
|
|
emitf((int)$<y_word>-1, 1);
|
2018-09-10 20:56:18 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2018-09-12 21:19:32 +00:00
|
|
|
dataflist
|
|
|
|
: numberf
|
|
|
|
| dataflist ',' numberf
|
|
|
|
;
|
|
|
|
|
1985-04-12 16:56:43 +00:00
|
|
|
expr : error
|
|
|
|
{ serror("expr syntax err");
|
|
|
|
$$.val = 0; $$.typ = S_UND;
|
|
|
|
}
|
2019-08-13 15:47:44 +00:00
|
|
|
| NUMBER8
|
|
|
|
{ $$.val = $1; /* valu_t = int64_t */
|
|
|
|
$$.typ = S_ABS;
|
|
|
|
}
|
1985-04-12 16:56:43 +00:00
|
|
|
| id_fb
|
2019-08-13 15:47:44 +00:00
|
|
|
{ $$.val = load($1);
|
1990-07-30 09:43:45 +00:00
|
|
|
last_it = $1;
|
1985-04-12 16:56:43 +00:00
|
|
|
$$.typ = $1->i_type & ~S_EXT;
|
|
|
|
}
|
|
|
|
| STRING
|
1990-08-01 14:30:45 +00:00
|
|
|
{ if (stringlen != 1)
|
1985-04-12 16:56:43 +00:00
|
|
|
serror("too many chars");
|
1990-08-01 14:30:45 +00:00
|
|
|
$$.val = stringbuf[0];
|
1985-04-12 16:56:43 +00:00
|
|
|
$$.typ = S_ABS;
|
|
|
|
}
|
|
|
|
| ASC_LPAR expr ASC_RPAR
|
|
|
|
{ $$ = $2;}
|
|
|
|
| expr OP_OO expr
|
|
|
|
{ $$.val = ($1.val || $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, 0);
|
|
|
|
}
|
|
|
|
| expr OP_AA expr
|
|
|
|
{ $$.val = ($1.val && $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, 0);
|
|
|
|
}
|
|
|
|
| expr '|' expr
|
|
|
|
{ $$.val = ($1.val | $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, 0);
|
|
|
|
}
|
|
|
|
| expr '^' expr
|
|
|
|
{ $$.val = ($1.val ^ $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, 0);
|
|
|
|
}
|
|
|
|
| expr '&' expr
|
|
|
|
{ $$.val = ($1.val & $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, 0);
|
|
|
|
}
|
|
|
|
| expr OP_EQ expr
|
|
|
|
{ $$.val = ($1.val == $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, '>');
|
|
|
|
}
|
|
|
|
| expr OP_NE expr
|
|
|
|
{ $$.val = ($1.val != $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, '>');
|
|
|
|
}
|
|
|
|
| expr '<' expr
|
|
|
|
{ $$.val = ($1.val < $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, '>');
|
|
|
|
}
|
|
|
|
| expr '>' expr
|
|
|
|
{ $$.val = ($1.val > $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, '>');
|
|
|
|
}
|
|
|
|
| expr OP_LE expr
|
|
|
|
{ $$.val = ($1.val <= $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, '>');
|
|
|
|
}
|
|
|
|
| expr OP_GE expr
|
|
|
|
{ $$.val = ($1.val >= $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, '>');
|
|
|
|
}
|
|
|
|
| expr OP_RR expr
|
|
|
|
{ $$.val = ($1.val >> $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, 0);
|
|
|
|
}
|
|
|
|
| expr OP_LL expr
|
|
|
|
{ $$.val = ($1.val << $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, 0);
|
|
|
|
}
|
|
|
|
| expr '+' expr
|
|
|
|
{ $$.val = ($1.val + $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, '+');
|
|
|
|
}
|
|
|
|
| expr '-' expr
|
|
|
|
{ $$.val = ($1.val - $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, '-');
|
|
|
|
}
|
|
|
|
| expr '*' expr
|
|
|
|
{ $$.val = ($1.val * $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, 0);
|
|
|
|
}
|
|
|
|
| expr '/' expr
|
|
|
|
{ if ($3.val == 0) {
|
|
|
|
if (pass == PASS_3)
|
|
|
|
serror("divide by zero");
|
|
|
|
$$.val = 0;
|
|
|
|
} else
|
|
|
|
$$.val = ($1.val / $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, 0);
|
|
|
|
}
|
|
|
|
| expr '%' expr
|
|
|
|
{ if ($3.val == 0) {
|
|
|
|
if (pass == PASS_3)
|
|
|
|
serror("divide by zero");
|
|
|
|
$$.val = 0;
|
|
|
|
} else
|
|
|
|
$$.val = ($1.val % $3.val);
|
|
|
|
$$.typ = combine($1.typ, $3.typ, 0);
|
|
|
|
}
|
|
|
|
| '+' expr %prec '*'
|
|
|
|
{ $$.val = $2.val;
|
|
|
|
$$.typ = combine(S_ABS, $2.typ, 0);
|
|
|
|
}
|
|
|
|
| '-' expr %prec '*'
|
|
|
|
{ $$.val = -$2.val;
|
|
|
|
$$.typ = combine(S_ABS, $2.typ, 0);
|
|
|
|
}
|
|
|
|
| '~' expr
|
|
|
|
{ $$.val = ~$2.val;
|
|
|
|
$$.typ = combine(S_ABS, $2.typ, 0);
|
|
|
|
}
|
|
|
|
| DOT
|
|
|
|
{ $$.val = DOTVAL;
|
|
|
|
$$.typ = DOTTYP|S_DOT;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
id_fb : IDENT
|
|
|
|
| FBSYM
|
|
|
|
;
|
|
|
|
absexp : expr
|
|
|
|
{ if (($1.typ & ~S_EXT) != S_ABS)
|
|
|
|
serror("must be absolute");
|
|
|
|
$$ = $1.val;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
optabs1
|
|
|
|
: /* empty */
|
|
|
|
{ $$ = 0;}
|
|
|
|
| absexp
|
|
|
|
{ $$ = $1;}
|
|
|
|
;
|
|
|
|
optabs2
|
|
|
|
: /* empty */
|
|
|
|
{ $$ = 0;}
|
|
|
|
| ',' absexp
|
|
|
|
{ $$ = $2;}
|
|
|
|
;
|
|
|
|
|
|
|
|
/* ========== Machine dependent rules ========== */
|
|
|
|
|
|
|
|
#include "mach4.c"
|
|
|
|
|
|
|
|
%%
|