66
77# A parameter (AKA option, AKA implementation-defined value) supported by an extension
88class 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
128131class 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
0 commit comments