1 /* $Id: ca.c,v 1.12 1994/06/24 10:19:37 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
7 * C O M P A C T A S S E M B L Y L A N G U A G E G E N E R A T I O N
15 #include "../share/types.h"
17 #include "../share/debug.h"
18 #include "../share/global.h"
19 #include "../share/lset.h"
20 #include "../share/files.h"
21 #include "../share/map.h"
22 #include "../share/alloc.h"
23 #include "../share/get.h"
27 /* This phase transforms the Intermediate Code of the global optimizer
28 * to 'standard' compact assembly language, which will be processed
29 * by the code generator.
36 char **dnames, **pnames; /* Dynamically allocated arrays of strings.
37 * pnames[i] contains a pointer to the name
38 * of the procedure with proc_id i.
43 STATIC line_p get_ca_lines(lf,p_out)
47 /* Read lines of EM text and link them.
48 * Register messages are outputted immediately after the PRO.
55 curinp = lf; /* EM input file */
61 if (feof(curinp)) break;
62 assert (l != (line_p) 0);
63 if (INSTR(l) == ps_end && INSTR(head) != ps_pro) {
64 /* Delete end pseudo after data-unit */
68 if (INSTR(l) == ps_mes && l->l_a.la_arg->a_a.a_offset == ms_reg) {
69 /* l is a register message */
70 if (l->l_a.la_arg->a_next == (arg_p) 0) {
71 /* register message without arguments */
81 if (INSTR(l) == ps_end) {
86 if (head != (line_p) 0 && INSTR(head) == ps_pro) {
87 /* append register message without arguments to list */
90 a = ARG(l) = newarg(ARGOFF);
91 a->a_a.a_offset = ms_reg;
93 l->l_next = head->l_next;
96 assert(headm == (line_p) 0);
101 STATIC int makedmap(dbl)
104 /* construct the dmap table */
109 /* determine the length of the table */
112 for (d = dbl; d != (dblock_p) 0; d = d->d_next) cnt++;
113 dmap = (dblock_p *) newmap(cnt);
114 for (d = dbl; d != (dblock_p) 0; d = d->d_next) {
115 assert(d->d_id <= cnt);
123 STATIC getdnames(dumpd)
126 /* Read the names of the datalabels from
133 dnames = (char **) newmap(dlength);
135 if (fscanf(dumpd,"%d %s",&id,str) == EOF) return;
136 assert(id <= dlength);
137 dnames[id] = (char *) newcore(strlen(str)+1);
138 strcpy(dnames[id], str);
142 STATIC getpnames(dumpp)
145 /* Read the names of the procedures from
152 pnames = (char **) newmap(plength);
154 if (fscanf(dumpp,"%d %s",&id,str) == EOF) return;
155 assert(id <= plength);
156 pnames[id] = (char *) newcore(strlen(str)+1);
157 strcpy(pnames[id], str);
168 int len = strlen(*s);
174 sprintf(&buf[3],"%d",nn);
176 *s = (char *) newcore(strlen(buf)+1);
184 /* The names of all internal procedures and data blocks
185 * are made different. As the optimizer combines several
186 * modules into one, there may be name conflicts between
187 * procedures or data blocks that were internal in
188 * different source modules.
194 for (p = fproc; p != (proc_p) 0; p = p->p_next) {
195 if (!(p->p_flags1 & PF_EXTERNAL)) {
196 new_name(&(pnames[p->p_id]));
199 for (d = fdblock; d != (dblock_p) 0; d = d->d_next) {
200 if (!(d->d_flags1 & DF_EXTERNAL) && dnames[d->d_id]) {
201 new_name(&(dnames[d->d_id]));
211 /* CA does not output proctable etc. files. Instead, its
212 * pname2 and dname2 arguments contain the names of the
213 * dump files created by IC.
215 FILE *f, *f2; /* The EM input and output. */
216 FILE *df, *pf; /* The dump files */
219 fproc = getptable(pname); /* proc table */
220 fdblock = getdtable(dname); /* data block table */
221 dlength = makedmap(fdblock); /* allocate dmap table */
222 df = openfile(dname2,"r");
225 pf = openfile(pname2,"r");
229 f = openfile(lname,"r");
231 cputmagic(f2); /* write magic number */
232 while ((lnp = get_ca_lines(f,&curproc)) != (line_p) 0) {