Skip to content

Commit

Permalink
Merge pull request #302 from riscv-software-src/ext_ver
Browse files Browse the repository at this point in the history
Make ExtensionVersion a proper object in Ruby
  • Loading branch information
james-ball-qualcomm authored Nov 22, 2024
2 parents 3f2695d + 1909fc1 commit 98a41f3
Show file tree
Hide file tree
Showing 19 changed files with 496 additions and 184 deletions.
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ task :regress do
ENV["VERSIONS"] = "all"
Rake::Task["gen:html_manual"].invoke
Rake::Task["gen:html"].invoke("generic_rv64")
ENV["EXT"] = "B"
ENV["VERSION"] = "latest"
Rake::Task["gen:ext_pdf"].invoke
Rake::Task["#{$root}/gen/certificate_doc/pdf/MockCertificateModel.pdf"].invoke
Rake::Task["#{$root}/gen/certificate_doc/pdf/MC100.pdf"].invoke
Rake::Task["#{$root}/gen/profile_doc/pdf/MockProfileRelease.pdf"].invoke
Expand Down
4 changes: 2 additions & 2 deletions backends/arch_gen/lib/arch_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def maybe_add_csr(csr_name, extra_env = {})
arch_def_mock.define_singleton_method(:possible_xlens) do
pos_xlen_local
end
impl_ext = @cfg_impl_ext.map { |e| ExtensionVersion.new(e[0], e[1]) }
impl_ext = @cfg_impl_ext.map { |e| ExtensionVersion.new(e[0], e[1], nil) }
arch_def_mock.define_singleton_method(:implemented_extensions) do
impl_ext
end
Expand Down Expand Up @@ -893,7 +893,7 @@ def maybe_add_inst(inst_name, extra_env = {})
arch_def_mock = Object.new
arch_def_mock.define_singleton_method(:fully_configured?) { true }
arch_def_mock.define_singleton_method(:possible_xlens) { possible_xlens }
impl_ext = @cfg_impl_ext.map { |e| ExtensionVersion.new(e[0], e[1]) }
impl_ext = @cfg_impl_ext.map { |e| ExtensionVersion.new(e[0], e[1], nil) }
arch_def_mock.define_singleton_method(:implemented_extensions) do
impl_ext
end
Expand Down
25 changes: 12 additions & 13 deletions backends/certificate_doc/templates/certificate.adoc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -298,30 +298,29 @@ Requirement <%= req.name %> only apply when <%= req.when_pretty %>.
*Version Requirement*: <%= ext_req.version_requirement %> +
<% ext.versions.each do |v| -%>
<%= v["version"] %>::
<%= v.version %>::
State:::
<%= v["state"] %>
<% if v["state"] == "ratified" -%>
<%= v.state %>
<% if v.state == "ratified" -%>
Ratification date:::
<%= v["ratification_date"] %>
<%= v.ratification_date %>
<% end # if %>
<% if v.key?("changes") -%>
<% if v.changes.size > 0 -%>
Changes:::
<% v["changes"].each do |c| -%>
<% v.changes.each do |c| -%>
* <%= c %>
<% end -%>
<% end -%>
<% if v.key?("url") -%>
<% unless v.url.nil? -%>
Ratification document:::
<%= v["url"] %>
<%= v.url %>
<% end -%>
<% if v.key?("implies") -%>
<% if v.implications.size > 0 -%>
Implies:::
<% implications = v["implies"][0].is_a?(Array) ? v["implies"] : [v["implies"]] -%>
<% implications.each do |i| -%>
* `<%= i[0] %>` version <%= i[1] %>
<% v.implications.each do |i| -%>
* `<%= i.name %>` version <%= i.version %>
<% end -%>
<% end -%>
<% end -%>
Expand All @@ -342,7 +341,7 @@ Requirement <%= req.name %> only apply when <%= req.when_pretty %>.
<% end -%>
// TODO: GitHub issue 92: Use version specified by each profile.
<% insts = arch_def.instructions.select { |i| i.defined_by?(ext.name,ext.min_version) } -%>
<% insts = arch_def.instructions.select { |i| i.defined_by?(ext.min_version) } -%>
<% unless insts.empty? -%>
==== Instructions
Expand Down
2 changes: 1 addition & 1 deletion backends/cfg_html_doc/adoc_gen.rake
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ require "ruby-prof"
when "ext"
puts "Generting full extension list"
arch_def.implemented_extensions.each do |ext_version|
lines << " * `#{ext_version.name}` #{ext_version.ext(arch_def).long_name}"
lines << " * `#{ext_version.name}` #{ext_version.ext.long_name}"
end
when "inst"
puts "Generting full instruction list"
Expand Down
25 changes: 14 additions & 11 deletions backends/cfg_html_doc/templates/ext.adoc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@ Implemented Version:: <%= ext_version.version %>
== Versions

