Skip to content

Commit f5be2b8

Browse files
authored
Merge pull request #350 from riscv-software-src/refactor
Big, Ugly Patch
2 parents 42d9d3c + 0ea6597 commit f5be2b8

File tree

294 files changed

+7635
-6985
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

294 files changed

+7635
-6985
lines changed

.prettierignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
gen
2+
.home
3+
.singularity
4+
node_modules
5+
.asciidoctor
6+
.bundle
7+
.git
8+
.github
9+
.vscode
10+
docs/ruby
11+
ext

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Metrics/AbcSize:
4040
Metrics/CyclomaticComplexity:
4141
Enabled: false
4242

43+
Metrics/ParameterLists:
44+
Enabled: true
45+
CountKeywordArgs: false
46+
4347
Metrics/PerceivedComplexity:
4448
Enabled: false
4549

Gemfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,27 @@ ruby "3.2.3"
44

55
source "https://rubygems.org"
66

7+
gem "activesupport"
78
gem "asciidoctor-diagram", "~> 2.2"
89
gem "asciidoctor-pdf"
910
gem "base64"
1011
gem "bigdecimal"
1112
gem "json_schemer", "~> 1.0"
1213
gem "minitest"
13-
gem "ruby-progressbar", "~> 1.13"
1414
gem "pygments.rb"
1515
gem "rake", "~> 13.0"
1616
gem "rouge"
17+
gem "ruby-progressbar", "~> 1.13"
1718
gem "treetop", "1.6.12"
1819
gem "ttfunk", "1.7" # needed to avoid having asciidoctor-pdf dependencies pulling in a buggy version of ttunk (1.8)
1920
gem "webrick"
2021
gem "yard"
2122

2223
group :development do
23-
gem "solargraph"
24-
gem 'rubocop-minitest'
25-
gem 'ruby-prof'
26-
gem "ruby-prof-flamegraph"
24+
gem "debug"
2725
gem "rdbg"
26+
gem "rubocop-minitest"
27+
gem "ruby-prof"
28+
gem "ruby-prof-flamegraph"
29+
gem "solargraph"
2830
end

Gemfile.lock

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ GEM
22
remote: https://rubygems.org/
33
specs:
44
Ascii85 (1.1.1)
5+
activesupport (8.0.0)
6+
base64
7+
benchmark (>= 0.3)
8+
bigdecimal
9+
concurrent-ruby (~> 1.0, >= 1.3.1)
10+
connection_pool (>= 2.2.5)
11+
drb
12+
i18n (>= 1.6, < 2)
13+
logger (>= 1.4.2)
14+
minitest (>= 5.1)
15+
securerandom (>= 0.3)
16+
tzinfo (~> 2.0, >= 2.0.5)
17+
uri (>= 0.13.1)
518
addressable (2.8.7)
619
public_suffix (>= 2.0.2, < 7.0)
720
afm (0.2.2)
@@ -31,18 +44,21 @@ GEM
3144
benchmark (0.3.0)
3245
bigdecimal (3.1.8)
3346
concurrent-ruby (1.3.3)
47+
connection_pool (2.4.1)
3448
css_parser (1.17.1)
3549
addressable
36-
date (3.4.1)
3750
debug (1.9.2)
3851
irb (~> 1.10)
3952
reline (>= 0.3.8)
4053
diff-lcs (1.5.1)
54+
drb (2.2.1)
4155
e2mmap (0.1.0)
4256
hana (1.3.7)
4357
hashery (2.1.2)
44-
io-console (0.8.0)
45-
irb (1.14.2)
58+
i18n (1.14.6)
59+
concurrent-ruby (~> 1.0)
60+
io-console (0.7.2)
61+
irb (1.14.1)
4662
rdoc (>= 4.0.0)
4763
reline (>= 0.4.2)
4864
jaro_winkler (1.6.0)
@@ -56,6 +72,7 @@ GEM
5672
kramdown-parser-gfm (1.1.0)
5773
kramdown (~> 2.0)
5874
language_server-protocol (3.17.0.3)
75+
logger (1.6.2)
5976
matrix (0.4.2)
6077
minitest (5.24.1)
6178
nokogiri (1.16.5-aarch64-linux)
@@ -89,8 +106,7 @@ GEM
89106
prawn-templates (0.1.2)
90107
pdf-reader (~> 2.0)
91108
prawn (~> 2.2)
92-
psych (5.2.1)
93-
date
109+
psych (5.2.0)
94110
stringio
95111
public_suffix (6.0.0)
96112
pygments.rb (3.0.0)
@@ -100,10 +116,10 @@ GEM
100116
rbs (2.8.4)
101117
rdbg (0.1.0)
102118
debug (>= 1.2.2)
103-
rdoc (6.9.1)
119+
rdoc (6.8.1)
104120
psych (>= 4.0.0)
105121
regexp_parser (2.9.2)
106-
reline (0.6.0)
122+
reline (0.5.11)
107123
io-console (~> 0.5)
108124
reverse_markdown (2.1.1)
109125
nokogiri
@@ -131,6 +147,7 @@ GEM
131147
ruby-prof (~> 0.13)
132148
ruby-progressbar (1.13.0)
133149
ruby-rc4 (0.1.5)
150+
securerandom (0.4.0)
134151
simpleidn (0.2.3)
135152
solargraph (0.50.0)
136153
backport (~> 1.2)
@@ -155,7 +172,10 @@ GEM
155172
treetop (1.6.12)
156173
polyglot (~> 0.3)
157174
ttfunk (1.7.0)
175+
tzinfo (2.0.6)
176+
concurrent-ruby (~> 1.0)
158177
unicode-display_width (2.5.0)
178+
uri (1.0.2)
159179
webrick (1.8.1)
160180
yard (0.9.36)
161181

@@ -164,10 +184,12 @@ PLATFORMS
164184
x86_64-linux-gnu
165185

166186
DEPENDENCIES
187+
activesupport
167188
asciidoctor-diagram (~> 2.2)
168189
asciidoctor-pdf
169190
base64
170191
bigdecimal
192+
debug
171193
json_schemer (~> 1.0)
172194
minitest
173195
pygments.rb

Rakefile

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require "ruby-progressbar"
99
require "yard"
1010
require "minitest/test_task"
1111

12-
require_relative $root / "lib" / "validate"
12+
require_relative $root / "lib" / "architecture"
1313

1414
directory "#{$root}/.stamps"
1515

@@ -19,22 +19,50 @@ end
1919

2020
directory "#{$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+
)
2834
end
2935

3036
namespace :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
3866
end
3967

4068
namespace :serve do
@@ -75,8 +103,7 @@ end
75103

76104
desc "Clean up all generated files"
77105
task :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."
80107
end
81108

82109
namespace :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("")
125145
end
126146
private :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))
@@ -187,7 +201,6 @@ end
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))
@@ -199,7 +212,6 @@ end
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

Comments
 (0)