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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [CC64/] [source/] [List.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
void ListTable(TABLE *t, int i);
29
 
30
void put_typedef(int td)
31
{
32
        lfs.printf(td ? (char *)"   1   " : (char *)"   -    ");
33
}
34
 
35
void put_sc(int scl)
36
{       switch(scl) {
37
                case sc_static:
38
                        lfs.printf("Static      ");
39
                        break;
40
                case sc_thread:
41
                        lfs.printf("Thread      ");
42
                        break;
43
                case sc_auto:
44
                        lfs.printf("Auto        ");
45
                        break;
46
                case sc_global:
47
                        lfs.printf("Global      ");
48
                        break;
49
                case sc_external:
50
                        lfs.printf("External    ");
51
                        break;
52
                case sc_type:
53
                        lfs.printf("Type        ");
54
                        break;
55
                case sc_const:
56
                        lfs.printf("Constant    ");
57
                        break;
58
                case sc_member:
59
                        lfs.printf("Member      ");
60
                        break;
61
                case sc_label:
62
                        lfs.printf("Label");
63
                        break;
64
                case sc_ulabel:
65
                        lfs.printf("Undefined label");
66
                        break;
67
                }
68
}
69
 
70
void put_ty(TYP *tp)
71
{
72
                if(tp == 0)
73
                return;
74
        switch(tp->type) {
75
                case bt_exception:
76
                        lfs.printf("Exception");
77
                        break;
78
                                case bt_byte:
79
                        lfs.printf("Byte");
80
                        break;
81
                                case bt_ubyte:
82
                        lfs.printf("Unsigned Byte");
83
                        break;
84
                case bt_char:
85
                        lfs.printf("Char");
86
                        break;
87
                case bt_short:
88
                        lfs.printf("Short");
89
                        break;
90
                case bt_enum:
91
                        lfs.printf("enum ");
92
                        goto ucont;
93
                case bt_long:
94
                        lfs.printf("Long");
95
                        break;
96
                case bt_unsigned:
97
                        lfs.printf("unsigned long");
98
                        break;
99
                case bt_float:
100
                        lfs.printf("Float");
101
                        break;
102
                case bt_double:
103
                        lfs.printf("Double");
104
                        break;
105
                case bt_pointer:
106
                        if( tp->val_flag == 0)
107
                                lfs.printf("Pointer to ");
108
                        else
109
                                lfs.printf("Array of ");
110
                        put_ty(tp->GetBtp());
111
                        break;
112
                case bt_class:
113
                        lfs.printf("class ");
114
                        goto ucont;
115
                case bt_union:
116
                        lfs.printf("union ");
117
                        goto ucont;
118
                case bt_struct:
119
                        lfs.printf("struct ");
120
ucont:                  if(tp->sname->length() == 0)
121
                                lfs.printf("<no name> ");
122
                        else
123
                                lfs.printf("%s ",(char *)tp->sname->c_str());
124
                        break;
125
                case bt_ifunc:
126
                case bt_func:
127
                        lfs.printf("Function returning ");
128
                        put_ty(tp->GetBtp());
129
                        break;
130
                }
131
}
132
 
133
void list_var(SYM *sp, int i)
134
{
135
        TypeArray *ta;
136
        Function *fn;
137
 
138
                int     j;
139
        for(j = i; j; --j)
140
                lfs.printf("    ");
141
                if (sp->tp)
142
                        lfs.printf("%d ", sp->tp->typeno);
143
                if (sp->name == nullptr) {
144
                        lfs.printf("%-10s =%06x", "<noname>", (unsigned int)sp->value.u);
145
                        if (sp->tp)
146
                                if (sp->tp->bit_width != -1)
147
                                        lfs.printf("  %d %d", sp->tp->bit_offset, sp->tp->bit_width);
148
                }
149
                else if (sp->name->length()== 0)
150
                        lfs.printf("%-10s =%06x ","<unnamed>",(unsigned int)sp->value.u);
151
                else {
152
                        lfs.printf("%-10s =%06x",(char *)sp->name->c_str(),(unsigned int)sp->value.u);
153
                        if (sp->tp)
154
                                if (sp->tp->bit_width != -1)
155
                                        lfs.printf("  %d %d",sp->tp->bit_offset,sp->tp->bit_width);
156
                }
157
//                      if (sp->IsPascal) ofs.printf("\tpascal ");
158
        if( sp->storage_class == sc_external)
159
                ofs.printf("\textern\t%s\n",(char *)sp->name->c_str());
160
        else if( sp->storage_class == sc_global )
161
                ofs.printf(";\tglobal\t%s\n",(char *)sp->name->c_str());
162
                put_typedef(sp->storage_class==sc_typedef);
163
        put_sc(sp->storage_class);
164
        put_ty(sp->tp);
165
        lfs.printf("\n");
166
        if(sp->tp == 0)
167
                return;
168
    if (sp->tp) {
169
                if (sp->tp->type==bt_ifunc || sp->tp->type==bt_func) {
170
                        fn = sp->fi;
171
                        lfs.printf("\t\tParameters:\n\t\t\t");
172
                        ta = fn->GetProtoTypes();
173
                        ta->Print(&lfs);
174
                        if (ta)
175
                                delete ta;
176
                        lfs.printf("Stack Space:\n\t\t");
177
                        lfs.printf("Argbot: %d\n\t\t", fn->argbot);
178
                        lfs.printf("Tmpbot: %d\n\t\t", fn->tempbot);
179
                        lfs.printf("Stkspc: %d\n\t\t", fn->stkspace);
180
                }
181
          }
182
          if (sp->tp) {
183
        if((sp->tp->type == bt_struct || sp->tp->type == bt_union || sp->tp->type==bt_class) &&
184
                sp->storage_class == sc_type)
185
                ListTable(&(sp->tp->lst),i+1);
186
    }
187
}
188
 
189
void ListTable(TABLE *t, int i)
190
{
191
        SYM *sp;
192
        int nn;
193
 
194
        if (t==&gsyms[0]) {
195
                for (nn = 0; nn < 257; nn++) {
196
                        t = &gsyms[nn];
197
                        sp = SYM::GetPtr(t->GetHead());
198
                        while(sp != NULL) {
199
                                list_var(sp,i);
200
                                sp = sp->GetNextPtr();
201
      }
202
                }
203
        }
204
        else {
205
                sp = SYM::GetPtr(t->GetHead());
206
                while(sp != NULL) {
207
                        list_var(sp,i);
208
                        sp = sp->GetNextPtr();
209
    }
210
        }
211
}
212
 
213
 
214
// Recursively list the vars contained in compound statements.
215
 
216
void ListCompound(Statement *stmt)
217
{
218
        Statement *s1;
219
 
220
        ListTable(&stmt->ssyms,0);
221
        for (s1 = stmt->s1; s1; s1 = s1->next) {
222
                if (s1->stype == st_compound)
223
                        ListCompound(s1);
224
                if (s1->s1) {
225
                        if (s1->s1->stype==st_compound)
226
                                ListCompound(s1->s1);
227
                }
228
                if (s1->s2) {
229
                        if (s1->s2->stype==st_compound)
230
                                ListCompound(s1->s2);
231
                }
232
        }
233
}
234
 
235
// Immediate constants have low priority.
236
// Even though their use might be high, they are given a low priority.
237
 
238
void DumpCSETable()
239
{
240
        int nn;
241
        CSE *csp;
242
 
243
        dfs.printf("<CSETable>For %s\n",(char *)currentFn->sym->name->c_str());
244
        dfs.printf(
245
"*The expression must be used three or more times before it will be allocated\n"
246
"to a register.\n");
247
        dfs.printf("N OD Uses DUses Void Reg Sym\n");
248
        for (nn = 0; nn < currentFn->csetbl->csendx; nn++) {
249
                csp = &currentFn->csetbl->table[nn];
250
                dfs.printf("%d: ", nn);
251
                dfs.printf("%d   ",csp->OptimizationDesireability());
252
                dfs.printf("%d   ",csp->uses);
253
                dfs.printf("%d   ",csp->duses);
254
                dfs.printf("%d   ",(int)csp->voidf);
255
                dfs.printf("%d   ",csp->reg);
256
                if (csp->exp && csp->exp->sym)
257
                        dfs.printf("%s   ",(char *)csp->exp->sym->name->c_str());
258
                if (csp->exp && csp->exp->sp)
259
                        dfs.printf("%s   ", (char *)((std::string *)(csp->exp->sp))->c_str());
260
                dfs.printf("\n");
261
        }
262
        dfs.printf("</CSETable>\n");
263
}
264
 

powered by: WebSVN 2.1.0

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