OpenCores
URL https://opencores.org/ocsvn/thor/thor/trunk

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [CC64/] [source/] [Type.cpp] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2012-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
// CC64 - 'C' derived language compiler
9
//  - 64 bit CPU
10
//
11
// This source file is free software: you can redistribute it and/or modify 
12
// it under the terms of the GNU Lesser General Public License as published 
13
// by the Free Software Foundation, either version 3 of the License, or     
14
// (at your option) any later version.                                      
15
//                                                                          
16
// This source file is distributed in the hope that it will be useful,      
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
19
// GNU General Public License for more details.                             
20
//                                                                          
21
// You should have received a copy of the GNU General Public License        
22
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
23
//                                                                          
24
// ============================================================================
25
//
26
#include "stdafx.h"
27
 
28
extern int64_t initbyte();
29
extern int64_t initchar();
30
extern int64_t initshort();
31
extern int64_t initlong();
32
extern int64_t initquad();
33
extern int64_t initfloat();
34
extern int64_t inittriple();
35
int64_t InitializePointer();
36
 
37
 
38
bool TYP::IsScalar()
39
{
40
        return
41
                type == bt_byte ||
42
                type == bt_char ||
43
                type == bt_short ||
44
                type == bt_long ||
45
                type == bt_ubyte ||
46
                type == bt_uchar ||
47
                type == bt_ushort ||
48
                type == bt_ulong ||
49
                type == bt_enum ||
50
                type == bt_exception ||
51
                type == bt_unsigned;
52
}
53
 
54
 
55
TYP *TYP::GetBtp() {
56
    if (btp==0)
57
      return nullptr;
58
    return &compiler.typeTable[btp];
59
};
60
TYP *TYP::GetPtr(int n) {
61
  if (n==0)
62
    return nullptr;
63
  return &compiler.typeTable[n];
64
};
65
int TYP::GetIndex() { return this - &compiler.typeTable[0]; };
66
 
67
TYP *TYP::Copy(TYP *src)
68
{
69
        TYP *dst = nullptr;
70
 
71
  dfs.printf("<TYP__Copy>\n");
72
        if (src) {
73
                dst = allocTYP();
74
//              if (dst==nullptr)
75
//                      throw gcnew C64::C64Exception();
76
                memcpy(dst,src,sizeof(TYP));
77
                dfs.printf("A");
78
                if (src->btp && src->GetBtp()) {
79
                dfs.printf("B");
80
                        dst->btp = Copy(src->GetBtp())->GetIndex();
81
                }
82
                dfs.printf("C");
83
                // We want to keep any base type indicator so Clear() isn't called.
84
                dst->lst.head = 0;
85
                dst->lst.tail = 0;
86
                dst->sname = new std::string(*src->sname);
87
                dfs.printf("D");
88
                TABLE::CopySymbolTable(&dst->lst,&src->lst);
89
        }
90
  dfs.printf("</TYP__Copy>\n");
91
        return dst;
92
}
93
 
94
TYP *TYP::Make(int bt, int siz)
95
{
96
        TYP *tp;
97
        dfs.puts("<TYP__Make>\n");
98
        tp = allocTYP();
99
        if (tp == nullptr)
100
                return nullptr;
101
        tp->val_flag = 0;
102
        tp->isArray = FALSE;
103
        tp->size = siz;
104
        tp->type = (e_bt)bt;
105
        tp->typeno = bt;
106
        tp->precision = siz * 8;
107
        if (bt == bt_pointer)
108
                tp->isUnsigned = TRUE;
109
        dfs.puts("</TYP__Make>\n");
110
        return tp;
111
}
112
 
113
// Given just a type number return the size
114
 
115
int TYP::GetSize(int num)
116
{
117
  if (num == 0)
118
    return 0;
119
  return compiler.typeTable[num].size;
120
}
121
 
