From 516874a5c16cb69a40cfee15390cfe00dd9908aa Mon Sep 17 00:00:00 2001 From: Derek Hower Date: Wed, 16 Oct 2024 08:40:14 -0700 Subject: [PATCH 1/2] Fix broken manual generation, ensure it's tested in regression --- Rakefile | 3 +++ backends/manual/templates/ext.adoc.erb | 4 ++-- lib/arch_obj_models/schema.rb | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 5b5efce73..094e6b1a1 100644 --- a/Rakefile +++ b/Rakefile @@ -269,6 +269,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") diff --git a/backends/manual/templates/ext.adoc.erb b/backends/manual/templates/ext.adoc.erb index 0f02baed4..b7f60fac9 100644 --- a/backends/manual/templates/ext.adoc.erb +++ b/backends/manual/templates/ext.adoc.erb @@ -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 %> |=== -- diff --git a/lib/arch_obj_models/schema.rb b/lib/arch_obj_models/schema.rb index 6c474c799..48f38ebdf 100644 --- a/lib/arch_obj_models/schema.rb +++ b/lib/arch_obj_models/schema.rb @@ -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) From 8a131086b74f32313d6cb28511b36ba221386511 Mon Sep 17 00:00:00 2001 From: Derek Hower Date: Wed, 16 Oct 2024 18:18:47 -0700 Subject: [PATCH 2/2] Avoid fork in param extra_validation --- backends/arch_gen/lib/arch_gen.rb | 50 +++++++++++++++++-------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/backends/arch_gen/lib/arch_gen.rb b/backends/arch_gen/lib/arch_gen.rb index 7baff6b83..bd9a7a3ef 100644 --- a/backends/arch_gen/lib/arch_gen.rb +++ b/backends/arch_gen/lib/arch_gen.rb @@ -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