Class: Udb::Portfolio
- Inherits:
-
TopLevelDatabaseObject
- Object
- DatabaseObject
- TopLevelDatabaseObject
- Udb::Portfolio
- Defined in:
- lib/udb/obj/portfolio.rb
Overview
Holds information about a Portfolio (certificate or profile). The inherited “data” member is YAML data from the architecture for this portfolio object.
Direct Known Subclasses
Defined Under Namespace
Classes: ExtraNote, InScopeParameter, Recommendation, RevisionHistory
Instance Method Summary collapse
-
#all_in_scope_exts_with_param(param) ⇒ Array<Extension>
Sorted list of all in-scope extensions that define this parameter in the database and the parameter is in-scope.
-
#all_in_scope_exts_without_param(param) ⇒ Array<Extension>
List of all in-scope extensions that define this parameter in the database but the parameter is out-of-scope.
-
#all_in_scope_params ⇒ Array<InScopeParameter>
List of parameters specified by any extension in portfolio.
-
#all_out_of_scope_params ⇒ Array<Parameter>
Sorted list of parameters out of scope across all in scope extensions.
-
#base ⇒ Integer
32 or 64.
-
#csr_presence(csr_name) ⇒ String
Given an CSR
csr_name, return the presence as a string. -
#csr_presence_obj(csr_name) ⇒ Presence
Given an CSR
csr_name, return the presence. -
#description ⇒ String
Large enough to need its own heading (generally one level deeper than the “introduction”).
- #extension_note(ext_name) ⇒ String?
-
#extension_presence(ext_name) ⇒ String
Given an extension
ext_name, return the presence as a string. -
#extension_presence_obj(ext_name) ⇒ Presence
Given an extension
ext_name, return the presence. - #extra_notes ⇒ Object
- #extra_notes_for_presence(desired_presence_obj) ⇒ Array<String>
-
#in_scope_csrs(design) ⇒ Array<Csr>
Unsorted list of all CSRs associated with extensions listed as mandatory or optional in portfolio.
-
#in_scope_exception_codes(design) ⇒ Array<ExceptionCode>
TODO: See github.com/riscv-software-src/riscv-unified-db/issues/291 TODO: Still needs work and haven’t created in_scope_interrupt_codes yet.
- #in_scope_ext_reqs(desired_presence = nil) ⇒ Array<PortfolioExtensionRequirement>
-
#in_scope_extensions ⇒ Array<Extension>
Sorted list of all mandatory or optional extensions in portfolio.
-
#in_scope_instructions(design) ⇒ Array<Instruction>
Sorted list of all instructions associated with extensions listed as mandatory or optional in portfolio.
-
#in_scope_interrupt_codes(design) ⇒ Array<InterruptCode>
TODO: Actually implement this to use Design.
-
#in_scope_min_satisfying_extension_versions ⇒ ExtensionVersion
List of all mandatory or optional extensions listed in portfolio.
-
#in_scope_params(ext_req) ⇒ Array<InScopeParameter>
Sorted list of extension parameters from portfolio for given extension.
- #initialize(obj_yaml, yaml_path, arch) constructor
-
#instruction_presence(inst_name) ⇒ Presence?
Given an instruction
inst_name, return the presence as a string. -
#instruction_presence_obj(inst_name) ⇒ Presence?
Given an instruction
inst_name, return the presence. -
#introduction ⇒ String
Small enough (~1 paragraph) to be suitable immediately after a higher-level heading.
- #mandatory_ext_reqs ⇒ Object
- #optional_ext_reqs ⇒ Object
-
#out_of_scope_params(ext_name) ⇒ Array<Parameter>
Sorted list of parameters that are out of scope for named extension.
- #recommendations ⇒ Object
- #revision_history ⇒ Object
-
#to_cfg_arch ⇒ ConfiguredArchitecture
returns a config arch that treats the Portfolio like a partial config.
-
#to_cfg_arch_for_optional ⇒ ConfiguredArchitecture
returns a config arch that treats the optional extensions in Portfolio like a partial config.
- #to_config ⇒ Hash{String => T.untyped}
-
#uses_optional_types? ⇒ Boolean
Does the profile differentiate between different types of optional.
-
#version ⇒ Gem::Version
Semantic version of the Portfolio.
-
#version_greatest_presence(ext_name, ext_versions) ⇒ Array<String>
Returns the greatest presence string for each of the specified versions.
Constructor Details
#initialize(obj_yaml, yaml_path, arch)
380 381 382 |
# File 'lib/udb/obj/portfolio.rb', line 380 def initialize(obj_yaml, yaml_path, arch) super # Calls parent class with same args I got end |
Instance Method Details
#all_in_scope_exts_with_param(param) ⇒ Array<Extension>
Returns Sorted list of all in-scope extensions that define this parameter in the database and the parameter is in-scope.
821 |
# File 'lib/udb/obj/portfolio.rb', line 821 def all_in_scope_exts_with_param(param) = [] |
#all_in_scope_exts_without_param(param) ⇒ Array<Extension>
Returns List of all in-scope extensions that define this parameter in the database but the parameter is out-of-scope.
826 |
# File 'lib/udb/obj/portfolio.rb', line 826 def all_in_scope_exts_without_param(param) = [] |
#all_in_scope_params ⇒ Array<InScopeParameter>
Returns List of parameters specified by any extension in portfolio.
805 |
# File 'lib/udb/obj/portfolio.rb', line 805 def all_in_scope_params = [] |
#all_out_of_scope_params ⇒ Array<Parameter>
Returns Sorted list of parameters out of scope across all in scope extensions.
812 |
# File 'lib/udb/obj/portfolio.rb', line 812 def all_out_of_scope_params = [] |
#base ⇒ Integer
Returns 32 or 64.
391 |
# File 'lib/udb/obj/portfolio.rb', line 391 def base = @data["base"] |
#csr_presence(csr_name) ⇒ String
Returns Given an CSR csr_name, return the presence as a string. If the CSR name isn’t found in the portfolio, return “-”.
581 582 583 584 585 586 587 588 589 |
# File 'lib/udb/obj/portfolio.rb', line 581 def csr_presence(csr_name) @csr_presence ||= {} return @csr_presence[csr_name] unless @csr_presence[csr_name].nil? presence_obj = csr_presence_obj(csr_name) @csr_presence[csr_name] = presence_obj.nil? ? "-" : presence_obj.to_s end |
#csr_presence_obj(csr_name) ⇒ Presence
Returns Given an CSR csr_name, return the presence. If the CSR name isn’t found in the portfolio, return nil.
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 |
# File 'lib/udb/obj/portfolio.rb', line 552 def csr_presence_obj(csr_name) @csr_presence_obj ||= {} return @csr_presence_obj[csr_name] unless @csr_presence_obj[csr_name].nil? csr = arch.csr(csr_name) raise "Can't find CSR object '#{csr_name}' in arch class" if csr.nil? is_mandatory = mandatory_ext_reqs.any? do |ext_req| csr.defined_by_condition.satisfied_by_cfg_arch?(to_cfg_arch) == SatisfiedResult::Yes end is_optional = !is_mandatory && optional_ext_reqs.any? do |ext_req| csr.defined_by_condition.satisfied_by_cfg_arch?(to_cfg_arch_for_optional) == SatisfiedResult::Yes end @csr_presence_obj[csr_name] = if is_mandatory Presence::Mandatory elsif is_optional Presence::Option else nil end end |
#description ⇒ String
Returns Large enough to need its own heading (generally one level deeper than the “introduction”).
388 |
# File 'lib/udb/obj/portfolio.rb', line 388 def description = @data["description"] |
#extension_note(ext_name) ⇒ String?
618 619 620 621 622 623 624 |
# File 'lib/udb/obj/portfolio.rb', line 618 def extension_note(ext_name) # Get extension information from YAML for passed in extension name. ext_data = @data["extensions"][ext_name] raise "Cannot find extension named #{ext_name}" if ext_data.nil? return ext_data["note"] unless ext_data.nil? end |
#extension_presence(ext_name) ⇒ String
Returns Given an extension ext_name, return the presence as a string. If the extension name isn’t found in the portfolio, return “-”.
407 408 409 410 411 |
# File 'lib/udb/obj/portfolio.rb', line 407 def extension_presence(ext_name) presence_obj = extension_presence_obj(ext_name) presence_obj.nil? ? "-" : presence_obj.to_s end |
#extension_presence_obj(ext_name) ⇒ Presence
Returns Given an extension ext_name, return the presence. If the extension name isn’t found in the portfolio, return nil.
398 399 400 401 402 403 |
# File 'lib/udb/obj/portfolio.rb', line 398 def extension_presence_obj(ext_name) # Get extension information from YAML for passed in extension name. ext_data = @data["extensions"][ext_name] ext_data.nil? ? nil : Presence.from_yaml(ext_data["presence"]) end |
#extra_notes ⇒ Object
928 929 930 931 932 933 934 935 936 |
# File 'lib/udb/obj/portfolio.rb', line 928 def extra_notes return @extra_notes unless @extra_notes.nil? @extra_notes = [] @data["extra_notes"]&.each do |extra_note| @extra_notes << ExtraNote.new(extra_note) end @extra_notes end |
#extra_notes_for_presence(desired_presence_obj) ⇒ Array<String>
939 940 941 942 943 944 945 946 947 |
# File 'lib/udb/obj/portfolio.rb', line 939 def extra_notes_for_presence(desired_presence_obj) extra_notes.select do |extra_note| if desired_presence_obj == Presence::Mandatory extra_note.presence_obj == desired_presence_obj else extra_note.presence_obj != Presence::Mandatory end end end |
#in_scope_csrs(design) ⇒ Array<Csr>
Returns Unsorted list of all CSRs associated with extensions listed as mandatory or optional in portfolio. Uses CSRs provided by the minimum version of the extension that meets the extension requirement.
737 738 739 740 741 742 743 744 |
# File 'lib/udb/obj/portfolio.rb', line 737 def in_scope_csrs(design) raise ArgumentError, "Require an PortfolioDesign object but got a #{design.class} object" unless design.is_a?(PortfolioDesign) return @in_scope_csrs unless @in_scope_csrs.nil? @in_scope_csrs = .map { |ext_ver| ext_ver.in_scope_csrs(design) }.flatten.uniq end |
#in_scope_exception_codes(design) ⇒ Array<ExceptionCode>
TODO: See github.com/riscv-software-src/riscv-unified-db/issues/291 TODO: Still needs work and haven’t created in_scope_interrupt_codes yet. TODO: Extensions should provide conditional information (“when” statements?)
that we evaluate here to determine if a particular exception code can
actually be generated in a design.
Also, probably shouldn't be calling "ext?" since that doesn't the in_scope lists of extensions.
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 |
# File 'lib/udb/obj/portfolio.rb', line 754 def in_scope_exception_codes(design) raise ArgumentError, "Require an PortfolioDesign object but got a #{design.class} object" unless design.is_a?(PortfolioDesign) return @in_scope_exception_codes unless @in_scope_exception_codes.nil? @in_scope_exception_codes = .reduce([]) do |list, ext_version| ecodes = ext_version.exception_codes next list if ecodes.nil? ecodes.each do |ecode| list << ecode end list end.uniq end |
#in_scope_ext_reqs(desired_presence = nil) ⇒ Array<PortfolioExtensionRequirement>
635 636 637 638 639 640 641 642 643 644 645 646 647 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 |
# File 'lib/udb/obj/portfolio.rb', line 635 def in_scope_ext_reqs(desired_presence = nil) in_scope_ext_reqs = [] # Convert desired_present argument to Presence object if not nil. desired_presence_converted = if desired_presence.nil? nil else desired_presence.is_a?(Presence) ? desired_presence : Presence.from_yaml(desired_presence) end missing_ext = T.let(false, T::Boolean) @data["extensions"]&.each do |ext_name, ext_data| next if ext_name[0] == "$" # Does extension even exist? # If not, don't raise an error right away so we can find all of the missing extensions and report them all. ext = arch.extension(ext_name) if ext.nil? Udb.logger.warn "Extension #{ext_name} for #{name} not found in database" missing_ext = true else actual_presence = ext_data["presence"] # Could be a String or Hash raise "Missing extension presence for extension #{ext_name}" if actual_presence.nil? # Convert presence String or Hash to object. actual_presence_obj = Presence.from_yaml(actual_presence) match = if desired_presence.nil? true # Always match else if desired_presence_converted == Presence::Mandatory actual_presence_obj == Presence::Mandatory else # treat all optional types as equal actual_presence_obj != Presence::Mandatory end end if match in_scope_ext_reqs << if ext_data.key?("version") PortfolioExtensionRequirement.new( ext_name, ext_data["version"], arch: @arch, presence: actual_presence_obj, note: ext_data["note"], req_id: "REQ-EXT-#{ext_name}") else PortfolioExtensionRequirement.new( ext_name, ">= 0", arch: @arch, presence: actual_presence_obj, note: ext_data["note"], req_id: "REQ-EXT-#{ext_name}") end end end end raise "One or more extensions referenced by #{name} missing in database" if missing_ext in_scope_ext_reqs.sort_by!(&:name) end |
#in_scope_extensions ⇒ Array<Extension>
Returns Sorted list of all mandatory or optional extensions in portfolio. Each extension can have multiple versions (contains ExtensionVersion array).
698 699 700 701 702 703 704 705 706 |
# File 'lib/udb/obj/portfolio.rb', line 698 def in_scope_extensions return @in_scope_extensions unless @in_scope_extensions.nil? @in_scope_extensions = in_scope_ext_reqs.map do |ext_req| ext_req.extension end.reject(&:nil?) # Filter out extensions that don't exist yet. @in_scope_extensions.sort_by!(&:name) end |
#in_scope_instructions(design) ⇒ Array<Instruction>
Returns Sorted list of all instructions associated with extensions listed as mandatory or optional in portfolio. Uses instructions provided by the minimum version of the extension that meets the extension requirement.
724 725 726 727 728 729 730 731 |
# File 'lib/udb/obj/portfolio.rb', line 724 def in_scope_instructions(design) raise ArgumentError, "Require an PortfolioDesign object but got a #{design.class} object" unless design.is_a?(PortfolioDesign) return @in_scope_instructions unless @in_scope_instructions.nil? @in_scope_instructions = .map { |ext_ver| ext_ver.in_scope_instructions(design) }.flatten.uniq.sort end |
#in_scope_interrupt_codes(design) ⇒ Array<InterruptCode>
TODO: Actually implement this to use Design. See in_scope_exception_codes() above.
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 |
# File 'lib/udb/obj/portfolio.rb', line 774 def in_scope_interrupt_codes(design) raise ArgumentError, "Require an PortfolioDesign object but got a #{design.class} object" unless design.is_a?(PortfolioDesign) return @in_scope_interrupt_codes unless @in_scope_interrupt_codes.nil? @in_scope_interrupt_codes = .reduce([]) do |list, ext_version| icodes = ext_version.interrupt_codes next list if icodes.nil? icodes.each do |icode| list << icode end list end.uniq end |
#in_scope_min_satisfying_extension_versions ⇒ ExtensionVersion
Returns List of all mandatory or optional extensions listed in portfolio. The minimum version of each extension that satisfies the extension requirements is provided.
710 711 712 713 714 715 716 717 718 |
# File 'lib/udb/obj/portfolio.rb', line 710 def return @in_scope_min_satisfying_extension_versions unless @in_scope_min_satisfying_extension_versions.nil? @in_scope_min_satisfying_extension_versions = in_scope_ext_reqs.map do |ext_req| ext_req..min end.reject(&:nil?) # Filter out extensions that don't exist yet. @in_scope_min_satisfying_extension_versions end |
#in_scope_params(ext_req) ⇒ Array<InScopeParameter>
Returns Sorted list of extension parameters from portfolio for given extension.
809 |
# File 'lib/udb/obj/portfolio.rb', line 809 def in_scope_params(ext_req) = [] |
#instruction_presence(inst_name) ⇒ Presence?
Returns Given an instruction inst_name, return the presence as a string. If the instruction name isn’t found in the portfolio, return “-”.
540 541 542 543 544 545 546 547 548 |
# File 'lib/udb/obj/portfolio.rb', line 540 def instruction_presence(inst_name) @instruction_presence ||= {} return @instruction_presence[inst_name] unless @instruction_presence[inst_name].nil? presence_obj = instruction_presence_obj(inst_name) @instruction_presence[inst_name] = presence_obj.nil? ? "-" : presence_obj.to_s end |
#instruction_presence_obj(inst_name) ⇒ Presence?
Returns Given an instruction inst_name, return the presence. If the instruction name isn’t found in the portfolio, return nil.
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 |
# File 'lib/udb/obj/portfolio.rb', line 416 def instruction_presence_obj(inst_name) @instruction_presence_obj ||= {} return @instruction_presence_obj[inst_name] unless @instruction_presence_obj[inst_name].nil? inst = arch.instruction(inst_name) raise "Can't find instruction object '#{inst_name}' in arch class" if inst.nil? is_mandatory = mandatory_ext_reqs.any? do |ext_req| inst.defined_by_condition.satisfied_by_cfg_arch?(to_cfg_arch) == SatisfiedResult::Yes end is_optional = !is_mandatory && optional_ext_reqs.any? do |ext_req| inst.defined_by_condition.satisfied_by_cfg_arch?(to_cfg_arch_for_optional) == SatisfiedResult::Yes end @instruction_presence_obj[inst_name] = if is_mandatory Presence::Mandatory elsif is_optional Presence::Option else nil end end |
#introduction ⇒ String
Returns Small enough (~1 paragraph) to be suitable immediately after a higher-level heading.
385 |
# File 'lib/udb/obj/portfolio.rb', line 385 def introduction = @data["introduction"] |
#mandatory_ext_reqs ⇒ Object
626 |
# File 'lib/udb/obj/portfolio.rb', line 626 def mandatory_ext_reqs = in_scope_ext_reqs(Presence::Mandatory) |
#optional_ext_reqs ⇒ Object
627 |
# File 'lib/udb/obj/portfolio.rb', line 627 def optional_ext_reqs = in_scope_ext_reqs(Presence::Option) |
#out_of_scope_params(ext_name) ⇒ Array<Parameter>
Returns Sorted list of parameters that are out of scope for named extension.
816 |
# File 'lib/udb/obj/portfolio.rb', line 816 def out_of_scope_params(ext_name) = [] |
#recommendations ⇒ Object
961 962 963 964 965 966 967 968 969 |
# File 'lib/udb/obj/portfolio.rb', line 961 def recommendations return @recommendations unless @recommendations.nil? @recommendations = [] @data["recommendations"]&.each do |recommendation| @recommendations << Recommendation.new(recommendation) end @recommendations end |
#revision_history ⇒ Object
903 904 905 906 907 908 909 910 911 |
# File 'lib/udb/obj/portfolio.rb', line 903 def revision_history return @revision_history unless @revision_history.nil? @revision_history = [] @data["revision_history"].each do |rev| @revision_history << RevisionHistory.new(rev) end @revision_history end |
#to_cfg_arch ⇒ ConfiguredArchitecture
returns a config arch that treats the Portfolio like a partial config
486 487 488 489 490 491 492 493 494 495 |
# File 'lib/udb/obj/portfolio.rb', line 486 def to_cfg_arch @cfg_arch_for_mandatory ||= begin Tempfile.create do |f| f.write YAML.dump(to_config) f.fsync @cfg_arch.config.info.resolver.cfg_arch_for(Pathname.new f.path) end end end |
#to_cfg_arch_for_optional ⇒ ConfiguredArchitecture
returns a config arch that treats the optional extensions in Portfolio like a partial config
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
# File 'lib/udb/obj/portfolio.rb', line 499 def to_cfg_arch_for_optional @cfg_arch_for_optional ||= begin contents = { "$schema" => "config_schema.json#", "kind" => "architecture configuration", "type" => "partially configured", "name" => name, "description" => description, "params" => all_in_scope_params.map do |p| if p.single_value? [p.name, p.value] else nil end end.compact.to_h, "mandatory_extensions" => optional_ext_reqs.map do |ext_req| { "name" => ext_req.name, "version" => \ if ext_req.requirement_specs.size == 1 ext_req.requirement_specs.fetch(0).to_s else ext_req.requirement_specs.map(&:to_s) end } end, "additional_extensions" => true } Tempfile.create do |f| f.write YAML.dump(contents) f.fsync @cfg_arch.config.info.resolver.cfg_arch_for(Pathname.new f.path) end end end |
#to_config ⇒ Hash{String => T.untyped}
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 |
# File 'lib/udb/obj/portfolio.rb', line 444 def to_config { "$schema" => "config_schema.json#", "kind" => "architecture configuration", "type" => "partially configured", "name" => name, "description" => description, "params" => all_in_scope_params.map do |p| if p.single_value? [p.name, p.value] else nil end end.compact.to_h, "mandatory_extensions" => mandatory_ext_reqs.map do |ext_req| { "name" => ext_req.name, "version" => \ if ext_req.requirement_specs.size == 1 ext_req.requirement_specs.fetch(0).to_s else ext_req.requirement_specs.map(&:to_s) end } end, "non_mandatory_extensions" => optional_ext_reqs.map do |ext_req| { "name" => ext_req.name, "version" => \ if ext_req.requirement_specs.size == 1 ext_req.requirement_specs.fetch(0).to_s else ext_req.requirement_specs.map(&:to_s) end } end, "additional_extensions" => true } end |
#uses_optional_types? ⇒ Boolean
Returns Does the profile differentiate between different types of optional.
792 793 794 795 796 797 |
# File 'lib/udb/obj/portfolio.rb', line 792 def uses_optional_types? return @uses_optional_types unless @uses_optional_types.nil? @uses_optional_types = in_scope_ext_reqs(Presence::Option).any? { |ext_req| ext_req.presence != Presence::Option } end |
#version ⇒ Gem::Version
Returns Semantic version of the Portfolio.
394 |
# File 'lib/udb/obj/portfolio.rb', line 394 def version = Gem::Version.new(@data["version"]) |
#version_greatest_presence(ext_name, ext_versions) ⇒ Array<String>
Returns the greatest presence string for each of the specified versions.
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'lib/udb/obj/portfolio.rb', line 593 def version_greatest_presence(ext_name, ext_versions) presences = [] # See if any extension requirement in this profile lists this version as either mandatory or optional. ext_versions.map do |v| greatest_presence = T.let(nil, T.nilable(Presence)) in_scope_ext_reqs.each do |ext_req| if ext_req.satisfied_by?(v) presence = extension_presence_obj(ext_name) unless presence.nil? greatest_presence = presence unless greatest_presence == Presence::Mandatory end end end presences << (greatest_presence.nil? ? "-" : greatest_presence.to_s_concise) end presences end |