forked from chipsalliance/Surelog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_batch_script.tcl
executable file
·127 lines (108 loc) · 4.04 KB
/
create_batch_script.tcl
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
#!/usr/bin/tclsh
# Copyright 2019 Alain Dargelas
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script creates a batch script for Surelog.
# - It analyzes recursively the directories under the working directory and searches for .sv files by default
# - It takes an optionnal <command> line option to add a <command> invokation from Surelog.
# Surelog will invoke that linux command with a filelist passed as argument.
# - The resulting batch file batch.txt can be passed to surelog
# Usages:
# create_batch_script.tcl [exe=<Linux executable>] [ext=<.v,.sv,...>] [batch=<script_name>] [options="<surelog options>"]
#
#
# Example:
# create_batch_script.tcl exe=verible ext=.v,.sv batch=batch.txt options="-writepp -parse"
#
# surelog -batch batch.txt
#
puts "Command line: $argv"
set EXTENSIONS ".sv"
set EXECUTABLE ""
set BATCH_SCRIPT "batch.txt"
set SURELOG_OPTIONS "-writepp -parse -nocache -nobuiltin -noinfo -nocomp -noelab -timescale=1ns/1ns -nostdout"
if [regexp {exe=([a-zA-Z0-9_/\.]+)} $argv tmp EXECUTABLE] {
puts "Creating callbacks to: $EXECUTABLE"
}
if [regexp {batch=([a-zA-Z0-9_/\.]+)} $argv tmp BATCH_SCRIPT] {
}
if [regexp {ext=([a-zA-Z0-9_/\.,]+)} $argv tmp EXTENSIONS] {
}
if [regexp {\{options=(.*)\}} $argv tmp SURELOG_OPTIONS] {
}
puts "Creating batch script: $BATCH_SCRIPT"
proc findFiles { basedir pattern } {
# Fix the directory name, this ensures the directory name is in the
# native format for the platform and contains a final directory seperator
set basedir [string trimright [file join [file normalize $basedir] { }]]
set fileList {}
# Look in the current directory for matching files, -type {f r}
# means ony readable normal files are looked at, -nocomplain stops
# an error being thrown if the returned list is empty
foreach fileName [glob -nocomplain -type {f r} -path $basedir $pattern] {
lappend fileList $fileName
}
# Now look for any sub direcories in the current directory
foreach dirName [glob -nocomplain -type {d r} -path $basedir *] {
# Recusively call the routine on the sub directory and append any
# new files to the results
set subDirList [findFiles $dirName $pattern]
if { [llength $subDirList] > 0 } {
foreach subDirFile $subDirList {
lappend fileList $subDirFile
}
}
}
return $fileList
}
proc create_file_list {} {
global EXTENSIONS EXECUTABLE BATCH_SCRIPT SURELOG_OPTIONS
set fid [open $BATCH_SCRIPT "w"]
set fileList ""
foreach EXT [split $EXTENSIONS ","] {
puts "Scanning for *$EXT files"
append fileList "[findFiles . *$EXT] "
}
regsub -all "[pwd]/" $fileList "" fileList
set count 0
foreach file $fileList {
if [regexp "slpp" $file] {
continue
}
set fid1 [open $file]
set content [read $fid1]
close $fid1
set dir_name [file dirname $file]
set uvm_dir "../../../UVM/1800.2-2017-1.0/src/"
if {$dir_name == "."} {
set uvm_dir "../../UVM/1800.2-2017-1.0/src/"
} elseif [regexp {/} $dir_name] {
set uvm_dir "../../../../UVM/1800.2-2017-1.0/src/"
}
set import_uvm ""
if [regexp {import[ ]+uvm_pkg} $content] {
set import_uvm "$uvm_dir/uvm_pkg.sv"
}
set cmd "-cd $dir_name -I$uvm_dir $import_uvm $SURELOG_OPTIONS [file tail $file] -l [file tail $file].log"
if {$EXECUTABLE != ""} {
set cmd "$cmd -exe $EXECUTABLE"
}
puts $fid $cmd
#puts $cmd
incr count
}
close $fid
puts "Created $count batch commands in: $BATCH_SCRIPT"
puts "Please run surelog -batch $BATCH_SCRIPT"
}
create_file_list