19 namespace eval HogProjectObj {
21 proc New {project_name {repo_path .} args} {
22 set top_path [
file normalize [
file join $repo_path Top]]
23 set proj_path [
file normalize [
file join $top_path $project_name]]
24 set top_name [
file rootname [
file tail $project_name]]
27 project_name [
tstr $project_name] \
28 project [
tstr [
file tail $project_name]] \
29 group_name [
tstr [
file dirname $project_name]] \
30 design [
tstr $project_name] \
31 project_path [
tstr $proj_path] \
32 conf_path [
tstr [
file normalize [
file join $proj_path hog.conf]]] \
33 list_path [
tstr [
file normalize [
file join $proj_path list]]] \
34 build_dir [
tstr [
file normalize [
file join $repo_path Projects $project_name]]] \
35 top_name [
tstr $top_name] \
36 synth_top_module [
tstr "top_${top_name}"] \
37 config [tdict create] \
38 list_files [tlist create] \
39 libraries [tlist create] \
40 filesets [tlist create] \
41 project_files [tdict create] \
44 if {[dict exists $args -config]} { tdict set p config [dict get $args -config]}
45 if {[dict exists $args -user]} { tdict set p user [dict get $args -user]}
52 namespace eval Projects {
55 proc GetInfo {project_name {repo_path .}} {
57 set conf_path [tdict getval $p conf_path]
58 if {[
file exists $conf_path]} {
60 dict for {section content} $PROPERTIES {
61 dict for {key val} $content {
62 Msg Debug "Setting property $key to $val for section $section"
63 tdict set p config $section $key $val
71 proc GetAll {{repo_path .}} {
72 set top_path [
file normalize $repo_path/Top]
73 set ret [tdict create]
74 foreach conf [lsort [
findFiles [
file normalize $top_path] hog.conf]] {
75 set name [
Relative $top_path [
file dirname $conf]]
76 tdict set ret $name [
GetInfo $name $repo_path]
85 proc LoadListFiles {hog_projectVar {ext_path ""} {tool ""}} {
86 upvar 1 $hog_projectVar p
88 set list_path [tdict getval $p list_path]
89 set repo_path [Repo::Get repo_path]
92 set _conf [
file normalize [
file join [
file dirname $list_path] hog.conf]]
93 if {[
file exists $_conf]} {
98 foreach list_file [lsort [glob -nocomplain -directory $list_path "*"]] {
99 set ext [
file extension $list_file]
100 if {$ext ni {.src .con .sim .ext .ipb}} { continue}
101 if {$ext eq ".ext" && $ext_path eq ""} {
102 Msg Warning "Skipping $list_file: no ext_path provided."
105 set root_path [
expr {$ext eq ".ext" ? $ext_path : $repo_path}]
106 set lib [
file rootname [
file tail $list_file]]
107 set lf_list [tdict get $p list_files]
108 tlist append lf_list [
tstr [
file normalize $list_file]]
109 tdict set p list_files $lf_list
114 set proj_conf [
file normalize [
file join [
file dirname $list_path] hog.conf]]
115 if {[
file exists $proj_conf]} {
117 set tracked [dict create]
118 tdict for {fp _} [tdict get $p project_files] { dict set tracked $fp 1 }
119 dict for {comp_name cfg_abs} $hls_configs {
120 if {[dict exists $tracked $cfg_abs]} { continue }
121 set lib_name "${comp_name}.src"
122 _AddFile p [ListFile::HogFileObj::New $cfg_abs -library $lib_name -fileset sources_1]
123 dict set tracked $cfg_abs 1
124 foreach hls_extra [ExpandHlsConfigFiles $cfg_abs] {
125 if {[dict exists $tracked $hls_extra]} { continue }
126 _AddFile p [ListFile::HogFileObj::New $hls_extra -library $lib_name -fileset sources_1]
127 dict set tracked $hls_extra 1
134 proc _AddFile {hog_projectVar hog_file} {
135 upvar 1 $hog_projectVar p
137 set path [tobj value [tdict get $hog_file path]]
138 set libs [tdict get $p libraries]
139 set fsets [tdict get $p filesets]
140 set files [tdict get $p project_files]
142 tlist foreach lib [tdict get $hog_file libraries] {
143 if {![tlist elemExists $libs [tobj value $lib]]} { tlist append libs $lib }
145 tlist foreach fs [tdict get $hog_file filesets] {
146 if {![tlist elemExists $fsets [tobj value $fs]]} { tlist append fsets $fs }
149 if {[tdict exists $files $path]} {
150 set existing [tdict get $files $path]
152 tdict set files $path $existing
154 tdict set files $path $hog_file
157 tdict set p libraries $libs
158 tdict set p filesets $fsets
159 tdict set p project_files $files
163 proc _ParseListFile {hog_projectVar list_file path lib fileset tool} {
164 upvar 1 $hog_projectVar p
166 set ext [
file extension $list_file]
167 if {$fileset eq ""} {
169 .sim {
set fileset $lib}
170 .con {
set fileset "constrs_1"}
171 default {
set fileset "sources_1"}
175 set fp [open $list_file r]
180 if {[regexp {^[\t\s]*$} $line] || [regexp {^[\t\s]*#} $line]} { continue}
182 set tokens [regexp -all -inline {\S+} $line]
183 set srcfile "$path/[
lindex $tokens 0]"
184 set srcfiles [glob -nocomplain $srcfile]
186 if {$srcfiles != $srcfile && ![
string equal $srcfiles ""]} {
187 Msg Debug "Wildcard source expanded from $srcfile to $srcfiles"
188 }
elseif {![
file exists $srcfile]} {
189 Msg CriticalWarning "File: $srcfile (from list file: $list_file) does not exist."
193 foreach vhdlfile $srcfiles {
194 if {![
file exists $vhdlfile]} { continue}
195 set vhdlfile [
file normalize $vhdlfile]
196 set fext [
file extension $vhdlfile]
197 set raw_tokens [
lrange $tokens 1 end]
202 set ref_path [
expr {$ref_path eq "" ? $path : [file normalize $path/$ref_path]}]
207 if {$fext in {.src .sim .con}} {
208 Msg Error "$vhdlfile cannot be included in $list_file; $fext must be their own list file."
214 if {$ext eq ".src" && $fext eq ".cfg"} {
215 set lib_name [tlist getval [tdict get $hog_file libraries] 0]
217 if {$hls_extra eq $vhdlfile} { continue}
218 Msg Debug "HLS cfg expansion: adding $hls_extra to $lib_name"
234 proc GetProjectFiles {hog_project args} {
235 set lib_pat [
expr {[dict exists $args -library] ? [dict get $args -library] : ""}]
236 set fs_pat [
expr {[dict exists $args -fileset] ? [dict get $args -fileset] : ""}]
237 set file_pat [
expr {[dict exists $args -file] ? [dict get $args -file] : ""}]
238 set symlinks [
expr {[dict exists $args -symlinks] ? [dict get $args -symlinks] : 1}]
239 set as [
expr {[dict exists $args -as] ? [dict get $args -as] : "objects"}]
241 set result [
expr {$as eq "tdict" ? [tdict create] : {}}]
242 tdict for {fp hog_file} [tdict get $hog_project project_files] {
243 if {$lib_pat ne ""} {
245 tlist foreach lib [tdict get $hog_file libraries] {
246 if {[regexp -- $lib_pat [tobj value $lib]]} { set ok 1; break }
248 if {!$ok} { continue }
252 tlist foreach fs [tdict get $hog_file filesets] {
253 if {[regexp -- $fs_pat [tobj value $fs]]} { set ok 1; break }
255 if {!$ok} { continue }
257 if {$file_pat ne "" && ![regexp -- $file_pat $fp]} { continue }
259 if {$as eq "tdict"} {
260 tdict set result $fp $hog_file
261 } elseif {$as eq "objects"} {
262 lappend result $hog_file
266 set target [tdict getval $hog_file symlink_target]
267 if {$target ne ""} { lappend result $target }
276 proc SHAFiles {hog_project} {
278 tlist foreachval lf [tdict get $hog_project list_files] {
280 if {[file exists $lf] && [file type $lf] eq "link"} {
281 lappend paths [GetLinkedFile $lf]