Pristine Ack-5.5
[Ack-5.5.git] / mach / z80 / cg / mach.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  *
5  */
6
7 #ifndef NORCSID
8 static char rcs_mach[] = "$Id: mach.c,v 2.4 1994/06/24 13:55:11 ceriel Exp $" ;
9 static char rcs_h[] = RCS_H ;
10 #endif
11
12 /*
13  * machine dependent back end routines for the Zilog Z80 (as well as Intel 8080)
14  */
15
16 con_part(sz,w) register sz; word w; {
17
18         while (part_size % sz)
19                 part_size++;
20         if (part_size == TEM_WSIZE)
21                 part_flush();
22         if (sz == 1) {
23                 w &= 0xFF;
24                 if (part_size)
25                         w <<= 8;
26                 part_word |= w;
27         } else {
28                 assert(sz == 2);
29                 part_word = w;
30         }
31         part_size += sz;
32 }
33
34 con_mult(sz) word sz; {
35         long atol();
36
37         if (argval != 4)
38                 fatal("bad icon/ucon size");
39         fprintf(codefile, ".data4\t%ld\n", atol(str));
40 }
41
42 con_float() {
43         static int been_here;
44         int sz = argval;
45
46         if (sz != 4 && sz != 8) {
47                 fatal("bad fcon size");
48         }
49         if (! been_here) {
50                 been_here = 1;
51                 fprintf(stderr,"warning: dummy floating constant(s)\n");
52         }
53         while (sz) {
54                 fprintf(codefile, ".data4 0     !dummy float\n");
55                 sz -= 4;
56         }
57 }
58
59
60 prolog(nlocals) full nlocals; {
61
62         fprintf(codefile,"\tpush\tiy\n\tld\thl,0\n\tadd\thl,sp\n\tpush\thl\n\tpop\tiy\n");
63         switch (nlocals) {
64         case 8: fprintf(codefile,"\tpush\thl\n");
65         case 6: fprintf(codefile,"\tpush\thl\n");
66         case 4: fprintf(codefile,"\tpush\thl\n");
67         case 2: fprintf(codefile,"\tpush\thl\n");
68         case 0: break;
69         default:
70                 fprintf(codefile,"\tld\thl,%d\n\tadd\thl,sp\n\tld\tsp,hl\n",-nlocals);
71                 break;
72         }
73 }
74
75 mes(type) word type ; {
76         int argt ;
77
78         switch ( (int)type ) {
79         case ms_ext :
80                 for (;;) {
81                         switch ( argt=getarg(
82                             ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
83                         case sp_cend :
84                                 return ;
85                         default:
86                                 strarg(argt) ;
87                                 fprintf(codefile,".define %s\n",argstr) ;
88                                 break ;
89                         }
90                 }
91         default :
92                 while ( getarg(any_ptyp) != sp_cend ) ;
93                 break ;
94         }
95 }
96
97 char *segname[] = {
98         ".sect .text",
99         ".sect .data",
100         ".sect .rom",
101         ".sect .bss"
102 };