|
|
1.1 root 1: /*ident "@(#)ctrans:src/size.c 1.1.4.3" */
2: /*********************************************************************
3:
4: C++ source for cfront, the C++ compiler front-end
5: written in the computer science research center of Bell Labs
6:
7: Copyright (c) 1984 AT&T, Inc. All rigths Reserved
8: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T, INC.
9:
10: size.c:
11:
12: initialize alignment and sizeof "constants"
13:
14: **********************************************************************/
15:
16: #include "cfront.h"
17: #include "size.h"
18:
19: // default sizes:
20: // Note: #if doesn't work on all systems
21: #ifdef u3b
22: #define Abbb
23: #endif
24: #ifdef u3b2
25: #define Abbb
26: #endif
27: #ifdef u3b5
28: #define Abbb
29: #endif
30: #ifdef u3b15
31: #define Abbb
32: #endif
33: #ifdef pyr
34: #define Abbb
35: #endif
36:
37:
38: #ifdef alliant
39: #define Am68
40: #endif
41: #ifdef apollo
42: #define Am68
43: #endif
44: #if defined(sun2) || defined(mc68010)
45: #define Am68
46: #endif
47: #if defined(sun3) || defined(mc68020)
48: #define Am68
49: #endif
50: #if defined(mc68k) || defined(hp9000s200) || defined(hp9000s300)
51: #define Am68
52: #endif
53:
54: #ifdef iAPX286
55: #ifdef LARGE
56: #define Ai286l
57: #endif
58: #endif
59:
60: #ifdef Abbb
61: /* AT&T 3Bs */
62: #define DBI_IN_WORD 32
63: #define DBI_IN_BYTE 8
64: #define DSZ_CHAR 1
65: #define DAL_CHAR 1
66: #define DSZ_SHORT 2
67: #define DAL_SHORT 2
68: #define DSZ_INT 4
69: #define DAL_INT 4
70: #define DSZ_LONG 4
71: #define DAL_LONG 4
72: #define DSZ_FLOAT 4
73: #define DAL_FLOAT 4
74: #define DSZ_DOUBLE 8
75: #define DAL_DOUBLE 4
76: #define DSZ_LDOUBLE 8
77: #define DAL_LDOUBLE 4
78: #define DSZ_STRUCT 4
79: #define DAL_STRUCT 4
80: //#define DSZ_FRAME 4
81: //#define DAL_FRAME 4
82: #define DSZ_WORD 4
83: #define DSZ_WPTR 4
84: #define DAL_WPTR 4
85: #define DSZ_BPTR 4
86: #define DAL_BPTR 4
87: //#define DSZ_TOP 0
88: //#define DSZ_BOTTOM 0
89: #define DLARGEST_INT "2147483647" /* 2**31 - 1 */
90: #define DF_SENSITIVE 0
91: #define DF_OPTIMIZED 1
92: #else
93: #ifdef Am68
94: /* most M68K boxes */
95: #if defined(hp9000s200) || defined(hp9000s300) || defined(sun)
96: #define DBI_IN_WORD 32
97: #else
98: #define DBI_IN_WORD 16
99: #endif
100:
101: #define DBI_IN_BYTE 8
102: #define DSZ_CHAR 1
103: #define DAL_CHAR 1
104: #define DSZ_SHORT 2
105: #define DAL_SHORT 2
106: #define DSZ_INT 4
107: #define DAL_INT 2
108: #define DSZ_LONG 4
109: #define DAL_LONG 2
110: #define DSZ_FLOAT 4
111: #define DAL_FLOAT 2
112: #define DSZ_DOUBLE 8
113: #define DAL_DOUBLE 2
114: #define DSZ_LDOUBLE 8
115: #define DAL_LDOUBLE 2
116: #define DSZ_STRUCT 2
117: #define DAL_STRUCT 2
118: //#define DSZ_FRAME 4
119: //#define DAL_FRAME 4
120: #ifdef sun
121: #define DSZ_WORD 4
122: #define DZB_BOUNDARY 2
123: #else
124: #define DSZ_WORD 2
125: #define DZB_BOUNDARY 2
126: #endif
127: #define DSZ_WPTR 4
128: #define DAL_WPTR 2
129: #define DSZ_BPTR 4
130: #define DAL_BPTR 2
131: //#define DSZ_TOP 0
132: //#define DSZ_BOTTOM 0
133: #define DLARGEST_INT "2147483647" /* 2**31 - 1 */
134: #define DF_SENSITIVE 0
135: #define DF_OPTIMIZED 1
136: #else
137: #ifdef Ai286l
138: /* Intel 80286 large model */
139: #define DBI_IN_WORD 16
140: #define DBI_IN_BYTE 8
141: #define DSZ_CHAR 1
142: #define DAL_CHAR 1
143: #define DSZ_SHORT 2
144: #define DAL_SHORT 2
145: #define DSZ_INT 2
146: #define DAL_INT 2
147: #define DSZ_LONG 4
148: #define DAL_LONG 2
149: #define DSZ_FLOAT 4
150: #define DAL_FLOAT 2
151: #define DSZ_DOUBLE 8
152: #define DAL_DOUBLE 2
153: #define DSZ_LDOUBLE 8
154: #define DAL_LDOUBLE 2
155: #define DSZ_STRUCT 2
156: #define DAL_STRUCT 2
157: //#define DSZ_FRAME 4
158: //#define DAL_FRAME 4
159: #define DSZ_WORD 2
160: #define DSZ_WPTR 4
161: #define DAL_WPTR 2
162: #define DSZ_BPTR 4
163: #define DAL_BPTR 2
164: //#define DSZ_TOP 0
165: //#define DSZ_BOTTOM 0
166: #define DLARGEST_INT "32767" /* 2**15 - 1 */
167: #define DF_SENSITIVE 0
168: #define DF_OPTIMIZED 1
169: #else
170: #if defined(uts) || defined(hp9000s800) || defined(sun4) || defined(sparc)
171: /* Amdahl running UTS, HP RISC */
172: #define DBI_IN_WORD 32
173: #define DBI_IN_BYTE 8
174: #define DSZ_CHAR 1
175: #define DAL_CHAR 1
176: #define DSZ_SHORT 2
177: #define DAL_SHORT 2
178: #define DSZ_INT 4
179: #define DAL_INT 4
180: #define DSZ_LONG 4
181: #define DAL_LONG 4
182: #define DSZ_FLOAT 4
183: #define DAL_FLOAT 4
184: #define DSZ_DOUBLE 8
185: #define DAL_DOUBLE 8
186: #define DSZ_LDOUBLE 8
187: #define DAL_LDOUBLE 8
188: #define DSZ_STRUCT 1
189: #define DAL_STRUCT 1
190: #define DSZ_WORD 4
191: #define DSZ_WPTR 4
192: #define DAL_WPTR 4
193: #define DSZ_BPTR 4
194: #define DAL_BPTR 4
195: #define DLARGEST_INT "2147483647" /* 2**31 - 1 */
196: #define DF_SENSITIVE 0
197: #define DF_OPTIMIZED 1
198: #else
199: #ifdef hpux
200: /* hp */
201: #define DBI_IN_WORD 32
202: #define DBI_IN_BYTE 8
203: #define DSZ_CHAR 1
204: #define DAL_CHAR 1
205: #define DSZ_SHORT 2
206: #define DAL_SHORT 2
207: #define DSZ_INT 4
208: #define DAL_INT 4
209: #define DSZ_LONG 4
210: #define DAL_LONG 4
211: #define DSZ_FLOAT 4
212: #define DAL_FLOAT 4
213: #define DSZ_DOUBLE 8
214: #define DAL_DOUBLE 8
215: #define DSZ_LDOUBLE 8
216: #define DAL_LDOUBLE 8
217: #define DSZ_STRUCT 1
218: #define DAL_STRUCT 1
219: #define DSZ_WORD 4
220: #define DSZ_WPTR 4
221: #define DAL_WPTR 4
222: #define DSZ_BPTR 4
223: #define DAL_BPTR 4
224: #define DLARGEST_INT "2147483647" /* 2**31 - 1 */
225: #define DF_SENSITIVE 1
226: #define DF_OPTIMIZED 1
227: #else
228: #if defined(vax) || defined(ibm032) || defined(i386)
229: /* VAX, IBM 32, Intel 386 */
230: #define DBI_IN_WORD 32
231: #define DBI_IN_BYTE 8
232: #define DSZ_CHAR 1
233: #define DAL_CHAR 1
234: #define DSZ_SHORT 2
235: #define DAL_SHORT 2
236: #define DSZ_INT 4
237: #define DAL_INT 4
238: #define DSZ_LONG 4
239: #define DAL_LONG 4
240: #define DSZ_FLOAT 4
241: #define DAL_FLOAT 4
242: #define DSZ_DOUBLE 8
243: #define DAL_DOUBLE 4
244: #define DSZ_LDOUBLE 8
245: #define DAL_LDOUBLE 4
246: #define DSZ_STRUCT 1
247: #define DAL_STRUCT 1
248: //#define DSZ_FRAME 4
249: //#define DAL_FRAME 4
250: #define DSZ_WORD 4
251: #define DSZ_WPTR 4
252: #define DAL_WPTR 4
253: #define DSZ_BPTR 4
254: #define DAL_BPTR 4
255: //#define DSZ_TOP 0
256: //#define DSZ_BOTTOM 0
257: #define DLARGEST_INT "2147483647" /* 2**31 - 1 */
258: #define DF_SENSITIVE 0
259: #define DF_OPTIMIZED 1
260: #else
261: #ifdef mc300
262: #define DBI_IN_WORD 32
263: #define DBI_IN_BYTE 8
264: #define DSZ_CHAR 1
265: #define DAL_CHAR 1
266: #define DSZ_SHORT 2
267: #define DAL_SHORT 2
268: #define DSZ_INT 4
269: #define DAL_INT 4
270: #define DSZ_LONG 4
271: #define DAL_LONG 4
272: #define DSZ_FLOAT 4
273: #define DAL_FLOAT 4
274: #define DSZ_DOUBLE 8
275: #define DAL_DOUBLE 4
276: #define DSZ_LDOUBLE 8
277: #define DAL_LDOUBLE 4
278: #define DSZ_STRUCT 2
279: #define DAL_STRUCT 2
280: //#define DSZ_FRAME 4
281: //#define DAL_FRAME 4
282: #define DSZ_WORD 4
283: #define DSZ_WPTR 4
284: #define DAL_WPTR 4
285: #define DSZ_BPTR 4
286: #define DAL_BPTR 4
287: //#define DSZ_TOP 0
288: //#define DSZ_BOTTOM 0
289: #define DLARGEST_INT "2147483647" /* 2**31 - 1 */
290: #define DF_SENSITIVE 0
291: #define DF_OPTIMIZED 1
292: #else
293: /* defaults: 0 => error */
294: #define DBI_IN_WORD 0
295: #define DBI_IN_BYTE 0
296: #define DSZ_CHAR 1
297: #define DAL_CHAR 1
298: #define DSZ_SHORT 0
299: #define DAL_SHORT 0
300: #define DSZ_INT 0
301: #define DAL_INT 0
302: #define DSZ_LONG 0
303: #define DAL_LONG 0
304: #define DSZ_FLOAT 0
305: #define DAL_FLOAT 0
306: #define DSZ_DOUBLE 0
307: #define DAL_DOUBLE 0
308: #define DSZ_LDOUBLE 0
309: #define DAL_LDOUBLE 0
310: #define DSZ_STRUCT 0
311: #define DAL_STRUCT 0
312: #define DSZ_WORD 0
313: #define DSZ_WPTR 0
314: #define DAL_WPTR 0
315: #define DSZ_BPTR 0
316: #define DAL_BPTR 0
317: #define DLARGEST_INT "0"
318: #define DF_SENSITIVE 0
319: #define DF_OPTIMIZED 0
320: #endif
321: #endif
322: #endif
323: #endif
324: #endif
325: #endif
326: #endif
327:
328: #ifndef DZB_BOUNDARY
329: // #define ZB_BOUNDARY DSZ_WORD
330: #define DZB_BOUNDARY DSZ_WORD
331: #endif
332:
333: int BI_IN_WORD = DBI_IN_WORD;
334: int BI_IN_BYTE = DBI_IN_BYTE;
335: int SZ_CHAR = DSZ_CHAR;
336: int AL_CHAR = DAL_CHAR;
337: int SZ_SHORT = DSZ_SHORT;
338: int AL_SHORT = DAL_SHORT;
339: int SZ_INT = DSZ_INT;
340: int AL_INT = DAL_INT;
341: int SZ_LONG = DSZ_LONG;
342: int AL_LONG = DAL_LONG;
343: int SZ_FLOAT = DSZ_FLOAT;
344: int AL_FLOAT = DAL_FLOAT;
345: int SZ_DOUBLE = DSZ_DOUBLE;
346: int AL_DOUBLE = DAL_DOUBLE;
347: int SZ_LDOUBLE = DSZ_LDOUBLE;
348: int AL_LDOUBLE = DAL_LDOUBLE;
349: int SZ_STRUCT = DSZ_STRUCT;
350: int AL_STRUCT = DAL_STRUCT;
351: //int SZ_FRAME = DSZ_FRAME;
352: //int AL_FRAME = DAL_FRAME;
353: int SZ_WORD = DSZ_WORD;
354: int ZB_BOUNDARY = DZB_BOUNDARY;
355: int SZ_WPTR = DSZ_WPTR;
356: int AL_WPTR = DAL_WPTR;
357: int SZ_BPTR = DSZ_BPTR;
358: int AL_BPTR = DAL_BPTR;
359: //int SZ_TOP = DSZ_TOP;
360: //int SZ_BOTTOM = DSZ_BOTTOM;
361: char* LARGEST_INT = DLARGEST_INT;
362: int F_SENSITIVE = DF_SENSITIVE;
363: int F_OPTIMIZED = DF_OPTIMIZED;
364:
365: int arg1 = 0;
366: int arg2 = 0;
367:
368: int get_line(FILE* fp)
369: {
370: char s[32];
371:
372: if (fscanf(fp," %s %d %d",s,&arg1,&arg2) == EOF) return 0;
373: // fprintf(stderr,"xxx %s %d %d",s,arg1,arg2);
374: if (strcmp("char",s) == 0) {
375: SZ_CHAR = arg1;
376: AL_CHAR = arg2;
377: return 1;
378: }
379: if (strcmp("short",s) == 0) {
380: SZ_SHORT = arg1;
381: AL_SHORT = arg2;
382: return 1;
383: }
384: if (strcmp("int",s) == 0) {
385: SZ_INT = arg1;
386: AL_INT = arg2;
387: if (fscanf(fp," %s",s) == EOF) return 0;
388: LARGEST_INT = new char[strlen(s)+1];
389: strcpy(LARGEST_INT,s);
390: return 1;
391: }
392: if (strcmp("long",s) == 0) {
393: SZ_LONG = arg1;
394: AL_LONG = arg2;
395: return 1;
396: }
397: if (strcmp("float",s) == 0) {
398: SZ_FLOAT = arg1;
399: AL_FLOAT = arg2;
400: return 1;
401: }
402: if (strcmp("double",s) == 0) {
403: SZ_DOUBLE = arg1;
404: AL_DOUBLE = arg2;
405: return 1;
406: }
407: if (strcmp("ldouble",s) == 0) {
408: SZ_LDOUBLE = arg1;
409: AL_LDOUBLE = arg2;
410: return 1;
411: }
412: if (strcmp("bit",s) == 0) {
413: BI_IN_BYTE = arg1;
414: BI_IN_WORD = arg2;
415: return 1;
416: }
417: if (strcmp("struct",s) == 0) {
418: SZ_STRUCT = arg1;
419: AL_STRUCT = arg2;
420: return 1;
421: }
422: if (strcmp("struct2",s) == 0) {
423: F_SENSITIVE = arg1;
424: F_OPTIMIZED = arg2;
425: return 1;
426: }
427: if (strcmp("frame",s) == 0) {
428: // SZ_FRAME = arg1;
429: // AL_FRAME = arg2;
430: return 1;
431: }
432: if (strcmp("word",s) == 0) {
433: SZ_WORD = arg1;
434: return 1;
435: }
436: if (strcmp("zero_bitfield_boundary",s) == 0) {
437: ZB_BOUNDARY = arg1;
438: return 1;
439: }
440: if (strcmp("wptr",s) == 0) {
441: SZ_WPTR = arg1;
442: AL_WPTR = arg2;
443: return 1;
444: }
445: if (strcmp("bptr",s) == 0) {
446: SZ_BPTR = arg1;
447: AL_BPTR = arg2;
448: return 1;
449: }
450: if (strcmp("top",s) == 0) {
451: // SZ_TOP = arg1;
452: // SZ_BOTTOM = arg2;
453: return 1;
454: }
455: return 0;
456: }
457:
458: int read_align(char* f)
459: {
460: char* p = f;
461: if (*p == 0) {
462: fprintf(stderr,"size/align file missing\n");
463: ext(1);
464: }
465: FILE* fp = fopen(f,"r");
466: if (fp == 0) return 1;
467: while (get_line(fp)) ;
468: return 0;
469: }
470: /*
471: print_align(char* s)
472: {
473: fprintf(stderr,"%s sizes and alignments\n\n",s);
474:
475: fprintf(stderr," size align largest\n");
476: fprintf(stderr,"char %d %d\n",SZ_CHAR,AL_CHAR);
477: fprintf(stderr,"short %d %d\n",SZ_SHORT,AL_SHORT);
478: fprintf(stderr,"int %d %d %s\n",SZ_INT,AL_INT,LARGEST_INT);
479: fprintf(stderr,"long %d %d\n",SZ_LONG,AL_LONG);
480: fprintf(stderr,"float %d %d\n",SZ_FLOAT,AL_FLOAT);
481: fprintf(stderr,"double %d %d\n",SZ_DOUBLE,AL_DOUBLE);
482: fprintf(stderr,"ldouble %d %d\n",SZ_LDOUBLE,AL_LDOUBLE);
483: fprintf(stderr,"bptr %d %d\n",SZ_BPTR,AL_BPTR);
484: fprintf(stderr,"wptr %d %d\n",SZ_WPTR,AL_WPTR);
485: fprintf(stderr,"struct %d %d\n",SZ_STRUCT,AL_STRUCT);
486: fprintf(stderr,"struct2 %d %d\n",F_SENSITIVE,F_OPTIMIZED);
487: // fprintf(stderr,"frame %d %d\n",SZ_FRAME,AL_FRAME);
488:
489: fprintf(stderr,"%d bits in a byte, %d bits in a word, %d bytes in a word zero bitfield aligned to %d bytes\n",
490: BI_IN_BYTE, BI_IN_WORD, SZ_WORD, ZB_BOUNDARY);
491: return 1;
492: }
493: */
494:
495: int c_strlen(const char* s)
496: /*
497: return sizeof(s) with escapes processed
498: sizeof("") == 1 the terminating 0
499: sizeof("a") == 2
500: sizeof("\0x") == 3 0 x 0
501: sizeof("\012") == 2 '\012'
502: sizeof("\01") '\001'
503: sizeof("\x") == 2 \ ignored
504:
505: */
506: {
507: int i = 1;
508: for (const char* p = s; *p; i++,p++) {
509: if (*p == '\\') { // '\?
510: switch (*++p) {
511: case '0':
512: switch (p[1]) { // '\01' or '\012'
513: case '0': case '1': case '2': case '3':
514: case '4': case '5': case '6': case '7':
515: break;
516: default:
517: continue; // '\0'
518: }
519: /* no break */
520: case '1': case '2': case '3':
521: case '4': case '5': case '6': case '7': // '\123'
522: switch (*++p) {
523: case '0': case '1': case '2': case '3':
524: case '4': case '5': case '6': case '7':
525: switch (*++p) {
526: case '0': case '1': case '2': case '3':
527: case '4': case '5': case '6': case '7':
528: break;
529: default:
530: --p;
531: }
532: break;
533: default:
534: --p;
535: }
536: }
537: }
538: }
539: return i;
540: }
541: /* ODI notes --
542:
543: * move all the initialization #ifdef's into here so they
544: * can be changed without recompiling the whole compiler.
545: * Add ZB_BOUNDARY to represent the start of a bitfield 32 bit
546: * throw as distinct from the "word", which is 32 bits on a sun.
547: *
548:
549: */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.