From 4b92f6f71bafb1051321dc3d8a8effa652fb3d87 Mon Sep 17 00:00:00 2001 From: Derek Hower <134728312+dhower-qc@users.noreply.github.com> Date: Mon, 11 Nov 2024 17:41:59 +0000 Subject: [PATCH] Rename $mref -> $inherits --- .../MockCertificateModel.yaml | 2 +- arch/inst/I/addi.yaml | 2 +- arch/profile_release/MockProfileRelease.yaml | 2 +- arch/profile_release/RVA20.yaml | 2 +- arch/profile_release/RVA22.yaml | 4 +- arch/profile_release/RVI20.yaml | 2 +- lib/test/test_yaml_loader.rb | 58 +++++++++---------- lib/yaml_loader.rb | 34 +++++------ schemas/inst_schema.json | 2 +- 9 files changed, 54 insertions(+), 54 deletions(-) diff --git a/arch/certificate_model/MockCertificateModel.yaml b/arch/certificate_model/MockCertificateModel.yaml index bb9ef120d3..f97dddf570 100644 --- a/arch/certificate_model/MockCertificateModel.yaml +++ b/arch/certificate_model/MockCertificateModel.yaml @@ -38,7 +38,7 @@ MockCertificateModel: # XXX - Remove version information since specifying priv/unpriv ISA manual should imply this. extensions: - $mref: + $inherits: - "../profile_release/MockProfileRelease.yaml#/MockProfileRelease/profiles/MP-U-64/extensions" - "../profile_release/MockProfileRelease.yaml#/MockProfileRelease/profiles/MP-S-64/extensions" I: diff --git a/arch/inst/I/addi.yaml b/arch/inst/I/addi.yaml index e27fb90f92..5c105c3a1f 100644 --- a/arch/inst/I/addi.yaml +++ b/arch/inst/I/addi.yaml @@ -9,7 +9,7 @@ addi: match: -----------------000-----0010011 variables: - name: imm - $mref: ../../common/inst_variable_types.yaml#/itype_imm + $inherits: ../../common/inst_variable_types.yaml#/itype_imm - name: rs1 location: 19-15 - name: rd diff --git a/arch/profile_release/MockProfileRelease.yaml b/arch/profile_release/MockProfileRelease.yaml index 0b1ed4d5f9..636e2f410c 100644 --- a/arch/profile_release/MockProfileRelease.yaml +++ b/arch/profile_release/MockProfileRelease.yaml @@ -42,7 +42,7 @@ MockProfileRelease: email: micky@disney.com company: Disney extensions: - $mref: "#/MockProfileRelease/profiles/MP-U-64/extensions" + $inherits: "#/MockProfileRelease/profiles/MP-U-64/extensions" A: presence: mandatory S: diff --git a/arch/profile_release/RVA20.yaml b/arch/profile_release/RVA20.yaml index b1d8770949..195f603c63 100644 --- a/arch/profile_release/RVA20.yaml +++ b/arch/profile_release/RVA20.yaml @@ -43,7 +43,7 @@ RVA20: most important profile within application processors in terms of the amount of software that targets this profile. extensions: - $mref: "RVI20.yaml#/RVI20/profiles/RVI20U64/extensions" + $inherits: "RVI20.yaml#/RVI20/profiles/RVI20U64/extensions" $remove: Zifencei # Not allowed as an option for Unpriv ISA (only available in Priv ISA). A: presence: mandatory diff --git a/arch/profile_release/RVA22.yaml b/arch/profile_release/RVA22.yaml index 556bf8abf1..c564c915b3 100644 --- a/arch/profile_release/RVA22.yaml +++ b/arch/profile_release/RVA22.yaml @@ -43,7 +43,7 @@ RVA22: most important profile within application processors in terms of the amount of software that targets this profile. extensions: - $mref: "RVA20.yaml#/RVA20/profiles/RVA20U64/extensions" + $inherits: "RVA20.yaml#/RVA20/profiles/RVA20U64/extensions" Zihpm: presence: mandatory version: "= 2.0" @@ -167,7 +167,7 @@ RVA22: processors. RVA22S64 is based on privileged architecture version 1.12. extensions: - $mref: "RVA20.yaml#/RVA20/profiles/RVA20S64/extensions" + $inherits: "RVA20.yaml#/RVA20/profiles/RVA20S64/extensions" S: presence: mandatory version: "= 1.12" diff --git a/arch/profile_release/RVI20.yaml b/arch/profile_release/RVI20.yaml index 74538c7f9b..759619caee 100644 --- a/arch/profile_release/RVI20.yaml +++ b/arch/profile_release/RVI20.yaml @@ -84,6 +84,6 @@ RVI20: Implementations are strongly recommended to raise illegal-instruction exceptions on attempts to execute unimplemented opcodes. RVI20U64: - $mref: "#/RVI20/profiles/RVI20U32" + $inherits: "#/RVI20/profiles/RVI20U32" base: 64 marketing_name: RVI20U64 \ No newline at end of file diff --git a/lib/test/test_yaml_loader.rb b/lib/test/test_yaml_loader.rb index 06222acc24..6471eea95b 100644 --- a/lib/test/test_yaml_loader.rb +++ b/lib/test/test_yaml_loader.rb @@ -15,7 +15,7 @@ def test_remove key2: value2 child: - $mref: "#/base" + $inherits: "#/base" $remove: key2 key3: value3 YAML @@ -36,7 +36,7 @@ def test_multiple_remove key3: value3 child: - $mref: "#/base" + $inherits: "#/base" $remove: - key2 - key3 @@ -51,7 +51,7 @@ def test_multiple_remove assert_equal({ "key1" => "value1", "key4" => "value4" }, doc["child"]) end - def test_that_mref_with_nested_replace_works + def test_that_inherits_with_nested_replace_works yaml = <<~YAML base: key1: @@ -59,12 +59,12 @@ def test_that_mref_with_nested_replace_works key2: value2 middle: - $mref: "#/base" + $inherits: "#/base" key3: value3 key4: value4 bottom: - $mref: + $inherits: - "#/base" - "#/middle" key1: @@ -82,19 +82,19 @@ def test_that_mref_with_nested_replace_works assert_equal({ "key1" => {"sub_key1" => "value1", "sub_key6" => "value6"}, "key2" => "value2_new", "key3" => "value3", "key4" => "value4_new", "key5" => "value5" }, doc["bottom"]) end - def test_that_spurious_recursive_mref_works + def test_that_spurious_recursive_inherits_works yaml = <<~YAML base: key1: value1 key2: value2 middle: - $mref: "#/base" + $inherits: "#/base" key3: value3 key4: value4 bottom: - $mref: + $inherits: - "#/base" - "#/middle" key2: value2_new @@ -111,19 +111,19 @@ def test_that_spurious_recursive_mref_works assert_equal({ "key1" => "value1", "key2" => "value2_new", "key3" => "value3", "key4" => "value4_new", "key5" => "value5" }, doc["bottom"]) end - def test_that_recursive_mref_works + def test_that_recursive_inherits_works yaml = <<~YAML base: key1: value1 key2: value2 middle: - $mref: "#/base" + $inherits: "#/base" key3: value3 key4: value4 bottom: - $mref: "#/middle" + $inherits: "#/middle" key2: value2_new key4: value4_new key5: value5 @@ -138,7 +138,7 @@ def test_that_recursive_mref_works assert_equal({ "key1" => "value1", "key2" => "value2_new", "key3" => "value3", "key4" => "value4_new", "key5" => "value5" }, doc["bottom"]) end - def test_that_nested_mref_works + def test_that_nested_inherits_works yaml = <<~YAML top: base: @@ -148,7 +148,7 @@ def test_that_nested_mref_works bottom: child: - $mref: "#/top/base" + $inherits: "#/top/base" key3: value3_new YAML @@ -160,7 +160,7 @@ def test_that_nested_mref_works assert_equal({ "key1" => "value1", "key2" => "value2", "key3" => "value3_new" }, doc["bottom"]["child"]) end - def test_that_mref_doesnt_delete_keys + def test_that_inherits_doesnt_delete_keys yaml = <<~YAML base: key1: value1 @@ -168,7 +168,7 @@ def test_that_mref_doesnt_delete_keys key3: value3 child: - $mref: "#/base" + $inherits: "#/base" key3: value3_new YAML @@ -180,7 +180,7 @@ def test_that_mref_doesnt_delete_keys assert_equal({ "key1" => "value1", "key2" => "value2", "key3" => "value3_new" }, doc["child"]) end - def test_that_double_mref_doesnt_delete_keys + def test_that_double_inherits_doesnt_delete_keys yaml = <<~YAML base1: key1: value1 @@ -193,7 +193,7 @@ def test_that_double_mref_doesnt_delete_keys key6: value6 child: - $mref: + $inherits: - "#/base1" - "#/base2" key3: value3_new @@ -274,7 +274,7 @@ def test_refs_in_the_different_document assert_equal({ "a" => "hash" }, doc["obj3"]) end - def test_mrefs_in_the_same_document + def test_inheritss_in_the_same_document yaml = <<~YAML $defs: target1: A string @@ -282,15 +282,15 @@ def test_mrefs_in_the_same_document a: hash obj1: - $mref: "#/$defs/target2" + $inherits: "#/$defs/target2" obj2: - $mref: "#/$defs/target2" + $inherits: "#/$defs/target2" a: Should take precedence obj3: a: Should take precedence - $mref: "#/$defs/target2" + $inherits: "#/$defs/target2" YAML @@ -304,7 +304,7 @@ def test_mrefs_in_the_same_document assert_equal({ "a" => "Should take precedence" }, doc["obj3"]) end - def test_mrefs_in_the_different_document + def test_inheritss_in_the_different_document yaml1 = <<~YAML $defs: target1: A string @@ -319,15 +319,15 @@ def test_mrefs_in_the_different_document yaml2 = <<~YAML obj1: - $mref: "#{f1_path.basename}#/$defs/target2" + $inherits: "#{f1_path.basename}#/$defs/target2" obj2: - $mref: "#{f1_path.basename}#/$defs/target2" + $inherits: "#{f1_path.basename}#/$defs/target2" a: Should take precedence obj3: a: Should take precedence - $mref: "#{f1_path.basename}#/$defs/target2" + $inherits: "#{f1_path.basename}#/$defs/target2" YAML f2 = Tempfile.new("yml") @@ -340,7 +340,7 @@ def test_mrefs_in_the_different_document assert_equal({ "a" => "Should take precedence" }, doc["obj3"]) end - def test_multi_mrefs_in_the_same_document + def test_multi_inheritss_in_the_same_document yaml = <<~YAML $defs: target1: @@ -349,7 +349,7 @@ def test_multi_mrefs_in_the_same_document a: hash obj1: - $mref: + $inherits: - "#/$defs/target1" - "#/$defs/target2" @@ -363,7 +363,7 @@ def test_multi_mrefs_in_the_same_document assert_equal({ "a" => "hash", "b" => "nice" }, doc["obj1"]) end - def test_that_invalid_mrefs_raise + def test_that_invalid_inheritss_raise yaml = <<~YAML $defs: target1: @@ -372,7 +372,7 @@ def test_that_invalid_mrefs_raise a: hash obj1: - $mref: "#/path/to/nowwhere" + $inherits: "#/path/to/nowwhere" YAML diff --git a/lib/yaml_loader.rb b/lib/yaml_loader.rb index 1c7166ce1d..f080234c4b 100644 --- a/lib/yaml_loader.rb +++ b/lib/yaml_loader.rb @@ -3,7 +3,7 @@ require "pathname" require "yaml" -# loads a YAML file and expands any $ref/$mref references +# loads a YAML file and expands any $ref/$inherits references class YamlLoader @cache = {} @@ -46,16 +46,16 @@ def self.expand(filename, obj, yaml_opts = {}) ref end - elsif obj.keys.include?("$mref") - # we handle the mref key first so that any override will take priority - mref = obj["$mref"] - raise ArgumentError, "Missing reference after $mref (did you forget to put a relative reference in quotes?)" if mref.nil? - mref_targets = mref.is_a?(String) ? [mref] : mref + elsif obj.keys.include?("$inherits") + # we handle the inherits key first so that any override will take priority + inherits = obj["$inherits"] + raise ArgumentError, "Missing reference after $inherits (did you forget to put a relative reference in quotes?)" if inherits.nil? + inherits_targets = inherits.is_a?(String) ? [inherits] : inherits new_obj = {} - mref_targets.each do |mref_target| - relative_path = mref_target.split("#")[0] + inherits_targets.each do |inherits_target| + relative_path = inherits_target.split("#")[0] target_obj = if relative_path.empty? YAML.load_file(filename, **yaml_opts) @@ -63,25 +63,25 @@ def self.expand(filename, obj, yaml_opts = {}) target_filename = File.realpath(File.join(filename.dirname, relative_path)) unless File.exist?(target_filename) - raise DereferenceError, "While locating $mref in #{filename}, #{target_filename} does not exist" + raise DereferenceError, "While locating $inherits in #{filename}, #{target_filename} does not exist" end YamlLoader.load(target_filename, yaml_opts) end - mref_target_suffix = mref_target.split("#/")[1] - mref_target_path = mref_target_suffix.split("/") + inherits_target_suffix = inherits_target.split("#/")[1] + inherits_target_path = inherits_target_suffix.split("/") begin - target_obj = target_obj.dig(*mref_target_path) + target_obj = target_obj.dig(*inherits_target_path) rescue TypeError => e if e.message == "no implicit conversion of String into Integer" - warn "$mref: \"#{mref_target}\" found in file #{filename} references an Array but needs to reference a Hash" + warn "$inherits: \"#{inherits_target}\" found in file #{filename} references an Array but needs to reference a Hash" end raise e end - raise DereferenceError, "JSON Path #{mref_target_suffix} in file #{filename} does not exist in #{relative_path}" if target_obj.nil? - raise ArgumentError, "$mref: \"#{mref_target}\" in file #{filename} references a #{target_obj.class} but needs to reference a Hash" unless target_obj.is_a?(Hash) + raise DereferenceError, "JSON Path #{inherits_target_suffix} in file #{filename} does not exist in #{relative_path}" if target_obj.nil? + raise ArgumentError, "$inherits: \"#{inherits_target}\" in file #{filename} references a #{target_obj.class} but needs to reference a Hash" unless target_obj.is_a?(Hash) target_obj = expand(filename, target_obj, yaml_opts) target_obj.each do |target_key, target_value| @@ -94,7 +94,7 @@ def self.expand(filename, obj, yaml_opts = {}) end end - obj.delete("$mref") + obj.delete("$inherits") # now merge target_obj and obj keys = (obj.keys + new_obj.keys).uniq final_obj = {} @@ -138,7 +138,7 @@ def self.expand(filename, obj, yaml_opts = {}) new_obj end - # load a YAML file and expand any $ref/$mref references + # load a YAML file and expand any $ref/$inherits references # @param filename [String,Pathname] path to the YAML file # @param yaml_opts [Hash] options to pass to YAML.load_file # @return [Object] the loaded YAML file diff --git a/schemas/inst_schema.json b/schemas/inst_schema.json index 976586db94..9d88295fc9 100644 --- a/schemas/inst_schema.json +++ b/schemas/inst_schema.json @@ -62,7 +62,7 @@ "name": { "type": "string" }, - "$mref": { + "$inherits": { "type": "string", "pattern": "^(\\.\\./)+common/inst_variable_types\\.yaml#/[a-zA-Z0-9_]+", "description": "Reference to variable metadata"