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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [CC64/] [source/] [TypeArray.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 std::string *TypenoToChars(int typeno);
29
 
30
TypeArray::TypeArray()
31
{
32
  length = 0;
33
  ZeroMemory(this,sizeof(this));
34
}
35
 
36
// The most significant bit of the register number indicates if register is
37
// an auto var or not. auto vars consume stack space.
38
 
39
void TypeArray::Add(int tp, __int16 regno)
40
{
41
  if (this==nullptr)
42
    return;
43
  if (length < sizeof(types) / sizeof(types[0])) {
44
    types[length] = tp;
45
        preg[length] = regno;
46
    length++;
47
  }
48
}
49
 
50
void TypeArray::Add(TYP *tp, __int16 regno)
51
{
52
  if (tp) {
53
    Add(tp->typeno, regno);
54
  }
55
  else {
56
    Add(0,0);
57
  }
58
}
59
 
60
bool TypeArray::IsEmpty()
61
{
62
  int nn;
63
 
64
  if (this==nullptr)
65
    return true;
66
  for (nn = 0; nn < length; nn++) {
67
    if (types[nn]==bt_ellipsis)
68
      return true;
69
    if (types[nn])
70
      return false;
71
  }
72
  return true;
73
}
74
 
75
bool TypeArray::IsByte(int typ)
76
{
77
        return (typ==bt_byte || typ==bt_ubyte);
78
}
79
 
80
bool TypeArray::IsChar(int typ)
81
{
82
        return (typ==bt_char || typ==bt_uchar);
83
}
84
bool TypeArray::IsShort(int typ)
85
{
86
        return (typ==bt_short || typ==bt_ushort);
87
}
88
bool TypeArray::IsLong(int typ)
89
{
90
        return (typ==bt_long || typ==bt_ulong);
91
}
92
bool TypeArray::IsInt(int typ)
93
{
94
        return (IsChar(typ)||IsShort(typ)||IsLong(typ)||IsByte(typ));
95
}
96
 
97
bool TypeArray::IsEqual(TypeArray *ta)
98
{
99
  int m;
100
  int nn;
101
  int t,tat;
102
 
103
  dfs.printf("IsEqual:");
104
  if (this==ta) {
105
    dfs.printf("T1");
106
    return (true);
107
  }
108
  if (ta==nullptr && IsEmpty()) {
109
    dfs.printf("T2");
110
    return (true);
111
  }
112
  if (this==nullptr || ta==nullptr) {
113
    dfs.printf("F1");
114
    return (false);
115
 }
116
  m = (length > ta->length) ? length : ta->length;
117
  for (nn = 0; nn < m; nn++) {
118
    if (types[nn]==bt_ellipsis) {
119
      dfs.printf("T3");
120
      return (true);
121
    }
122
        t = types[nn];
123
        tat = ta->types[nn];
124
    if (t != tat) {
125
      if (t==bt_long && tat==bt_ulong)
126
        continue;
127
      if (t==bt_ulong && tat==bt_long)
128
        continue;
129
      if (t==bt_short && tat==bt_ushort)
130
        continue;
131
      if (t==bt_ushort && tat==bt_short)
132
        continue;
133
      if (t==bt_char && tat==bt_uchar)
134
        continue;
135
      if (t==bt_uchar && tat==bt_char)
136
        continue;
137
          // Loose type matching
138
          if (IsInt(t) && IsInt(tat))
139
                  continue;
140
      dfs.printf("F2");
141
      return false;
142
    }
143
  }
144
  dfs.printf("T3");
145
  return true;
146
}
147
 
148
TypeArray *TypeArray::Alloc()
149
{
150
  TypeArray *tp = (TypeArray *)allocx(sizeof(TypeArray));
151
  return tp;
152
}
153
 
154
void TypeArray::Clear()
155
{
156
  if (this) {
157
    memset(types,0,sizeof(types));
158
    length = 0;
159
  }
160
}
161
 
162
void TypeArray::Print(txtoStream *fs)
163
{
164
  int nn;
165
 
166
  fs->printf("Type array:\n   ");
167
  if (this) {
168
    for (nn = 0; nn < length; nn++)
169
        fs->printf((char *)"%03d ",types[nn]);
170
  }
171
  fs->printf("\n");
172
}
173
 
174
void TypeArray::Print()
175
{
176
  Print(&dfs);
177
}
178
 
179
// Build a signature string.
180
 
181
std::string *TypeArray::BuildSignature()
182
{
183
        static std::string *str;
184
        int n;
185
 
186
        str = new std::string("");
187
        for (n = 0; n < length; n++) {
188
                str->append(*TypenoToChars(types[n]));
189
        }
190
        return str;
191
}
192
 
193
 

powered by: WebSVN 2.1.0

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