ack/util/ass/ass60.c

235 lines
5.5 KiB
C
Raw Permalink Normal View History

1984-07-02 15:35:56 +00:00
/*
1987-03-10 01:26:51 +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".
1984-07-02 15:35:56 +00:00
*
*/
#include "ass00.h"
#include "assex.h"
#include "ip_spec.h"
1984-11-08 12:08:31 +00:00
1984-07-02 15:35:56 +00:00
#ifdef DUMP
2019-03-17 14:41:25 +00:00
static char *typestr[] =
{ "missing", "const", "procname", "glosym", "locsym", "glosym+off", "pseudo" };
static char *labstr[] =
{ "EMPTY", "no", "yes", "seen", "notpresent" };
static char formstr[] =
{ 'm', 's', '-', '1', '2', '4', '8' };
static char *r_data[] =
{ "null", "glob", "head", "loc", "adr" };
1984-07-02 15:35:56 +00:00
2019-03-17 14:41:25 +00:00
cons_t nicepr(int typ, addr_u *ap)
{
1984-07-02 15:35:56 +00:00
register proc_t *pl;
2019-03-17 14:41:25 +00:00
switch (typ)
{
case CONST:
return (ap->ad_i);
case LOCSYM:
2022-08-01 20:08:23 +00:00
return (int_cast (intptr_t)ap->ad_lp);
2019-03-17 14:41:25 +00:00
case GLOOFF:
return (ap->ad_df.df_gp - mglobs);
case GLOSYM:
return (ap->ad_gp - mglobs);
case PROCNAME:
pl = ap->ad_pp;
;
if (pl->p_status & EXT)
return ((pl - xprocs) + 1000);
else
return (pl - mprocs);
default:
if (typ >= VALLOW && typ <= VALHIGH)
return VAL1(typ);
break;
1984-07-02 15:35:56 +00:00
}
2019-03-17 14:41:25 +00:00
return (0);
1984-07-02 15:35:56 +00:00
}
2019-03-17 14:41:25 +00:00
char *pflags(int flg)
{
static char res[9];
register char *cp;
1984-07-02 15:35:56 +00:00
2019-03-17 14:41:25 +00:00
cp = res;
if (flg & OPESC)
*cp++ = 'e';
switch (flg & OPRANGE)
{
case OP_NEG:
*cp++ = 'N';
break;
case OP_POS:
*cp++ = 'P';
break;
1984-07-02 15:35:56 +00:00
}
2019-03-17 14:41:25 +00:00
if (flg & OPWORD)
*cp++ = 'w';
if (flg & OPNZ)
*cp++ = 'o';
*cp++ = formstr[flg & OPTYPE];
*cp++ = 0;
return res;
1984-07-02 15:35:56 +00:00
}
2019-03-17 14:41:25 +00:00
void dump(int n)
1984-07-02 15:35:56 +00:00
{
register glob_t *gb;
register line_t *ln;
register locl_t *lbp;
register locl_t *lbhead;
proc_t *pl;
int i;
int insno;
2019-03-17 14:41:25 +00:00
extern char em_mnem[][4];
1984-07-02 15:35:56 +00:00
2019-03-17 14:41:25 +00:00
if (d_flag == 0)
return;
if ((n == 0 && d_flag) || (n == 4 && d_flag >= 2)
|| (n < 100 && d_flag >= 3))
{
printf("\nEM1-assembler ***** pass %1d complete:\n", n);
printf("current size %ld\n", prog_size);
printf(" %9.9s%9.9s%14.14s%8.8s%8.8s\n", "instr_nr", "type1", "addr1",
"length", "format");
for (ln = pstate.s_fline; ln;
ln = ln->l_next, n >= 3 || n == 0 ? i++ : i--)
{
insno = ctrunc(ln->instr_num);
if (insno == sp_fpseu)
{
i = ln->ad.ad_ln.ln_first;
continue;
}
printf("%4d ", i);
switch (insno)
{
default:
printf(" %3.3s", em_mnem[insno]);
break;
case sp_ilb1:
printf("l ");
break;
case sp_fpseu:
printf("p ");
break;
}
printf(" %9.9s%14ld",
typestr[ln->type1 < VALLOW ? ln->type1 : CONST],
nicepr(ln->type1, &ln->ad));
if (ln->opoff != NO_OFF)
printf("%5d %.6s", oplength(*(ln->opoff)),
pflags(*(ln->opoff)));
printf("\n");
1984-07-02 15:35:56 +00:00
}
2019-03-17 14:41:25 +00:00
printf("\n %8s%8s%8s%8s%8s\n", "labnum", "labid", "minval", "maxval",
"defined");
for (i = 0, lbhead = *pstate.s_locl; i < LOCLABSIZE; lbhead++, i++)
{
if (lbhead->l_defined != EMPTY)
printf("%4d\n", i);
for (lbp = lbhead; lbp != lbp_cast 0; lbp = lbp->l_chain)
{
if (lbp->l_defined != EMPTY)
printf(" %8d%8d%8d%8d %-s\n",
lbp->l_hinum * LOCLABSIZE + i,
2022-08-01 20:08:23 +00:00
int_cast (intptr_t)lbp, lbp->l_min, lbp->l_max,
2019-03-17 14:41:25 +00:00
labstr[(unsigned char)lbp->l_defined]);
}
1984-07-02 15:35:56 +00:00
}
}
2019-03-17 14:41:25 +00:00
if (((n == 0 || n >= 100) && d_flag) || (n <= 1 && d_flag >= 2))
{
if (n == 0 || n == 100)
{
printf("File %s", curfile);
if (archmode)
printf("(%.14s)", archhdr.ar_name);
printf(" :\n\n");
1984-07-02 15:35:56 +00:00
}
2019-03-17 14:41:25 +00:00
printf("Local data labels:\n");
printf("\n\t%8.8s %8.8s %8.8s\n", "g_name", "g_status", "g_addr");
for (gb = mglobs, i = 0; gb < &mglobs[oursize->n_mlab]; gb++, i++)
if (gb->g_name[0] != 0)
{
printf("%5d\t%8.6s", i, gb->g_name);
printf(" %8o %8ld\n", gb->g_status, gb->g_val.g_addr);
}
printf("\n\nGlobal data labels\n");
printf("\n\t%8.8s %8.8s %8.8s\n", "g_name", "g_status", "g_addr");
for (gb = xglobs, i = 0; gb < &xglobs[oursize->n_glab]; gb++, i++)
if (gb->g_name != 0)
{
printf("%5d\t%8.6s", i, gb->g_name);
printf(" %8o %8ld\n", gb->g_status, gb->g_val.g_addr);
}
printf("\n\nLocal procedures\n");
printf("\n\t%8.8s%8s%8s\t%8s%8s\n", "name", "status", "num", "off",
"locals");
for (pl = mprocs; pl < &mprocs[oursize->n_mproc]; pl++)
if (pl->p_name)
{
printf("%4d\t%-8s%8o%8d", pl - mprocs, pl->p_name, pl->p_status,
pl->p_num);
if (pl->p_status & DEF)
printf("\t%8ld%8ld", proctab[pl->p_num].pr_off,
proctab[pl->p_num].pr_loc);
printf("\n");
}
printf("\nGlobal procedures\n");
printf("\n\t%8s%8s%8s\t%8s%8s\n", "name", "status", "num", "off",
"locals");
for (pl = xprocs; pl < &xprocs[oursize->n_xproc]; pl++)
if (pl->p_name)
{
printf("%4d\t%-8s%8o%8d", pl - xprocs, pl->p_name, pl->p_status,
pl->p_num);
if (pl->p_status & DEF)
printf("\t%8ld%8ld", proctab[pl->p_num].pr_off,
proctab[pl->p_num].pr_loc);
printf("\n");
}
if (r_flag)
{
register relc_t *rl;
printf("\nData relocation\n");
printf("\n\t%10s %10s %10s\n", "offset", "type", "value");
for (rl = f_data; rl; rl = rl->r_next)
{
printf("\t%10ld %10s ", rl->r_off, r_data[rl->r_typ]);
switch (rl->r_typ)
{
case RELADR:
case RELHEAD:
printf("%10ld\n", rl->r_val.rel_i);
break;
case RELGLO:
printf("%8.8s\n", rl->r_val.rel_gp->g_name);
break;
case RELLOC:
printf("%10d\n", rl->r_val.rel_lp);
break;
case RELNULL:
printf("\n");
break;
}
}
printf("\n\nText relocation\n");
printf("\n\t%10s %10s %10s\n", "offset", "flags", "value");
for (rl = f_text; rl; rl = rl->r_next)
{
printf("\t%10ld %10s ", rl->r_off,
pflags(opchoice[rl->r_typ & ~RELMNS]));
if (rl->r_typ & RELMNS)
printf("%10ld\n", rl->r_val.rel_i);
else
printf("\n");
1984-07-02 15:35:56 +00:00
}
}
2019-03-17 14:41:25 +00:00
}
1984-07-02 15:35:56 +00:00
}
#endif