122
// Basic type is one of the built in types supported by the compiler.
123
// Returns the basic type number for the type. The basic type number does
124
// not include complex types like struct, union, or class. For a struct,
125
// union, or class one of bt_struct, bt_union or bt_class is returned.
126
 
127
int TYP::GetBasicType(int num)
128
{
129
  if (num==0)
130
    return 0;
131
  return compiler.typeTable[num].type;
132
}
133
 
134
int TYP::GetHash()
135
{
136
        int n;
137
        TYP *p, *p1;
138
 
139
        n = 0;
140
        p = this;
141
        if (p==nullptr)
142
                throw new C64PException(ERR_NULLPOINTER,2);
143
        do {
144
                if (p->type==bt_pointer)
145
                        n+=20000;
146
                p1 = p;
147
                p = p->GetBtp();
148
        } while (p);
149
        n += p1->typeno;
150
        return n;
151
}
152
 
153
int TYP::GetElementSize()
154
{
155
        int n;
156
        TYP *p, *p1;
157
 
158
        n = 0;
159
        p = this;
160
        do {
161
                p1 = p;
162
                p = p->GetBtp();
163
        } while (p);
164
        switch(p1->type) {
165
        case bt_byte:
166
        case bt_ubyte:
167
                return 1;
168
        case bt_char:
169
        case bt_uchar:
170
                return 2;
171
        case bt_short:
172
        case bt_ushort:
173
                return 4;
174
        case bt_long:
175
        case bt_ulong:
176
        case bt_pointer:
177
                return 8;
178
        case bt_float:
179
        case bt_double:
180
                return 8;
181
        case bt_struct:
182
        case bt_class:
183
                return p1->size;
184
        default:
185
                return 8;
186
        }
187
        return n;
188
}
189
 
190
void TYP::put_ty()
191
{
192
        switch(type) {
193
        case bt_exception:
194
            lfs.printf("Exception");
195
            break;
196
        case bt_byte:
197
            lfs.printf("Byte");
198
            break;
199
        case bt_ubyte:
200
            lfs.printf("Unsigned Byte");
201
            break;
202
    case bt_char:
203
            lfs.printf("Char");
204
            break;
205
    case bt_short:
206
            lfs.printf("Short");
207
            break;
208
    case bt_enum:
209
            lfs.printf("enum ");
210
            goto ucont;
211
    case bt_long:
212
            lfs.printf("Long");
213
            break;
214
    case bt_unsigned:
215
            lfs.printf("unsigned long");
216
            break;
217
    case bt_float:
218
            lfs.printf("Float");
219
            break;
220
    case bt_double:
221
            lfs.printf("Double");
222
            break;
223
    case bt_pointer:
224
            if( val_flag == 0)
225
                    lfs.printf("Pointer to ");
226
            else
227
                    lfs.printf("Array of ");
228
            GetBtp()->put_ty();
229
            break;
230
    case bt_class:
231
            lfs.printf("class ");
232
            goto ucont;
233
    case bt_union:
234
            lfs.printf("union ");
235
            goto ucont;
236
    case bt_struct:
237
            lfs.printf("struct ");
238
ucont:                  if(sname->length() == 0)
239
                    lfs.printf("<no name> ");
240
            else
241
                    lfs.printf("%s ",(char *)sname->c_str());
242
            break;
243
    case bt_ifunc:
244
    case bt_func:
245
            lfs.printf("Function returning ");
246
            GetBtp()->put_ty();
247
            break;
248
    }
249
}
250
 
