Skip to content

Commit 3a30c4f

Browse files
adingank-qualcommdhower-qcThinkOpenly
authored
Merge new command "list csrs" CLI (riscv-software-src#909)
Added `test_list_csrs` with an assertion for equality of the number of CSRs reported with [the number of yaml files under `csr` directory](https://github.com/riscv-software-src/riscv-unified-db/blob/d0e69a4e02b33e0ea082a6fbc83f6f6e38480031/tools/ruby-gems/udb/test/test_cli.rb#L77). --------- Signed-off-by: Ajit Dingankar <[email protected]> Co-authored-by: Derek Hower <[email protected]> Co-authored-by: Paul Clarke <[email protected]>
1 parent f74a1fd commit 3a30c4f

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

Gemfile.lock

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ GEM
130130
nokogiri (1.18.8-x86_64-linux-gnu)
131131
racc (~> 1.4)
132132
observer (0.1.2)
133-
ostruct (0.6.1)
133+
ostruct (0.6.2)
134134
parallel (1.27.0)
135135
parser (3.3.8.0)
136136
ast (~> 2.4.1)
@@ -188,18 +188,18 @@ GEM
188188
nokogiri
189189
rexml (3.4.1)
190190
rouge (4.5.2)
191-
rubocop (1.76.0)
191+
rubocop (1.77.0)
192192
json (~> 2.3)
193193
language_server-protocol (~> 3.17.0.2)
194194
lint_roller (~> 1.1.0)
195195
parallel (~> 1.10)
196196
parser (>= 3.3.0.2)
197197
rainbow (>= 2.2.2, < 4.0)
198198
regexp_parser (>= 2.9.3, < 3.0)
199-
rubocop-ast (>= 1.45.0, < 2.0)
199+
rubocop-ast (>= 1.45.1, < 2.0)
200200
ruby-progressbar (~> 1.7)
201201
unicode-display_width (>= 2.4.0, < 4.0)
202-
rubocop-ast (1.45.0)
202+
rubocop-ast (1.45.1)
203203
parser (>= 3.3.7.2)
204204
prism (~> 1.4)
205205
rubocop-github (0.26.0)
@@ -239,7 +239,7 @@ GEM
239239
simplecov-html (0.13.1)
240240
simplecov_json_formatter (0.1.4)
241241
simpleidn (0.2.3)
242-
solargraph (0.55.0)
242+
solargraph (0.56.0)
243243
backport (~> 1.2)
244244
benchmark (~> 0.4)
245245
bundler (~> 2.0)
@@ -251,6 +251,7 @@ GEM
251251
observer (~> 0.1)
252252
ostruct (~> 0.6)
253253
parser (~> 3.0)
254+
prism (~> 1.4)
254255
rbs (~> 3.3)
255256
reverse_markdown (~> 3.0)
256257
rubocop (~> 1.38)
@@ -287,7 +288,7 @@ GEM
287288
terminal-table (4.0.0)
288289
unicode-display_width (>= 1.1.1, < 4)
289290
thor (1.3.2)
290-
tilt (2.6.0)
291+
tilt (2.6.1)
291292
treetop (1.6.12)
292293
polyglot (~> 0.3)
293294
ttfunk (1.7.0)

tools/ruby-gems/udb/lib/udb/cli.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,37 @@ def parameters
245245
out.puts JSON.dump(yaml)
246246
end
247247
end
248+
249+
250+
desc "csrs", "list all csrs for a config"
251+
method_option :arch, aliases: "-a", type: :string, desc: "Path to architecture database", default: Udb.default_std_isa_path.to_s
252+
method_option :arch_overlay, type: :string, desc: "Path to architecture overlay directory", default: Udb.default_custom_isa_path.to_s
253+
method_option :gen, type: :string, desc: "Path to folder used for generation", default: Udb.default_gen_path.to_s
254+
method_option :config, type: :string, required: true, desc: "Configuration name, or path to a config file", default: "_"
255+
method_option :config_dir, type: :string, desc: "Path to directory with config files", default: Udb.default_cfgs_path.to_s
256+
def csrs
257+
raise ArgumentError, "Arch directory does not exist: #{options[:arch]}" unless File.directory?(options[:arch])
258+
259+
cfg_file =
260+
if File.file?(options[:config])
261+
Pathname.new(options[:config])
262+
elsif File.file?("#{options[:config_dir]}/#{options[:config]}.yaml")
263+
Pathname.new("#{options[:config_dir]}/#{options[:config]}.yaml")
264+
else
265+
raise ArgumentError, "Cannot find config: #{options[:config]}"
266+
end
267+
268+
resolver =
269+
Udb::Resolver.new(
270+
std_path_override: Pathname.new(options[:arch]),
271+
custom_path_override: Pathname.new(options[:arch_overlay]),
272+
gen_path_override: Pathname.new(options[:gen])
273+
)
274+
cfg_arch = resolver.cfg_arch_for(cfg_file.realpath)
275+
cfg_arch.csrs.each do |csr|
276+
puts csr.name
277+
end
278+
end
248279
end
249280
end
250281

tools/ruby-gems/udb/test/test_cli.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,16 @@ def test_disasm
6262
assert_match " lui", out
6363
assert_empty err
6464
end
65+
66+
def test_list_csrs
67+
out, err = capture_io do
68+
run_cmd("list csrs")
69+
end
70+
assert_empty err
71+
repo_top = Udb.repo_root
72+
num_csr_yaml_files = `find #{repo_top}/spec/std/isa/csr/ -name '*.yaml' | wc -l`.to_i
73+
puts num_csr_yaml_files
74+
assert_equal num_csr_yaml_files, out.split.length
75+
end
76+
6577
end

0 commit comments

Comments
 (0)