Skip to content

Commit 3f2695d

Browse files
authored
Merge pull request #286 from riscv-software-src/ref_resolve
Add ref() to arch_def
2 parents 5e6c568 + 34f6f87 commit 3f2695d

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

lib/arch_def.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,57 @@ def data
856856
@arch_def
857857
end
858858

859+
# given a `$ref` target, return the Ruby object
860+
#
861+
# @params uri [String] JSON Reference pointer
862+
# @return [Object] The pointed-to object
863+
def ref(uri)
864+
raise ArgumentError, "JSON Reference must contain one '#'" unless uri.count("#") == 1
865+
866+
file_path, obj_path = uri.split("#")
867+
obj =
868+
case file_path
869+
when /^certificate_class.*/
870+
cert_class_name = File.basename(file_path, ".yaml")
871+
cert_class(cert_class_name)
872+
when /^certificate_model.*/
873+
cert_mode_name = File.basename(file_path, ".yaml")
874+
cert_model(cert_model_name)
875+
when /^csr.*/
876+
csr_name = File.basename(file_path, ".yaml")
877+
csr(csr_name)
878+
when /^ext.*/
879+
ext_name = File.basename(file_path, ".yaml")
880+
extension(ext_name)
881+
when /^inst.*/
882+
inst_name = File.basename(file_path, ".yaml")
883+
instruction(inst_name)
884+
when /^manual.*/
885+
manual_name = File.basename(file_path, ".yaml")
886+
manual(manual_name)
887+
when /^profile_class.*/
888+
profile_class_name = File.basename(file_path, ".yaml")
889+
profile_class(profile_class_name)
890+
when /^profile_release.*/
891+
profile_release_name = File.basename(file_path, ".yaml")
892+
profile_release(profile_release_name)
893+
else
894+
raise "Unhandled ref object: #{file_path}"
895+
end
896+
897+
if obj_path.nil?
898+
obj
899+
else
900+
parts = obj_path.split("/")
901+
parts.each do |part|
902+
raise "Error in $ref. There is no method '#{part}' for a #{obj.class.name}" unless obj.respond_to?(part.to_sym)
903+
904+
obj = obj.send(part)
905+
end
906+
obj
907+
end
908+
end
909+
859910
# @return [Array<Csr>] List of all implemented CSRs
860911
def implemented_csrs
861912
return @implemented_csrs unless @implemented_csrs.nil?

lib/arch_obj_models/certificate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def tsc_profile
4848

4949
# @return [CertClass] The certification class that this model belongs to.
5050
def cert_class
51-
cert_class = @arch_def.cert_class(File.basename(@data["class"]['$ref'].split("#")[0], ".yaml"))
51+
cert_class = @arch_def.ref(@data["class"]['$ref'])
5252
raise "No certificate class named '#{@data["class"]}'" if cert_class.nil?
5353

5454
cert_class

0 commit comments

Comments
 (0)