251
bool TYP::IsSameType(TYP *a, TYP *b, bool exact)
252
{
253
        if (a == b)
254
                return (true);
255
 
256
        switch (a->type) {
257
 
258
        case bt_float:
259
                if (b->type == bt_float)
260
                        return (true);
261
                if (b->type == bt_double)
262
                        return (true);
263
                return (false);
264
 
265
        case bt_double:
266
                if (b->type == bt_float)
267
                        return (true);
268
                if (b->type == bt_double)
269
                        return (true);
270
                return (false);
271
 
272
        case bt_long:
273
                if (b->type == bt_long)
274
                        return (true);
275
                if (!exact) {
276
                        if (b->type == bt_ulong)
277
                                return (true);
278
                        if (b->type == bt_short)
279
                                return (true);
280
                        if (b->type == bt_ushort)
281
                                return (true);
282
                        if (b->type == bt_char)
283
                                return (true);
284
                        if (b->type == bt_uchar)
285
                                return (true);
286
                        if (b->type == bt_byte)
287
                                return (true);
288
                        if (b->type == bt_ubyte)
289
                                return (true);
290
                        if (b->type == bt_enum)
291
                                return (true);
292
                }
293
                return (false);
294
 
295
        case bt_ulong:
296
                if (b->type == bt_ulong)
297
                        return (true);
298
                if (!exact) {
299
                        if (b->type == bt_long)
300
                                return (true);
301
                        if (b->type == bt_short)
302
                                return (true);
303
                        if (b->type == bt_ushort)
304
                                return (true);
305
                        if (b->type == bt_char)
306
                                return (true);
307
                        if (b->type == bt_uchar)
308
                                return (true);
309
                        if (b->type == bt_byte)
310
                                return (true);
311
                        if (b->type == bt_ubyte)
312
                                return (true);
313
                        if (b->type == bt_enum)
314
                                return (true);
315
                }
316
                return (false);
317
 
318
        case bt_short:
319
                if (b->type == bt_short)
320
                        return (true);
321
                if (!exact) {
322
                        if (b->type == bt_long)
323
                                return (true);
324
                        if (b->type == bt_ulong)
325
                                return (true);
326
                        if (b->type == bt_ushort)
327
                                return (true);
328
                        if (b->type == bt_char)
329
                                return (true);
330
                        if (b->type == bt_uchar)
331
                                return (true);
332
                        if (b->type == bt_byte)
333
                                return (true);
334
                        if (b->type == bt_ubyte)
335
                                return (true);
336
                        if (b->type == bt_enum)
337
                                return (true);
338
                }
339
                return (false);
340
 
341
        case bt_ushort:
342
                if (b->type == bt_ushort)
343
                        return (true);
344
                if (!exact) {
345
                        if (b->type == bt_long)
346
                                return (true);
347
                        if (b->type == bt_ulong)
348
                                return (true);
349
                        if (b->type == bt_short)
350
                                return (true);
351
                        if (b->type == bt_char)
352
                                return (true);
353
                        if (b->type == bt_uchar)
354
                                return (true);
355
                        if (b->type == bt_byte)
356
                                return (true);
357
                        if (b->type == bt_ubyte)
358
                                return (true);
359
                        if (b->type == bt_enum)
360
                                return (true);
361
                }
362
                return (false);
363
 
364
        case bt_uchar:
365
                if (b->type == bt_uchar)
366
                        return (true);
367
                if (!exact) {
368
                        if (b->type == bt_long)
369
                                return (true);
370
                        if (b->type == bt_ulong)
371
                                return (true);
372
                        if (b->type == bt_short)
373
                                return (true);
374
                        if (b->type == bt_ushort)
375
                                return (true);
376
                        if (b->type == bt_char)
377
                                return (true);
378
                        if (b->type == bt_byte)
379
                                return (true);
380
                        if (b->type == bt_ubyte)
381
                                return (true);
382
                        if (b->type == bt_enum)
383
                                return (true);
384
                }
385
                return (false);
386
 
387
        case bt_char:
388
                if (b->type == bt_char)
389
                        return (true);
390
                if (!exact) {
391
                        if (b->type == bt_long)
392
                                return (true);
393
                        if (b->type == bt_ulong)
394
                                return (true);
395
                        if (b->type == bt_short)
396
                                return (true);
397
                        if (b->type == bt_ushort)
398
                                return (true);
399
                        if (b->type == bt_uchar)
400
                                return (true);
401
                        if (b->type == bt_byte)
402
                                return (true);
403
                        if (b->type == bt_ubyte)
404
                                return (true);
405
                        if (b->type == bt_enum)
406
                                return (true);
407
                }
408
                return (false);
409
 
410
        case bt_byte:
411
                if (b->type == bt_byte)
412
                        return (true);
413
                if (!exact) {
414
                        if (b->type == bt_long)
415
                                return (true);
416
                        if (b->type == bt_ulong)
417
                                return (true);
418
                        if (b->type == bt_short)
419
                                return (true);
420
                        if (b->type == bt_ushort)
421
                                return (true);
422
                        if (b->type == bt_uchar)
423
                                return (true);
424
                        if (b->type == bt_char)
425
                                return (true);
426
                        if (b->type == bt_ubyte)
427
                                return (true);
428
                        if (b->type == bt_enum)
429
                                return (true);
430
                }
431
                return (false);
432
 
433
        case bt_ubyte:
434
                if (b->type == bt_ubyte)
435
                        return (true);
436
                if (!exact) {
437
                        if (b->type == bt_long)
438
                                return (true);
439
                        if (b->type == bt_ulong)
440
                                return (true);
441
                        if (b->type == bt_short)
442
                                return (true);
443
                        if (b->type == bt_ushort)
444
                                return (true);
445
                        if (b->type == bt_uchar)
446
                                return (true);
447
                        if (b->type == bt_char)
448
                                return (true);
449
                        if (b->type == bt_byte)
450
                                return (true);
451
                        if (b->type == bt_enum)
452
                                return (true);
453
                }
454
                return (false);
455
 
456
        case bt_pointer:
457
                if (a->type != b->type)
458
                        return (false);
459
                if (a->GetBtp() == b->GetBtp())
460
                        return (true);
461
                if (a->GetBtp() && b->GetBtp())
462
                        return (TYP::IsSameType(a->GetBtp(), b->GetBtp(), exact));
463
                return (false);
464
 
465
        case bt_struct:
466
        case bt_union:
467
        case bt_class:
468
                if (a->type != b->type)
469
                        return (false);
470
                if (a->GetBtp() == b->GetBtp())
471
                        return (true);
472
                if (a->GetBtp() && b->GetBtp())
473
                        return (TYP::IsSameType(a->GetBtp(), b->GetBtp(), exact));
474
                return (false);
475
 
476
        case bt_enum:
477
                if (a->typeno == b->typeno)
478
                        return (true);
479
                if (!exact) {
480
                        if (b->type == bt_long
481
                                || b->type == bt_ulong
482
                                || b->type == bt_short
483
                                || b->type == bt_ushort
484
                                || b->type == bt_char
485
                                || b->type == bt_uchar
486
                                || b->type == bt_enum
487
                                )
488
                                return (true);
489
                }
490
                return (false);
491
        }
492
        return (false);
493
}
494
 
