-
Notifications
You must be signed in to change notification settings - Fork 12
/
Rakefile
283 lines (246 loc) · 9.83 KB
/
Rakefile
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
# frozen_string_literal: true
require "etc"
$root = Pathname.new(__FILE__).dirname.realpath
$lib = $root / "lib"
require "ruby-progressbar"
require "yard"
require "minitest/test_task"
require_relative $root / "lib" / "validate"
directory "#{$root}/.stamps"
Dir.glob("#{$root}/backends/*/tasks.rake") do |rakefile|
load rakefile
end
directory "#{$root}/.stamps"
file "#{$root}/.stamps/dev_gems" => "#{$root}/.stamps" do
Dir.chdir($root) do
sh "bundle config set --local with development"
sh "bundle install"
FileUtils.touch "#{$root}/.stamps/dev_gems"
end
end
namespace :gen do
desc "Generate documentation for the ruby tooling"
task tool_doc: "#{$root}/.stamps/dev_gems" do
Dir.chdir($root) do
sh "bundle exec yard doc --yardopts arch_def.yardopts"
sh "bundle exec yard doc --yardopts idl.yardopts"
end
end
end
namespace :serve do
desc <<~DESC
Start an HTML server to view the generated HTML documentation for the tool
The default port is 8000, though it can be overridden with an argument
DESC
task :tool_doc, [:port] => "gen:tool_doc" do |_t, args|
args.with_defaults(port: 8000)
puts <<~MSG
Server will come up on http://#{`hostname`.strip}:#{args[:port]}.
It will regenerate the documentation on every access
MSG
sh "yard server -p #{args[:port]} --reload"
end
end
Minitest::TestTask.create :idl_test do |t|
t.test_globs = ["#{$root}/lib/idl/tests/test_*.rb"]
end
desc "Clean up all generated files"
task :clean do
FileUtils.rm_rf $root / "gen"
FileUtils.rm_rf $root / ".stamps"
end
namespace :validate do
task :insts do
puts "Checking instruction encodings..."
inst_paths = Dir.glob("#{$root}/arch/inst/**/*.yaml").map { |f| Pathname.new(f) }
inst_paths.each do |inst_path|
Validator.instance.validate_instruction(inst_path)
end
puts "All instruction encodings pass basic sanity tests"
end
task schema: "gen:arch" do
validator = Validator.instance
puts "Checking arch files against schema.."
arch_files = Dir.glob("#{$root}/arch/**/*.yaml")
progressbar = ProgressBar.create(total: arch_files.size)
arch_files.each do |f|
progressbar.increment
validator.validate(f)
end
puts "All files validate against their schema"
end
task idl: ["gen:arch", "#{$root}/.stamps/arch-gen-_32.stamp", "#{$root}/.stamps/arch-gen-_64.stamp"] do
print "Parsing IDL code for RV32..."
arch_def_32 = arch_def_for("_32")
puts "done"
arch_def_32.type_check
print "Parsing IDL code for RV64..."
arch_def_64 = arch_def_for("_64")
puts "done"
arch_def_64.type_check
puts "All IDL passed type checking"
end
end
desc "Validate the arch docs"
task validate: ["validate:schema", "validate:idl", "validate:insts"]
def insert_warning(str, from)
# insert a warning on the second line
lines = str.lines
first_line = lines.shift
lines.unshift(first_line, "\n# WARNING: This file is auto-generated from #{Pathname.new(from).relative_path_from($root)}\n\n").join("")
end
private :insert_warning
(3..31).each do |hpm_num|
file "#{$root}/arch/csr/Zihpm/mhpmcounter#{hpm_num}.yaml" => [
"#{$root}/arch/csr/Zihpm/mhpmcounterN.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/Zihpm/mhpmcounterN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/mhpmcounterN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/mhpmcounter#{hpm_num}h.yaml" => [
"#{$root}/arch/csr/Zihpm/mhpmcounterNh.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/Zihpm/mhpmcounterNh.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/mhpmcounterNh.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/mhpmevent#{hpm_num}.yaml" => [
"#{$root}/arch/csr/Zihpm/mhpmeventN.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/Zihpm/mhpmeventN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/mhpmeventN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/mhpmevent#{hpm_num}h.yaml" => [
"#{$root}/arch/csr/Zihpm/mhpmeventNh.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/Zihpm/mhpmeventNh.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/mhpmeventNh.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/hpmcounter#{hpm_num}.yaml" => [
"#{$root}/arch/csr/Zihpm/hpmcounterN.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/Zihpm/hpmcounterN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/hpmcounterN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zihpm/hpmcounter#{hpm_num}h.yaml" => [
"#{$root}/arch/csr/Zihpm/hpmcounterNh.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/Zihpm/hpmcounterNh.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zihpm/hpmcounterNh.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
end
(0..63).each do |pmpaddr_num|
file "#{$root}/arch/csr/I/pmpaddr#{pmpaddr_num}.yaml" => [
"#{$root}/arch/csr/I/pmpaddrN.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/I/pmpaddrN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/I/pmpaddrN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
end
(0..15).each do |pmpcfg_num|
file "#{$root}/arch/csr/I/pmpcfg#{pmpcfg_num}.yaml" => [
"#{$root}/arch/csr/I/pmpcfgN.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/I/pmpcfgN.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/I/pmpcfgN.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
end
file "#{$root}/arch/csr/I/mcounteren.yaml" => [
"#{$root}/arch/csr/I/mcounteren.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/I/mcounteren.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/I/mcounteren.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/S/scounteren.yaml" => [
"#{$root}/arch/csr/S/scounteren.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/S/scounteren.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/S/scounteren.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/H/hcounteren.yaml" => [
"#{$root}/arch/csr/H/hcounteren.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/H/hcounteren.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/H/hcounteren.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
file "#{$root}/arch/csr/Zicntr/mcountinhibit.yaml" => [
"#{$root}/arch/csr/Zicntr/mcountinhibit.layout",
__FILE__
] do |t|
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
erb = ERB.new(File.read($root / "arch/csr/Zicntr/mcountinhibit.layout"), trim_mode: "-")
erb.filename = "#{$root}/arch/csr/Zicntr/mcountinhibit.layout"
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
end
namespace :gen do
desc "Generate architecture files from layouts"
task :arch do
(3..31).each do |hpm_num|
Rake::Task["#{$root}/arch/csr/Zihpm/mhpmcounter#{hpm_num}.yaml"].invoke
Rake::Task["#{$root}/arch/csr/Zihpm/mhpmcounter#{hpm_num}h.yaml"].invoke
Rake::Task["#{$root}/arch/csr/Zihpm/mhpmevent#{hpm_num}.yaml"].invoke
Rake::Task["#{$root}/arch/csr/Zihpm/mhpmevent#{hpm_num}h.yaml"].invoke
Rake::Task["#{$root}/arch/csr/Zihpm/hpmcounter#{hpm_num}.yaml"].invoke
Rake::Task["#{$root}/arch/csr/Zihpm/hpmcounter#{hpm_num}h.yaml"].invoke
end
Rake::Task["#{$root}/arch/csr/I/mcounteren.yaml"].invoke
Rake::Task["#{$root}/arch/csr/S/scounteren.yaml"].invoke
Rake::Task["#{$root}/arch/csr/H/hcounteren.yaml"].invoke
Rake::Task["#{$root}/arch/csr/Zicntr/mcountinhibit.yaml"].invoke
(0..63).each do |pmpaddr_num|
Rake::Task["#{$root}/arch/csr/I/pmpaddr#{pmpaddr_num}.yaml"].invoke
end
(0..15).each do |pmpcfg_num|
Rake::Task["#{$root}/arch/csr/I/pmpcfg#{pmpcfg_num}.yaml"].invoke
end
end
end
desc <<~DESC
Run the regression tests
These tests must pass before a commit will be allowed in the main branch on GitHub
DESC
task :regress do
Rake::Task["idl_test"].invoke
Rake::Task["validate"].invoke
ENV["MANUAL_NAME"] = "isa"
ENV["VERSIONS"] = "all"
Rake::Task["gen:html_manual"].invoke
Rake::Task["gen:html"].invoke("generic_rv64")
Rake::Task["gen:crd_pdf"].invoke("MockCRD-1")
Rake::Task["gen:crd_pdf"].invoke("MC-1")
Rake::Task["gen:profile_pdf"].invoke("rva")
puts
puts "Regression test PASSED"
end