@@ -9,7 +9,7 @@ require "ruby-progressbar"
99require "yard"
1010require "minitest/test_task"
1111
12- require_relative $root / "lib" / "validate "
12+ require_relative $root / "lib" / "architecture "
1313
1414directory "#{ $root} /.stamps"
1515
1919
2020directory "#{ $root} /.stamps"
2121
22- file "#{ $root} /.stamps/dev_gems" => "#{ $root} /.stamps" do
23- Dir . chdir ( $root) do
24- sh "bundle config set --local with development"
25- sh "bundle install"
26- FileUtils . touch "#{ $root} /.stamps/dev_gems"
27- end
22+ def cfg_arch_for ( config_name )
23+ Rake ::Task [ "#{ $root} /.stamps/resolve-#{ config_name } .stamp" ] . invoke
24+
25+ @cfg_archs ||= { }
26+ return @cfg_archs [ config_name ] if @cfg_archs . key? ( config_name )
27+
28+ @cfg_archs [ config_name ] =
29+ ConfiguredArchitecture . new (
30+ config_name ,
31+ $root / "gen" / "resolved_arch" / config_name ,
32+ overlay_path : $root / "cfgs" / config_name / "arch_overlay"
33+ )
2834end
2935
3036namespace :gen do
3137 desc "Generate documentation for the ruby tooling"
3238 task tool_doc : "#{ $root} /.stamps/dev_gems" do
3339 Dir . chdir ( $root) do
34- sh "bundle exec yard doc --yardopts arch_def .yardopts"
40+ sh "bundle exec yard doc --yardopts cfg_arch .yardopts"
3541 sh "bundle exec yard doc --yardopts idl.yardopts"
3642 end
3743 end
44+
45+ desc "Resolve the standard in arch/, and write it to resolved_arch/"
46+ task "resolved_arch" do
47+ sh "#{ $root} /.home/.venv/bin/python3 lib/yaml_resolver.py resolve arch resolved_arch"
48+ end
49+ end
50+
51+ # rule to generate standard for any configurations with an overlay
52+ rule %r{#{ $root} /.stamps/resolve-.+\. stamp} => proc { |tname |
53+ cfg_name = File . basename ( tname , ".stamp" ) . sub ( "resolve-" , "" )
54+ arch_files = Dir . glob ( "#{ $root} /arch/**/*.yaml" )
55+ overlay_files = Dir . glob ( "#{ $root} /cfgs/#{ cfg_name } /arch_overlay/**/*.yaml" )
56+ [
57+ "#{ $root} /.stamps" ,
58+ "#{ $root} /lib/yaml_resolver.py"
59+ ] + arch_files + overlay_files
60+ } do |t |
61+ cfg_name = File . basename ( t . name , ".stamp" ) . sub ( "resolve-" , "" )
62+ sh "#{ $root} /.home/.venv/bin/python3 lib/yaml_resolver.py merge arch cfgs/#{ cfg_name } /arch_overlay gen/arch/#{ cfg_name } "
63+ sh "#{ $root} /.home/.venv/bin/python3 lib/yaml_resolver.py resolve gen/arch/#{ cfg_name } gen/resolved_arch/#{ cfg_name } "
64+
65+ FileUtils . touch t . name
3866end
3967
4068namespace :serve do
75103
76104desc "Clean up all generated files"
77105task :clean do
78- FileUtils . rm_rf $root / "gen"
79- FileUtils . rm_rf $root / ".stamps"
106+ warn "Don't run clean using Rake. Run `./do clean` (alias for `./bin/clean`) instead."
80107end
81108
82109namespace :test do
@@ -88,30 +115,23 @@ namespace :test do
88115 end
89116 puts "All instruction encodings pass basic sanity tests"
90117 end
91- task schema : "gen:arch" do
92- validator = Validator . instance
118+ task schema : "gen:resolved_arch" do
93119 puts "Checking arch files against schema.."
94- arch_files = Dir . glob ( "#{ $root} /arch/**/*.yaml" )
95- progressbar = ProgressBar . create ( total : arch_files . size )
96- arch_files . each do |f |
97- progressbar . increment
98- validator . validate ( f )
99- end
100- Rake ::Task [ "test:insts" ] . invoke
120+ Architecture . new ( "#{ $root} /resolved_arch" ) . validate ( show_progress : true )
101121 puts "All files validate against their schema"
102122 end
103- task idl_model : [ "gen:arch " , "#{ $root} /.stamps/arch-gen-_32 .stamp" , "#{ $root} /.stamps/arch-gen-_64 .stamp" ] do
123+ task idl : [ "gen:resolved_arch " , "#{ $root} /.stamps/resolve-rv32 .stamp" , "#{ $root} /.stamps/resolve-rv64 .stamp" ] do
104124 print "Parsing IDL code for RV32..."
105- arch_def_32 = arch_def_for ( "_32 ")
125+ cfg_arch32 = cfg_arch_for ( "rv32 ")
106126 puts "done"
107127
108- arch_def_32 . type_check
128+ cfg_arch32 . type_check
109129
110130 print "Parsing IDL code for RV64..."
111- arch_def_64 = arch_def_for ( "_64 ")
131+ cfg_arch64 = cfg_arch_for ( "rv64 ")
112132 puts "done"
113133
114- arch_def_64 . type_check
134+ cfg_arch64 . type_check
115135
116136 puts "All IDL passed type checking"
117137 end
@@ -121,7 +141,7 @@ def insert_warning(str, from)
121141 # insert a warning on the second line
122142 lines = str . lines
123143 first_line = lines . shift
124- lines . unshift ( first_line , "\n # WARNING: This file is auto-generated from #{ Pathname . new ( from ) . relative_path_from ( $root) } \n \n " ) . join ( "" )
144+ lines . unshift ( first_line , "\n # WARNING: This file is auto-generated from #{ Pathname . new ( from ) . relative_path_from ( $root) } " ) . join ( "" )
125145end
126146private :insert_warning
127147
@@ -130,7 +150,6 @@ private :insert_warning
130150 "#{ $root} /arch/csr/Zihpm/mhpmcounterN.layout" ,
131151 __FILE__
132152 ] do |t |
133- puts "Generating #{ Pathname . new ( t . name ) . relative_path_from ( $root) } "
134153 erb = ERB . new ( File . read ( $root / "arch/csr/Zihpm/mhpmcounterN.layout" ) , trim_mode : "-" )
135154 erb . filename = "#{ $root} /arch/csr/Zihpm/mhpmcounterN.layout"
136155 File . write ( t . name , insert_warning ( erb . result ( binding ) , t . prerequisites . first ) )
@@ -139,7 +158,6 @@ private :insert_warning
139158 "#{ $root} /arch/csr/Zihpm/mhpmcounterNh.layout" ,
140159 __FILE__
141160 ] do |t |
142- puts "Generating #{ Pathname . new ( t . name ) . relative_path_from ( $root) } "
143161 erb = ERB . new ( File . read ( $root / "arch/csr/Zihpm/mhpmcounterNh.layout" ) , trim_mode : "-" )
144162 erb . filename = "#{ $root} /arch/csr/Zihpm/mhpmcounterNh.layout"
145163 File . write ( t . name , insert_warning ( erb . result ( binding ) , t . prerequisites . first ) )
@@ -148,7 +166,6 @@ private :insert_warning
148166 "#{ $root} /arch/csr/Zihpm/mhpmeventN.layout" ,
149167 __FILE__
150168 ] do |t |
151- puts "Generating #{ Pathname . new ( t . name ) . relative_path_from ( $root) } "
152169 erb = ERB . new ( File . read ( $root / "arch/csr/Zihpm/mhpmeventN.layout" ) , trim_mode : "-" )
153170 erb . filename = "#{ $root} /arch/csr/Zihpm/mhpmeventN.layout"
154171 File . write ( t . name , insert_warning ( erb . result ( binding ) , t . prerequisites . first ) )
@@ -157,7 +174,6 @@ private :insert_warning
157174 "#{ $root} /arch/csr/Zihpm/mhpmeventNh.layout" ,
158175 __FILE__
159176 ] do |t |
160- puts "Generating #{ Pathname . new ( t . name ) . relative_path_from ( $root) } "
161177 erb = ERB . new ( File . read ( $root / "arch/csr/Zihpm/mhpmeventNh.layout" ) , trim_mode : "-" )
162178 erb . filename = "#{ $root} /arch/csr/Zihpm/mhpmeventNh.layout"
163179 File . write ( t . name , insert_warning ( erb . result ( binding ) , t . prerequisites . first ) )
@@ -166,7 +182,6 @@ private :insert_warning
166182 "#{ $root} /arch/csr/Zihpm/hpmcounterN.layout" ,
167183 __FILE__
168184 ] do |t |
169- puts "Generating #{ Pathname . new ( t . name ) . relative_path_from ( $root) } "
170185 erb = ERB . new ( File . read ( $root / "arch/csr/Zihpm/hpmcounterN.layout" ) , trim_mode : "-" )
171186 erb . filename = "#{ $root} /arch/csr/Zihpm/hpmcounterN.layout"
172187 File . write ( t . name , insert_warning ( erb . result ( binding ) , t . prerequisites . first ) )
@@ -175,7 +190,6 @@ private :insert_warning
175190 "#{ $root} /arch/csr/Zihpm/hpmcounterNh.layout" ,
176191 __FILE__
177192 ] do |t |
178- puts "Generating #{ Pathname . new ( t . name ) . relative_path_from ( $root) } "
179193 erb = ERB . new ( File . read ( $root / "arch/csr/Zihpm/hpmcounterNh.layout" ) , trim_mode : "-" )
180194 erb . filename = "#{ $root} /arch/csr/Zihpm/hpmcounterNh.layout"
181195 File . write ( t . name , insert_warning ( erb . result ( binding ) , t . prerequisites . first ) )
187201 "#{ $root} /arch/csr/I/pmpaddrN.layout" ,
188202 __FILE__
189203 ] do |t |
190- puts "Generating #{ Pathname . new ( t . name ) . relative_path_from ( $root) } "
191204 erb = ERB . new ( File . read ( $root / "arch/csr/I/pmpaddrN.layout" ) , trim_mode : "-" )
192205 erb . filename = "#{ $root} /arch/csr/I/pmpaddrN.layout"
193206 File . write ( t . name , insert_warning ( erb . result ( binding ) , t . prerequisites . first ) )
199212 "#{ $root} /arch/csr/I/pmpcfgN.layout" ,
200213 __FILE__
201214 ] do |t |
202- puts "Generating #{ Pathname . new ( t . name ) . relative_path_from ( $root) } "
203215 erb = ERB . new ( File . read ( $root / "arch/csr/I/pmpcfgN.layout" ) , trim_mode : "-" )
204216 erb . filename = "#{ $root} /arch/csr/I/pmpcfgN.layout"
205217 File . write ( t . name , insert_warning ( erb . result ( binding ) , t . prerequisites . first ) )
@@ -210,7 +222,6 @@ file "#{$root}/arch/csr/I/mcounteren.yaml" => [
210222 "#{ $root} /arch/csr/I/mcounteren.layout" ,
211223 __FILE__
212224] do |t |
213- puts "Generating #{ Pathname . new ( t . name ) . relative_path_from ( $root) } "
214225 erb = ERB . new ( File . read ( $root / "arch/csr/I/mcounteren.layout" ) , trim_mode : "-" )
215226 erb . filename = "#{ $root} /arch/csr/I/mcounteren.layout"
216227 File . write ( t . name , insert_warning ( erb . result ( binding ) , t . prerequisites . first ) )
@@ -220,7 +231,6 @@ file "#{$root}/arch/csr/S/scounteren.yaml" => [
220231 "#{ $root} /arch/csr/S/scounteren.layout" ,
221232 __FILE__
222233] do |t |
223- puts "Generating #{ Pathname . new ( t . name ) . relative_path_from ( $root) } "
224234 erb = ERB . new ( File . read ( $root / "arch/csr/S/scounteren.layout" ) , trim_mode : "-" )
225235 erb . filename = "#{ $root} /arch/csr/S/scounteren.layout"
226236 File . write ( t . name , insert_warning ( erb . result ( binding ) , t . prerequisites . first ) )
@@ -230,7 +240,6 @@ file "#{$root}/arch/csr/H/hcounteren.yaml" => [
230240 "#{ $root} /arch/csr/H/hcounteren.layout" ,
231241 __FILE__
232242] do |t |
233- puts "Generating #{ Pathname . new ( t . name ) . relative_path_from ( $root) } "
234243 erb = ERB . new ( File . read ( $root / "arch/csr/H/hcounteren.layout" ) , trim_mode : "-" )
235244 erb . filename = "#{ $root} /arch/csr/H/hcounteren.layout"
236245 File . write ( t . name , insert_warning ( erb . result ( binding ) , t . prerequisites . first ) )
@@ -240,7 +249,6 @@ file "#{$root}/arch/csr/Zicntr/mcountinhibit.yaml" => [
240249 "#{ $root} /arch/csr/Zicntr/mcountinhibit.layout" ,
241250 __FILE__
242251] do |t |
243- puts "Generating #{ Pathname . new ( t . name ) . relative_path_from ( $root) } "
244252 erb = ERB . new ( File . read ( $root / "arch/csr/Zicntr/mcountinhibit.layout" ) , trim_mode : "-" )
245253 erb . filename = "#{ $root} /arch/csr/Zicntr/mcountinhibit.layout"
246254 File . write ( t . name , insert_warning ( erb . result ( binding ) , t . prerequisites . first ) )
@@ -284,7 +292,7 @@ namespace :test do
284292 Rake ::Task [ "test:idl_compiler" ] . invoke
285293 Rake ::Task [ "test:lib" ] . invoke
286294 Rake ::Task [ "test:schema" ] . invoke
287- Rake ::Task [ "test:idl_model " ] . invoke
295+ Rake ::Task [ "test:idl " ] . invoke
288296 end
289297
290298 desc <<~DESC
0 commit comments