Class: Udb::ConfiguredArchitecture

Inherits:
Architecture show all
Extended by:
T::Sig
Defined in:
lib/udb/cfg_arch.rb,
lib/udb/condition.rb

Defined Under Namespace

Classes: MemoizedState, ValidationResult

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config)

Initialize a new configured architecture definition

Parameters:

  • arch_path (Pathnam)

    Path to the resolved architecture directory corresponding to the configuration

  • name (String)

    The name associated with this ConfiguredArchitecture

  • config (AbstractConfig)

    The configuration object



548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File 'lib/udb/cfg_arch.rb', line 548

def initialize(name, config)
  Udb.logger.info "Constructing ConfiguredArchiture for #{name}"
  super(config.info.resolved_spec_path)

  @name = name.to_s.freeze
  @name_sym = @name.to_sym.freeze

  @memo = MemoizedState.new(
    multi_xlen_in_mode: {},
    extension_requirements_hash: {},
    extension_versions_hash: {}
  )

  @config = config
  @config_type = T.let(@config.type, ConfigType)
  @mxlen = config.mxlen
  @mxlen.freeze

  @idl_compiler = Idl::Compiler.new
end

Instance Attribute Details

#configAbstractConfig (readonly)

Returns:



51
52
53
# File 'lib/udb/cfg_arch.rb', line 51

def config
  @config
end

#idl_compilerIdl::Compiler (readonly)

Returns The IDL compiler.

Returns:

  • (Idl::Compiler)

    The IDL compiler



41
42
43
# File 'lib/udb/cfg_arch.rb', line 41

def idl_compiler
  @idl_compiler
end

#nameString (readonly)

Returns Name of this definition. Special names are:

  • ‘_’ - The generic architecture, with no configuration settings.

  • ‘rv32’ - A generic RV32 architecture, with only one parameter set (XLEN == 32)

  • ‘rv64’ - A generic RV64 architecture, with only one parameter set (XLEN == 64).

Returns:

  • (String)

    Name of this definition. Special names are:

    • ‘_’ - The generic architecture, with no configuration settings.

    • ‘rv32’ - A generic RV32 architecture, with only one parameter set (XLEN == 32)

    • ‘rv64’ - A generic RV64 architecture, with only one parameter set (XLEN == 64)



48
49
50
# File 'lib/udb/cfg_arch.rb', line 48

def name
  @name
end

Class Method Details

.generate_obj_methods(fn_name, arch_dir, obj_class)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

metaprogramming function to create accessor methods for top-level database objects

This is defined in ConfiguredArchitecture, rather than Architecture because the object models all expect to work with a ConfiguredArchitecture

For example, created the following functions:

extensions        # array of all extensions
extension_hash    # hash of all extensions, indexed by name
extension(name)   # getter for extension 'name'
instructions      # array of all extensions
instruction_hash  # hash of all extensions, indexed by name
instruction(name) # getter for extension 'name'
...

Parameters:



600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
# File 'lib/udb/cfg_arch.rb', line 600

def self.generate_obj_methods(fn_name, arch_dir, obj_class)

  plural_fn = ActiveSupport::Inflector.pluralize(fn_name)

  define_method(plural_fn) do
    return @objects[arch_dir] unless @objects[arch_dir].nil?

    @objects[arch_dir] = Concurrent::Array.new
    @object_hashes[arch_dir] = Concurrent::Hash.new
    Dir.glob(@arch_dir / arch_dir / "**" / "*.yaml") do |obj_path|
      f = File.open(obj_path)
      f.flock(File::LOCK_EX)
      obj_yaml = YAML.load(f.read, filename: obj_path, permitted_classes: [Date])
      f.flock(File::LOCK_UN)
      @objects[arch_dir] << obj_class.new(obj_yaml, Pathname.new(obj_path).realpath, T.cast(self, ConfiguredArchitecture))
      @object_hashes[arch_dir][@objects[arch_dir].last.name] = @objects[arch_dir].last
    end
    @objects[arch_dir]
  end

  define_method("#{fn_name}_hash") do
    return @object_hashes[arch_dir] unless @object_hashes[arch_dir].nil?

    send(plural_fn) # create the hash

    @object_hashes[arch_dir]
  end

  define_method(fn_name) do |name|
    return @object_hashes[arch_dir][name] unless @object_hashes[arch_dir].nil?

    send(plural_fn) # create the hash

    @object_hashes[arch_dir][name]
  end
end

Instance Method Details

#config_typeConfigType

Returns:



239
# File 'lib/udb/cfg_arch.rb', line 239

def config_type = @config_type