495
// Initialize the type. Unions can't be initialized.
496
 
497
int64_t TYP::Initialize()
498
{
499
        int64_t nbytes;
500
 
501
        switch (type) {
502
        case bt_ubyte:
503
        case bt_byte:
504
                nbytes = initbyte();
505
                break;
506
        case bt_uchar:
507
        case bt_char:
508
        case bt_enum:
509
                nbytes = initchar();
510
                break;
511
        case bt_ushort:
512
        case bt_short:
513
                nbytes = initshort();
514
                break;
515
        case bt_pointer:
516
                if (val_flag)
517
                        nbytes = InitializeArray();
518
                else
519
                        nbytes = InitializePointer();
520
                break;
521
        case bt_exception:
522
        case bt_ulong:
523
        case bt_long:
524
                nbytes = initlong();
525
                break;
526
        case bt_struct:
527
                nbytes = InitializeStruct();
528
                break;
529
        case bt_union:
530
                nbytes = InitializeUnion();
531
                break;
532
        case bt_quad:
533
                nbytes = initquad();
534
                break;
535
        case bt_float:
536
        case bt_double:
537
                nbytes = initfloat();
538
                break;
539
        case bt_triple:
540
                nbytes = inittriple();
541
                break;
542
        default:
543
                error(ERR_NOINIT);
544
                nbytes = 0;
545
        }
546
        return (nbytes);
547
}
548
 
