Class: Udb::ConfiguredArchitecture
- Inherits:
-
Architecture
- Object
- Architecture
- Udb::ConfiguredArchitecture
- Extended by:
- T::Sig
- Defined in:
- lib/udb/cfg_arch.rb
Instance Attribute Summary collapse
- #config ⇒ AbstractConfig readonly
-
#global_ast ⇒ Idl::IsaAst
readonly
Abstract syntax tree of global scope.
-
#idl_compiler ⇒ Idl::Compiler
readonly
The IDL compiler.
-
#name ⇒ String
readonly
Name of this definition.
Class Method Summary collapse
-
.validate(config_path, std_path: Udb.default_std_isa_path, custom_path: Udb.default_custom_isa_path, gen_path: Udb.default_gen_path) ⇒ Boolean
validate a configuration.
Instance Method Summary collapse
- #config_type ⇒ ConfigType
-
#convert_monospace_to_links(adoc) ⇒ String
Given an adoc string, find names of CSR/Instruction/Extension enclosed in ‘monospace` and replace them with links to the relevant object page.
-
#explicitly_implemented_extension_versions ⇒ Array<ExtensionVersion>
List of extension versions explicitly marked as implemented in the config.
- #ext?(ext_name, ext_version_requirements = []) ⇒ Boolean
-
#fetch ⇒ Idl::FetchAst
Fetch block.
- #fully_configured? ⇒ Boolean
-
#functions ⇒ Array<Idl::FunctionBodyAst>
List of all functions defined by the architecture.
-
#globals ⇒ Array<Idl::GlobalAst, Idl::GlobalWithInitializationAst>
List of globals.
-
#hash ⇒ Integer
hash for Hash lookup.
-
#implemented_exception_codes ⇒ Array<ExceptionCode>
All exception codes known to be implemented.
-
#implemented_functions ⇒ Array<Idl::FunctionDefAst>
List of all reachable IDL functions for the config.
-
#implemented_interrupt_codes ⇒ Array<InterruptCode>
All interrupt codes known to be implemented.
-
#initialize(name, config)
constructor
Initialize a new configured architecture definition.
-
#inspect ⇒ String
Returns a string representation of the object, suitable for debugging.
-
#largest_encoding ⇒ Integer
The largest instruction encoding in the config.
-
#mandatory_extension_reqs ⇒ Array<ExtensionRequirement>
List of all mandatory extension requirements (not transitive).
-
#multi_xlen? ⇒ Boolean
Returns whether or not it may be possible to switch XLEN given this definition.
-
#multi_xlen_in_mode?(mode) ⇒ Boolean
Returns whether or not it may be possible to switch XLEN in
mode
given this definition. - #mxlen ⇒ Integer?
-
#not_prohibited_csrs ⇒ Array<Csr>
(also: #possible_csrs)
List of all CSRs that it is possible to implement.
-
#not_prohibited_extension_versions ⇒ Array<ExtensionVersion>
(also: #possible_extension_versions)
List of all ExtensionVersions that are possible to support.
-
#not_prohibited_extensions ⇒ Array<Extension>
(also: #possible_extensions)
List of extensions that are possibly supported.
-
#not_prohibited_instructions ⇒ Array<Instruction>
(also: #possible_instructions)
List of all instructions that are not prohibited by the config, sorted by name.
-
#out_of_scope_params ⇒ Array<Parameter>
Returns list of parameters that out of scope for the config.
-
#param_syms ⇒ Hash{String => Idl::Var, Idl::Type}
return the params as a hash of symbols for the SymbolTable.
- #param_values ⇒ Hash{String => T.untyped}
-
#params_with_value ⇒ Array<ParameterWithValue>
List of all parameters with one known value in the config.
-
#params_without_value ⇒ Array<Parameter>
List of all available parameters without one known value in the config.
- #partially_configured? ⇒ Boolean
-
#possible_xlens ⇒ Array<Integer>
List of possible XLENs in any mode for this config.
- #prohibited_ext?(ext) ⇒ Boolean
-
#reachable_functions ⇒ Array<Idl::FunctionDefAst>
List of functions that can be reached by the configuration.
-
#render_erb(erb_template, what = "") ⇒ String
passes erb_template through ERB within the content of this config.
- #symtab ⇒ nil, Idl::SymbolTable
-
#transitive_implemented_csrs ⇒ Array<Csr>
(also: #implemented_csrs)
List of all implemented CSRs.
-
#transitive_implemented_extension_versions ⇒ Array<ExtensionVersion>
(also: #implemented_extension_versions)
List of all extensions known to be implemented in this config, including transitive implications.
-
#transitive_implemented_instructions ⇒ Array<Instruction>
(also: #implemented_instructions)
List of all implemented instructions, sorted by name.
-
#transitive_prohibited_extension_versions ⇒ Array<ExtensionVersion>
(also: #prohibited_extension_versions)
List of all extension versions that are prohibited.
-
#transitive_prohibited_instructions ⇒ Array<Instruction>
(also: #prohibited_instructions)
List of all prohibited instructions, sorted by name.
-
#type_check(show_progress: true, io: $stdout)
type check all IDL, including globals, instruction ops, and CSR functions.
- #unconfigured? ⇒ Boolean
Constructor Details
#initialize(name, config)
Initialize a new configured architecture definition
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'lib/udb/cfg_arch.rb', line 400 def initialize(name, config) super(config.info.resolved_spec_path) @name = name.to_s.freeze @name_sym = @name.to_sym.freeze @config = config @config_type = T.let(@config.type, ConfigType) @mxlen = config.mxlen @mxlen.freeze @idl_compiler = Idl::Compiler.new symtab_callbacks = Idl::SymbolTable::BuiltinFunctionCallbacks.new( implemented: ( Idl::SymbolTable.make_implemented_callback do |ext_name| if fully_configured? ext?(ext_name) else # we can know if it is implemented, but not if it's not implemented for a partially configured if ext?(ext_name) true elsif prohibited_ext?(ext_name) false end end end ), implemented_version: ( Idl::SymbolTable.make_implemented_version_callback do |ext_name, version| if fully_configured? ext?(ext_name, [version]) else # we can know if it is implemented, but not if it's not implemented for a partially configured if ext?(ext_name, [version]) true elsif prohibited_ext?(ext_name) false end end end ), implemented_csr: ( Idl::SymbolTable.make_implemented_csr_callback do |csr_addr| if fully_configured? if transitive_implemented_csrs.any? { |c| c.address == csr_addr } true end else if not_prohibited_csrs.none? { |c| c.address == csr_addr } false end end end ) ) params = params_with_value.concat(params_without_value).concat(out_of_scope_params) params.uniq! { |p| p.name } @symtab = Idl::SymbolTable.new( mxlen:, possible_xlens:, params:, builtin_funcs: symtab_callbacks, builtin_enums: [ Idl::SymbolTable::EnumDef.new( name: "ExtensionName", element_values: (1..extensions.size).to_a, element_names: extensions.map(&:name) ), Idl::SymbolTable::EnumDef.new( name: "ExceptionCode", element_values: exception_codes.map(&:num), element_names: exception_codes.map(&:var) ), Idl::SymbolTable::EnumDef.new( name: "InterruptCode", element_values: interrupt_codes.map(&:num), element_names: interrupt_codes.map(&:var) ) ], name: @name, csrs: ) = config.info. custom_globals_path = .nil? ? Pathname.new("/does/not/exist") : / "isa" / "globals.isa" idl_path = File.exist?(custom_globals_path) ? custom_globals_path : config.info.spec_path / "isa" / "globals.isa" @global_ast = @idl_compiler.compile_file( idl_path ) @global_ast.add_global_symbols(@symtab) @symtab.deep_freeze raise if @symtab.name.nil? @global_ast.freeze_tree(@symtab) @params_with_value = T.let(nil, T.nilable(T::Array[ParameterWithValue])) end |
Instance Attribute Details
#config ⇒ AbstractConfig (readonly)
52 53 54 |
# File 'lib/udb/cfg_arch.rb', line 52 def config @config end |
#global_ast ⇒ Idl::IsaAst (readonly)
Returns Abstract syntax tree of global scope.
42 43 44 |
# File 'lib/udb/cfg_arch.rb', line 42 def global_ast @global_ast end |
#idl_compiler ⇒ Idl::Compiler (readonly)
Returns The IDL compiler.
38 39 40 |
# File 'lib/udb/cfg_arch.rb', line 38 def idl_compiler @idl_compiler end |
#name ⇒ String (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).
49 50 51 |
# File 'lib/udb/cfg_arch.rb', line 49 def name @name end |
Class Method Details
.validate(config_path, std_path: Udb.default_std_isa_path, custom_path: Udb.default_custom_isa_path, gen_path: Udb.default_gen_path) ⇒ Boolean
validate a configuration
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/udb/cfg_arch.rb', line 247 def self.validate( config_path, std_path: Udb.default_std_isa_path, custom_path: Udb.default_custom_isa_path, gen_path: Udb.default_gen_path ) config_spec = YAML.load_file(config_path) case config_spec.fetch("type") when "unconfigured" true # nothing else to do! when "fully configured" validate_full_config(config_path, std_path:, custom_path:, gen_path:) when "partially configured" validate_partial_config(config_path, std_path:, custom_path:, gen_path:) else raise "Not a valid configuration type: #{config_spec.fetch('type')}" end end |
Instance Method Details
#convert_monospace_to_links(adoc) ⇒ String
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.
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 |
# File 'lib/udb/cfg_arch.rb', line 1148 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 |
#explicitly_implemented_extension_versions ⇒ Array<ExtensionVersion>
Returns List of extension versions explicitly marked as implemented in the config. Does not include extensions implied by explicitly implemented extensions.
671 672 673 674 675 676 677 678 679 680 681 682 |
# File 'lib/udb/cfg_arch.rb', line 671 def explicitly_implemented_extension_versions return @explicitly_implemented_extension_versions if defined?(@explicitly_implemented_extension_versions) unless fully_configured? raise ArgumentError, "implemented_extension_versions only valid for fully configured systems" end @explicitly_implemented_extension_versions ||= T.cast(@config, FullConfig).implemented_extensions.map do |e| ExtensionVersion.new(e.fetch("name"), e.fetch("version"), self, fail_if_version_does_not_exist: true) end end |
#ext?(ext_name) ⇒ Boolean #ext?(ext_name, ext_version_requirements) ⇒ Boolean
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 |
# File 'lib/udb/cfg_arch.rb', line 871 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? transitive_implemented_extension_versions.any? do |e| if ext_version_requirements.empty? e.name == ext_name.to_s else requirement = ExtensionRequirement.new(ext_name.to_s, ext_version_requirements, arch: self) 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 = ExtensionRequirement.new(ext_name.to_s, ext_version_requirements, arch: self) e..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 |
#fetch ⇒ Idl::FetchAst
Returns Fetch block.
927 928 929 |
# File 'lib/udb/cfg_arch.rb', line 927 def fetch @fetch ||= @global_ast.fetch end |
#fully_configured? ⇒ Boolean
55 |
# File 'lib/udb/cfg_arch.rb', line 55 def fully_configured? = @config.fully_configured? |
#functions ⇒ Array<Idl::FunctionBodyAst>
Returns List of all functions defined by the architecture.
921 922 923 |
# File 'lib/udb/cfg_arch.rb', line 921 def functions @functions ||= @global_ast.functions end |
#globals ⇒ Array<Idl::GlobalAst, Idl::GlobalWithInitializationAst>
Returns List of globals.
933 934 935 936 937 |
# File 'lib/udb/cfg_arch.rb', line 933 def globals return @globals unless @globals.nil? @globals = @global_ast.globals end |
#hash ⇒ Integer
hash for Hash lookup
182 |
# File 'lib/udb/cfg_arch.rb', line 182 def hash = @name_sym.hash |
#implemented_exception_codes ⇒ Array<ExceptionCode>
Returns All exception codes known to be implemented.
907 908 909 910 |
# File 'lib/udb/cfg_arch.rb', line 907 def implemented_exception_codes @implemented_exception_codes ||= implemented_extension_versions.map { |ext_ver| ext_ver.exception_codes }.compact.flatten end |
#implemented_functions ⇒ Array<Idl::FunctionDefAst>
Returns List of all reachable IDL functions for the config.
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 |
# File 'lib/udb/cfg_arch.rb', line 1049 def implemented_functions return @implemented_functions unless @implemented_functions.nil? @implemented_functions = [] puts " Finding all reachable functions from instruction operations" transitive_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(mxlen) end else inst.reachable_functions(inst.base) end end @implemented_functions = @implemented_functions.flatten @implemented_functions.uniq!(&:name) puts " Finding all reachable functions from CSR operations" transitive_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 symtab = @symtab.global_clone symtab.push(@global_ast.fetch.body) fetch_fns = @global_ast.fetch.body.reachable_functions(symtab) fetch_fns.each do |f| @implemented_functions << f unless @implemented_functions.any? { |i| i.name == f.name } end symtab.release @implemented_functions end |
#implemented_interrupt_codes ⇒ Array<InterruptCode>
Returns All interrupt codes known to be implemented.
914 915 916 917 |
# File 'lib/udb/cfg_arch.rb', line 914 def implemented_interrupt_codes @implemented_interupt_codes ||= implemented_extension_versions.map { |ext_ver| ext_ver.interrupt_codes }.compact.flatten end |
#inspect ⇒ String
Returns a string representation of the object, suitable for debugging.
504 |
# File 'lib/udb/cfg_arch.rb', line 504 def inspect = "ConfiguredArchitecture##{name}" |
#largest_encoding ⇒ Integer
Returns The largest instruction encoding in the config.
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 |
# File 'lib/udb/cfg_arch.rb', line 1036 def largest_encoding @largest_encoding ||= if fully_configured? transitive_implemented_instructions.map(&:max_encoding_width).max elsif partially_configured? not_prohibited_instructions.map(&:max_encoding_width).max else instructions.map(&:max_encoding_width).max end end |
#mandatory_extension_reqs ⇒ Array<ExtensionRequirement>
Returns List of all mandatory extension requirements (not transitive).
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
# File 'lib/udb/cfg_arch.rb', line 723 def mandatory_extension_reqs return @mandatory_extension_reqs if defined?(@mandatory_extension_reqs) @mandatory_extension_reqs ||= T.cast(@config, PartialConfig).mandatory_extensions.map do |e| ename = T.cast(e["name"], String) ext = extension(ename) raise "Cannot find extension #{e['name']} in the architecture definition" if ext.nil? if e["version"].is_a?(Array) ExtensionRequirement.new(ename, T.cast(e.fetch("version"), T::Array[String]), presence: Presence.new("mandatory"), arch: self) else ExtensionRequirement.new(ename, T.cast(e.fetch("version"), String), presence: Presence.new("mandatory"), arch: self) 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.
80 81 82 83 84 |
# File 'lib/udb/cfg_arch.rb', line 80 def multi_xlen? return true if @mxlen.nil? ["S", "U", "VS", "VU"].any? { |mode| multi_xlen_in_mode?(mode) } 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)
99 100 101 102 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 |
# File 'lib/udb/cfg_arch.rb', line 99 def multi_xlen_in_mode?(mode) return false if mxlen == 32 case mode when "M" mxlen.nil? when "S" return true if unconfigured? if fully_configured? ext?(:S) && (param_values["SXLEN"] == 3264) 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"] == 3264 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"] == 3264) 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"] == 3264 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"] == 3264) 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"] == 3264 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"] == 3264) 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"] == 3264 else raise "Unexpected configuration state" end when "D" mxlen.nil? else raise ArgumentError, "Bad mode" end end |
#mxlen ⇒ Integer?
64 |
# File 'lib/udb/cfg_arch.rb', line 64 def mxlen = @config.mxlen |
#not_prohibited_csrs ⇒ Array<Csr> Also known as: possible_csrs
Returns List of all CSRs that it is possible to implement.
957 958 959 960 961 962 963 964 965 966 967 968 969 970 |
# File 'lib/udb/cfg_arch.rb', line 957 def not_prohibited_csrs @not_prohibited_csrs ||= if @config.fully_configured? transitive_implemented_csrs elsif @config.partially_configured? csrs.select do |csr| csr.defined_by_condition.satisfied_by? do |ext_req| not_prohibited_extension_versions.any? { |ext_ver| ext_req.satisfied_by?(ext_ver) } end end else csrs end end |
#not_prohibited_extension_versions ⇒ Array<ExtensionVersion> Also known as: possible_extension_versions
Returns List of all ExtensionVersions that are possible to support.
759 760 761 762 763 764 765 766 767 768 769 770 |
# File 'lib/udb/cfg_arch.rb', line 759 def not_prohibited_extension_versions return @not_prohibited_extension_versions if defined?(@not_prohibited_extension_versions) @not_prohibited_extension_versions ||= if @config.fully_configured? transitive_implemented_extension_versions elsif @config.partially_configured? extensions.map(&:versions).flatten.reject { |ext_ver| transitive_prohibited_extension_versions.include?(ext_ver) } else extensions.map(&:versions).flatten end end |
#not_prohibited_extensions ⇒ Array<Extension> Also known as: possible_extensions
Returns List of extensions that are possibly supported.
742 743 744 745 746 747 748 749 750 751 752 753 754 |
# File 'lib/udb/cfg_arch.rb', line 742 def not_prohibited_extensions return @not_prohibited_extensions if defined?(@not_prohibited_extensions) @not_prohibited_extensions ||= if @config.fully_configured? transitive_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 - transitive_prohibited_extension_versions).empty? } else extensions end end |
#not_prohibited_instructions ⇒ Array<Instruction> Also known as: possible_instructions
Returns List of all instructions that are not prohibited by the config, sorted by name.
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 |
# File 'lib/udb/cfg_arch.rb', line 1010 def not_prohibited_instructions return @not_prohibited_instructions if defined?(@not_prohibited_instructions) @not_prohibited_instructions_mutex ||= Thread::Mutex.new @not_prohibited_instructions_mutex.synchronize do @not_prohibited_instructions ||= if @config.fully_configured? transitive_implemented_instructions elsif @config.partially_configured? instructions.select do |inst| possible_xlens.any? { |xlen| inst.defined_in_base?(xlen) } && \ inst.defined_by_condition.satisfied_by? do |ext_req| not_prohibited_extension_versions.any? { |ext_ver| ext_req.satisfied_by?(ext_ver) } end end else instructions end end @not_prohibited_instructions end |
#out_of_scope_params ⇒ Array<Parameter>
Returns list of parameters that out of scope for the config
653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
# File 'lib/udb/cfg_arch.rb', line 653 def out_of_scope_params return @out_of_scope_params unless @out_of_scope_params.nil? @out_of_scope_params = [] extensions.each do |ext| ext.params.each do |ext_param| next if params_with_value.any? { |p| p.name == ext_param.name } next if params_without_value.any? { |p| p.name == ext_param.name } @out_of_scope_params << ext_param end end @out_of_scope_params end |
#param_syms ⇒ Hash{String => Idl::Var, Idl::Type}
return the params as a hash of symbols for the SymbolTable
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 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 198 def param_syms syms = {} params_with_value.each do |param_with_value| type = Idl::Type.from_json_schema(param_with_value.schema).make_const if type.kind == :array && type.width == :unknown type = Idl::Type.new(:array, width: T.cast(param_with_value.value, T.untyped).length, sub_type: type.sub_type, qualifiers: [:const]) end # could already be present... existing_sym = syms[param_with_value.name] if existing_sym.nil? syms[param_with_value.name] = Idl::Var.new(param_with_value.name, type, param_with_value.value, param: true) else unless existing_sym.type.equal_to?(type) && existing_sym.value == param_with_value.value raise Idl::SymbolTable::DuplicateSymError, "Definition error: Param #{param_with_value.name} is defined by multiple extensions and is not the same definition in each" end end end # now add all parameters, even those not implemented params_without_value.each do |param| if param.exts.size == 1 syms[param.name] = Idl::Var.new(param.name, param.idl_type.make_const, param: true) else # could already be present... existing_sym = syms[param.name] if existing_sym.nil? syms[param.name] = Idl::Var.new(param.name, param.idl_type.make_const, param: true) else unless existing_sym.type.equal_to?(param.idl_type) raise "Definition error: Param #{param.name} is defined by multiple extensions and is not the same definition in each" end end end end syms end |
#param_values ⇒ Hash{String => T.untyped}
67 |
# File 'lib/udb/cfg_arch.rb', line 67 def param_values = @config.param_values |
#params_with_value ⇒ Array<ParameterWithValue>
Returns List of all parameters with one known value in the config.
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 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 |
# File 'lib/udb/cfg_arch.rb', line 582 def params_with_value @params_with_value ||= T.let( case @config_type when ConfigType::UnConfig T.cast([], T::Array[ParameterWithValue]) when ConfigType::Full params = T.let([], T::Array[ParameterWithValue]) transitive_implemented_extension_versions.each do |ext_version| ext = T.must(extension(ext_version.name)) ext.params.each do |ext_param| if !@config.param_values.key?(ext_param.name) if ext_param.when.satisfied_by_cfg_arch?(self) != SatisfiedResult::No raise "missing parameter value for #{ext_param.name} in config #{config.name}" else next end end next if params.any? { |p| p.name == ext_param.name } params << ParameterWithValue.new( ext_param, @config.param_values.fetch(ext_param.name) ) end end params when ConfigType::Partial params = T.let([], T::Array[ParameterWithValue]) mandatory_extension_reqs.each do |ext_requirement| ext = T.must(extension(ext_requirement.name)) ext.params.each do |ext_param| # Params listed in the config always only have one value. next unless @config.param_values.key?(ext_param.name) next if params.any? { |p| p.name == ext_param.name } params << ParameterWithValue.new( ext_param, T.must(@config.param_values[ext_param.name]) ) end end params else T.absurd(@config_type) end, T.nilable(T::Array[ParameterWithValue])) end |
#params_without_value ⇒ Array<Parameter>
Returns List of all available parameters without one known value in the config.
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 |
# File 'lib/udb/cfg_arch.rb', line 633 def params_without_value return @params_without_value unless @params_without_value.nil? @params_without_value = [] extensions.each do |ext| next if possible_extensions.none? { |poss| poss.name == ext.name } ext.params.each do |ext_param| # Params listed in the config always only have one value. next if @config.param_values.key?(ext_param.name) next if @params_without_value.any? { |p| p.name == ext_param.name } next if ext_param.when.satisfied_by_cfg_arch?(self) == SatisfiedResult::No @params_without_value << ext_param end end @params_without_value end |
#partially_configured? ⇒ Boolean
58 |
# File 'lib/udb/cfg_arch.rb', line 58 def partially_configured? = @config.partially_configured? |
#possible_xlens ⇒ Array<Integer>
Returns List of possible XLENs in any mode for this config.
178 |
# File 'lib/udb/cfg_arch.rb', line 178 def possible_xlens = multi_xlen? ? [32, 64] : [mxlen] |
#prohibited_ext?(ext) ⇒ Boolean #prohibited_ext?(ext) ⇒ Boolean
847 848 849 850 851 852 853 854 855 |
# File 'lib/udb/cfg_arch.rb', line 847 def prohibited_ext?(ext) if ext.is_a?(ExtensionVersion) transitive_prohibited_extension_versions.include?(ext) elsif ext.is_a?(String) || ext.is_a?(Symbol) transitive_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 |
#reachable_functions ⇒ Array<Idl::FunctionDefAst>
Returns List of functions that can be reached by the configuration.
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 |
# File 'lib/udb/cfg_arch.rb', line 1095 def reachable_functions return @reachable_functions unless @reachable_functions.nil? insts = not_prohibited_instructions @reachable_functions = [] insts.each do |inst| fns = if inst.base.nil? if multi_xlen? (inst.reachable_functions(32) + inst.reachable_functions(64)) else inst.reachable_functions(mxlen) end else inst.reachable_functions(inst.base) end @reachable_functions.concat(fns) end @reachable_functions += not_prohibited_csrs.flat_map(&:reachable_functions).uniq # now add everything from fetch symtab = @symtab.global_clone symtab.push(@global_ast.fetch.body) @reachable_functions += @global_ast.fetch.body.reachable_functions(symtab) symtab.release # now add everything from external functions symtab = @symtab.global_clone @global_ast.functions.select { |fn| fn.external? }.each do |fn| symtab.push(fn) @reachable_functions << fn fn.apply_template_and_arg_syms(symtab) @reachable_functions += fn.reachable_functions(symtab) symtab.pop end symtab.release @reachable_functions.uniq! @reachable_functions end |
#render_erb(erb_template, what = "") ⇒ String
passes erb_template through ERB within the content of this config
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 |
# File 'lib/udb/cfg_arch.rb', line 1252 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 warn "While rendering ERB template: #{what}" raise ensure t.close t.unlink end end |
#symtab ⇒ nil, Idl::SymbolTable
187 188 189 190 191 |
# File 'lib/udb/cfg_arch.rb', line 187 def symtab raise NotImplementedError, "Un-configured ConfiguredArchitectures have no symbol table" if @symtab.nil? @symtab end |
#transitive_implemented_csrs ⇒ Array<Csr> Also known as: implemented_csrs
Returns List of all implemented CSRs.
941 942 943 944 945 946 947 948 949 950 951 952 |
# File 'lib/udb/cfg_arch.rb', line 941 def transitive_implemented_csrs unless fully_configured? raise ArgumentError, "transitive_implemented_csrs is only defined for fully configured systems" end @transitive_implemented_csrs ||= csrs.select do |csr| csr.defined_by_condition.satisfied_by? do |ext_req| transitive_implemented_extension_versions.any? { |ext_ver| ext_req.satisfied_by?(ext_ver) } end end end |
#transitive_implemented_extension_versions ⇒ Array<ExtensionVersion> Also known as: implemented_extension_versions
Returns List of all extensions known to be implemented in this config, including transitive implications.
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 716 717 718 |
# File 'lib/udb/cfg_arch.rb', line 686 def transitive_implemented_extension_versions return @transitive_implemented_extension_versions unless @transitive_implemented_extension_versions.nil? raise "transitive_implemented_extension_versions is only valid for a fully configured definition" unless @config.fully_configured? @transitive_implemented_extension_versions = explicitly_implemented_extension_versions.dup added_ext_vers = [] loop do @transitive_implemented_extension_versions.each do |ext_ver| ext_ver.implications.each do |cond_ext_ver| applies = cond_ext_ver.cond.satisfied_by? do |ext_req| @transitive_implemented_extension_versions.any? do |inner_ext_ver| next false if ext_ver == inner_ext_ver ext_req.satisfied_by?(inner_ext_ver) end end if applies && !@transitive_implemented_extension_versions.include?(cond_ext_ver.ext_ver) added_ext_vers << cond_ext_ver.ext_ver end end end break if added_ext_vers.empty? added_ext_vers.each { |ext_ver| @transitive_implemented_extension_versions << ext_ver } added_ext_vers = [] end @transitive_implemented_extension_versions.sort! @transitive_implemented_extension_versions end |
#transitive_implemented_instructions ⇒ Array<Instruction> Also known as: implemented_instructions
Returns List of all implemented instructions, sorted by name.
975 976 977 978 979 980 981 982 983 984 985 986 |
# File 'lib/udb/cfg_arch.rb', line 975 def transitive_implemented_instructions unless fully_configured? raise ArgumentError, "transitive_implemented_instructions is only defined for fully configured systems" end @transitive_implemented_instructions ||= instructions.select do |inst| inst.defined_by_condition.satisfied_by? do |ext_req| transitive_implemented_extension_versions.any? { |ext_ver| ext_req.satisfied_by?(ext_ver) } end end end |
#transitive_prohibited_extension_versions ⇒ Array<ExtensionVersion> Also known as: prohibited_extension_versions
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.
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 |
# File 'lib/udb/cfg_arch.rb', line 791 def transitive_prohibited_extension_versions return @transitive_prohibited_extension_versions unless @transitive_prohibited_extension_versions.nil? @transitive_prohibited_extension_versions = [] if @config.partially_configured? @transitive_prohibited_extension_versions = T.cast(@config, PartialConfig).prohibited_extensions.map do |ext_req_data| ext_req = ExtensionRequirement.new(T.cast(ext_req_data.fetch("name"), String), ext_req_data.fetch("version"), arch: self) ext_req..each { |ext_ver| add_ext_ver_and_conflicts(ext_ver) } end # now add any extensions that are prohibited by a mandatory extension mandatory_extension_reqs.each do |ext_req| ext_req. do |ext_ver| add_ext_ver_and_conflicts(ext_ver) end end # now add everything that is not mandatory or implied by mandatory, if additional extensions are not allowed unless T.cast(@config, PartialConfig).additional_extensions_allowed? extensions.each do |ext| ext.versions.each do |ext_ver| next if mandatory_extension_reqs.any? { |ext_req| ext_req.satisfied_by?(ext_ver) } next if mandatory_extension_reqs.any? { |ext_req| ext_req.extension.implies.include?(ext_ver) } @transitive_prohibited_extension_versions << ext_ver end end end elsif @config.fully_configured? extensions.each do |ext| ext.versions.each do |ext_ver| @transitive_prohibited_extension_versions << ext_ver unless transitive_implemented_extension_versions.include?(ext_ver) end end # else, unconfigured....nothing to do # rubocop:disable Layout/CommentIndentation end @transitive_prohibited_extension_versions end |
#transitive_prohibited_instructions ⇒ Array<Instruction> Also known as: prohibited_instructions
Returns List of all prohibited instructions, sorted by name.
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 |
# File 'lib/udb/cfg_arch.rb', line 991 def transitive_prohibited_instructions # an instruction is prohibited if it is not defined by any .... TODO LEFT OFF HERE.... @transitive_prohibited_instructions ||= if fully_configured? instructions - transitive_implemented_instructions elsif partially_configured? instructions.select do |inst| inst.defined_by_condition.satisfied_by? do |ext_req| not_prohibited_extension_versions.none? { |ext_ver| ext_req.satisfied_by?(ext_ver) } end end else [] end end |
#type_check(show_progress: true, io: $stdout)
This method returns an undefined value.
type check all IDL, including globals, instruction ops, and CSR functions
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
# File 'lib/udb/cfg_arch.rb', line 513 def type_check(show_progress: true, io: $stdout) io.puts "Type checking IDL code for #{@config.name}..." if show_progress = if show_progress ProgressBar.create(title: "Instructions", total: possible_instructions.size) end possible_instructions.each do |inst| .increment 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 = if show_progress ProgressBar.create(title: "CSRs", total: possible_csrs.size) end possible_csrs.each do |csr| .increment 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 = if show_progress ProgressBar.create(title: "Functions", total: func_list.size) end func_list.each do |func| .increment if show_progress func.type_check(@symtab) end puts "done" if show_progress end |
#unconfigured? ⇒ Boolean
61 |
# File 'lib/udb/cfg_arch.rb', line 61 def unconfigured? = @config.unconfigured? |