Skip to content

Commit 98a41f3

Browse files
Merge pull request #302 from riscv-software-src/ext_ver
Make ExtensionVersion a proper object in Ruby
2 parents 3f2695d + 1909fc1 commit 98a41f3

File tree

19 files changed

+496
-184
lines changed

19 files changed

+496
-184
lines changed

Rakefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ task :regress do
287287
ENV["VERSIONS"] = "all"
288288
Rake::Task["gen:html_manual"].invoke
289289
Rake::Task["gen:html"].invoke("generic_rv64")
290+
ENV["EXT"] = "B"
291+
ENV["VERSION"] = "latest"
292+
Rake::Task["gen:ext_pdf"].invoke
290293
Rake::Task["#{$root}/gen/certificate_doc/pdf/MockCertificateModel.pdf"].invoke
291294
Rake::Task["#{$root}/gen/certificate_doc/pdf/MC100.pdf"].invoke
292295
Rake::Task["#{$root}/gen/profile_doc/pdf/MockProfileRelease.pdf"].invoke

backends/arch_gen/lib/arch_gen.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ def maybe_add_csr(csr_name, extra_env = {})
639639
arch_def_mock.define_singleton_method(:possible_xlens) do
640640
pos_xlen_local
641641
end
642-
impl_ext = @cfg_impl_ext.map { |e| ExtensionVersion.new(e[0], e[1]) }
642+
impl_ext = @cfg_impl_ext.map { |e| ExtensionVersion.new(e[0], e[1], nil) }
643643
arch_def_mock.define_singleton_method(:implemented_extensions) do
644644
impl_ext
645645
end
@@ -893,7 +893,7 @@ def maybe_add_inst(inst_name, extra_env = {})
893893
arch_def_mock = Object.new
894894
arch_def_mock.define_singleton_method(:fully_configured?) { true }
895895
arch_def_mock.define_singleton_method(:possible_xlens) { possible_xlens }
896-
impl_ext = @cfg_impl_ext.map { |e| ExtensionVersion.new(e[0], e[1]) }
896+
impl_ext = @cfg_impl_ext.map { |e| ExtensionVersion.new(e[0], e[1], nil) }
897897
arch_def_mock.define_singleton_method(:implemented_extensions) do
898898
impl_ext
899899
end

backends/certificate_doc/templates/certificate.adoc.erb

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -298,30 +298,29 @@ Requirement <%= req.name %> only apply when <%= req.when_pretty %>.
298298
*Version Requirement*: <%= ext_req.version_requirement %> +
299299
300300
<% ext.versions.each do |v| -%>
301-
<%= v["version"] %>::
301+
<%= v.version %>::
302302
State:::
303-
<%= v["state"] %>
304-
<% if v["state"] == "ratified" -%>
303+
<%= v.state %>
304+
<% if v.state == "ratified" -%>
305305
Ratification date:::
306-
<%= v["ratification_date"] %>
306+
<%= v.ratification_date %>
307307
<% end # if %>
308-
<% if v.key?("changes") -%>
308+
<% if v.changes.size > 0 -%>
309309
Changes:::
310310
311-
<% v["changes"].each do |c| -%>
311+
<% v.changes.each do |c| -%>
312312
* <%= c %>
313313
<% end -%>
314314
315315
<% end -%>
316-
<% if v.key?("url") -%>
316+
<% unless v.url.nil? -%>
317317
Ratification document:::
318-
<%= v["url"] %>
318+
<%= v.url %>
319319
<% end -%>
320-
<% if v.key?("implies") -%>
320+
<% if v.implications.size > 0 -%>
321321
Implies:::
322-
<% implications = v["implies"][0].is_a?(Array) ? v["implies"] : [v["implies"]] -%>
323-
<% implications.each do |i| -%>
324-
* `<%= i[0] %>` version <%= i[1] %>
322+
<% v.implications.each do |i| -%>
323+
* `<%= i.name %>` version <%= i.version %>
325324
<% end -%>
326325
<% end -%>
327326
<% end -%>
@@ -342,7 +341,7 @@ Requirement <%= req.name %> only apply when <%= req.when_pretty %>.
342341
<% end -%>
343342
344343
// TODO: GitHub issue 92: Use version specified by each profile.
345-
<% insts = arch_def.instructions.select { |i| i.defined_by?(ext.name,ext.min_version) } -%>
344+
<% insts = arch_def.instructions.select { |i| i.defined_by?(ext.min_version) } -%>
346345
<% unless insts.empty? -%>
347346
==== Instructions
348347

backends/cfg_html_doc/adoc_gen.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ require "ruby-prof"
9292
when "ext"
9393
puts "Generting full extension list"
9494
arch_def.implemented_extensions.each do |ext_version|
95-
lines << " * `#{ext_version.name}` #{ext_version.ext(arch_def).long_name}"
95+
lines << " * `#{ext_version.name}` #{ext_version.ext.long_name}"
9696
end
9797
when "inst"
9898
puts "Generting full instruction list"

backends/cfg_html_doc/templates/ext.adoc.erb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,26 @@ Implemented Version:: <%= ext_version.version %>
77
== Versions
88