549
int64_t TYP::InitializeArray()
550
{
551
        int64_t nbytes;
552
        char *p;
553
 
554
        nbytes = 0;
555
        if (lastst == begin) {
556
                NextToken();               /* skip past the brace */
557
                while (lastst != end) {
558
                        // Allow char array initialization like { "something", "somethingelse" }
559
                        if (lastst == sconst && (GetBtp()->type == bt_char || GetBtp()->type == bt_uchar)) {
560
                                nbytes = strlen(laststr) * 2 + 2;
561
                                p = laststr;
562
                                while (*p)
563
                                        GenerateChar(*p++);
564
                                GenerateChar(0);
565
                                NextToken();
566
                        }
567
                        else
568
                                nbytes += GetBtp()->Initialize();
569
                        if (lastst == comma)
570
                                NextToken();
571
                        else if (lastst != end)
572
                                error(ERR_PUNCT);
573
                }
574
                NextToken();               /* skip closing brace */
575
        }
576
        else if (lastst == sconst && (GetBtp()->type == bt_char || GetBtp()->type == bt_uchar)) {
577
                nbytes = strlen(laststr) * 2 + 2;
578
                p = laststr;
579
                while (*p)
580
                        GenerateChar(*p++);
581
                GenerateChar(0);
582
                NextToken();
583
        }
584
        else if (lastst != semicolon)
585
                error(ERR_ILLINIT);
586
        if (nbytes < size) {
587
                genstorage(size - nbytes);
588
                nbytes = size;
589
        }
590
        else if (size != 0 && nbytes > size)
591
                error(ERR_INITSIZE);    /* too many initializers */
592
        return (nbytes);
593
}
594
 
595
int64_t TYP::InitializeStruct()
596
{
597
        SYM *sp;
598
        int64_t nbytes;
599
 
600
        needpunc(begin, 25);
601
        nbytes = 0;
602
        sp = sp->GetPtr(lst.GetHead());      /* start at top of symbol table */
603
        while (sp != 0) {
604
                while (nbytes < sp->value.i) {     /* align properly */
605
                                                                                   //                    nbytes += GenerateByte(0);
606
                        GenerateByte(0);
607
                        //                    nbytes++;
608
                }
609
                nbytes += sp->tp->Initialize();
610
                if (lastst == comma)
611
                        NextToken();
612
                else if (lastst == end)
613
                        break;
614
                else
615
                        error(ERR_PUNCT);
616
                sp = sp->GetNextPtr();
617
        }
618
        if (nbytes < size)
619
                genstorage(size - nbytes);
620
        needpunc(end, 26);
621
        return (size);
622
}
623
 
624
 
