1 /* $Id: em.c,v 1.10 1994/06/24 11:10:26 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".
6 /* EM CODE OUTPUT ROUTINES */
8 /* I/O part of em_code module.
9 Also contains C_open, C_close
14 #include "em_private.h"
19 int (*C_outpart)(), (*C_swtout)(), (*C_swttmp)();
30 char *strcpy(), *strcat();
35 #if BUFSIZ <= 1024 && BIGMACHINE
36 #define BUFFERSIZ 8*BUFSIZ
38 #define BUFFERSIZ BUFSIZ
41 static char obuf[BUFFERSIZ];
42 char *C_top = &obuf[BUFFERSIZ];
44 char *C_current_out = obuf;
52 static unsigned int bufsiz;
56 C_BASE = Malloc(BUFFERSIZ);
58 C_current_out = C_BASE;
61 C_BASE = Srealloc(C_BASE, (bufsiz << 1));
62 C_current_out = C_BASE + bufsiz;
65 C_top = C_BASE + bufsiz;
69 if (C_opp != obuf && sys_write(C_ofp, obuf, (int)(C_opp - obuf)) == 0) {
77 #define Xputbyte(c) if (C_ontmpfile) C_current_out++; put(c)
79 #define Xputbyte(c) put(c)
90 #define C_putbyte Xputbyte
104 /* Open file "nm" for output
108 C_ofp = STDOUT; /* standard output */
110 if (sys_open(nm, OP_WRITE, &C_ofp) == 0)
118 /* Finish the code-generation.
130 C_curr_part->p_parts->pp_end = C_current_out - C_BASE;
133 if (! C_sequential) {
138 sys_remove(C_tmpfile);
139 if (C_ibuf) free(C_ibuf);
153 return C_ofp != 0; /* true if code is being generated */
158 The C_pt_*() functions serve as formatting functions of the
159 various EM language constructs.
160 See "Description of a Machine Architecture for use with
161 Block Structured Languages" par. 11.2 for the meaning of these
170 /*** the readable code generating routines ***/
194 sprint(buf, "*%ld", (long) l);
198 extern char em_mnem[][4];
199 extern char em_pseu[][4];
205 wrs(em_mnem[x - sp_fmnem]);
215 sprint(buf, "%ld", (long) l);
229 p = bts2str(x, (int) y, xbuf);
243 wrs(em_pseu[x - sp_fpseu]);
253 sprint(buf, ".%ld", (long) l);
266 sprint(buf,"+%ld", (long) v);
280 sprint(buf,"+%ld", (long) v);
299 sprint(buf, "%ld", (long) l);
304 C_pt_wcon(sp, v, sz) /* sp_icon, sp_ucon or sp_fcon with int repr */
309 int ch = sp == sp_icon ? 'I' : sp == sp_ucon ? 'U' : 'F';
331 #else /* READABLE_EM */
333 #define put8(x) C_putbyte(x)
334 #define put16(x) put8((int) x); put8((int) (x >> 8))
335 #define put32(x) put16((int) x); put16((int) (x >> 16))
338 The C_pt_*() functions serve as formatting functions of the
339 various EM language constructs.
340 See "Description of a Machine Architecture for use with
341 Block Structured Languages" par. 11.2 for the meaning of these
351 /*** the compact code generating routines ***/
352 #define fit16i(x) ((x) >= (long)0xFFFF8000 && (x) <= (long)0x00007FFF)
353 #define fit8u(x) ((x) <= 0xFF) /* x is already unsigned */
387 if (l >= (arith) -sp_zcst0 && l < (arith) (sp_ncst0 - sp_zcst0)) {
388 /* we can convert 'l' to an int because its value
389 can be stored in a byte.
391 put8((int)l + (sp_zcst0 + sp_fcst0));
394 if (fit16i(l)) { /* the cast from long to int causes no trouble here */
425 C_pt_cst((arith) (len = strlen(s)));
463 C_pt_wcon(sp, v, sz) /* sp_icon, sp_ucon or sp_fcon with int repr */
468 /* how 'bout signextension int --> long ??? */
485 #endif /* READABLE_EM */