Given an adoc string, find names of CSR/Instruction/Extension enclosed in ‘monospace` and replace them with links to the relevant object page. See backend_helpers.rb for a definition of the proprietary link format.

Parameters:

  • adoc (String)

    Asciidoc source

Returns:

  • (String)

    Asciidoc source, with link placeholders



1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
# File 'lib/udb/cfg_arch.rb', line 1316

def convert_monospace_to_links(adoc)
  h = Class.new do include Udb::Helpers::TemplateHelpers end.new
  adoc.gsub(/`([\w.]+)`/) do |match|
    name = Regexp.last_match(1)
    csr_name, field_name = T.must(name).split(".")
    csr = not_prohibited_csrs.find { |c| c.name == csr_name }
    if !field_name.nil? && !csr.nil? && csr.field?(field_name)
      h.link_to_udb_doc_csr_field(csr_name, field_name)
    elsif !csr.nil?
      h.link_to_udb_doc_csr(csr_name)
    elsif not_prohibited_instructions.any? { |inst| inst.name == name }
      h.link_to_udb_doc_inst(name)
    elsif not_prohibited_extensions.any? { |ext| ext.name == name }
      h.link_to_udb_doc_ext(name)
    else
      match
    end
  end
end

#eql?(other) ⇒ Boolean

Parameters:

  • other (BasicObject)

Returns:

  • (Boolean)


191
192
193
194
195
# File 'lib/udb/cfg_arch.rb', line 191

def eql?(other)
  return false unless other.__send__(:is_a?, ConfiguredArchitecture)

  @name.eql?(other.__send__(:name))
end

#expand_implemented_extension_list(ext_vers) ⇒ Array<ExtensionVersion>

given the current (invalid) config, try to come up with a list of extension versions that, if added, might make the config valid

For example, if C, F, and D are implemented but not Zca, Zcf, Zcd, return [Zca, Zcf, Zcd]

Parameters:

Returns:



830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
# File 'lib/udb/cfg_arch.rb', line 830

def expand_implemented_extension_list(ext_vers)

  # build up a condition requiring all ext_vers, have it expand, and then minimize it
  # what's left is the full list
  condition =
    Condition.conjunction(ext_vers.map(&:to_condition), self)

  res = condition.implied_extension_requirements
  (ext_vers +
  res.map do |cond_ext_req|
    if cond_ext_req.cond.empty?
      cond_ext_req.ext_req.satisfying_versions.fetch(0)
    else
      nil
    end
  end.compact).uniq
end

#explicitly_implemented_extension_versionsObject

Deprecated.

in favor of implemented_extension_versions



774
# File 'lib/udb/cfg_arch.rb', line 774

def explicitly_implemented_extension_versions = implemented_extension_versions

#ext?(ext_name) ⇒ Boolean #ext?(ext_name, ext_version_requirements) ⇒ Boolean

sig { params(ext_name: T.any(String, Symbol), ext_version_requirements: T::Array).returns(T::Boolean) }

Overloads:

  • #ext?(ext_name) ⇒ Boolean

    Returns True if the extension ‘name` is implemented.

    Parameters:

    • ext_name (#to_s)

      Extension name (case sensitive)

    Returns:

    • (Boolean)

      True if the extension ‘name` is implemented

  • #ext?(ext_name, ext_version_requirements) ⇒ Boolean

    Returns True if the extension ‘name` meeting `ext_version_requirements` is implemented.

    Examples:

    Checking extension presence with a version requirement

    ConfigurationArchitecture.ext?(:S, ">= 1.12")

    Checking extension presence with multiple version requirements

    ConfigurationArchitecture.ext?(:S, ">= 1.12", "< 1.15")

    Checking extension precsence with a precise version requirement

    ConfigurationArchitecture.ext?(:S, 1.12)

    Parameters:

    • ext_name (#to_s)

      Extension name (case sensitive)

    • ext_version_requirements (Number, String, Array)

      Extension version requirements

    Returns:

    • (Boolean)

      True if the extension ‘name` meeting `ext_version_requirements` is implemented



1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
# File 'lib/udb/cfg_arch.rb', line 1014

def ext?(ext_name, ext_version_requirements = [])
  @ext_cache ||= {}
  cached_result = @ext_cache[[ext_name, ext_version_requirements]]
  return cached_result unless cached_result.nil?

  result =
    if @config.fully_configured?
      implemented_extension_versions.any? do |e|
        if ext_version_requirements.empty?
          e.name == ext_name.to_s
        else
          requirement = extension_requirement(ext_name.to_s, ext_version_requirements)
          requirement.satisfied_by?(e)
        end
      end
    elsif @config.partially_configured?
      mandatory_extension_reqs.any? do |e|
        if ext_version_requirements.empty?
          e.name == ext_name.to_s
        else
          requirement = extension_requirement(ext_name.to_s, ext_version_requirements)
          e.satisfying_versions.all? do |ext_ver|
            requirement.satisfied_by?(ext_ver)
          end
        end
      end
    else
      raise "unexpected type" unless unconfigured?

      false
    end
  @ext_cache[[ext_name, ext_version_requirements]] = result
end

#extension_requirement(name, requirements) ⇒ ExtensionRequirement

Parameters:

Returns:



780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
# File 'lib/udb/cfg_arch.rb', line 780

def extension_requirement(name, requirements)
  requirement_specs =
    if requirements.is_a?(Array)
      if requirements.fetch(0).is_a?(RequirementSpec)
        requirements
      else
        requirements.map { |r| RequirementSpec.new(r) }
      end
    else
      if requirements.is_a?(RequirementSpec)
        requirements
      else
        RequirementSpec.new(requirements)
      end
    end
  key =
    if requirement_specs.is_a?(Array)
      [name, *requirement_specs].hash
    else
      [name, requirement_specs].hash
    end

  cached_ext_req = @memo.extension_requirements_hash[key]
  if cached_ext_req.nil?
    ext_req = ExtensionRequirement.send(:new, name, requirement_specs, arch: self)
    @memo.extension_requirements_hash[key] = ext_req
  else
    cached_ext_req
  end
end

#extension_version(name, version) ⇒ ExtensionVersion

Parameters:

Returns:



812
813
814
815
816
817
818
819
820
821
822
823
# File 'lib/udb/cfg_arch.rb', line 812

def extension_version(name, version)
  version_spec = version.is_a?(VersionSpec) ? version : VersionSpec.new(version)
  key = [name, version_spec].hash

  cached_ext_ver = @memo.extension_versions_hash[key]
  if cached_ext_ver.nil?
    ext_req = ExtensionVersion.send(:new, name, version_spec, self, fail_if_version_does_not_exist: true)
    @memo.extension_versions_hash[key] = ext_req
  else
    cached_ext_ver
  end
end

#fetchIdl::FetchAst

Returns Fetch block.

Returns:

  • (Idl::FetchAst)

    Fetch block



1080
1081
1082
# File 'lib/udb/cfg_arch.rb', line 1080

def fetch
  @fetch ||= global_ast.fetch
end

#fully_configured?Boolean

Returns:

  • (Boolean)


54
# File 'lib/udb/cfg_arch.rb', line 54

def fully_configured? = @config.fully_configured?

#function(name) ⇒ Idl::FunctionDefAst?

Parameters:

  • name (String)

Returns:

  • (Idl::FunctionDefAst, nil)


1074
1075
1076
# File 'lib/udb/cfg_arch.rb', line 1074

def function(name)
  function_hash[name]
end

#function_hashHash{String => Idl::FunctionDefAst}

Returns:

  • (Hash{String => Idl::FunctionDefAst})


1069
1070
1071
# File 'lib/udb/cfg_arch.rb', line 1069

def function_hash
  @function_hash ||= functions.map { |f| [f.name, f] }.to_h
end

#functionsArray<Idl::FunctionDefAst>

Returns List of all functions defined by the architecture.

Returns:

  • (Array<Idl::FunctionDefAst>)

    List of all functions defined by the architecture



1064
1065
1066
# File 'lib/udb/cfg_arch.rb', line 1064

def functions
  @functions ||= global_ast.functions
end

#global_astIdl::IsaAst

Returns:

  • (Idl::IsaAst)


214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/udb/cfg_arch.rb', line 214

def global_ast
  @global_ast ||=
    begin
      # now add globals to the phase1 symtab
      overlay_path = @config.info.overlay_path
      custom_globals_path = overlay_path.nil? ? Pathname.new("/does/not/exist") : overlay_path / "isa" / "globals.isa"
      idl_path = File.exist?(custom_globals_path) ? custom_globals_path : @config.info.spec_path / "isa" / "globals.isa"
      Udb.logger.info "Compiling global IDL"
      pb =
        Udb.create_progressbar(
          "Compiling IDL for #{name} [:bar]",
          clear: true,
          frequency: 2
        )
      @idl_compiler.pb = pb
      ast = @idl_compiler.compile_file(
        idl_path
      )
      pb.finish
      @idl_compiler.unset_pb
      ast
    end
end

#globalsArray<Idl::GlobalAst, Idl::GlobalWithInitializationAst>

Returns List of globals.

Returns:

  • (Array<Idl::GlobalAst, Idl::GlobalWithInitializationAst>)

    List of globals



1086
1087
1088
1089
1090
# File 'lib/udb/cfg_arch.rb', line 1086

def globals
  return @globals unless @globals.nil?

  @globals = global_ast.globals
end

#hashInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

hash for Hash lookup

Returns:

  • (Integer)


188
# File 'lib/udb/cfg_arch.rb', line 188

def hash = @name_sym.hash

#implemented_csrsArray<Csr>

Returns List of all implemented CSRs.

Returns:

  • (Array<Csr>)

    List of all implemented CSRs



1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
# File 'lib/udb/cfg_arch.rb', line 1094

def implemented_csrs
  @implemented_csrs ||=
    begin
      unless fully_configured?
        raise ArgumentError, "implemented_csrs is only defined for fully configured systems"
      end

      csrs.select do |csr|
        csr.defined_by_condition.satisfied_by_cfg_arch?(self) == SatisfiedResult::Yes
      end
    end
end

#implemented_exception_codesArray<ExceptionCode>

Returns All exception codes known to be implemented.

Returns:

  • (Array<ExceptionCode>)

    All exception codes known to be implemented



1050
1051
1052
1053
# File 'lib/udb/cfg_arch.rb', line 1050

def implemented_exception_codes
  @implemented_exception_codes ||=
    exception_codes.select { |code| code.defined_by_condition.satisfied_by_cfg_arch?(self) }
end

#implemented_extension_version(ext_name) ⇒ ExtensionVersion?

Parameters:

  • ext_name (String)

Returns:



850
851
852
853
854
855
# File 'lib/udb/cfg_arch.rb', line 850

def implemented_extension_version(ext_name)
  @memo.implemented_extension_version_hash ||=
    implemented_extension_versions.to_h { |ext_ver| [ext_ver.name, ext_ver] }

  @memo.implemented_extension_version_hash[ext_name]
end

#implemented_extension_versionsArray<ExtensionVersion>

Returns List of extension versions explicitly marked as implemented in the config.

Returns:

  • (Array<ExtensionVersion>)

    List of extension versions explicitly marked as implemented in the config.



760
761
762
763
764
765
766
767
768
769
770
771
# File 'lib/udb/cfg_arch.rb', line 760

def implemented_extension_versions
  @memo.implemented_extension_versions ||=
    begin
      unless fully_configured?
        raise ArgumentError, "implemented_extension_versions only valid for fully configured systems"
      end

      T.cast(@config, FullConfig).implemented_extensions.map do |e|
        extension_version(e.fetch("name"), e.fetch("version"))
      end
    end
end

#implemented_functionsArray<Idl::FunctionDefAst>

Returns List of all reachable IDL functions for the config.

Returns:

  • (Array<Idl::FunctionDefAst>)

    List of all reachable IDL functions for the config



1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
# File 'lib/udb/cfg_arch.rb', line 1202

def implemented_functions
  return @implemented_functions unless @implemented_functions.nil?

  @implemented_functions = []

  Udb.logger.info "  Finding all reachable functions from instruction operations"

  implemented_instructions.each do |inst|
    @implemented_functions <<
      if inst.base.nil?
        if multi_xlen?
          (inst.reachable_functions(32) +
           inst.reachable_functions(64))
        else
          inst.reachable_functions(possible_xlens.fetch(0))
        end
      else
        inst.reachable_functions(T.must(inst.base))
      end
  end
  @implemented_functions = @implemented_functions.flatten
  @implemented_functions.uniq!(&:name)

  Udb.logger.info "  Finding all reachable functions from CSR operations"

  implemented_csrs.each do |csr|
    csr_funcs = csr.reachable_functions
    csr_funcs.each do |f|
      @implemented_functions << f unless @implemented_functions.any? { |i| i.name == f.name }
    end
  end

  # now add everything from fetch
  st = symtab.global_clone
  st.push(global_ast.fetch.body)
  fetch_fns = global_ast.fetch.body.reachable_functions(st)
  fetch_fns.each do |f|
    @implemented_functions << f unless @implemented_functions.any? { |i| i.name == f.name }
  end
  st.release

  @implemented_functions
end

#implemented_instructionsArray<Instruction>

Returns List of all implemented instructions, sorted by name.

Returns:

  • (Array<Instruction>)

    List of all implemented instructions, sorted by name



1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
# File 'lib/udb/cfg_arch.rb', line 1133

def implemented_instructions
  unless fully_configured?
    raise ArgumentError, "implemented_instructions is only defined for fully configured systems"
  end

  @implemented_instructions ||=
    instructions.select do |inst|
      inst.defined_by_condition.satisfied_by_cfg_arch?(self) == SatisfiedResult::Yes
    end
end

#implemented_interrupt_codesArray<InterruptCode>

Returns All interrupt codes known to be implemented.

Returns:

  • (Array<InterruptCode>)

    All interrupt codes known to be implemented



1057
1058
1059
1060
# File 'lib/udb/cfg_arch.rb', line 1057

def implemented_interrupt_codes
  @implemented_interupt_codes ||=
    implemented_exception_codes.select { |code| code.defined_by_condition.satisfied_by_cfg_arch?(self) }
end

#implemented_non_isa_specsArray<T.untyped>

Returns List of all implemented non-ISA specs, filtered by configuration.

Returns:

  • (Array<T.untyped>)

    List of all implemented non-ISA specs, filtered by configuration



1457
1458
1459
1460
1461
1462
1463
1464
1465
# File 'lib/udb/cfg_arch.rb', line 1457

def implemented_non_isa_specs
  return @implemented_non_isa_specs if defined?(@implemented_non_isa_specs)

  @implemented_non_isa_specs = possible_non_isa_specs.select do |spec|
    spec.exists_in_cfg?(self)
  end

  @implemented_non_isa_specs
end

#inspectObject



569
570
571
# File 'lib/udb/cfg_arch.rb', line 569

def inspect
  "CfgArch##{name}"
end

#largest_encodingInteger

Returns The largest instruction encoding in the config.

Returns:

  • (Integer)

    The largest instruction encoding in the config



1196
1197
1198
# File 'lib/udb/cfg_arch.rb', line 1196

def largest_encoding
  @largest_encoding ||= possible_instructions.map(&:max_encoding_width).max
end

#mandatory_extension_reqsArray<ExtensionRequirement>

Returns List of all mandatory extension requirements (not transitive).

Returns:



859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
# File 'lib/udb/cfg_arch.rb', line 859

def mandatory_extension_reqs
  @mandatory_extension_reqs ||=
    begin
      raise "Only partial configs have mandatory extension requirements" unless @config.is_a?(PartialConfig)

      @config.mandatory_extensions.map do |e|
        ename = T.cast(e["name"], String)

        if e["version"].nil?
          extension_requirement(ename, ">= 0")
        else
          extension_requirement(ename, e.fetch("version"))
        end
      end
    end
end

#multi_xlen?Boolean

Returns whether or not it may be possible to switch XLEN given this definition.

There are three cases when this will return true:

1. A mode (e.g., U) is known to be implemented, and the CSR bit that controls XLEN in that mode is known to be writable.
2. A mode is known to be implemented, but the writability of the CSR bit that controls XLEN in that mode is not known.
3. It is not known if the mode is implemented.

Returns:

  • (Boolean)

    true if this configuration might execute in multiple xlen environments (e.g., that in some mode the effective xlen can be either 32 or 64, depending on CSR values)



81
82
83
84
85
86
87
88
# File 'lib/udb/cfg_arch.rb', line 81

def multi_xlen?
  @memo.multi_xlen ||=
    begin
      return true if @mxlen.nil?

      ["S", "U", "VS", "VU"].any? { |mode| multi_xlen_in_mode?(mode) }
    end
end

#multi_xlen_in_mode?(mode) ⇒ Boolean

Returns whether or not it may be possible to switch XLEN in mode given this definition.

There are three cases when this will return true:

1. +mode+ (e.g., U) is known to be implemented, and the CSR bit that controls XLEN in +mode+ is known to be writable.
2. +mode+ is known to be implemented, but the writability of the CSR bit that controls XLEN in +mode+ is not known.
3. It is not known if +mode+ is implemented.

Will return false if mode is not possible (e.g., because U is a prohibited extension)

Parameters:

  • mode (String)

    mode to check. One of “M”, “S”, “U”, “VS”, “VU”

Returns:

  • (Boolean)

    true if this configuration might execute in multiple xlen environments in mode (e.g., that in some mode the effective xlen can be either 32 or 64, depending on CSR values)



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/udb/cfg_arch.rb', line 103

def multi_xlen_in_mode?(mode)
  @memo.multi_xlen_in_mode[mode] ||=
    begin
      return false if mxlen == 32

      case mode
      when "M", "D"
        mxlen.nil?
      when "S"
        return true if unconfigured?

        if fully_configured?
          ext?(:S) && (param_values["SXLEN"].size > 1)
        elsif partially_configured?
          return false if prohibited_ext?(:S)

          return true unless ext?(:S) # if S is not known to be implemented, we can't say anything about it

          return true unless param_values.key?("SXLEN")

          param_values["SXLEN"].size > 1
        else
          raise "Unexpected configuration state"
        end
      when "U"
        return false if prohibited_ext?(:U)

        return true if unconfigured?

        if fully_configured?
          ext?(:U) && (param_values["UXLEN"].size > 1)
        elsif partially_configured?
          return true unless ext?(:U) # if U is not known to be implemented, we can't say anything about it

          return true unless param_values.key?("UXLEN")

          param_values["UXLEN"].size > 1
        else
          raise "Unexpected configuration state"
        end
      when "VS"
        return false if prohibited_ext?(:H)

        return true if unconfigured?

        if fully_configured?
          ext?(:H) && (param_values["VSXLEN"].size > 1)
        elsif partially_configured?
          return true unless ext?(:H) # if H is not known to be implemented, we can't say anything about it

          return true unless param_values.key?("VSXLEN")

          param_values["VSXLEN"].size > 1
        else
          raise "Unexpected configuration state"
        end
      when "VU"
        return false if prohibited_ext?(:H)

        return true if unconfigured?

        if fully_configured?
          ext?(:H) && (param_values["VUXLEN"].size > 1)
        elsif partially_configured?
          return true unless ext?(:H) # if H is not known to be implemented, we can't say anything about it

          return true unless param_values.key?("VUXLEN")

          param_values["VUXLEN"].size > 1
        else
          raise "Unexpected configuration state"
        end
      else
        raise ArgumentError, "Bad mode: #{mode}"
      end
    end
end

#mxlenInteger?

MXLEN parameter value, or nil if it is not known

Returns:

  • (Integer, nil)


64
# File 'lib/udb/cfg_arch.rb', line 64

def mxlen = @config.mxlen

#optional_extension_versionsArray<ExtensionRequirement>

list of all the extension versions that optional, i.e: lis of all the extension versions would not fufill a mandatory requirement and are not prhohibited

Returns:



879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
# File 'lib/udb/cfg_arch.rb', line 879

def optional_extension_versions
  @optional_extension_versions ||=
    begin
      if fully_configured?
        []
      elsif partially_configured?
        # optional is all extensions - mandatory - prohibited
        extension_versions.reject do |ext_ver|
          mandatory_extension_reqs.any? { |ext_req| ext_req.satisfied_by?(ext_ver) } ||
            prohibited_extension_versions.any? { |prohibited_ext_ver| prohibited_ext_ver == ext_ver }
        end
      else
        # unconfig; all extension versions are optional
        extension_versions
      end
    end
end

#out_of_scope_paramsArray<Parameter>

Returns list of parameters that out of scope for the config

Returns:



744
745
746
747
748
749
750
751
752
753
754
755
756
# File 'lib/udb/cfg_arch.rb', line 744

def out_of_scope_params
  @memo.out_of_scope_params ||=
    begin
      out_of_scope_params = []
      params.each do |param|
        next if params_with_value.any? { |p| p.name == param.name }
        next if params_without_value.any? { |p| p.name == param.name }

        out_of_scope_params << param
      end
      out_of_scope_params
    end
end

#param_valuesHash{String => T.untyped}

known parameter values as a hash of param_name => param_value

Returns:

  • (Hash{String => T.untyped})


68
# File 'lib/udb/cfg_arch.rb', line 68

def param_values = @config.param_values

#params_with_valueArray<ParameterWithValue>

Returns List of all parameters with one known value in the config.

Returns:

  • (Array<ParameterWithValue>)

    List of all parameters with one known value in the config



719
720
721
722
723
724
725
726
727
728
729
730
# File 'lib/udb/cfg_arch.rb', line 719

def params_with_value
  @memo.params_with_value ||=
    @config.param_values.map do |param_name, param_value|
      p = param(param_name)
      if p.nil?
        Udb.logger.warn "#{param_name} is not a parameter"
        nil
      else
        ParameterWithValue.new(p, param_value)
      end
    end.compact
end

#params_without_valueArray<Parameter>

List of all available parameters without one known value in the config

Returns:



734
735
736
737
738
739
740
# File 'lib/udb/cfg_arch.rb', line 734

def params_without_value
  @memo.params_without_value ||=
    params.select do |p|
      !@config.param_values.key?(p.name) \
        && p.defined_by_condition.could_be_satisfied_by_cfg_arch?(self)
    end
end

#partially_configured?Boolean

Returns:

  • (Boolean)


57
# File 'lib/udb/cfg_arch.rb', line 57

def partially_configured? = @config.partially_configured?

#possible_csrs(show_progress: false) ⇒ Array<Csr> Also known as: not_prohibited_csrs

Returns List of all CSRs that it is possible to implement.

Parameters:

  • show_progress (Boolean) (defaults to: false)

Returns:

  • (Array<Csr>)

    List of all CSRs that it is possible to implement



1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
# File 'lib/udb/cfg_arch.rb', line 1112

def possible_csrs(show_progress: false)
  @not_prohibited_csrs ||=
    if @config.fully_configured?
      implemented_csrs
    elsif @config.partially_configured?
      bar =
        if show_progress
          TTY::ProgressBar.new("determining possible CSRs [:bar]", total: csrs.size, output: $stdout)
        end
      csrs.select do |csr|
        bar.advance if show_progress
        csr.defined_by_condition.satisfied_by_cfg_arch?(self) != SatisfiedResult::No
      end
    else
      csrs
    end
end

#possible_extension_versionsObject

the complete set of extension versions that could be implemented in this config



924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
# File 'lib/udb/cfg_arch.rb', line 924

def possible_extension_versions
  @possible_extension_versions ||=
    begin
      if @config.partially_configured?
        # collect all the explictly prohibited extensions
        prohibited_ext_reqs =
          T.cast(@config, PartialConfig).prohibited_extensions.map do |ext_req_yaml|
            ExtensionRequirement.create_from_yaml(ext_req_yaml, self)
          end
        prohibition_condition =
          Condition.conjunction(prohibited_ext_reqs.map(&:to_condition), self)

        # collect all mandatory
        mandatory_ext_reqs =
          T.cast(@config, PartialConfig).mandatory_extensions.map do |ext_req_yaml|
            ExtensionRequirement.create_from_yaml(ext_req_yaml, self)
          end
        mandatory_condition =
          Condition.conjunction(mandatory_ext_reqs.map(&:to_condition), self)

        if T.cast(@config, PartialConfig).additional_extensions_allowed?
          # non-mandatory extensions are OK.
          extensions.map(&:versions).flatten.select do |ext_ver|
            # select all versions that can be satisfied simultaneous with
            # the mandatory and !prohibition conditions
            condition = ext_ver.to_condition & mandatory_condition & -prohibition_condition

            # can't just call condition.could_be_satisfied_by_cfg_arch? here because
            # that implementation calls possible_extension_versions (this function),
            # and we'll get stuck in an infinite loop
            #
            # so, instead, we partially evaluate whatever parameters are known and then
            # see if the formula is satisfiable
            condition.partially_evaluate_for_params(self, expand: true).satisfiable?
          end
        else
          # non-mandatory extensions are NOT allowed
          # we want to return the list of extension versions implied by mandatory,
          # minus any that are explictly prohibited
          mandatory_extension_reqs.map(&:satisfying_versions).flatten.select do |ext_ver|
            condition = -prohibition_condition & ext_ver.to_condition

            # see comment above for why we don't call could_be_satisfied_by_cfg_arch?
            condition.partially_evaluate_for_params(self, expand: true).satisfiable?
          end
        end
      elsif @config.fully_configured?
        # full config: only the implemented versions are possible
        implemented_extension_versions
      else
        # unconfig; everything is possible
        extensions.map(&:versions).flatten
      end
    end
end

#possible_extensionsArray<Extension> Also known as: not_prohibited_extensions

Returns List of extensions that are possibly supported.

Returns:

  • (Array<Extension>)

    List of extensions that are possibly supported



899
900
901
902
903
904
905
906
907
908
909
910
911
# File 'lib/udb/cfg_arch.rb', line 899

def possible_extensions
  return @not_prohibited_extensions if defined?(@not_prohibited_extensions)

  @not_prohibited_extensions ||=
    if @config.fully_configured?
      implemented_extension_versions.map { |ext_ver| ext_ver.ext }.uniq
    elsif @config.partially_configured?
      # reject any extension in which all of the extension versions are prohibited
      extensions.reject { |ext| (ext.versions - prohibited_extension_versions).empty? }
    else
      extensions
    end
end

#possible_instructions(show_progress: false) ⇒ Array<Instruction> Also known as: not_prohibited_instructions

Returns List of all instructions that are not prohibited by the config, sorted by name.

Parameters:

  • show_progress (Boolean) (defaults to: false)

Returns:

  • (Array<Instruction>)

    List of all instructions that are not prohibited by the config, sorted by name



1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
# File 'lib/udb/cfg_arch.rb', line 1168

def possible_instructions(show_progress: false)
  return @not_prohibited_instructions if defined?(@not_prohibited_instructions)

  @not_prohibited_instructions ||=
    if @config.fully_configured?
      implemented_instructions
    elsif @config.partially_configured?
      bar =
        if show_progress
          TTY::ProgressBar.new("determining possible instructions [:bar]", total: instructions.size, output: $stdout)
        end
      instructions.select do |inst|
        bar.advance if show_progress

        possible_xlens.any? { |xlen| inst.defined_in_base?(xlen) } && \
          inst.defined_by_condition.satisfied_by_cfg_arch?(self) != SatisfiedResult::No
      end
    else
      instructions
    end

  @not_prohibited_instructions
end

#possible_non_isa_specsArray<T.untyped>

Returns List of all non-ISA specs that could apply to this configuration.

Returns:

  • (Array<T.untyped>)

    List of all non-ISA specs that could apply to this configuration



1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
# File 'lib/udb/cfg_arch.rb', line 1426

def possible_non_isa_specs
  return @possible_non_isa_specs if defined?(@possible_non_isa_specs)



  @possible_non_isa_specs = []

  # Discover local non-ISA specifications
  non_isa_path = Pathname.new(__dir__).parent.parent.parent.parent.parent / "spec/custom/non_isa"
  if non_isa_path.exist?
    non_isa_path.glob("*.yaml").each do |spec_file|
      next if spec_file.basename.to_s.start_with?("prm") # Skip PRM files

      begin
        spec_name = spec_file.basename(".yaml").to_s
        spec_data = YAML.load_file(spec_file)
        next unless spec_data["kind"] == "non-isa specification"

        spec_obj = Udb::NonIsaSpecification.new(spec_name, spec_data)
        @possible_non_isa_specs << spec_obj
      rescue => e
        Udb.logger.warn "Failed to load non-ISA spec #{spec_file}: #{e.message}"
      end
    end
  end

  @possible_non_isa_specs.sort_by(&:name)
end

#possible_xlensArray<Integer>

Returns List of possible XLENs in any mode for this config.

Returns:

  • (Array<Integer>)

    List of possible XLENs in any mode for this config



183
# File 'lib/udb/cfg_arch.rb', line 183

def possible_xlens = multi_xlen? ? [32, 64] : [mxlen]

#prohibited_ext?(ext) ⇒ Boolean #prohibited_ext?(ext) ⇒ Boolean

Overloads:

  • #prohibited_ext?(ext) ⇒ Boolean

    Returns true if the ExtensionVersion ext is prohibited

    Parameters:

    Returns:

    • (Boolean)
  • #prohibited_ext?(ext) ⇒ Boolean

    Returns true if any version of the extension named ext is prohibited

    Parameters:

    • ext (String)

      An extension name

    Returns:

    • (Boolean)

Parameters:

Returns:

  • (Boolean)


990
991
992
993
994
995
996
997
998
# File 'lib/udb/cfg_arch.rb', line 990

def prohibited_ext?(ext)
  if ext.is_a?(ExtensionVersion)
    prohibited_extension_versions.include?(ext)
  elsif ext.is_a?(String) || ext.is_a?(Symbol)
    prohibited_extension_versions.any? { |ext_ver| ext_ver.name == ext.to_s }
  else
    raise ArgumentError, "Argument to prohibited_ext? should be an ExtensionVersion or a String"
  end
end

#prohibited_extension_versionsArray<ExtensionVersion>

Returns List of all extension versions that are prohibited. This includes extensions explicitly prohibited by the config file and extensions that conflict with a mandatory extension.

Returns:

  • (Array<ExtensionVersion>)

    List of all extension versions that are prohibited. This includes extensions explicitly prohibited by the config file and extensions that conflict with a mandatory extension.



918
919
920
921
# File 'lib/udb/cfg_arch.rb', line 918

def prohibited_extension_versions
  @prohibited_extension_versions ||=
    extension_versions - possible_extension_versions
end

#prohibited_instructionsArray<Instruction>

Returns List of all prohibited instructions, sorted by name.

Returns:

  • (Array<Instruction>)

    List of all prohibited instructions, sorted by name



1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
# File 'lib/udb/cfg_arch.rb', line 1149

def prohibited_instructions
  # an instruction is prohibited if it is not defined by any .... TODO LEFT OFF HERE....
  @prohibited_instructions ||=
    if fully_configured?
      instructions - implemented_instructions
    elsif partially_configured?
      instructions.select do |inst|
        inst.defined_by_condition.satisfied_by_cfg_arch?(self) == SatisfiedResult::No
      end
    else
      []
    end
end

#reachable_functions(show_progress: false) ⇒ Array<Idl::FunctionDefAst>

Returns List of functions that can be reached by the configuration.

Parameters:

  • show_progress (Boolean) (defaults to: false)

Returns:

  • (Array<Idl::FunctionDefAst>)

    List of functions that can be reached by the configuration



1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
# File 'lib/udb/cfg_arch.rb', line 1248

def reachable_functions(show_progress: false)
  return @reachable_functions unless @reachable_functions.nil?

  @reachable_functions = []

  insts = possible_instructions(show_progress:)
  csrs = possible_csrs(show_progress:)

  bar =
    if show_progress
      TTY::ProgressBar.new("determining reachable IDL functions [:bar]", total: insts.size + csrs.size + 1 + global_ast.functions.size, output: $stdout)
    end

  possible_instructions.each do |inst|
    bar.advance if show_progress

    fns =
      if inst.base.nil?
        if multi_xlen?
          (inst.reachable_functions(32) +
          inst.reachable_functions(64))
        else
          inst.reachable_functions(possible_xlens.fetch(0))
        end
      else
        inst.reachable_functions(T.must(inst.base))
      end

    @reachable_functions.concat(fns)
  end

  @reachable_functions +=
    possible_csrs.flat_map do |csr|
      bar.advance if show_progress

      csr.reachable_functions
    end.uniq

  # now add everything from fetch
  st = @symtab.global_clone
  st.push(global_ast.fetch.body)
  @reachable_functions += global_ast.fetch.body.reachable_functions(st)
  bar.advance if show_progress
  st.release

  # now add everything from external functions
  st = @symtab.global_clone
  global_ast.functions.select { |fn| fn.external? }.each do |fn|
    st.push(fn)
    @reachable_functions << fn
    fn.apply_template_and_arg_syms(st)
    @reachable_functions += fn.reachable_functions(st)
    bar.advance if show_progress
    st.pop
  end
  st.release

  @reachable_functions.uniq!
  @reachable_functions
end

#render_erb(erb_template, what = "") ⇒ String

passes erb_template through ERB within the content of this config

Parameters:

  • erb_template (String)

    ERB source

  • what (String) (defaults to: "")

Returns:

  • (String)

    The rendered text



1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
# File 'lib/udb/cfg_arch.rb', line 1408

def render_erb(erb_template, what = "")
  t = Tempfile.new("template")
  t.write erb_template
  t.flush
  begin
    Tilt["erb"].new(t.path, trim: "-").render(erb_env)
  rescue
    Udb.logger.error "While rendering ERB template: #{what}"
    raise
  ensure
    t.close
    t.unlink
  end
end

#symtabIdl::SymbolTable

Returns Symbol table with global scope included.

Returns:

  • (Idl::SymbolTable)

    Symbol table with global scope included



199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/udb/cfg_arch.rb', line 199

def symtab
  @symtab ||=
    begin
      @symtab = create_symtab

      global_ast.add_global_symbols(@symtab)

      @symtab.deep_freeze
      raise if @symtab.name.nil?
      global_ast.freeze_tree(@symtab)
      @symtab
    end
end

#transitive_implemented_csrsObject

Deprecated.

in favor of implemented_csrs



1108
# File 'lib/udb/cfg_arch.rb', line 1108

def transitive_implemented_csrs = implemented_csrs

#transitive_implemented_extension_versionsObject

Deprecated.

in favor of implemented_extension_versions



777
# File 'lib/udb/cfg_arch.rb', line 777

def transitive_implemented_extension_versions = implemented_extension_versions

#transitive_implemented_instructionsObject



1145
# File 'lib/udb/cfg_arch.rb', line 1145

def transitive_implemented_instructions = implemented_instructions

#transitive_implemented_non_isa_specsObject

Deprecated.

in favor of #implemented_non_isa_specs



1468
# File 'lib/udb/cfg_arch.rb', line 1468

def transitive_implemented_non_isa_specs = implemented_non_isa_specs

#transitive_prohibited_instructionsObject



1164
# File 'lib/udb/cfg_arch.rb', line 1164

def transitive_prohibited_instructions = prohibited_instructions

#type_check(show_progress: true, io: $stdout)

This method returns an undefined value.

type check all IDL, including globals, instruction ops, and CSR functions

Parameters:

  • show_progress (Boolean) (defaults to: true)

    whether to show progress bars

  • io (IO) (defaults to: $stdout)

    where to write progress bars



648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
# File 'lib/udb/cfg_arch.rb', line 648

def type_check(show_progress: true, io: $stdout)
  io.puts "Type checking IDL code for #{@config.name}..." if show_progress
  insts = possible_instructions(show_progress:)

  progressbar =
    if show_progress
      TTY::ProgressBar.new("type checking possible instructions [:bar]", total: insts.size, output: $stdout)
    end

  possible_instructions.each do |inst|
    progressbar.advance if show_progress
    if @mxlen == 32
      inst.type_checked_operation_ast(32) if inst.rv32?
    elsif @mxlen == 64
      inst.type_checked_operation_ast(64) if inst.rv64?
      inst.type_checked_operation_ast(32) if possible_xlens.include?(32) && inst.rv32?
    end
  end

  progressbar =
    if show_progress
      TTY::ProgressBar.new("type checking CSRs [:bar]", total: possible_csrs.size, output: $stdout)
    end

  possible_csrs.each do |csr|
    progressbar.advance if show_progress
    if csr.has_custom_sw_read?
      if (possible_xlens.include?(32) && csr.defined_in_base32?)
        csr.type_checked_sw_read_ast(32)
      end
      if (possible_xlens.include?(64) && csr.defined_in_base64?)
        csr.type_checked_sw_read_ast(64)
      end
    end
    csr.possible_fields.each do |field|
      unless field.type_ast.nil?
        if possible_xlens.include?(32) && csr.defined_in_base32? && field.defined_in_base32?
          field.type_checked_type_ast(32)
        end
        if possible_xlens.include?(64) && csr.defined_in_base64? && field.defined_in_base64?
          field.type_checked_type_ast(64)
        end
      end
      unless field.reset_value_ast.nil?
        if ((possible_xlens.include?(32) && csr.defined_in_base32? && field.defined_in_base32?) ||
            (possible_xlens.include?(64) && csr.defined_in_base64? && field.defined_in_base64?))
          field.type_checked_reset_value_ast if csr.defined_in_base32? && field.defined_in_base32?
        end
      end
      unless field.sw_write_ast(symtab).nil?
        field.type_checked_sw_write_ast(symtab, 32) if possible_xlens.include?(32) && csr.defined_in_base32? && field.defined_in_base32?
        field.type_checked_sw_write_ast(symtab, 64) if possible_xlens.include?(64) && csr.defined_in_base64? && field.defined_in_base64?
      end
    end
  end

  func_list = reachable_functions(show_progress:)
  progressbar =
    if show_progress
      TTY::ProgressBar.new("type checking functions [:bar]", total: func_list.size, output: $stdout)
    end
  func_list.each do |func|
    progressbar.advance if show_progress
    func.type_check(symtab)
  end

  puts "done" if show_progress
end

#unconfigured?Boolean

Returns:

  • (Boolean)


60
# File 'lib/udb/cfg_arch.rb', line 60

def unconfigured? = @config.unconfigured?

#valid?ValidationResult

whether or not the configuration is valid. if it’s not, reasons are provided

Returns:



249
250
251
252
253
254
255
256
257
# File 'lib/udb/cfg_arch.rb', line 249

def valid?
  if fully_configured?
    full_config_valid?
  elsif partially_configured?
    partial_config_valid?
  else
    ValidationResult.new(valid: true, reasons: [])
  end
end