Skip to content

Commit dac5370

Browse files
Only use ConfiguredArchitecture when neccessary in Portfolios and dependent objects. Also cleaned up some code in obj.rb that seems stale (related to supporting either an Architecture or ConfiguredArchitecture).
1 parent ec8e3d4 commit dac5370

File tree

9 files changed

+111
-137
lines changed

9 files changed

+111
-137
lines changed

cert_flow.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ bootstrap_cert_model = bootstrap_cfg_arch.cert_model(cert_model_name = "MC100-32
1717
Loads yaml under gen/resolved_arch/rv32 into @cert_models hash
1818
Calls cert_model.new() -> DatabaseObject.initialize(yaml, yaml_path, arch=base_cfg_arch)
1919
@data = yaml
20-
@cfg_arch = arch # rv32 (nil if Architecture object provided)
21-
@specification = arch # rv32
20+
@arch = arch # rv32
2221
cfg_arch = bootstrap_cert_model.to_cfg_arch # In Portfolio class
2322
Creates hash with mandatory extensions (with version requirement) and fully-constrained params (single_value?)
2423
Uses in_scope_ext_reqs() and all_in_scope_ext_params() in Portfolio

lib/arch_obj_models/certificate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CertModel < Portfolio
2424
# @param data_path [String] Path to yaml file
2525
# @param cfg_arch [ConfiguredArchitecture] Architecture for a specific configuration
2626
def initialize(obj_yaml, yaml_path, arch: nil)
27-
super(obj_yaml, yaml_path, arch: arch)
27+
super # Calls parent class with the same args I got
2828

2929
unless arch.is_a?(ConfiguredArchitecture)
3030
raise ArgumentError, "For #{name} arch is a #{arch.class} but must be a ConfiguredArchitecture"

lib/arch_obj_models/csr.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def format_changes_with_xlen?(cfg_arch)
5656
end
5757

5858
# @param cfg_arch [ConfiguredArchitecture] A configuration
59-
# @return [Array<Idl::FunctionDefAst>] List of functions reachable from this CSR's sw_read or a field's sw_wirte function
59+
# @return [Array<Idl::FunctionDefAst>] List of functions reachable from this CSR's sw_read or a field's sw_write function
6060
def reachable_functions(cfg_arch)
6161
return @reachable_functions unless @reachable_functions.nil?
6262

lib/arch_obj_models/extension.rb

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
# A parameter (AKA option, AKA implementation-defined value) supported by an extension
88
class ExtensionParameter
9-
# @return [ConfiguredArchitecture] The defining configured architecture
10-
attr_reader :cfg_arch
9+
# @return [Architecture] The defining architecture
10+
attr_reader :arch
1111

1212
# @return [String] Parameter name
1313
attr_reader :name
@@ -36,8 +36,11 @@ def schema_type
3636
@schema.to_pretty_s
3737
end
3838

39+
# @param ext [Extension]
40+
# @param name [String]
41+
# @param data [Hash<String, Object]
3942
def initialize(ext, name, data)
40-
@cfg_arch = ext.cfg_arch
43+
@arch = ext.arch
4144
@data = data
4245
@name = name
4346
@desc = data["description"]
@@ -46,7 +49,7 @@ def initialize(ext, name, data)
4649
also_defined_in = []
4750
unless data["also_defined_in"].nil?
4851
if data["also_defined_in"].is_a?(String)
49-
other_ext = @cfg_arch.extension(data["also_defined_in"])
52+
other_ext = @arch.extension(data["also_defined_in"])
5053
raise "Definition error in #{ext.name}.#{name}: #{data['also_defined_in']} is not a known extension" if other_ext.nil?
5154

5255
also_defined_in << other_ext
@@ -56,7 +59,7 @@ def initialize(ext, name, data)
5659
end
5760

5861
data["also_defined_in"].each do |other_ext_name|
59-
other_ext = @cfg_arch.extension(other_ext_name)
62+
other_ext = @arch.extension(other_ext_name)
6063
raise "Definition error in #{ext.name}.#{name}: #{data['also_defined_in']} is not a known extension" if other_ext.nil?
6164

6265
also_defined_in << other_ext
@@ -74,7 +77,7 @@ def defined_in_extension_version?(version)
7477
return true if @data.dig("when", "version").nil?
7578

7679
@exts.any? do |ext|
77-
ExtensionRequirement.new(ext.name, @data["when"]["version"], cfg_arch: ext.cfg_arch).satisfied_by?(version)
80+
ExtensionRequirement.new(ext.name, @data["when"]["version"], arch: ext.arch).satisfied_by?(version)
7881
end
7982
end
8083

@@ -126,9 +129,6 @@ def initialize(param, value)
126129

127130
# Extension definition
128131
class Extension < DatabaseObject
129-
# @return [ConfiguredArchitecture] The architecture defintion
130-
attr_reader :cfg_arch
131-
132132
# @return [String] Long name of the extension
133133
def long_name = @data["long_name"]
134134

@@ -149,7 +149,7 @@ def versions
149149
return @versions unless @versions.nil?
150150

151151
@versions = @data["versions"].map do |v|
152-
ExtensionVersion.new(name, v["version"], cfg_arch)
152+
ExtensionVersion.new(name, v["version"], arch)
153153
end
154154
@versions.sort!
155155
@versions
@@ -195,9 +195,9 @@ def params
195195
# @return [Array<ExtensionVersion>] Array of extensions implied by any version of this extension meeting version_requirement
196196
def implies(version_requirement = nil)
197197
if version_requirement.nil?
198-
return [] unless ExtensionRequirement.new(@new, cfg_arch: @cfg_arch).satisfied_by?(max_version.version)
198+
return [] unless ExtensionRequirement.new(@new, arch: @arch).satisfied_by?(max_version.version)
199199
else
200-
return [] unless ExtensionRequirement.new(@new, version_requirement, cfg_arch: @cfg_arch).satisfied_by?(max_version.version)
200+
return [] unless ExtensionRequirement.new(@new, version_requirement, arch: @arch).satisfied_by?(max_version.version)
201201
end
202202

203203
max_version.implications
@@ -208,15 +208,15 @@ def conflicts
208208
return [] if @data["conflicts"].nil?
209209

210210
if @data["conflicts"].is_a?(String)
211-
[ExtensionRequirement.new(@data["conflicts"], cfg_arch: @cfg_arch)]
211+
[ExtensionRequirement.new(@data["conflicts"], arch: @arch)]
212212
elsif @data["conflicts"].is_a?(Hash)
213-
[ExtensionRequirement.new(@data["conflicts"]["name"], @data["conflicts"]["version"], cfg_arch: @cfg_arch)]
213+
[ExtensionRequirement.new(@data["conflicts"]["name"], @data["conflicts"]["version"], arch: @arch)]
214214
elsif @data["conflicts"].is_a?(Array)
215215
@data["conflicts"].map do |conflict|
216216
if conflict.is_a?(String)
217-
ExtensionRequirement.new(conflict, cfg_arch: @cfg_arch)
217+
ExtensionRequirement.new(conflict, arch: @arch)
218218
elsif conflict.is_a?(Array)
219-
ExtensionRequirement.new(conflict["name"], conflict["version"], cfg_arch: @cfg_arch)
219+
ExtensionRequirement.new(conflict["name"], conflict["version"], arch: @arch)
220220
else
221221
raise "Invalid conflicts data: #{conflict.inspect}"
222222
end
@@ -230,14 +230,14 @@ def conflicts
230230
def instructions
231231
return @instructions unless @instructions.nil?
232232

233-
@instructions = cfg_arch.instructions.select { |i| versions.any? { |v| i.defined_by?(v) }}
233+
@instructions = arch.instructions.select { |i| versions.any? { |v| i.defined_by?(v) }}
234234
end
235235

236236
# @return [Array<Csr>] the list of CSRs implemented by *any version* of this extension (may be empty)
237237
def csrs
238238
return @csrs unless @csrs.nil?
239239

240-
@csrs = cfg_arch.csrs.select { |csr| versions.any? { |v| csr.defined_by?(v) } }
240+
@csrs = arch.csrs.select { |csr| versions.any? { |v| csr.defined_by?(v) } }
241241
end
242242

243243
# return the set of reachable functions from any of this extensions's CSRs or instructions in the given evaluation context
@@ -258,6 +258,8 @@ def reachable_functions(symtab)
258258
funcs += inst.reachable_functions(symtab, 64) if inst.defined_in_base?(64)
259259
end
260260

261+
# The one place in this file that needs a ConfiguredArchitecture object instead of just Architecture.
262+
raise "In #{name}, need to provide ConfiguredArchitecture" if cfg_arch.nil?
261263
csrs.each do |csr|
262264
funcs += csr.reachable_functions(cfg_arch)
263265
end
@@ -282,25 +284,24 @@ class ExtensionVersion
282284

283285
# @param name [#to_s] The extension name
284286
# @param version [String] The version specifier
285-
# @param cfg_arch [ConfiguredArchitecture] The architecture definition
286-
def initialize(name, version_str, cfg_arch, fail_if_version_does_not_exist: false)
287+
# @param arch [Architecture] The architecture definition
288+
def initialize(name, version_str, arch, fail_if_version_does_not_exist: false)
287289
@name = name.to_s
288290
@version_str = version_str
289291
@version_spec = VersionSpec.new(version_str)
290292

291-
raise ArgumentError, "Must supply arch" if cfg_arch.nil?
292-
293-
@cfg_arch = cfg_arch
293+
raise ArgumentError, "Must supply arch" if arch.nil?
294+
@arch = arch
294295

295-
@ext = @cfg_arch.extension(@name)
296-
raise "Extension #{name} not found in configured architecture #{cfg_arch.name}" if @ext.nil?
296+
@ext = @arch.extension(@name)
297+
raise "Extension #{name} not found in architecture" if @ext.nil?
297298

298299
@data = @ext.data["versions"].find { |v| VersionSpec.new(v["version"]) == @version_spec }
299300

300301
if fail_if_version_does_not_exist && @data.nil?
301-
raise ArgumentError, "Version #{version_str} of #{@name} extension in #{cfg_arch.name} is not defined"
302+
raise ArgumentError, "Version #{version_str} of #{@name} extension is not defined"
302303
elsif @data.nil?
303-
warn "Version #{version_str} of #{@name} extension in #{cfg_arch.name} is not defined"
304+
warn "Version #{version_str} of #{@name} extension is not defined"
304305
end
305306
end
306307

@@ -391,14 +392,14 @@ def requirement_condition
391392
when nil
392393
AlwaysTrueSchemaCondition.new
393394
when Hash
394-
SchemaCondition.new(@data["requires"], @cfg_arch)
395+
SchemaCondition.new(@data["requires"], @arch)
395396
else
396-
SchemaCondition.new({ "oneOf" => [@data["requires"]] }, @cfg_arch)
397+
SchemaCondition.new({ "oneOf" => [@data["requires"]] }, @arch)
397398
end
398399
if @data.key?("implies")
399400
rs = [r] + implications.map(&:requirement_condition)
400401
rs = rs.reject(&:empty?)
401-
r = SchemaCondition.all_of(*rs.map(&:to_h), cfg_arch: @cfg_arch) unless rs.empty?
402+
r = SchemaCondition.all_of(*rs.map(&:to_h), arch: @arch) unless rs.empty?
402403
end
403404
r
404405
end
@@ -439,9 +440,9 @@ def implications
439440
return @implications
440441
when Array
441442
if @data["implies"][0].is_a?(Array)
442-
@implications.concat(@data["implies"].map { |e| ExtensionVersion.new(e[0], e[1], @cfg_arch) })
443+
@implications.concat(@data["implies"].map { |e| ExtensionVersion.new(e[0], e[1], @arch) })
443444
else
444-
@implications << ExtensionVersion.new(@data["implies"][0], @data["implies"][1], @cfg_arch)
445+
@implications << ExtensionVersion.new(@data["implies"][0], @data["implies"][1], @arch)
445446
end
446447
end
447448
@implications.sort!
@@ -460,14 +461,14 @@ def transitive_implications
460461
return @transitive_implications
461462
when Array
462463
if @data["implies"][0].is_a?(Array)
463-
impls = @data["implies"].map { |e| ExtensionVersion.new(e[0], e[1], @cfg_arch) }
464+
impls = @data["implies"].map { |e| ExtensionVersion.new(e[0], e[1], @arch) }
464465
@transitive_implications.concat(impls)
465466
impls.each do |i|
466467
transitive_impls = i.implications
467468
@transitive_implications.concat(transitive_impls) unless transitive_impls.empty?
468469
end
469470
else
470-
impl = ExtensionVersion.new(@data["implies"][0], @data["implies"][1], @cfg_arch)
471+
impl = ExtensionVersion.new(@data["implies"][0], @data["implies"][1], @arch)
471472
@transitive_implications << impl
472473
transitive_impls = impl.implications
473474
@transitive_implications.concat(transitive_impls) unless transitive_impls.empty?
@@ -502,9 +503,7 @@ def <=>(other)
502503
def implemented_csrs
503504
return @implemented_csrs unless @implemented_csrs.nil?
504505

505-
raise "implemented_csrs needs an cfg_arch" if @cfg_arch.nil?
506-
507-
@implemented_csrs = @cfg_arch.csrs.select do |csr|
506+
@implemented_csrs = @arch.csrs.select do |csr|
508507
csr.defined_by?(self)
509508
end
510509
end
@@ -513,9 +512,7 @@ def implemented_csrs
513512
def implemented_instructions
514513
return @implemented_instructions unless @implemented_instructions.nil?
515514

516-
raise "implemented_instructions needs an cfg_arch" if @cfg_arch.nil?
517-
518-
@implemented_instructions = @cfg_arch.instructions.select do |inst|
515+
@implemented_instructions = @arch.instructions.select do |inst|
519516
inst.defined_by?(self)
520517
end
521518
end
@@ -694,22 +691,23 @@ def to_s
694691
def extension
695692
return @extension unless @extension.nil?
696693

697-
raise "Cannot get extension; cfg_arch was not initialized" if @cfg_arch.nil?
694+
raise "Cannot get extension; arch was not initialized" if @arch.nil?
698695

699-
@extension = @cfg_arch.extension(@name)
696+
@extension = @arch.extension(@name)
700697
end
701698

702699
# @param name [#to_s] Extension name
703700
# @param requirements [String] Single requirement
704701
# @param requirements [Array<String>] List of requirements, all of which must hold
705-
def initialize(name, *requirements, cfg_arch: nil, note: nil, req_id: nil, presence: nil)
706-
raise ArgumentError, "Arch is required" if cfg_arch.nil?
702+
# @param arch [Architecture]
703+
def initialize(name, *requirements, arch: nil, note: nil, req_id: nil, presence: nil)
704+
raise ArgumentError, "For #{name}, arch not allowed to be nil" if arch.nil?
705+
raise ArgumentError, "For #{name}, Architecture is required" unless arch.is_a?(Architecture)
707706

708707
@name = name.to_s.freeze
709-
@cfg_arch = cfg_arch
710-
@ext = @cfg_arch.extension(@name)
711-
712-
raise ArgumentError, "Could not find extension named '#{@name}' in #{@cfg_arch.name}" if @ext.nil?
708+
@arch = arch
709+
@ext = @arch.extension(@name)
710+
raise ArgumentError, "Could not find extension named '#{@name}'" if @ext.nil?
713711

714712
requirements =
715713
if requirements.empty?
@@ -726,7 +724,7 @@ def initialize(name, *requirements, cfg_arch: nil, note: nil, req_id: nil, prese
726724

727725
# @return [Array<ExtensionVersion>] The list of extension versions that satisfy this extension requirement
728726
def satisfying_versions
729-
ext = @cfg_arch.extension(@name)
727+
ext = @arch.extension(@name)
730728
return [] if ext.nil?
731729

732730
ext.versions.select { |v| satisfied_by?(v) }
@@ -773,7 +771,7 @@ def satisfied_by?(*args)
773771

774772
# @return [Array<Csr>] List of CSRs defined by any extension satisfying this requirement
775773
def csrs
776-
@csrs ||= @cfg_arch.csrs.select do |csr|
774+
@csrs ||= @arch.csrs.select do |csr|
777775
satisfying_versions.any? do |ext_ver|
778776
csr.defined_by?(ext_ver)
779777
end

lib/arch_obj_models/manual.rb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ class Manual < DatabaseObject
88
def versions
99
return @versions unless @versions.nil?
1010

11-
@versions =
12-
if @cfg_arch.nil?
13-
@specification.manual_versions.select { |mv| mv.manual == self }
14-
else
15-
@cfg_arch.manual_versions.select { |mv| mv.manual == self }
16-
end
11+
@versions = @arch.manual_versions.select { |mv| mv.manual == self }
1712
end
1813

1914
def version(name)
@@ -126,12 +121,7 @@ class ManualVersion < DatabaseObject
126121
def manual
127122
return @manual unless @manual.nil?
128123

129-
@manual =
130-
if @cfg_arch.nil?
131-
@specification.ref(@data["manual"]["$ref"])
132-
else
133-
@cfg_arch.ref(@data["manual"]["$ref"])
134-
end
124+
@manual = @arch.ref(@data["manual"]["$ref"])
135125
raise "Error: manual #{@data['manual']['$ref']} is not found" if @manual.nil?
136126

137127
@manual

0 commit comments

Comments
 (0)