Skip to content

Commit 16591d0

Browse files
authored
Merge pull request #416 from riscv-software-src/ext_table
in ext_pdf, display inst defined by as table when the condition is simple
2 parents 2cfeb6e + 0b11bd7 commit 16591d0

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

backends/common_templates/adoc/inst.adoc.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,14 @@ Operation::
8181
8282
Included in::
8383
84+
<%- if inst.defined_by_condition.flat? -%>
85+
|===
86+
| Extension | Version
87+
88+
<%- inst.defined_by_condition.flat_versions.each do |r| -%>
89+
| *<%= r.name %>* | <%= r.requirement_specs_to_s %>
90+
<%- end -%>
91+
|===
92+
<%- else -%>
8493
<%= inst.defined_by_condition.to_asciidoc %>
94+
<%- end -%>

backends/ext_pdf_doc/templates/ext_pdf.adoc.erb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,22 @@ Requires::
182182
--
183183
<%- end -%>
184184

185+
<<<
186+
== Conventions
187+
188+
Version requirements are specified as conditions using the following operators:
189+
190+
[cols="1,2"]
191+
|===
192+
| Operator | Meaning
193+
194+
| `~> VERSION` | Accepts any version that is _compatible_ with `VERSION`. By default, a version A is compatible with a version B if A's version number is greater than or equal to version B. If that default assumption is ever broken, it will be noted in the list of extension versions.
195+
| `= VERSION` | Accepts only version `VERSION`.
196+
| `>= VERSION` | Accepts any version greater than or equal to `VERSION`.
197+
| `\<= VERSION` | Accepts any version less than or equal to `VERSION`.
198+
| `> VERSION` | Accepts any version greater than `VERSION`.
199+
| `< VERSION` | Accepts any version less than `VERSION`.
200+
|===
185201

186202
<<<
187203
== Extension description

lib/arch_obj_models/obj.rb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,66 @@ def is_a_version_requirement(ver)
413413
end
414414
end
415415

416+
# @return [Boolean] True if the condition is a join of N terms over the same operator
417+
#
418+
# A or B or C #=> true
419+
# A and B #=> true
420+
# A or B and C #=> false
421+
def flat?
422+
case @hsh
423+
when String
424+
true
425+
when Hash
426+
@hsh.key?("name") || @hsh[@hsh.keys.first].all? { |child| child.is_a?(String) || (child.is_a?(Hash) && child.key?("name")) }
427+
else
428+
raise "unexpected"
429+
end
430+
end
431+
432+
# @return [:or, :and] The operator for a flat condition
433+
# Only valid if #flat? is true
434+
def flat_op
435+
case @hsh
436+
when String
437+
:or
438+
when Hash
439+
@hsh.key?("name") ? :or : { "allOf" => :and, "anyOf" => :or }[@hsh.keys.first]
440+
else
441+
raise "unexpected"
442+
end
443+
end
444+
445+
# @return [Array<ExtensionRequirement>] The elements of the flat join
446+
# Only valid if #flat? is true
447+
def flat_versions
448+
case @hsh
449+
when String
450+
[ExtensionRequirement.new(@hsh, arch: @arch)]
451+
when Hash
452+
if @hsh.key?("name")
453+
if @hsh.key?("version").nil?
454+
[ExtensionRequirement.new(@hsh["name"], arch: @arch)]
455+
else
456+
[ExtensionRequirement.new(@hsh["name"], @hsh["version"], arch: @arch)]
457+
end
458+
else
459+
@hsh[@hsh.keys.first].map do |r|
460+
if r.is_a?(String)
461+
ExtensionRequirement.new(r, arch: @arch)
462+
else
463+
if r.key?("version").nil?
464+
ExtensionRequirement.new(r["name"], arch: @arch)
465+
else
466+
ExtensionRequirement.new(r["name"], r["version"], arch: @arch)
467+
end
468+
end
469+
end
470+
end
471+
else
472+
raise "unexpected"
473+
end
474+
end
475+
416476
def to_asciidoc(cond = @hsh, indent = 0)
417477
case cond
418478
when String
@@ -616,6 +676,8 @@ def satisfied_by? = true
616676

617677
def empty? = true
618678

679+
def flat? = false
680+
619681
def to_h = {}
620682
def minimize = {}
621683
end

0 commit comments

Comments
 (0)