Skip to content

Commit

Permalink
Merge pull request #104 from riscv-software-src/manual_appendices
Browse files Browse the repository at this point in the history
Fix broken manual generation, ensure it's tested in regression
  • Loading branch information
dhower-qc authored Oct 17, 2024
2 parents 70b9359 + 8a13108 commit ce35896
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ DESC
task :regress do
Rake::Task["idl_test"].invoke
Rake::Task["validate"].invoke
ENV["MANUAL_NAME"] = "isa"
ENV["VERSIONS"] = "all"
Rake::Task["gen:html_manual"].invoke
Rake::Task["gen:html"].invoke("generic_rv64")
Rake::Task["gen:crd_pdf"].invoke("MockCRD-1")
Rake::Task["gen:crd_pdf"].invoke("MC-1")
Expand Down
50 changes: 28 additions & 22 deletions backends/arch_gen/lib/arch_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,33 +129,39 @@ def ext?(name)

# checks any "extra_validation" given by parameter definitions
def params_extra_validation
fork do
# add parameters as a constant
params.each do |key, value|
self.class.const_set(key, value)
end

@implemented_extensions.each do |ext|
ext_name = ext["name"]
gen_ext_path = @gen_dir / "arch" / "ext" / "#{ext_name}.yaml"
ext_yaml = YAML.safe_load gen_ext_path.read
unless ext_yaml[ext_name]["params"].nil?
ext_yaml[ext_name]["params"].each do |param_name, param_data|
next unless param_data.key?("extra_validation")
begin
eval param_data["extra_validation"]
rescue StandardError => e
warn "While checking extension parameter #{ext_name}::#{param_name}.extra_validation"
warn param_data["extra_validation"]
warn e
exit 1
end
agen = self

eval_context = Class.new do
end

eval_context.class.define_method(:ext?) { |name| agen.send(:ext?, name) }
eval_context.class.define_method(:assert) { |cond| agen.send(:assert, cond) }

# add parameters as a constant
params.each do |key, value|
eval_context.const_set(key, value)
end


@implemented_extensions.each do |ext|
ext_name = ext["name"]
gen_ext_path = @gen_dir / "arch" / "ext" / "#{ext_name}.yaml"
ext_yaml = YAML.safe_load gen_ext_path.read
unless ext_yaml[ext_name]["params"].nil?
ext_yaml[ext_name]["params"].each do |param_name, param_data|
next unless param_data.key?("extra_validation")
begin
eval_context.class_eval param_data["extra_validation"]
rescue StandardError => e
warn "While checking extension parameter #{ext_name}::#{param_name}.extra_validation"
warn param_data["extra_validation"]
warn e
exit 1
end
end
end
end
Process.wait
exit 1 unless $CHILD_STATUS.success?
end
private :params_extra_validation

Expand Down
4 changes: 2 additions & 2 deletions backends/manual/templates/ext.adoc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ This extension has the following implementation options:
+
--
|===
h| Type | <%= param.schema["type"] %>
h| Valid Values | <%= Schema.new(param.schema).to_pretty_s %>
h| Type | <%= param.schema.type_pretty %>
h| Valid Values | <%= param.schema.to_pretty_s %>
h| Description a| <%= param.desc %>
|===
--
Expand Down
5 changes: 5 additions & 0 deletions lib/arch_obj_models/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def initialize(schema_hash)
# @return [Hash] Hash representation of the JSON Schema
def to_h = @schema_hash

# @return [String] Human-readable type of the schema (e.g., array, string, integer)
def type_pretty
@schema_hash["type"]
end

# @return [String] A human-readable description of the schema
def to_pretty_s(schema_hash = @schema_hash)
raise ArgumentError, "Expecting hash" unless schema_hash.is_a?(Hash)
Expand Down

0 comments on commit ce35896

Please sign in to comment.