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

Subversion Repositories thor

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
// Currently under construction (not used yet).
3
//        __
4
//   \\__/ o\    (C) 2017-2018  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch<remove>@finitron.ca
7
//       ||
8
//
9
// CC64 - 'C' derived language compiler
10
//  - 64 bit CPU
11
//
12
// This source file is free software: you can redistribute it and/or modify 
13
// it under the terms of the GNU Lesser General Public License as published 
14
// by the Free Software Foundation, either version 3 of the License, or     
15
// (at your option) any later version.                                      
16
//                                                                          
17
// This source file is distributed in the hope that it will be useful,      
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
20
// GNU General Public License for more details.                             
21
//                                                                          
22
// You should have received a copy of the GNU General Public License        
23
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
24
//                                                                          
25
// ============================================================================
26
//
27
#include "stdafx.h"
28
extern int optimized;
29
extern OCODE *LabelTable[50000];
30
 
31
OCODE *PeepList::FindLabel(int64_t i)
32
{
33
        if (i >= 50000 || i < 0)
34
                return (nullptr);
35
        return (LabelTable[i]);
36
}
37
 
38
 
39
// Count the length of the peep list from the current position to the end of
40
// the list. Used during some code generation optimizations.
41
 
42
int PeepList::Count(OCODE *ip)
43
{
44
        int cnt;
45
 
46
        for (cnt = 0; ip && ip != tail; cnt++)
47
                ip = ip->fwd;
48
        return (cnt);
49
}
50
 
51
void PeepList::InsertBefore(OCODE *an, OCODE *cd)
52
{
53
        cd->fwd = an;
54
        cd->back = an->back;
55
        if (an->back)
56
                an->back->fwd = cd;
57
        an->back = cd;
58
}
59
 
60
void PeepList::InsertAfter(OCODE *an, OCODE *cd)
61
{
62
        cd->fwd = an->fwd;
63
        cd->back = an;
64
        if (an->fwd)
65
                an->fwd->back = cd;
66
        an->fwd = cd;
67
}
68
 
69
void PeepList::Add(OCODE *cd)
70
{
71
        if (!dogen)
72
                return;
73
 
74
        if (head == NULL)
75
        {
76
                ArgRegCount = regFirstArg;
77
                head = tail = cd;
78
                cd->fwd = nullptr;
79
                cd->back = nullptr;
80
        }
81
        else
82
        {
83
                cd->fwd = nullptr;
84
                cd->back = tail;
85
                tail->fwd = cd;
86
                tail = cd;
87
        }
88
        if (cd->opcode != op_label) {
89
                if (cd->oper1 && IsArgumentReg(cd->oper1->preg))
90
                        ArgRegCount = max(ArgRegCount, cd->oper1->preg);
91
                if (cd->oper2 && IsArgumentReg(cd->oper2->preg))
92
                        ArgRegCount = max(ArgRegCount, cd->oper2->preg);
93
                if (cd->oper3 && IsArgumentReg(cd->oper3->preg))
94
                        ArgRegCount = max(ArgRegCount, cd->oper3->preg);
95
                if (cd->oper4 && IsArgumentReg(cd->oper4->preg))
96
                        ArgRegCount = max(ArgRegCount, cd->oper4->preg);
97
        }
98
}
99
 
100
void PeepList::Remove()
101
{
102
        OCODE *ip, *ip1, *ip2;
103
 
104
        if (1)//(RemoveEnabled)
105
                for (ip = head; ip; ip = ip1) {
106
                        ip1 = ip->fwd;
107
                        ip2 = ip->back;
108
                        if (ip->remove) {
109
                                if (ip1 && ip1->comment == nullptr)
110
                                        ip1->comment = ip->comment;
111
                                if (ip2)
112
                                        ip2->fwd = ip1;
113
                                if (ip1)
114
                                        ip1->back = ip2;
115
                        }
116
                }
117
}
118
 
119
 
120
// Potentially any called routine could throw an exception. So call
121
// instructions could act like branches to the default catch tacked
122
// onto the end of a subroutine. This is important to prevent the
123
// default catch from being optimized away. It's possible that there's
124
// no other way to reach the catch.
125
// A bex instruction, which isn't a real instruction, is added to the
126
// instruction stream so that links are created in the CFG to the
127
// catch handlers. At a later stage of the compile all the bex
128
// instructions are removed, since they were there only to aid in
129
// compiler optimizations.
130
 
131
void PeepList::RemoveCompilerHints2()
132
{
133
        OCODE *ip;
134
 
135
        for (ip = head; ip != NULL; ip = ip->fwd)
136
        {
137
                if (ip->opcode == op_bex)
138
                        MarkRemove(ip);
139
        }
140
        Remove();
141
}
142
 
143
void PeepList::storeHex(txtoStream& ofs)
144
{
145
        OCODE *ip;
146
 
147
        ofs.printf("; CC64 Hex Intermediate Representation File\n");
148
        ofs.printf("; This is an automatically generated file.\n");
149
        for (ip = head; ip != NULL; ip = ip->fwd)
150
        {
151
                ip->storeHex(ofs);
152
        }
153
        ofs.printf("%c", 26);
154
}
155
 
156
void PeepList::loadHex(std::ifstream& ifs)
157
{
158
        char buf[50];
159
        OCODE *cd;
160
        int op;
161
 
162
        head = tail = nullptr;
163
        while (!ifs.eof()) {
164
                ifs.read(buf, 1);
165
                switch (buf[0]) {
166
                case 'O':
167
                        cd = OCODE::loadHex(ifs);
168
                        Add(cd);
169
                        break;
170
                default:        // ;
171
                        while (buf[0] != '\n' && !ifs.eof())
172
                                ifs.read(buf, 1);
173
                        break;
174
                }
175
        }
176
}

powered by: WebSVN 2.1.0

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