-
Notifications
You must be signed in to change notification settings - Fork 15
/
frontend.c
1255 lines (1135 loc) · 22.5 KB
/
frontend.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Tokenizer
*
* It might be nicer to switch to an algorithm with less meta-data
* but we have to balance code size/data size/speed
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#include "symtab.h"
#include "token.h"
#include "target.h"
static char *symtab;
/* _itoa : always use our own inbuilt one. We don't want to suck in all
of sscanf */
static char buf[11]; /* Int could be 32bit */
char *_uitoa(unsigned int i)
{
char *p = buf + sizeof(buf);
int c;
*--p = '\0';
do {
c = i % 10;
i /= 10;
*--p = '0' + c;
} while (i);
return p;
}
char *_itoa(int i)
{
char *p;
if (i >= 0)
return _uitoa(i);
p = _uitoa(-i);
*--p = '-';
return p;
}
static unsigned char filename[33] = { "<stdin>" };
static unsigned filechange = 1;
static int isoctal(unsigned char c)
{
if (c >= '0' && c <= '7')
return 1;
return 0;
}
static int iscsymbol(unsigned char c)
{
if (c == '_' || isalnum(c) || c >= 0x80)
return 1;
return 0;
}
static int iscsymstart(unsigned char c)
{
if (c == '_' || isalpha(c) || c >= 0x80)
return 1;
return 0;
}
/*
* Glue for now
*/
static unsigned err;
static unsigned line = 1;
static unsigned oldline = 0;
static void colonspace(void)
{
write(2, ": ", 2);
}
static void writes(const char *p)
{
unsigned len = strlen(p);
write(2, p, len);
}
static void report(char code, const char *p)
{
writes((const char *) filename);
colonspace();
writes(_itoa(line));
colonspace();
write(2, &code, 1);
colonspace();
writes(p);
write(2, "\n", 1);
}
void error(const char *p)
{
report('E', p);
err++;
}
void warning(const char *p)
{
report('W', p);
}
void fatal(const char *p)
{
error(p);
exit(1);
}
#define BLOCK 512
static uint8_t buffer[BLOCK]; /* 128 for CPM */
static uint8_t *bufptr = buffer + BLOCK;
static uint16_t bufleft = 0;
/* Pull the input stream in blocks and optimize for our case as this
is of course a very hot path. This design allows for future running
on things like CP/M and with the right block size is also optimal for
Fuzix */
static unsigned bgetc(void)
{
if (bufleft == 0) {
bufleft = read(0, buffer, BLOCK);
if (bufleft == 0)
return EOF;
bufptr = buffer;
}
bufleft--;
return *bufptr++;
}
static unsigned pushback;
static unsigned pbstack[2];
static unsigned isnl = 1;
static unsigned lastbslash;
static void directive(void);
unsigned get(void)
{
int c;
if (pushback) {
c = pbstack[--pushback];
pushback = 0;
if (c == '\n') {
isnl = 1;
line++;
}
return c;
}
c = bgetc();
while (c == '#' && isnl) {
directive();
c = bgetc();
}
isnl = 0;
if (c == '\n') {
line++;
isnl = 1;
}
/* backslash newline continuation */
if (lastbslash && c == '\n')
c = bgetc();
if (c == '\\')
lastbslash = 1;
else
lastbslash = 0;
if (c == EOF)
return 0;
return c;
}
unsigned get_nb(void)
{
unsigned c;
do {
c = get();
} while (c && isspace(c));
return c;
}
void unget(unsigned c)
{
if (pushback > 2)
fatal("double pushback");
pbstack[pushback++] = c;
if (c == '\n')
line--;
}
void required(unsigned cr)
{
unsigned c = get();
if (c != cr) {
error("expected quote");
unget(c);
}
}
/* # directive from cpp # line file - # line "file" */
/* TODO file name saving */
static void directive(void)
{
unsigned char *p = filename;
unsigned c;
line = 0;
do {
c = bgetc();
} while (isspace(c));
while (isdigit(c)) {
line = 10 * line + c - '0';
c = bgetc();
}
if (c == '\n')
return;
/* Should be a quote next */
c = bgetc();
if (c == '"') {
while ((c = bgetc()) != EOF && c != '"') {
/* Skip magic names */
if (p == filename && c == '<')
p = filename + 32;
if (c == '/')
p = filename;
else if (p < filename + 32)
*p++ = c;
}
filechange = 1;
}
*p = 0;
while ((c = bgetc()) != EOF) {
if (c == '\n')
return;
}
fatal("bad cpp");
}
#define NHASH 64
/* We could infer the symbol number from the table position in theory */
static struct name symbols[MAXNAME];
static struct name *nextsym = symbols;
static struct name *symbase; /* Base of post keyword symbols */
static struct name *symhash[NHASH];
/* Start of symbol range */
static unsigned symnum = T_SYMBOL;
/*
* Add a symbol to our symbol tables as we discover it. Log the
* fact if tracing.
*/
static struct name *new_symbol(const char *name, unsigned hash, unsigned id)
{
struct name *s;
if (nextsym == symbols + MAXNAME)
fatal("too many sybmols");
s = nextsym++;
strncpy(s->name, name, NAMELEN);
s->next = symhash[hash];
s->id = id;
symhash[hash] = s;
return s;
}
/*
* Find a symbol in a given has table
*/
static struct name *find_symbol(const char *name, unsigned hash)
{
struct name *s = symhash[hash];
while (s) {
if (strncmp(s->name, name, NAMELEN) == 0)
return s;
s = s->next;
}
return NULL;
}
/*
* A simple but adequate hashing algorithm. A better one would
* be worth it for performance.
*/
static unsigned hash_symbol(const char *name)
{
int hash = 0;
uint8_t n = 0;
while (*name && n++ < NAMELEN)
hash += *name++;
return (hash & (NHASH - 1));
}
static void write_symbol_table(void)
{
unsigned len = (uint8_t *) nextsym - (uint8_t *) symbase;
uint8_t n[2];
/* FIXME: proper temporary file! */
int fd = open(symtab, O_WRONLY | O_CREAT | O_TRUNC, 0600);
if (fd == -1) {
perror(symtab);
exit(1);
}
n[0] = len;
n[1] = len >> 8;
if (write(fd, n, 2) != 2 || write(fd, symbase, len) != len)
error("symbol I/O");
close(fd);
}
/*
* Token stream writing. We have a single special case to handle
* which is strings.
*/
static uint8_t outbuf[BLOCK];
static uint8_t *outptr = outbuf;
static void outbyte(unsigned char c)
{
*outptr++ = c;
if (outptr == outbuf + BLOCK) {
outptr = outbuf;
if (write(1, outbuf, BLOCK) != BLOCK)
error("I/O");
}
}
static void outflush(void)
{
unsigned len = outptr - outbuf;
if (len && write(1, outbuf, len) != len)
error("I/O");
}
static void outbyte_quoted(unsigned char c)
{
if (c == 0 || c == 0xFF)
outbyte(0xFF);
if (c == 0)
outbyte(0xFE);
else
outbyte(c);
}
static unsigned char tokdata[8];
static unsigned char *tokptr = tokdata;
static void encode_byte(unsigned c)
{
*tokptr++ = c;
}
static void write_token(unsigned c)
{
unsigned char *tp;
unsigned n = 0;
if (oldline != line || filechange) {
oldline = line;
outbyte(T_LINE & 0xFF);
outbyte(T_LINE >> 8);
outbyte(line);
if (filechange) {
outbyte(0x80 | (line >> 8));
tp = filename;
while (*tp && n++ < 32)
outbyte(*tp++);
outbyte(0);
} else
outbyte(line >> 8);
filechange = 0;
}
/* Write the token, then any data for it */
outbyte(c);
outbyte(c >> 8);
tp = tokdata;
while (tp < tokptr)
outbyte(*tp++);
/* Reset the data pointer */
tokptr = tokdata;
}
/* C keywords, ignoring all the modern crap */
static const char *keytab[] = {
/* Types */
"char",
"double",
"enum",
"float",
"int",
"long",
"short",
"signed",
"struct",
"union",
"unsigned",
"void",
/* Storage classes */
"auto",
"extern",
"register",
"static",
/* Modifiers */
"const",
"volatile",
/* Then the rest */
"break",
"case",
"continue",
"default",
"do",
"else",
"for",
"goto",
"if",
"return",
"sizeof",
"switch",
"typedef",
"while",
/* Nonsense */
"restrict",
NULL
};
/* Add keywords. These get added first so they head the hash lists */
static void keywords(void)
{
const char **p = keytab;
int i = T_KEYWORD;
while (*p) {
new_symbol(*p, hash_symbol(*p), i++);
p++;
}
symbase = nextsym;
}
/* Read up to 14 more bytes into the symbol name, plus a terminator */
static void get_symbol_tail(char *p)
{
unsigned n = 14;
unsigned c;
while ((c = get()) != 0) {
if (!iscsymbol(c))
break;
if (n) {
n--;
*p++ = c;
}
}
*p = 0;
unget(c);
}
/* Also does keywords */
static unsigned tokenize_symbol(unsigned c)
{
char symstr[16];
unsigned h;
struct name *s;
*symstr = c;
get_symbol_tail(symstr + 1);
/* We can't do cunning tricks to spot labels in this pass because
foo: is ambiguous between a label and a ?: */
h = hash_symbol(symstr);
s = find_symbol(symstr, h);
if (s)
return s->id;
return new_symbol(symstr, h, symnum++)->id;
}
/*
* Software float encoding. This is a bit long winded because
* we want it to work on an 8bit micro on a compiler that
* has no floating point so that you can bootstrap an FP
* compiler with an integer only one.
*/
/*
* This does all the clever stuff and is about the only
* IEEE754 dependent part of the operation except negate.
*
* We are passed a 32.32 fixed point value in sum/frac along
* with a binary exponent (exp) from building the bits, and a
* decimal exponent from the user.
*
* We turn this into a 28bit mantissa for ease of manipulation
* and then exponentiate for the passed exponent adjusting the
* binary exponent as we go to keep the bits. Finally we normalize it
* to 24bit manitissa and assemble an unsigned IEEE 754 float.
*
* This is not paritcularly fast. It's adequate for the compiler
* but it's not clear there is any gain from using an FP version
* for FP capable compilers.
*/
static uint16_t rtype;
static uint32_t result;
static void overflow(void)
{
error("overflow");
}
static void exp_overflow(void)
{
warning("exponent under/overflow");
}
#ifdef IBMFLOAT
/* Older IBM style floating point
Numbers are encoded as
Sign.1 Exponent.8 Mantissa.24
Unlike IEEE754 however the exponent is in nybbles and there may be
up to 3 leading zeros in the mantissa. Negative zero is also verboten */
static void convert_fix32(int exp, uint32_t sum, uint32_t frac, int uexp)
{
rtype = T_FLOATVAL;
if (sum == 0 && frac == 0) {
result = 0;
return;
}
/* Do the initial work bit by bit */
/* Start by getting it down to 28bits */
while (!(sum & 0x08000000)) {
sum <<= 1;
if (frac & 0x80000000)
sum |= 1;
frac <<= 1;
exp--;
}
/* A 28bit number will never overflow when multiplied by ten */
while (uexp > 0) {
sum *= 10;
/* Shift it down to keep it fitting */
while (sum & 0xF0000000) {
sum >>= 1;
exp++;
}
uexp--;
}
while (uexp < 0) {
sum /= 10;
while (!(sum & 0x08000000)) {
sum <<= 1;
exp--;
}
uexp++;
}
exp += 22;
/* Align the mantissa on a nybble basis */
while(exp & 3) {
sum >>= 1;
exp++;
}
/* Now work in nybbles */
exp >>= 2;
/* If the sum has too many bits then shift it down and adjust
the exponent */
while (sum & 0xFF000000) {
sum >>= 4;
exp++;
}
/* If there are leading zero bits, then shift up and merge in frac */
while ((sum & 0x00F00000) == 0) {
sum <<= 4;
/* Copy 4 bits up at a time */
sum |= (frac >> 28);
frac <<= 4;
exp--;
}
/* Bias */
exp += 64;
/* No denormals */
if (exp < 1) {
exp_overflow();
result = 0; /* Zero */
return;
}
if (exp > 127) {
exp_overflow();
result = 0x7F800000; /* Infinity */
return;
}
/* Assemble result */
sum &= 0x00FFFFFF;
sum |= (exp << 24) & 0x7F800000UL;
result = sum;
}
#else
static void convert_fix32(int exp, uint32_t sum, uint32_t frac, int uexp)
{
rtype = T_FLOATVAL;
if (sum == 0 && frac == 0) {
result = 0;
return;
}
/* Start by getting it down to 28bits */
while (!(sum & 0x08000000)) {
sum <<= 1;
if (frac & 0x80000000)
sum |= 1;
frac <<= 1;
exp--;
}
/* A 28bit number will never overflow when multiplied by ten */
while (uexp > 0) {
sum *= 10;
/* Shift it down to keep it fitting */
while (sum & 0xF0000000) {
sum >>= 1;
exp++;
}
uexp--;
}
/* Fix up the exponent in the other direction */
while (uexp < 0) {
sum /= 10;
while (!(sum & 0x08000000)) {
sum <<= 1;
exp--;
}
uexp++;
}
exp += 22;
/* If the sum has too many bits then shift it down and adjust
the exponent */
while (sum & 0xFF000000) {
sum >>= 1;
exp++;
}
/* If there are leading zero bits, then shift up and merge in frac */
while ((sum & 0x00800000) == 0) {
sum <<= 1;
if (frac & 0x80000000)
sum++;
frac <<= 1;
exp--;
}
exp += 128;
/* No denormals */
if (exp < 1) {
exp_overflow();
result = 0; /* Zero */
return;
}
if (exp > 254) {
exp_overflow();
result = 0x7F800000; /* Infinity */
return;
}
/* Assemble result */
sum &= 0x007FFFFF;
sum |= (exp << 23) & 0x7F800000UL;
result = sum;
}
#endif
/* After the E or P in a floating point value is a signed decimal exponent.
Parse this */
static int parse_exponent(void)
{
uint32_t sum = 0, n;
int neg = 1;
unsigned c;
c = get();
if (c == '-') {
neg = -1;
c = get();
} else if (c == '+')
c = get();
/* Parse integer digits only */
while (isdigit(c)) {
c -= '0';
n = sum * 10 + c;
if (n < sum)
overflow();
sum = n;
c = get();
}
unget(c);
/* If it is out of the range then error */
if (sum > 128)
exp_overflow();
return sum * neg;
}
/* Decimal float format digits.digitsEdigits. We don't handle
the 0.0000000000000000000000000000000001 type silly yet */
/* Table of decminal fractions as binary value. We only need 24bit
precision worst case so this is adequate */
static const uint32_t fraction[10] = {
/* 0.100000 */ 0x199999A0,
/* 0.010000 */ 0x28F5C28,
/* 0.001000 */ 0x418937,
/* 0.000100 */ 0x68DB8,
/* 0.000010 */ 0xA7C5,
/* 0.000001 */ 0x10C6,
/* 0.000000 */ 0x1AD,
/* 0.000000 */ 0x2A,
/* 0.000000 */ 0x4,
0
};
static void dec_format(unsigned c)
{
uint32_t sum = 0, frac = 0, n;
unsigned ex = 0, uex;
/* Parse digits before . : could be integer or float */
while (c != 'E' && c != 'e' && c != '.') {
if (!isdigit(c)) {
/* Done */
unget(c);
if (ex == 0) {
result = sum;
rtype = T_INTVAL;
return;
}
/* Oversized integer */
overflow();
return;
}
c -= '0';
n = sum * 10 + c;
/* If we wrap then keep shifting */
/* There's probably a better way to do this */
while (n < sum) {
sum >>= 1;
ex++;
n = sum * 10 + c;
}
sum = n;
c = get();
}
/* We have done the integer part, and found floaty stuff */
n = 0;
/* Parse any fractional part using the fraction table */
if (c == '.') {
while (1) {
c = get();
if (c == 'E' || c == 'e')
break;
if (!isdigit(c)) {
unget(c);
convert_fix32(ex, sum, frac, 0);
return;
}
c -= '0';
if (fraction[n]) {
frac += c * fraction[n];
n++;
}
}
}
/* If we shifted the non fractional part to make it fit then we
don't need the frac bits */
if (ex)
frac = 0;
/* Now look for an exponent */
if (c == 'E' || c == 'e')
uex = parse_exponent();
else
unget(c);
convert_fix32(ex, sum, frac, uex);
}
/*
* Hex format
* - parse a hex number
* - if we find a P or a . then it's a float
*/
static unsigned unhex(unsigned c)
{
c = toupper(c);
c -= '0';
if (c > 9)
c -= 7;
return c;
}
static void hex_format(void)
{
uint32_t sum = 0, frac = 0, n;
unsigned c;
int ct;
unsigned ex = 0, uex;
/* Parse digits before . : could be integer or float */
while (1) {
c = get();
if (c == '.' || c == 'P' || c == 'p')
break;
if (!isxdigit(c)) {
/* Done */
unget(c);
if (ex == 0) {
result = sum;
rtype = T_INTVAL;
return;
}
/* Oversized integer */
error("range");
return;
}
c = unhex(c);
n = sum << 4;
if (n >= sum)
sum = n + c;
else
/* Digits we are parsing are not relevant, but remember
the shift */
ex += 4;
}
/* We have done the integer part, and found floaty stuff */
ct = 28;
/* If we stopped parsing because we had too many bits then
don't add in the fractional part */
if (ex)
ct = -1;
if (c == '.') {
while (1) {
c = get();
if (c == 'P' || c == 'p')
break;
if (!isxdigit(c)) {
unget(c);
convert_fix32(ex, sum, frac, 0);
return;
}
/* Keep adding on fraction bits that fit */
c = unhex(c);
/* Only add relevant fractions */
if (ct >= 0) {
frac |= c << n;
ct -= 4;
}
}
}
/* Now look for an exponent */
if (c == 'P' || c == 'p')
uex = parse_exponent();
else
unget(c);
convert_fix32(ex, sum, frac, uex);
}
/*
* We parsed a 0, check for 0x or octal
*/
static void oct_format(void)
{
uint32_t sum = 0, n;
unsigned c;
c = get();
if (c == 'x' || c == 'X') {
hex_format();
return;
}
if (c == '.') {
/* Implied fractional part of decimal */
dec_format(c);
return;
}
while (c >= '0' && c <= '7') {
n = (sum << 3) + c - '0';
if (n < sum)
overflow();
sum = n;
c = get();
}
/* Done */
unget(c);
result = sum;
rtype = T_INTVAL;
}
/*
* Leading digit
* 0 octal or hex
* other decimal
*
* Parse a C number. The statics result and rtype
* are set up as the bits and the float/int status
*/
static void parse_digits(unsigned c)
{
if (c == '0')
oct_format();
else
dec_format(c);
}
/*
* TODO longlong if we add it to the compiler
*/
static unsigned tokenize_numeric(unsigned c, unsigned neg)
{
unsigned force_unsigned = 0;
unsigned force_long = 0;
unsigned force_float = 0;
unsigned cup;
parse_digits(c);
/* Look for trailing type information */
while (1) {
c = get();
cup = toupper(c);
if (cup == 'F' && !force_float)
force_float = 1;
else if (cup == 'U' && !force_unsigned)
force_unsigned = 1;
else if (cup == 'L' && !force_long)
force_long = 1;
else {
unget(c);
break;
}
}
/* UF is not valid but LF or FL is a double */
if (force_float && force_unsigned)
error("invalid type specifiers");
if (force_float && rtype != T_FLOATVAL) {
convert_fix32(0, result, 0, 0);
/* This also sets rtype */
}
if (neg) {
/* Assumes IEEE 754 (but also works IBMfloat...) */
if (rtype == T_FLOATVAL)
result ^= 0x80000000UL;
else
result = -result;
}
if (rtype != T_FLOATVAL) {
/* Anything can be shoved in a ulong */
rtype = T_ULONGVAL;
/* FIXME: this needs review for the -32768 case */
/* Will it fit in a uint ? */
if (!force_long && result <= TARGET_MAX_UINT) {
rtype = T_UINTVAL;
if (!force_unsigned && result <= TARGET_MAX_INT)
rtype = T_INTVAL;
} else if (!force_unsigned) {
/* Maybe a signed long then ? */
if (result <= TARGET_MAX_LONG)
rtype = T_LONGVAL;