99
<%- ext.versions.each do |v| -%>
10-
<%- implemented = arch_def.implemented_extensions.include?(ExtensionVersion.new(ext.name, v["version"])) -%>
11-
<%= v["version"] %>::
10+
<%- implemented = arch_def.implemented_extensions.include?(v) -%>
11+
<%= v.version %>::
1212
Ratification date:::
13-
<%= v["ratification_date"] %>
14-
<%- if v.key?("changes") -%>
13+
<%= v.ratification_date %>
14+
<%- unless v.changes.empty? -%>
1515
Changes:::
16-
<%= v["changes"] %>
16+
17+
<% v.changes.each do |c| -%>
18+
* <%= c %>
19+
<% end -%>
20+
1721
<%- end -%>
18-
<%- if v.key?("url") -%>
22+
<%- unless v.url.nil? -%>
1923
Ratification document:::
20-
<%= v["url"] %>
24+
<%= v.url %>
2125
<%- end -%>
22-
<%- if v.key?("implies") -%>
26+
<%- unless v.implications.empty? -%>
2327
Implies:::
24-
<%- implications = v["implies"][0].is_a?(Array) ? v["implies"] : [v["implies"]] -%>
25-
<%- implications.each do |i| -%>
26-
* `<%= i[0] %>` version <%= i[1] %>
28+
<%- v.implications.each do |i| -%>
29+
* `<%= i.name %>` version <%= i.version %>
2730
<%- end -%>
2831
<%- end -%>
2932
<%- end -%>

backends/ext_pdf_doc/tasks.rake

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,18 @@ rule %r{#{$root}/gen/ext_pdf_doc/.*/adoc/.*_extension\.adoc} => proc { |tname|
145145
erb.filename = template_path.to_s
146146

147147
ext = arch_def.extension(ext_name)
148-
version_num =
149-
if ENV.key?("EXT_VERSION")
150-
ENV["EXT_VERSION"]
148+
version_strs = ENV["VERSION"].split(",")
149+
versions =
150+
if version_strs.include?("all")
151+
ext.versions
151152
else
152-
ext.versions.max { |a, b| Gem::Version.new(a["version"]) <=> Gem::Version.new(b["version"]) }["version"]
153+
vs = ext.versions.select do |ext_ver|
154+
version_strs.include?(ext_ver.version.to_s)
155+
end
156+
vs << ext.max_version if version_strs.include?("latest")
157+
vs.uniq
153158
end
154-
ext_version = ext.versions.find { |v| v["version"] == version_num }
159+
max_version = versions.max { |a, b| a.version <=> b.version }
155160
FileUtils.mkdir_p File.dirname(t.name)
156161
File.write t.name, AsciidocUtils.resolve_links(arch_def.find_replace_links(erb.result(binding)))
157162
end
@@ -161,25 +166,36 @@ namespace :gen do
161166
Generate PDF documentation for :extension
162167
163168
If the extension is custom (from an arch_overlay), also give the config name
164-
DESC
165-
task :ext_pdf, [:extension] do |_t, args|
166-
extension = args[:extension]
167169
168-
Rake::Task[$root / "gen" / "ext_pdf_doc" / "_" / "pdf" / "#{extension}_extension.pdf"].invoke
169-
end
170+
Options:
170171
171-
desc <<~DESC
172-
Generate PDF documentation for :extension that is defined or overlayed in :cfg
172+
* EXT - The extension name
173+
* CFG - The config name, required only when an overlay is required
174+
* VERSION - A list of versions to include. May also be "all" or "latest".
175+
176+
Examples:
177+
178+
./do gen:ext_pdf EXT=Xqci CFG=qc_iu VERSION=latest
179+
./do gen:ext_pdf EXT=B VERSION=all
180+
./do gen:ext_pdf EXT=B VERSION=1.0.0
181+
./do gen:ext_pdf EXT=B VERSION=1.0.0,1.1.0
173182
174-
The latest version will be used, but can be overloaded by setting the EXT_VERSION environment variable.
175183
DESC
176-
task :cfg_ext_pdf, [:extension, :cfg] do |_t, args|
177-
raise ArgumentError, "Missing required argument :extension" if args[:extension].nil?
178-
raise ArgumentError, "Missing required argument :cfg" if args[:cfg].nil?
184+
task :ext_pdf, [:extension] do |_t, args|
185+
raise ArgumentError, "Missing required argument EXT" if ENV["EXT"].nil?
179186

180-
extension = args[:extension]
187+
extension = ENV["EXT"]
188+
cfg = ENV["CFG"]
189+
version = ENV["VERSION"]
190+
191+
versions = version.split(",")
192+
raise ArgumentError, "Nothing else should be specified with 'all'" if versions.include?("all") && versions.size > 1
181193

182-
Rake::Task[$root / "gen" / "ext_pdf_doc" / args[:cfg] / "pdf" / "#{extension}_extension.pdf"].invoke(args)
194+
if cfg.nil?
195+
Rake::Task[$root / "gen" / "ext_pdf_doc" / "_" / "pdf" / "#{extension}_extension.pdf"].invoke
196+
else
197+
Rake::Task[$root / "gen" / "ext_pdf_doc" / cfg / "pdf" / "#{extension}_extension.pdf"].invoke(args)
198+
end
183199
end
184200

185201
desc <<~DESC

0 commit comments

Comments
 (0)