Pristine Ack-5.5
[Ack-5.5.git] / mach / ns / ncg / 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 #ifndef NORCSID
7 static char rcsid[] = "$Id: mach.c,v 2.8 1994/06/24 13:10:14 ceriel Exp $" ;
8 #endif
9
10 con_part(sz, w)
11         register int    sz;
12         word            w;
13 {
14         while (part_size % sz) part_size++;
15
16         if (part_size == TEM_WSIZE)
17                 part_flush();
18         if (sz == 1 || sz == 2) {
19                 w &= (sz == 1 ? 0xFF : 0xFFFF);
20                 w <<= 8 * part_size;
21                 part_word |= w;
22         } else {
23                 assert(sz == 4);
24                 part_word = w;
25         }
26         part_size += sz;
27 }
28
29 con_mult(sz)
30         word    sz;
31 {
32         if (sz != 4)
33                 fatal("bad icon/ucon size");
34         fprintf(codefile,".data4\t%s\n",str);
35 }
36
37 #ifdef REGVARS
38 full lbytes;
39 struct regadm {
40         char *ra_str;
41         long ra_off;
42 } regadm[4];
43 int n_regvars;
44
45 regscore(off,size,typ,score,totyp) long off; {
46
47         /*This function is copied from pdp/ncg
48          */
49         /*
50          * This function is full of magic constants.
51          * They are a result of experimentation.
52          */
53
54         if (size != 2)
55                 return(-1);
56         score -= 1;     /* allow for save/restore */
57         if (off>=0)
58                 score -= 2;
59         if (typ==reg_pointer)
60                 score *= 17;
61         else if (typ==reg_loop)
62                 score = 10*score+50;    /* Guestimate */
63         else
64                 score *= 10;
65         return(score);  /* 10 * estimated # of words of profit */
66 }
67
68 i_regsave() {
69
70         n_regvars=0;
71 }
72
73 f_regsave(){
74         register i;
75         register int c = ' ';
76
77         fprintf(codefile, "enter [");
78         for (i=0; i<n_regvars; i++) {
79                 fprintf(codefile,"%c%s", c, regadm[i].ra_str);
80                 c = ',';
81         }
82         fprintf(codefile, "], %ld\n", lbytes);
83         for (i=0;i<n_regvars;i++)
84                 if (regadm[i].ra_off>=0)
85                         fprintf(codefile, "movd %ld(fp), %s",
86                           regadm[i].ra_off, regadm[i].ra_str);
87 }
88
89 regsave(regstr,off,size) char *regstr; long off; {
90
91         fprintf(codefile,"\t! Local %ld into %s\n",off,regstr);
92         regadm[n_regvars].ra_str = regstr;
93         regadm[n_regvars].ra_off = off;
94         n_regvars++;
95 }
96
97 regreturn() {
98         register int i;
99         register int c = ' ';
100
101         fprintf(codefile, "exit [");
102         for (i=1; i<n_regvars; i++) {
103                 fprintf(codefile,"%c%s", c, regadm[i].ra_str);
104                 c = ',';
105         }
106         fprintf(codefile, "]\n");
107 }
108
109 #endif
110
111 mes(type) word type ; {
112         int argt ;
113
114         switch ( (int)type ) {
115         case ms_ext :
116                 for (;;) {
117                         switch ( argt=getarg(
118                             ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
119                         case sp_cend :
120                                 return ;
121                         default:
122                                 strarg(argt) ;
123                                 fprintf(codefile,".define %s\n",argstr) ;
124                                 break ;
125                         }
126                 }
127         default :
128                 while ( getarg(any_ptyp) != sp_cend ) ;
129                 break ;
130         }
131 }
132
133 prolog(nlocals) full nlocals; {
134
135 #ifndef REGVARS
136         fprintf(codefile, "enter[], %ld\n",nlocals);
137 #else
138         lbytes = nlocals;
139 #endif
140 }
141
142 char *segname[] = {
143         ".sect .text",
144         ".sect .data",
145         ".sect .rom",
146         ".sect .bss"
147 };
148
149 con_float() {
150
151         static int warning_given;
152         int i;
153
154         if (! warning_given) {
155                 fprintf(stderr, "warning: dummy floating point constant\n");
156                 warning_given = 1;
157         }
158         for (i = argval; i > 0; i -= 4) {
159                 fputs(".data4 0 ! dummy float\n", codefile);
160         }
161 }