Hog Hog2026.2-1
pre-implementation.tcl
Go to the documentation of this file.
1 #!/usr/bin/env tclsh
2 # Copyright 2018-2026 The University of Birmingham
3 # Copyright 2018-2026 Max-Planck-Institute for Physics
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 set old_path [pwd]
18 set tcl_path [file normalize "[file dirname [info script]]/.."]
19 source $tcl_path/hog.tcl
20 
21 # Import tcllib
22 if {[IsSynplify] || [IsDiamond]} {
23  if {[info exists env(HOG_TCLLIB_PATH)]} {
24  lappend auto_path $env(HOG_TCLLIB_PATH)
25  } else {
26  puts "ERROR: To run Hog with Microsemi Libero SoC, you need to define the HOG_TCLLIB_PATH variable."
27  return
28  }
29 }
30 
31 if {[IsQuartus]} {
32  # Quartus
33  Msg Error "Pre-module scripts are not supported in Quartus mode!"
34  return TCL_ERROR
35 }
36 
37 # Go to repository path
38 cd "$tcl_path/../.."
39 
40 if {[IsXilinx]} {
41  # Vivado
42  if {[IsISE]} {
43  set proj_dir [get_property DIRECTORY [current_project]]
44  set project [file tail $proj_dir]
45  set proj_file $proj_dir/$project.prr
46  } else {
47  set proj_file [get_property parent.project_path [current_project]]
48  }
49  set proj_dir [file normalize [file dirname $proj_file]]
50  set proj_name [file rootname [file tail $proj_file]]
51 } elseif {[IsDiamond]} {
52  set proj_dir [file normalize "[pwd]/.."]
53  set proj_name [file tail $proj_dir]
54  set project $proj_name
55 } else {
56  #Tclssh
57  set proj_file $old_path/[file tail $old_path].xpr
58  Msg CriticalWarning "You seem to be running locally on tclsh, so this is a debug message. \
59  The project file will be set to $proj_file and was derived from the path you launched this script from: $old_path. \
60  If you want this script to work properly in debug mode, please launch it from the top folder of one project, \
61  for example Repo/Projects/fpga1/ or Repo/Top/fpga1/"
62 }
63 
64 set group_name [GetGroupName $proj_dir "$tcl_path/../.."]
65 
66 #number of threads
67 set maxThreads [GetMaxThreads [file normalize $tcl_path/../../Top/$group_name/$proj_name]]
68 
69 if {$maxThreads != 1} {
70  Msg Warning "Multithreading enabled. Bitfile will not be deterministic. Number of threads: $maxThreads"
71 } else {
72  Msg Info "Disabling multithreading to assure deterministic bitfile"
73 }
74 
75 if {[IsXilinx]} {
76  # Vivado
77  set_param general.maxThreads $maxThreads
78 } else {
79  #Tclssh
80 }
81 
82 
83 ######## Reset files before implementation ###########
84 ResetRepoFiles "./Projects/hog_reset_files"
85 
86 set user_pre_implementation_file "./Top/$group_name/$proj_name/pre-implementation.tcl"
87 if {[file exists $user_pre_implementation_file]} {
88  Msg Status "Sourcing user pre-implementation file $user_pre_implementation_file"
89  source $user_pre_implementation_file
90 }
91 
92 cd $old_path
93 Msg Info "All done"