|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
| 3 | +# Contains the "database" of RISC-V standards including extensions, instructions, |
| 4 | +# CSRs, Profiles, and Certificates. Could be either the standard spec (defined by RISC-V International) |
| 5 | +# of a custom spec (defined as an arch_overlay in cfgs/). |
| 6 | +# |
| 7 | +# Creates Ruby functions at runtime (see generate_obj_methods() and OBJS array). |
| 8 | +# 1) Function to return Array<klass> (every klass in database) |
| 9 | +# 2) Function to return Hash<String name, klass> (hash entry is nil if name doesn't exist) |
| 10 | +# 3) Function to return Klass given name (nil if name doesn't exist) |
| 11 | +# |
| 12 | +# klass Array<klass> Hash<String name,klass> Klass func(String name) |
| 13 | +# =============== ================== ======================= ========================= |
| 14 | +# Extension extensions() extension_hash() extension(name) |
| 15 | +# Instruction instructions() instruction_hash() instruction(name) |
| 16 | +# Csr csrs() csr_hash() csr(name) |
| 17 | +# CertClass cert_classes() cert_class_hash() cert_class(name) |
| 18 | +# CertModel cert_models() cert_model_hash() cert_model(name) |
| 19 | +# ProfileClass profile_classes() profile_class_hash() profile_class(name) |
| 20 | +# ProfileRelease profile_releases() profile_release_hash() profile_release(name) |
| 21 | +# Profile profiles() profile_hash() profile(name) |
| 22 | +# Manual manuals() manual_hash() manual(name) |
| 23 | +# ManualVersion manual_versions() manual_version_hash() manual_version(name) |
| 24 | +# |
| 25 | +# Statically created Ruby functions: |
| 26 | +# |
| 27 | +# klass Array<klass> Hash<String name,klass> Klass func(String name) |
| 28 | +# ================== ================== ======================= ========================= |
| 29 | +# ExtensionParameter params() param_hash() param(name) |
| 30 | +# PortfolioClass portfolio_classes() portfolio_class_hash() portfolio_class(name) |
| 31 | +# Portfolio portfolios() portfolio_hash() portfolio(name) |
| 32 | +# ExceptionCodes exception_codes() |
| 33 | +# InterruptCodes interrupt_codes() |
| 34 | + |
3 | 35 | require "active_support/inflector/methods" |
4 | 36 |
|
5 | 37 | require "json" |
|
19 | 51 | require_relative "arch_obj_models/portfolio" |
20 | 52 | require_relative "arch_obj_models/profile" |
21 | 53 |
|
22 | | -# Represents the entire RISC-V Architecture. |
23 | | -# |
24 | | -# Could be either the standard spec (defined by RISC-V International) |
25 | | -# of a custom spec (defined as an arch_overlay in cfgs/) |
26 | 54 | class Architecture |
27 | 55 | # @return [Pathname] Path to the directory with the standard YAML files |
28 | 56 | attr_reader :path |
@@ -169,20 +197,66 @@ def params |
169 | 197 | end |
170 | 198 |
|
171 | 199 | # @return [Hash<String, ExtensionParameter>] Hash of all extension parameters defined in the architecture |
172 | | - def params_hash |
173 | | - return @params_hash unless @params_hash.nil? |
| 200 | + def param_hash |
| 201 | + return @param_hash unless @param_hash.nil? |
174 | 202 |
|
175 | | - @params_hash = {} |
| 203 | + @param_hash = {} |
176 | 204 | params.each do |param| |
177 | | - @params_hash[param.name] = param |
| 205 | + @param_hash[param.name] = param |
178 | 206 | end |
179 | 207 | @param_hash |
180 | 208 | end |
181 | 209 |
|
182 | 210 | # @return [ExtensionParameter] Parameter named +name+ |
183 | 211 | # @return [nil] if there is no parameter named +name+ |
184 | 212 | def param(name) |
185 | | - params_hash[name] |
| 213 | + param_hash[name] |
| 214 | + end |
| 215 | + |
| 216 | + # @return [Array<PortfolioClass>] Alphabetical list of all portfolio classes defined in the architecture |
| 217 | + def portfolio_classes |
| 218 | + return @portfolio_classes unless @portfolio_classes.nil? |
| 219 | + |
| 220 | + @portfolio_classes = profile_classes.concat(cert_classes).sort_by!(&:name) |
| 221 | + end |
| 222 | + |
| 223 | + # @return [Hash<String, PortfolioClass>] Hash of all portfolio classes defined in the architecture |
| 224 | + def portfolio_class_hash |
| 225 | + return @portfolio_class_hash unless @portfolio_class_hash.nil? |
| 226 | + |
| 227 | + @portfolio_class_hash = {} |
| 228 | + portfolio_classes.each do |portfolio_class| |
| 229 | + @portfolio_class_hash[portfolio_class.name] = portfolio_class |
| 230 | + end |
| 231 | + @portfolio_class_hash |
| 232 | + end |
| 233 | + |
| 234 | + # @return [PortfolioClass] Portfolio class named +name+ |
| 235 | + # @return [nil] if there is no Portfolio class named +name+ |
| 236 | + def portfolio_class(name) = portfolio_class_hash[name] |
| 237 | + |
| 238 | + # @return [Array<Portfolio>] Alphabetical list of all portfolios defined in the architecture |
| 239 | + def portfolios |
| 240 | + return @portfolios unless @portfolios.nil? |
| 241 | + |
| 242 | + @portfolios = @profiles.concat(@certificates).sort_by!(&:name) |
| 243 | + end |
| 244 | + |
| 245 | + # @return [Hash<String, Portfolio>] Hash of all portfolios defined in the architecture |
| 246 | + def portfolio_hash |
| 247 | + return @portfolio_hash unless @portfolio_hash.nil? |
| 248 | + |
| 249 | + @portfolio_hash = {} |
| 250 | + portfolios.each do |portfolio| |
| 251 | + @portfolio_hash[portfolio.name] = portfolio |
| 252 | + end |
| 253 | + @portfolio_hash |
| 254 | + end |
| 255 | + |
| 256 | + # @return [PortfolioClass] Portfolio named +name+ |
| 257 | + # @return [nil] if there is no Portfolio named +name+ |
| 258 | + def portfolio(name) |
| 259 | + portfolio_hash[name] |
186 | 260 | end |
187 | 261 |
|
188 | 262 | # @return [Array<ExceptionCode>] All exception codes defined by the spec |
|
0 commit comments