summaryrefslogtreecommitdiff
path: root/scripts/qflow.sh.in
blob: 93ca7134487b2f0c3d55255dd216430dcedceaf5 (plain)
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#!/bin/tcsh -f
#
#------------------------------------------------------------------
# qflow.sh --- main program shell script
#------------------------------------------------------------------

# Environment variable overrides the tech type in all cases except
# when the technology is specified on the command line by -T.  If
# the environment variable is not set, the technology defaults to
# the technology that is issued with the qflow distribution.

set tech=`printenv QFLOW_TECH`
set has_tech=0
if ( $tech == "" ) then
   # But. . . check if there is already a "qflow_vars.sh".  If so,
   # parse it for "techname", and use that preferentially over the
   # default technology.
   if ( -f qflow_vars.sh ) then
      set tech=`cat qflow_vars.sh | grep techname | cut -d= -f2`
      set has_tech=1
   else
      set tech=osu035
      set has_tech=-1
   endif
endif

# Environment variable overrides the project root path in all cases
# except when the project root path is specified on the command line
# by -p.  If the environment variable does not exist, the project
# root directory is assumed to be the current working directory.

set project=`printenv QFLOW_PROJECT_ROOT`
if ( $project == "" ) then
   set project=`pwd`
endif

# Source file is not specified unless given on the command line,
# or if there is only one source file in the source directory.
set vsource=""

# Don't do anything unless told to on the command line
set actions=0
set dohelp=0
set doversion=0
set dosynth=0
set doplace=0
set dosta=0
set doroute=0
set dodecongest=0
set doclean=0
set dodisplay=0

