1 /* $Id: comm7.c,v 2.21 1994/06/24 13:22:14 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".
22 typ = ip->i_type & S_TYP;
23 if ((typ -= S_MIN) < 0) /* S_UND or S_ABS */
25 return(ip->i_valu + sect[typ].s_base);
27 if ((ip->i_type & S_TYP) == S_UND || (ip->i_type & S_COM)) {
30 serror("relocation error");
31 relonami = ip->i_valu+1;
46 typ = ip->i_type & S_TYP;
47 if ((typ -= S_MIN) >= 0)
48 val -= sect[typ].s_base;
50 if ((ip->i_type & S_TYP) == S_UND)
53 assert(pass != PASS_3 || (ip->i_type & S_VAR) || ip->i_valu == val);
72 if ((nleft -= n) < 0) {
73 next = malloc(MEMINCR);
75 fatal("out of memory");
76 nleft = (MEMINCR / sizeof(char)) - n;
87 combine(typ1, typ2, op)
100 if ((typ1 & ~S_DOT) == (typ2 & ~S_DOT) && typ1 != S_UND)
104 if (typ1 == S_ABS && typ2 == S_ABS)
107 ((typ1 & ~S_DOT) == (typ2 & ~S_DOT) && typ1 != S_UND)
114 if (typ1 == S_ABS && typ2 == S_ABS)
119 serror("illegal operator");
133 *p++ = (int) val & 017;
137 c = "0123456789ABCDEF"[*--p];
149 if ((listflag & 4) && (c = getc(listfile)) != '\n' && textline) {
151 printf(" \\\n\t\t\t");
156 } while (listcolm < 24);
160 } while ((c = getc(listfile)) != '\n');
172 /* ---------- code optimization ---------- */
175 #define PBITTABSZ 128
176 static char *pbittab[PBITTABSZ];
178 small(fitsmall, gain)
187 if (nbits == BITCHUNK) {
190 if (bitindex == PBITTABSZ) {
192 if (pass == PASS_1 && ! w_given) {
194 warning("bit table overflow");
198 if (pbittab[bitindex] == 0 && pass == PASS_1) {
199 if ((pbittab[bitindex] = calloc(MEMINCR, 1)) == 0) {
204 warning("out of space for bit table");
208 if (pbittab[bitindex] == 0)
211 bit = 1 << (nbits&7);
212 p = pbittab[bitindex]+(nbits>>3);
224 assert(fitsmall || (*p & bit) == 0);
231 /* ---------- output ---------- */
235 static int olddottyp = -1;
239 listcolm += printx(VALWIDTH, (valu_t)DOTVAL);
246 listcolm += printx(2, (valu_t) arg);
257 if (DOTTYP != olddottyp) {
258 wr_outsect(DOTTYP-S_MIN);
261 while (DOTSCT->s_zero) {
274 #ifdef BYTES_REVERSED
275 emit1((arg>>8)); emit1(arg);
277 emit1(arg); emit1((arg>>8));
284 #ifdef WORDS_REVERSED
285 emit2((int)(arg>>16)); emit2((int)(arg));
287 emit2((int)(arg)); emit2((int)(arg>>16));
297 emit1((int)val); break;
299 #ifdef BYTES_REVERSED
300 emit1(((int)val>>8)); emit1((int)val);
302 emit1((int)val); emit1(((int)val>>8));
306 #ifdef WORDS_REVERSED
307 emit2((int)(val>>16)); emit2((int)(val));
309 emit2((int)(val)); emit2((int)(val>>16));
330 /* ---------- Error checked file I/O ---------- */
336 if (freopen(s, "r", f) == NULL)
337 fatal("can't reopen %s", s);
346 if ((f = fopen(s, "w")) == NULL)
347 fatal("can't create %s", s);
352 #define TMPDIR "/tmp"
354 char *tmp_dir = TMPDIR;
362 if ((dir = getenv("TMPDIR")) == NULL)
364 sprintf(path, "%s/%s", dir, tail);
365 return(ffcreat(mktemp(path)));
368 /* ---------- Error handling ---------- */
371 yyerror(){} /* we will do our own error printing */
375 fatal("no sections");
380 fatal("write error");
384 fatal(s, a1, a2, a3, a4)
388 diag(" (fatal)\n", s, a1, a2, a3, a4);
396 fatal("assertion failed (%s, %d)", file, line);
403 diag(" (fatal)\n", "assertion failed");
409 serror(s, a1, a2, a3, a4)
413 diag("\n", s, a1, a2, a3, a4);
417 warning(s, a1, a2, a3, a4)
420 diag(" (warning)\n", s, a1, a2, a3, a4);
424 diag(tail, s, a1, a2, a3, a4)
429 fprintf(stderr, "\"%s\", line %ld: ", modulename, lineno);
431 fprintf(stderr, "%s: ", progname);
432 fprintf(stderr, s, a1, a2, a3, a4);
433 fprintf(stderr, tail);