Skip to content

Commit 412b09c

Browse files
Fixed definedBy should be using defined_by due to partial constraint changes (fix for issue 89)
1 parent e5904ea commit 412b09c

File tree

9 files changed

+35
-16
lines changed

9 files changed

+35
-16
lines changed

arch/crd/MC-1.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ MC-1:
6060
MTVAL_WIDTH: {} # Unconstrained
6161
MTVEC_MODES: {} # Unconstrained
6262
PHYS_ADDR_WIDTH: {} # Unconstrained
63+
CONFIG_PTR_ADDRESS:
64+
schema:
65+
const: 0xdeadbeef
66+
note: "This parameter and its associated CSR shouldn't be here. See GitHub issue #53."
6367
PRECISE_SYNCHRONOUS_EXCEPTIONS:
6468
schema:
6569
const: true

arch/crd/MockCRD-1.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ MockCRD-1:
118118
const: 32
119119
CONFIG_PTR_ADDRESS:
120120
schema:
121-
const: 0
121+
const: 0xdeadbeef
122+
note: "This parameter and its associated CSR shouldn't be here. See GitHub issue #53."
122123
- name: Zifencei
123124
presence: optional
124125
note: "Here's a note for Zifencei"

backends/crd_doc/templates/crd.adoc.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ Requirement <%= req.name %> only apply when <%= req.when_pretty %>.
291291
--
292292
<%- end -%>
293293
294-
<%- insts = crd.arch_def.instructions.select { |i| i.definedBy == ext_db.name || i.definedBy.include?(ext_db.name) } -%>
294+
// TODO: GitHub issue 92: Use version specified by each profile.
295+
<%- insts = crd.arch_def.instructions.select { |i| i.defined_by?(ext_db.name,ext_db.min_version) } -%>
295296
<%- unless insts.empty? -%>
296297
==== Instructions
297298

backends/profile_doc/templates/profile_pdf.adoc.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,8 @@ end.join(" | ") -%>
467467

468468
:leveloffset: -3
469469

470-
<%- insts = arch_def.instructions.select { |i| i.definedBy == ext.name || i.definedBy.include?(ext.name) } -%>
470+
// TODO: GitHub issue 92: Use version specified by each profile and add version info to inst table below.
471+
<%- insts = arch_def.instructions.select { |i| i.defined_by?(ext.name,ext.min_version) } -%>
471472
<%- unless insts.empty? -%>
472473
==== Instructions
473474

lib/arch_def.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def prohibited_extensions
313313
if e.is_a?(String)
314314
@prohibited_extensions << ExtensionRequirement.new(e, nil)
315315
else
316-
@prohibited_extensions << ExtensionRequirement.new(e["name"], e["requirements"])
316+
@prohibited_extensions << ExtensionRequirement.new(e["name"], e["requirements"], presence: "prohibited")
317317
end
318318
end
319319
end

lib/arch_obj_models/extension.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def conflicts
203203
def instructions
204204
return @instructions unless @instructions.nil?
205205

206-
@instructions = arch_def.instructions.select { |i| i.definedBy == name || (i.definedBy.is_a?(Array) && i.definedBy.include?(name)) }
206+
@instructions = arch_def.instructions.select { |i| @data["versions"].any? { |version| i.defined_by?(name, version["version"]) }}
207207
end
208208

209209
# @return [Array<Csr>] the list of CSRs implemented by this extension (may be empty)

lib/arch_obj_models/instruction.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ def ==(other)
99
if other.is_a?(Instruction)
1010
name == other.name
1111
else
12-
raise ArgumentError, "Instruction is comparable to a #{other.class.name}"
12+
raise ArgumentError, "Instruction is not comparable to a #{other.class.name}"
13+
end
14+
end
15+
16+
alias eql? ==
17+
18+
def <=>(other)
19+
if other.is_a?(Instruction)
20+
name <=> other.name
21+
else
22+
raise ArgumentError, "Instruction is not comparable to a #{other.class.name}"
1323
end
1424
end
1525

lib/arch_obj_models/obj.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ def defined_by?(*args)
106106
end
107107
elsif args.size == 2
108108
raise ArgumentError, "First parameter must be an extension name" unless args[0].respond_to?(:to_s)
109-
raise ArgumentError, "Second parameter must be an extension version" unless args[0].respond_to?(:to_s)
109+
version = args[1].is_a?(Gem::Version) ? args[1] : Gem::Version.new(args[1])
110110

111111
defined_by.satisfied_by? do |r|
112-
r.name == args[0] && r.version_requirement.satisfied_by?(args[1].to_s)
112+
r.name == args[0] && r.version_requirement.satisfied_by?(version)
113113
end
114+
else
115+
raise ArgumentError, "Unsupported number of arguments of " + args.size
114116
end
115117
end
116118

lib/arch_obj_models/profile.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ def initialize(data, arch_def)
1414

1515
def family = arch_def.profile_family(@data["family"])
1616

17-
# @return [Profile] Profile that this profile inherits from (the "hier")
17+
# @return [Profile] Profile that this profile inherits from
1818
# @return [nil] if this profile has no parent
1919
def inherits_from = arch_def.profile(@data["inherits"])
2020

2121
# @return ["M", "S", "U", "VS", "VU"] Privilege mode for the profile
2222
def mode
2323
if @data["mode"].nil?
24-
raise "No mode specified and no inheritance for profile '#{name}'" if inherits_from.empty?
25-
inherits_from.last.mode
24+
raise "No mode specified and no inheritance for profile '#{name}'" if inherits_from.nil?
25+
inherits_from.mode
2626
else
2727
@data["mode"]
2828
end
@@ -31,9 +31,9 @@ def mode
3131
# @return [32, 64] The base XLEN for the profile
3232
def base
3333
if @data["base"].nil?
34-
raise "No base specified and no inheritance for profile '#{name}'" if inherits_from.empty?
34+
raise "No base specified and no inheritance for profile '#{name}'" if inherits_from.nil?
3535

36-
inherits_from.last.base
36+
inherits_from.base
3737
else
3838
@data["base"]
3939
end
@@ -98,9 +98,9 @@ def mandatory_extension_requirements
9898
@data["extensions"]&.any? { |opt| opt["name"] == ext_req.name }
9999
}
100100

101-
@data["extensions"]&.each do |ext_ver|
102-
if ext_ver["presence"] == "mandatory"
103-
@mandatory_ext_reqs << ExtensionRequirement.new(ext_ver["name"], ext_ver["version"], presence: "mandatory")
101+
@data["extensions"]&.each do |ext_req|
102+
if ext_req["presence"] == "mandatory"
103+
@mandatory_ext_reqs << ExtensionRequirement.new(ext_req["name"], ext_req["version"], presence: "mandatory")
104104
end
105105
end
106106
end

0 commit comments

Comments
 (0)