while ($#argv > 0)
   switch($argv[1]:q)
      case -T:
      case --tech:
	 shift
	 set tech=$argv[1]
	 set has_tech=0
	 shift
	 breaksw
      case -p:
      case --project:
	 shift
	 set project=$argv[1]
	 shift
	 breaksw
      case -h:
      case --help:
	 set dohelp=1
	 shift
	 breaksw
      case -v:
      case --version:
	 set doversion=1
	 shift
	 breaksw
      case synth:
      case synthesize:
	 set dosynth=1
	 set actions=1
	 shift
	 breaksw
      case place:
	 set doplace=1
	 set actions=1
	 shift
	 breaksw
      case sta:
	 set dosta=1
	 set actions=1
	 shift
	 breaksw
      case route:
	 set doroute=1
	 set actions=1
	 shift
	 breaksw
      case decongest:
	 set dodecongest=1
	 shift
	 breaksw
      case build:
	 set dosynth=1
	 set doplace=1
	 set doroute=1
	 set dodecongest=1
	 set actions=1
	 shift
	 breaksw
      case all:
	 set dosynth=1
	 set doplace=1
	 set dosta=1
	 set doroute=1
	 set dodecongest=1
	 set doclean=1
	 set dodisplay=1
	 set actions=1
	 shift
	 breaksw
      case clean:
      case cleanup:
	 set doclean=1
	 shift
	 breaksw
      case display:
	 set dodisplay=1
	 shift
	 breaksw
      default:
	 if ($vsource != "") then
	    break
	 else
	    set vsource=$argv[1]
	    shift
	 endif
	 breaksw
   endsw
end

if ($doversion == 1 || $dohelp == 1) then
   echo "Qflow version QFLOW_VERSION"
   echo ""

   if ($doversion == 1) then
      exit 0
   endif
endif

if ($dohelp == 1 || $#argv != 0) then
   echo "Usage: qflow [processes] [options] <module_name>"
   echo "Processes:  synthesize			Synthesize verilog source"
   echo "            place			Run initial placement"
   echo "	     sta			Static timing analysis"
   echo "            route			Run placement and route"
   echo "	     decongest			Run congestion analysis, final place and route"
   echo "            clean			Remove temporary working files"
   echo "            display			Display routed result"
   echo ""
   echo "	     build			Run scripts synthesize to route"
   echo "	     all			Run scripts synthesize to display"
   echo ""
   echo "Options:    -T, --tech <name>		Use technology <name>"
   echo "	     -p, --project <name>	Project root directory is <name>"
   if ($dohelp == 1) then
      exit 0
   else
      exit 1
   endif
endif

echo ""
echo "--------------------------------"
echo "Qflow project setup"
echo "--------------------------------"
echo ""

if ($has_tech == 1) then
   echo "Technology set to $tech from existing qflow_vars.sh file"
else if ($has_tech == -1) then
   echo "No technology specified or found;  using default technology $tech"
else
   echo "Technology set to $tech"
endif

source QFLOW_SCRIPT_DIR/checkdirs.sh ${tech} ${project}

if ($vsource == "") then
   if (`ls ${sourcedir}/*.v | wc -l` == 1) then
      set vsource=`ls ${sourcedir}/*.v`
   else
      echo "Error:  No verilog source file or module name has been specified"
      echo "and directory ${sourcedir} contains multiple verilog files."
      exit 1
   endif
endif

# Module name is the root name of the verilog source file.
set modulename=${vsource:r}

#------------------------------------------------------------------
# Source the technology initialization script
#------------------------------------------------------------------

if ( -f ${techdir}/${tech}.sh ) then
   source $techdir/${tech}.sh
else
   echo "Error:  Cannot find tech init script ${techdir}/${tech}.sh to source"
   exit 1
endif

#------------------------------------------------------------------
# Prepare the script file to run in the project directory.  We
# specify all steps of the process and comment out those that
# have not been selected.  Finally, source the script.
#------------------------------------------------------------------

set varfile=${projectpath}/qflow_vars.sh
set execfile=${projectpath}/qflow_exec.sh
set userfile=${projectpath}/project_vars.sh

#------------------------------------------------------------------
# Check if a variables file exists.  If so, note that we are
# regenerating the flow, source the file, check if the technology
# is being changed, and report if so.
#------------------------------------------------------------------

set newtech = 0
if ( -f $varfile ) then
   set techorig=`cat $varfile | grep techname= | cut -d= -f2`
   if ( "${tech}" != "${techorig}" ) then
      echo "Warning:  Project technology changed from ${techorig} to ${tech}"
      set newtech = 1
   else
      echo "Regenerating files for existing project ${modulename}"
   endif
endif

echo "#\!/bin/tcsh" > ${varfile}
echo "#-------------------------------------------" >> ${varfile}
echo "# qflow variables for project ${project}" >> ${varfile}
echo "#-------------------------------------------" >> ${varfile}
echo "" >> ${varfile}

echo "set projectpath=${projectpath}" >> ${varfile}
echo "set techdir=${techdir}" >> ${varfile}
echo "set sourcedir=${sourcedir}" >> ${varfile}
echo "set synthdir=${synthdir}" >> ${varfile}
echo "set layoutdir=${layoutdir}" >> ${varfile}
echo "set techname=${techname}" >> ${varfile}
echo "set scriptdir=${scriptdir}" >> ${varfile}
echo "set bindir=${bindir}" >> ${varfile}
echo "set synthlog=${projectpath}/synth.log" >> ${varfile}
echo "if (-f ${projectpath}/project_vars.sh) then" >> ${varfile}
echo "    source ${projectpath}/project_vars.sh" >> ${varfile}
echo "endif" >> ${varfile}
echo "#-------------------------------------------" >> ${varfile}
echo "" >> ${varfile}

echo "#\!/bin/tcsh" > ${execfile}
echo "#-------------------------------------------" >> ${execfile}
echo "# qflow exec script for project ${project}" >> ${execfile}
echo "#-------------------------------------------" >> ${execfile}
echo "" >> ${execfile}

#-----------------------------------------------------
# The file "project_vars.sh" will ONLY be written if
# one does not already exist, and then it will be an
# empty file with a few pointers to values that can
# be set by the user.
#-----------------------------------------------------

if ( ! -f ${userfile} ) then
   echo "#\!/bin/tcsh" > ${userfile}
   echo "#------------------------------------------------------------" >> ${userfile}
   echo "# project variables for project ${project}" >> ${userfile}
   echo "#------------------------------------------------------------" >> ${userfile}
   echo "" >> ${userfile}
   echo "# Synthesis command options:" >> ${userfile}
   echo "# -------------------------------------------" >> ${userfile}
   echo "# set yosys_options = " >> ${userfile}
   echo "# set yosys_script = " >> ${userfile}
   echo "# set yosys_nodebug = " >> ${userfile}
   echo "# set abc_script = " >> ${userfile}
   echo "# set nobuffers = " >> ${userfile}
   echo "# set fanout_options = " >> ${userfile}
   echo "" >> ${userfile}
   echo "# Placement command options:" >> ${userfile}
   echo "# -------------------------------------------" >> ${userfile}
   echo "# set initial_density = " >> ${userfile}
   echo "" >> ${userfile}
   echo "# Router command options:" >> ${userfile}
   echo "# -------------------------------------------" >> ${userfile}
   echo "# set route_layers = " >> ${userfile}
   echo "# set via_stacks = " >> ${userfile}
   echo "# set qrouter_options = " >> ${userfile}
   echo ""
   echo "" >> ${userfile}
   echo "# Minimum operating period of the clock (in ps)" >> ${userfile}
   echo "# set vesta_options = --period 1E5" >> ${userfile}
   echo "" >> ${userfile}
   echo "#------------------------------------------------------------" >> ${userfile}
   echo "" >> ${userfile}
endif

if ($dosynth == 0) then
   echo -n "# " >> ${execfile}
endif
echo "${scriptdir}/synthesize.sh ${projectpath} ${modulename}" >> ${execfile}

if ($doplace == 0) then
   echo -n "# " >> ${execfile}
endif
# Use -d because the user may decide not to run fanout buffering,
# and the files generated by place2def.tcl are required for routing.
echo "${scriptdir}/placement.sh -d ${projectpath} ${modulename}" >> ${execfile}

if ($dosta == 0) then
   echo -n "# " >> ${execfile}
endif
echo "${scriptdir}/vesta.sh ${projectpath} ${modulename}" >> ${execfile}

if ($doroute == 0) then
   echo -n "# " >> ${execfile}
endif
echo "${scriptdir}/router.sh ${projectpath} ${modulename}" >> ${execfile}

if ($dodecongest == 0) then
   echo -n "# " >> ${execfile}
endif
echo "${scriptdir}/placement.sh -f -d ${projectpath} ${modulename}" >> ${execfile}

if ($dodecongest == 0) then
   echo -n "# " >> ${execfile}
endif
echo -n "${scriptdir}/router.sh ${projectpath} ${modulename}" >> ${execfile}
echo ' $status' >> ${execfile}

if ($doclean == 0) then
   echo -n "# " >> ${execfile}
endif
echo "${scriptdir}/cleanup.sh ${projectpath} ${modulename}" >> ${execfile}

if ($dodisplay == 0) then
   echo -n "# " >> ${execfile}
endif
echo "${scriptdir}/display.sh ${projectpath} ${modulename}" >> ${execfile}

if ( $actions == 0 ) then
   echo "No actions specified on command line;"
   echo "creating qflow script file ${execfile} only."
   echo "Uncomment lines in this file and source the file to run the flow."
endif

chmod u+x ${execfile}

# Drop the magic startup file into the layout directory if it does not exist
# If it exists but the technology directory has a newer file, or if we are
# changing technologies, then copy the old file to a backup and create a new
# one.

if (-d ${layoutdir}) then
   if (!(-f ${layoutdir}/.magicrc)) then
      cp ${techdir}/${magicrc} ${layoutdir}/.magicrc
   else if ( $newtech == 1 ) then
      echo "Technology changed:  Old .magicrc file moved to .magicrc.orig"
      cp ${layoutdir}/.magicrc ${layoutdir}/.magicrc.orig
      cp ${techdir}/${magicrc} ${layoutdir}/.magicrc
   else if ( -M ${techdir}/${magicrc} > -M ${layoutdir}/.magicrc ) then
      echo -n "Technology .magicrc file has been updated.  "
      echo "Old .magicrc file moved to .magicrc.orig"
      cp ${layoutdir}/.magicrc ${layoutdir}/.magicrc.orig
      cp ${techdir}/${magicrc} ${layoutdir}/.magicrc
   endif
endif

# Drop the GrayWolf parameter file into the layout directory if it does not
# exist.  Like the above, check if the techdir has a newer version, or if we
# are changing technologies.

if (-d ${layoutdir}) then
   if (!(-f ${layoutdir}/${modulename}.par)) then
      cp ${techdir}/${techname}.par ${layoutdir}/${modulename}.par
   else if ( $newtech == 1 ) then
      echo "Technology changed:  Old .par file moved to .par.orig"
      cp ${layoutdir}/${modulename}.par ${layoutdir}/${modulename}.par.orig
      cp ${techdir}/${techname}.par ${layoutdir}/${modulename}.par
   else if ( -M ${techdir}/${techname}.par > -M ${layoutdir}/${modulename}.par ) then
      echo "Technology .par file has been updated.  Old .par file moved to .par.orig"
      cp ${layoutdir}/${modulename}.par ${layoutdir}/${modulename}.par.orig
      cp ${techdir}/${techname}.par ${layoutdir}/${modulename}.par
   endif
endif


# Execute the script file to run any command that has not been commented out
exec ${execfile}

exit 0