Skip to content

Commit

Permalink
Merge pull request #111 from riscv-software-src/crd-james
Browse files Browse the repository at this point in the history
Fixing bugs we worked on earlier today.
  • Loading branch information
dhower-qc authored Oct 17, 2024
2 parents ce5a74a + 02c0b93 commit e1e595b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
3 changes: 3 additions & 0 deletions arch/crd/MC-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ MC-1:
# semantic version within the CRD family
version: "1.0"

# XLEN used by rakefile
base: 32

description: |
MC-1 can be though of as a minimal 32-bit RISC-V processor with M-mode support:
Expand Down
5 changes: 4 additions & 1 deletion arch/crd/MockCRD-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ MockCRD-1:

family: MockCRDFamily

# XLEN used by rakefile
base: 64

# semantic version within the CRD family
version: "1.0"

Expand Down Expand Up @@ -124,7 +127,7 @@ MockCRD-1:
const: little
XLEN:
schema:
const: 32
const: 64
CONFIG_PTR_ADDRESS:
schema:
const: 0xdeadbeef
Expand Down
7 changes: 5 additions & 2 deletions backends/crd_doc/tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ Dir.glob("#{$root}/arch/crd/*.yaml") do |f|
crd_name = File.basename(f, ".yaml")
crd_obj = YAML.load_file(f, permitted_classes: [Date])
raise "Ill-formed CRD file #{f}: missing 'family' field" if crd_obj.dig(crd_name, 'family').nil?

base = crd_obj[crd_name]["base"]
raise "Missing CRD base" if base.nil?

file "#{$root}/gen/crd_doc/adoc/#{crd_name}.adoc" => [
"#{$root}/arch/crd/#{crd_name}.yaml",
"#{$root}/arch/crd_family/#{crd_obj[crd_name]['family']}.yaml",
"#{CRD_DOC_DIR}/templates/crd.adoc.erb",
__FILE__,
"#{$root}/.stamps/arch-gen-_64.stamp"
"#{$root}/.stamps/arch-gen-_#{base}.stamp"
] do |t|
# TODO: schema validation
arch_def = arch_def_for("_64")
arch_def = arch_def_for("_#{base}")
crd = arch_def.crd(crd_name)
raise "No CRD defined for #{crd_name}" if crd.nil?

Expand Down
6 changes: 3 additions & 3 deletions backends/crd_doc/templates/crd.adoc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ If the "Allowed Value(s)" is "Any" then any value allowed by the type is accepta
<% if crd.all_in_scope_ext_params.empty? -%>
None
<% else -%>
[cols="4,2,1,1,3"]
[cols="4,2,1,1,2"]
|===
| Parameter | Type | Allowed Value(s) | Extension(s) | Note
Expand Down Expand Up @@ -316,7 +316,7 @@ The following instructions are added by this extension:
<% crd.in_scope_ext_params(ext_req).sort.each do |ext_param| -%>
[[ext-<%= ext_req.name %>-param-<%= ext_param.name %>-def]]
<%= ext_param.name %>::
<%= ext_param.name %> &#8658; <%= ext_param.param_db.schema_type %>::
+
--
<%= ext_param.param_db.desc %>
Expand All @@ -329,7 +329,7 @@ The following instructions are added by this extension:
<% crd.out_of_scope_params(ext_req.name).sort.each do |param_db| -%>
[[ext-<%= ext_req.name %>-param-<%= param_db.name %>-def]]
<%= param_db.name %>::
<%= param_db.name %> &#8658; <%= param_db.schema_type %>::
+
--
<%= param_db.desc %>
Expand Down
13 changes: 3 additions & 10 deletions lib/arch_obj_models/crd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@ def value
end

# @return [String] - # What parameter values are allowed by the CRD.
#
# Old implementation:
# def schema_pretty_crd_merged_with_param_db
# Schema.new(@param_db.schema).merge!(@schema_crd).to_pretty_s
# end
def allowed_values
if (@schema_crd.empty?)
# CRD doesn't add any constraints on parameter's value.
Expand All @@ -236,11 +231,9 @@ def allowed_values
# Create a Schema object just using information in the parameter database.
schema_obj = @param_db.schema

# Merge in constraints imposed by the CRD on the parameter.
schema_obj.merge!(@schema_crd)

# Create string showing allowed values of parameter with CRD constraints added
schema_obj.to_pretty_s
# Merge in constraints imposed by the CRD on the parameter and then
# create string showing allowed values of parameter with CRD constraints added
schema_obj.merge(@schema_crd).to_pretty_s
end

# sorts by name
Expand Down
8 changes: 3 additions & 5 deletions lib/arch_obj_models/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,12 @@ def large2hex(value)
end
end

def merge!(other_schema)
def merge(other_schema)
raise ArgumentError, "Expecting Schema" unless (other_schema.is_a?(Schema) || other_schema.is_a?(Hash))

hash = other_schema.is_a?(Schema) ? other_schema.instance_variable_get(:@schema_hash) : other_schema
other_hash = other_schema.is_a?(Schema) ? other_schema.instance_variable_get(:@schema_hash) : other_schema

@schema_hash.merge!(hash)

self
Schema.new(@schema_hash.merge(other_hash))
end

def empty?
Expand Down

0 comments on commit e1e595b

Please sign in to comment.