625
int64_t TYP::InitializeUnion()
626
{
627
        SYM *sp;
628
        int64_t nbytes;
629
        int64_t val;
630
        ENODE *node = nullptr;
631
        bool found = false;
632
 
633
        nbytes = 0;
634
        val = GetConstExpression(&node);
635
        if (node == nullptr)    // syntax error in GetConstExpression()
636
                return (0);
637
        sp = sp->GetPtr(lst.GetHead());      /* start at top of symbol table */
638
        while (sp != 0) {
639
                if (IsSameType(sp->tp, node->tp, false)) {
640
                        nbytes = node->esize;
641
                        switch (sp->tp->type) {
642
                        case bt_byte:   nbytes = 1; GenerateByte(val); break;
643
                        case bt_ubyte:  nbytes = 1; GenerateByte(val); break;
644
                        case bt_char:   nbytes = 2; GenerateChar(val); break;
645
                        case bt_uchar:  nbytes = 2; GenerateChar(val); break;
646
                        case bt_short:  nbytes = 4; GenerateWord(val); break;
647
                        case bt_ushort: nbytes = 4; GenerateWord(val); break;
648
                        case bt_long:   nbytes = 8; GenerateLong(val); break;
649
                        case bt_ulong:  nbytes = 8; GenerateLong(val); break;
650
                        case bt_float:  nbytes = 8; GenerateFloat((Float128 *)val); break;
651
                        case bt_double: nbytes = 8; GenerateFloat((Float128 *)val); break;
652
                        case bt_quad:   nbytes = 16; GenerateQuad((Float128 *)val); break;
653
                        }
654
                        found = true;
655
                        break;
656
                }
657
                sp = sp->GetNextPtr();
658
        }
659
        if (!found)
660
                error(ERR_INIT_UNION);
661
        if (lastst != semicolon)
662
                error(ERR_PUNCT);
663
        if (nbytes < size)
664
                genstorage(size - nbytes);
665
        return (size);
666
}
667
 
668
 
669
// GC support
670
 
671
bool TYP::FindPointerInStruct()
672
{
673
        SYM *sp;
674
 
675
        sp = sp->GetPtr(lst.GetHead());      // start at top of symbol table
676
        while (sp != 0) {
677
                if (sp->tp->FindPointer())
678
                        return (true);
679
                sp = sp->GetNextPtr();
680
        }
681
        return (false);
682
}
683
 
684
bool TYP::FindPointer()
685
{
686
        switch (type) {
687
        case bt_pointer: return (val_flag == FALSE);    // array ?
688
        case bt_struct: return (FindPointerInStruct());
689
        case bt_union: return (FindPointerInStruct());
690
        case bt_class: return (FindPointerInStruct());
691
        }
692
        return (false);
693
}
694
 
695
 
696
// Return whether or not the type might be able to be skipped over by the GC.
697
 
698
bool TYP::IsSkippable()
699
{
700
        switch (type) {
701
        case bt_struct: return(true);
702
        case bt_union: return(true);
703
        case bt_class: return(true);
704
        case bt_pointer:
705
                if (val_flag == TRUE)
706
                        return (true);
707
                return(false);
708
        }
709
        // For now primitive types are not skipped over. They would need to be 
710
        // grouped for skipping.
711
        return (false);
712
}
713
 
714
// The problem is there are two trees of information. The LHS and the RHS.
715
// The RHS is a tree of nodes containing expressions and data to load.
716
// The nodes in the RHS have to be matched up against the structure elements
717
// of the target LHS.
718
 
719
// This little bit of code is dead code. But it might be useful to match
720
// the expression trees at some point.
721
 
722
ENODE *TYP::BuildEnodeTree()
723
{
724
        ENODE *ep1, *ep2, *ep3;
725
        SYM *thead, *first;
726
 
727
        first = thead = SYM::GetPtr(lst.GetHead());
728
        ep1 = ep2 = nullptr;
729
        while (thead) {
730
                if (thead->tp->IsStructType()) {
731
                        ep3 = thead->tp->BuildEnodeTree();
732
                }
733
                else
734
                        ep3 = nullptr;
735
                ep1 = makenode(en_void, ep2, ep1);
736
                ep1->SetType(thead->tp);
737
                ep1->p[2] = ep3;
738
                thead = SYM::GetPtr(thead->next);
739
        }
740
        return (ep1);
741
}
742
 
743
 
744
// Get the natural alignment for a given type.
745
 
