transform HOL into BSS so that IL does not get confused

This commit is contained in:
ceriel 1989-05-30 14:32:12 +00:00
parent 69f02d8abc
commit e6fb294aac
5 changed files with 59 additions and 18 deletions

View file

@ -33,7 +33,8 @@
dblock_p db; dblock_p db;
dblock_p curhol = (dblock_p) 0; /* hol block in current scope */ dblock_p hol0_db; /* dblock for ABS block */
char *curhol; /* name of hol block in current scope */
dblock_p ldblock; /* last dblock */ dblock_p ldblock; /* last dblock */
proc_p lproc; /* last proc */ proc_p lproc; /* last proc */
short tabval; /* used by table1, table2 and table3 */ short tabval; /* used by table1, table2 and table3 */
@ -80,10 +81,12 @@ main(argc,argv)
lfile = openfile(lname2,"w"); lfile = openfile(lname2,"w");
pdump = openfile(argv[1],"w"); pdump = openfile(argv[1],"w");
ddump = openfile(argv[2],"w"); ddump = openfile(argv[2],"w");
hol0_db = block_of_lab((char *) 0);
while (next_file(argc,argv) != NULL) { while (next_file(argc,argv) != NULL) {
/* Read all EM input files, process the code /* Read all EM input files, process the code
* and concatenate all output. * and concatenate all output.
*/ */
curhol = (char *) 0;
process_lines(lfile); process_lines(lfile);
dump_procnames(prochash,NPROCHASH,pdump); dump_procnames(prochash,NPROCHASH,pdump);
dump_dblocknames(symhash,NSYMHASH,ddump); dump_dblocknames(symhash,NSYMHASH,ddump);
@ -276,6 +279,7 @@ int readline(instr_out, lnp_out)
case PSEU: case PSEU:
n = tabval; n = tabval;
lnp = inpseudo(n); /* read a pseudo */ lnp = inpseudo(n); /* read a pseudo */
if (n == ps_hol) n = ps_bss;
if (lnp == (line_p) 0) return DELETED_INSTR; if (lnp == (line_p) 0) return DELETED_INSTR;
*lnp_out = lnp; *lnp_out = lnp;
lnp->l_instr = n; lnp->l_instr = n;
@ -326,7 +330,7 @@ line_p readoperand(instr)
case PAR_G: case PAR_G:
lnp = newline(OPOBJECT); lnp = newline(OPOBJECT);
OBJ(lnp) = OBJ(lnp) =
object((char *) 0,(offset) tabval, object(curhol,(offset) tabval,
opr_size(instr)); opr_size(instr));
break; break;
case PAR_B: case PAR_B:
@ -345,7 +349,7 @@ line_p readoperand(instr)
if (flag == PAR_G) { if (flag == PAR_G) {
lnp = newline(OPOBJECT); lnp = newline(OPOBJECT);
OBJ(lnp) = OBJ(lnp) =
object((char *) 0, tabval2, object(curhol, tabval2,
opr_size(instr)); opr_size(instr));
break; break;
} }
@ -388,6 +392,32 @@ line_p readoperand(instr)
} }
static char *hol_label()
{
static int holno;
line_p lnp;
extern char *lastname;
/* Create a label for a hol pseudo, so that it can be converted
* into a bss. The label is appended to the list of instructions.
*/
sprintf(string, "_HH%d", ++holno);
symlookup(string, OCCURRING); /* to make it exa */
db = block_of_lab(string);
lnp = newline(OPSHORT);
SHORT(lnp) = (short) db->d_id;
lnp->l_instr = ps_sym;
if (firstline == (line_p) 0) {
firstline = lnp;
}
if (lastline != (line_p) 0) {
lastline->l_next = lnp;
}
lastline = lnp;
return lastname;
}
line_p inpseudo(n) line_p inpseudo(n)
short n; short n;
@ -408,16 +438,24 @@ line_p inpseudo(n)
switch(n) { switch(n) {
case ps_hol: case ps_hol:
/* hol pseudos are carefully converted into bss
* pseudos, so that the IL phase will not be
* bothered by this. Also, references to the ABS
* block will still work when passed through EGO.
*/
if (lastline != (line_p) 0 && is_datalabel(lastline)) {
curhol = string;
}
else {
curhol = hol_label();
}
n = ps_bss;
/* fall through */
case ps_bss: case ps_bss:
case ps_rom: case ps_rom:
case ps_con: case ps_con:
if (lastline == (line_p) 0 || !is_datalabel(lastline)) { if (lastline == (line_p) 0 || !is_datalabel(lastline)) {
if (n == ps_hol) {
/* A HOL need not be preceded
* by a label.
*/
curhol = db = block_of_lab((char *) 0);
} else {
assert(lastline != (line_p) 0); assert(lastline != (line_p) 0);
nlast = INSTR(lastline); nlast = INSTR(lastline);
if (n == nlast && if (n == nlast &&
@ -436,9 +474,8 @@ line_p inpseudo(n)
error("datablock without label"); error("datablock without label");
} }
} }
}
VD(db); VD(db);
m = (n == ps_hol || n == ps_bss ? 3 : 0); m = (n == ps_bss ? 3 : 0);
lnp = arglist(m); lnp = arglist(m);
/* Read the arguments, 3 for hol or bss and a list /* Read the arguments, 3 for hol or bss and a list
* of undetermined length for rom and con. * of undetermined length for rom and con.

View file

@ -58,7 +58,7 @@ struct num {
/* Global variables */ /* Global variables */
extern dblock_p db; extern dblock_p db;
extern dblock_p curhol; /* hol block in current scope */ extern dblock_p hol0_db; /* ABS block */
extern dblock_p ldblock; /* last dblock processed so far */ extern dblock_p ldblock; /* last dblock processed so far */
extern proc_p lproc; /* last proc processed so far */ extern proc_p lproc; /* last proc processed so far */
extern short tabval; /* used by table1, table2 and table3 */ extern short tabval; /* used by table1, table2 and table3 */

View file

@ -459,7 +459,7 @@ obj_p object(ident,off,size)
* within the datablock of the given name. * within the datablock of the given name.
*/ */
dbl = (ident == (char *) 0 ? curhol : symlookup(ident, OCCURRING)); dbl = (ident == (char *) 0 ? hol0_db : symlookup(ident, OCCURRING));
VD(dbl); VD(dbl);
return(make_object(dbl,off,size)); return(make_object(dbl,off,size));
} }

View file

@ -200,7 +200,7 @@ arch_init(arch)
infile = arch; infile = arch;
n = readshort(); n = readshort();
if (n != ARMAG) { if (n != (short)ARMAG) {
error("wrong archive magic number: %d",n); error("wrong archive magic number: %d",n);
} }
} }

View file

@ -22,6 +22,7 @@
sym_p symhash[NSYMHASH]; sym_p symhash[NSYMHASH];
prc_p prochash[NPROCHASH]; prc_p prochash[NPROCHASH];
num_p numhash[NNUMHASH]; num_p numhash[NNUMHASH];
char *lastname;
@ -131,6 +132,9 @@ dblock_p symlookup(name, status)
*spp = sp = newsym(); *spp = sp = newsym();
sp->sy_name = (char *) newcore(strlen(name)+1); sp->sy_name = (char *) newcore(strlen(name)+1);
strcpy(sp->sy_name, name); strcpy(sp->sy_name, name);
lastname = sp->sy_name; /* quick hack to get at
the name
*/
dp = sp->sy_dblock = newdblock(); dp = sp->sy_dblock = newdblock();
} }
if (fdblock == (dblock_p) 0) { if (fdblock == (dblock_p) 0) {