-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsynth.cc
More file actions
202 lines (168 loc) · 4.3 KB
/
synth.cc
File metadata and controls
202 lines (168 loc) · 4.3 KB
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
/*************************************************************************
*
* Copyright (c) 2023 Rajit Manohar
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
**************************************************************************
*/
#include "synth.h"
#include <common/config.h>
#include <common/misc.h>
#include <act/passes.h>
/*
To synthesize a design, we need to do a few things:
- all data types must be implemented with bools
=> structures must be implemented
=> int and bools must be implemented
=> channels must be implemented
- the implementation must override already defined variables
- the implementation must intantiate any fresh variables
Convention:
prefix_<name> is used to implement <name>, where <name> is the
*expanded* version of the original type.
The implementation begins by importing the original file.
*/
ActSynthesize::ActSynthesize (const char *prefix,
char *infile,
char *outfile,
char *exprfile)
{
const char *expr_file;
if (outfile) {
_out = fopen (outfile, "w");
if (!_out) {
fatal_error ("Could not open file `%s' for writing", outfile);
}
}
else {
_out = stdout;
}
if (config_exists ("act.output_window")) {
_pp = pp_init (_out, config_get_int ("act.output_window"));
}
else {
_pp = pp_init (_out, 78);
}
expr_file = exprfile;
if (expr_file) {
_expr = fopen (expr_file, "w");
_ename = Strdup (expr_file);
if (!_expr) {
fatal_error ("Could not open file `%s' for writing", expr_file);
}
}
else {
_expr = NULL;
_ename = NULL;
}
pp_printf_raw (_pp, "/* auto-generated by logic synthesis */\n");
if (infile) {
pp_printf_raw (_pp, "import \"%s\";\n", infile);
}
pp_forced (_pp, 0);
_top = NULL;
_decomp_vx = NULL;
_new_ports = NULL;
_prefix = prefix;
}
void ActSynthesize::Close ()
{
if (_pp) {
pp_stop (_pp);
_pp = NULL;
}
if (_out) {
if (_out != stdout) {
fclose (_out);
_out = NULL;
}
}
if (_expr) {
fclose (_expr);
_expr = NULL;
}
if (_ename) {
FREE (_ename);
_ename = NULL;
}
}
ActSynthesize::~ActSynthesize ()
{
Close ();
}
bool ActSynthesize::prepSynthesis (ActPass *ap, bool run_arb)
{
Process *p = ap->getRoot ();
if (!p) {
return false;
}
if (!p->isExpanded()) {
if (!ActNamespace::Global()->isExpanded()) {
ActNamespace::Act()->Expand ();
}
p = p->Expand (ActNamespace::Global(), p->CurScope (), 0, NULL);
}
_top = p;
/*-- Apply standard decompositions --*/
ActPass *gp;
ActCHPFuncInline *ip;
ActCHPMemory *mem;
ActCHPArbiter *arbp;
gp = ActNamespace::Act()->pass_find ("finline");
if (gp) {
ip = dynamic_cast<ActCHPFuncInline *> (gp);
}
else {
ip = new ActCHPFuncInline (ActNamespace::Act());
}
Assert (ip, "error in inline pass");
if (!ip->completed()) {
ip->run (p);
}
gp = ActNamespace::Act()->pass_find ("chpmem");
if (gp) {
mem = dynamic_cast<ActCHPMemory *> (gp);
}
else {
mem = new ActCHPMemory (ActNamespace::Act());
}
Assert (mem, "error in mem pass");
if (!mem->completed()) {
mem->run (p);
}
gp = ActNamespace::Act()->pass_find ("chparb");
if (gp) {
arbp = dynamic_cast<ActCHPArbiter *> (gp);
}
else {
arbp = new ActCHPArbiter (ActNamespace::Act());
}
Assert (arbp, "error in arbiter pass");
if (!arbp->completed() && run_arb) {
arbp->run (p);
}
/*-- Emit any additional imports needed --*/
emitTopImports (ap);
return true;
}
void ActSynthesize::finalSynthesis (Process *p)
{
if (!p) {
return;
}
emitFinal ();
}