746
int TYP::Alignment()
747
{
748
        //printf("DIAG: type NULL in alignment()\r\n");
749
        if (this == NULL)
750
                return AL_BYTE;
751
        switch (type) {
752
        case bt_byte:   case bt_ubyte:  return AL_BYTE;
753
        case bt_char:   case bt_uchar:  return AL_CHAR;
754
        case bt_short:  case bt_ushort: return AL_SHORT;
755
        case bt_long:   case bt_ulong:  return AL_LONG;
756
        case bt_enum:           return AL_CHAR;
757
        case bt_pointer:
758
                if (val_flag)
759
                        return (GetBtp()->Alignment());
760
                else
761
                        return (sizeOfPtr);//isShort ? AL_SHORT : AL_POINTER);
762
        case bt_float:          return AL_FLOAT;
763
        case bt_double:         return AL_DOUBLE;
764
        case bt_triple:         return AL_TRIPLE;
765
        case bt_class:
766
        case bt_struct:
767
        case bt_union:
768
                return (alignment) ? alignment : AL_STRUCT;
769
        default:                return AL_CHAR;
770
        }
771
}
772
 
773
 
774
// Figure out the worst alignment required.
775
 
776
int TYP::walignment()
777
{
778
        SYM *sp;
779
 
780
        //printf("DIAG: type NULL in alignment()\r\n");
781
        if (this == NULL)
782
                return imax(AL_BYTE, worstAlignment);
783
        switch (type) {
784
        case bt_byte:   case bt_ubyte:          return imax(AL_BYTE, worstAlignment);
785
        case bt_char:   case bt_uchar:     return imax(AL_CHAR, worstAlignment);
786
        case bt_short:  case bt_ushort:    return imax(AL_SHORT, worstAlignment);
787
        case bt_long:   case bt_ulong:     return imax(AL_LONG, worstAlignment);
788
        case bt_enum:           return imax(AL_CHAR, worstAlignment);
789
        case bt_pointer:
790
                if (val_flag)
791
                        return imax(GetBtp()->Alignment(), worstAlignment);
792
                else {
793
                        return (imax(sizeOfPtr, worstAlignment));
794
                        //                              return (imax(AL_POINTER,worstAlignment));
795
                }
796
        case bt_float:          return imax(AL_FLOAT, worstAlignment);
797
        case bt_double:         return imax(AL_DOUBLE, worstAlignment);
798
        case bt_triple:         return imax(AL_TRIPLE, worstAlignment);
799
        case bt_class:
800
        case bt_struct:
801
        case bt_union:
802
                sp = (SYM *)sp->GetPtr(lst.GetHead());
803
                worstAlignment = alignment;
804
                while (sp != NULL) {
805
                        if (sp->tp && sp->tp->alignment) {
806
                                worstAlignment = imax(worstAlignment, sp->tp->alignment);
807
                        }
808
                        else
809
                                worstAlignment = imax(worstAlignment, sp->tp->walignment());
810
                        sp = sp->GetNextPtr();
811
                }
812
                return (worstAlignment);
813
        default:                return (imax(AL_CHAR, worstAlignment));
814
        }
815
}
816
 
817
 
818
int TYP::roundAlignment()
819
{
820
        worstAlignment = 0;
821
        if (type == bt_struct || type == bt_union || type == bt_class) {
822
                return walignment();
823
        }
824
        return Alignment();
825
}
826
 
827
 
828
// Round the size of the type up according to the worst alignment.
829
 
830
int TYP::roundSize()
831
{
832
        int sz;
833
        int wa;
834
 
835
        worstAlignment = 0;
836
        if (type == bt_struct || type == bt_union || type == bt_class) {
837
                wa = walignment();
838
                sz = size;
839
                if (sz == 0)
840
                        return (0);
841
                if (sz % wa)
842
                        sz += (wa - (sz % wa));
843
                //while (sz % wa)
844
                //      sz++;
845
                return (sz);
846
        }
847
        //      return ((tp->precision+7)/8);
848
        return (size);
849
}
850
 
851
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.