<%- ext.versions.each do |v| -%>
<%- implemented = arch_def.implemented_extensions.include?(ExtensionVersion.new(ext.name, v["version"])) -%>
<%= v["version"] %>::
<%- implemented = arch_def.implemented_extensions.include?(v) -%>
<%= v.version %>::
Ratification date:::
<%= v["ratification_date"] %>
<%- if v.key?("changes") -%>
<%= v.ratification_date %>
<%- unless v.changes.empty? -%>
Changes:::
<%= v["changes"] %>

<% v.changes.each do |c| -%>
* <%= c %>
<% end -%>

<%- end -%>
<%- if v.key?("url") -%>
<%- unless v.url.nil? -%>
Ratification document:::
<%= v["url"] %>
<%= v.url %>
<%- end -%>
<%- if v.key?("implies") -%>
<%- unless v.implications.empty? -%>
Implies:::
<%- implications = v["implies"][0].is_a?(Array) ? v["implies"] : [v["implies"]] -%>
<%- implications.each do |i| -%>
* `<%= i[0] %>` version <%= i[1] %>
<%- v.implications.each do |i| -%>
* `<%= i.name %>` version <%= i.version %>
<%- end -%>
<%- end -%>
<%- end -%>
Expand Down
52 changes: 34 additions & 18 deletions backends/ext_pdf_doc/tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,18 @@ rule %r{#{$root}/gen/ext_pdf_doc/.*/adoc/.*_extension\.adoc} => proc { |tname|
erb.filename = template_path.to_s

ext = arch_def.extension(ext_name)
version_num =
if ENV.key?("EXT_VERSION")
ENV["EXT_VERSION"]
version_strs = ENV["VERSION"].split(",")
versions =
if version_strs.include?("all")
ext.versions
else
ext.versions.max { |a, b| Gem::Version.new(a["version"]) <=> Gem::Version.new(b["version"]) }["version"]
vs = ext.versions.select do |ext_ver|
version_strs.include?(ext_ver.version.to_s)
end
vs << ext.max_version if version_strs.include?("latest")
vs.uniq
end
ext_version = ext.versions.find { |v| v["version"] == version_num }
max_version = versions.max { |a, b| a.version <=> b.version }
FileUtils.mkdir_p File.dirname(t.name)
File.write t.name, AsciidocUtils.resolve_links(arch_def.find_replace_links(erb.result(binding)))
end
Expand All @@ -161,25 +166,36 @@ namespace :gen do
Generate PDF documentation for :extension
If the extension is custom (from an arch_overlay), also give the config name
DESC
task :ext_pdf, [:extension] do |_t, args|
extension = args[:extension]
Rake::Task[$root / "gen" / "ext_pdf_doc" / "_" / "pdf" / "#{extension}_extension.pdf"].invoke
end
Options:
desc <<~DESC
Generate PDF documentation for :extension that is defined or overlayed in :cfg
* EXT - The extension name
* CFG - The config name, required only when an overlay is required
* VERSION - A list of versions to include. May also be "all" or "latest".
Examples:
./do gen:ext_pdf EXT=Xqci CFG=qc_iu VERSION=latest
./do gen:ext_pdf EXT=B VERSION=all
./do gen:ext_pdf EXT=B VERSION=1.0.0
./do gen:ext_pdf EXT=B VERSION=1.0.0,1.1.0
The latest version will be used, but can be overloaded by setting the EXT_VERSION environment variable.
DESC
task :cfg_ext_pdf, [:extension, :cfg] do |_t, args|
raise ArgumentError, "Missing required argument :extension" if args[:extension].nil?
raise ArgumentError, "Missing required argument :cfg" if args[:cfg].nil?
task :ext_pdf, [:extension] do |_t, args|
raise ArgumentError, "Missing required argument EXT" if ENV["EXT"].nil?

extension = args[:extension]
extension = ENV["EXT"]
cfg = ENV["CFG"]
version = ENV["VERSION"]

versions = version.split(",")
raise ArgumentError, "Nothing else should be specified with 'all'" if versions.include?("all") && versions.size > 1

Rake::Task[$root / "gen" / "ext_pdf_doc" / args[:cfg] / "pdf" / "#{extension}_extension.pdf"].invoke(args)
if cfg.nil?
Rake::Task[$root / "gen" / "ext_pdf_doc" / "_" / "pdf" / "#{extension}_extension.pdf"].invoke
else
Rake::Task[$root / "gen" / "ext_pdf_doc" / cfg / "pdf" / "#{extension}_extension.pdf"].invoke(args)
end
end

desc <<~DESC
Expand Down
Loading

0 comments on commit 98a41f3

Please sign in to comment.