Skip to content

Commit f7f8236

Browse files
Remove unneccessary concepts of base from architecture and portfolios (especially rakefiles). Now use cfg "_" instead of rv32 or rv64 since there really is no difference in the generated design.
1 parent 3f3bcbd commit f7f8236

File tree

7 files changed

+44
-115
lines changed

7 files changed

+44
-115
lines changed

Rakefile

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,17 @@ require_relative $root / "lib" / "portfolio_design"
1515

1616
directory "#{$root}/.stamps"
1717

18+
# Load and execute Rakefile for each backend.
1819
Dir.glob("#{$root}/backends/*/tasks.rake") do |rakefile|
20+
puts "UPDATE: Loading #{rakefile}"
1921
load rakefile
2022
end
2123

2224
directory "#{$root}/.stamps"
2325

24-
# @param base_isa_name [String] rv32 or rv64
25-
# @param base [Integer] 32 or 64
26-
# @return [Architecture]
27-
def arch_for(base_isa_name, base)
28-
Rake::Task["#{$root}/.stamps/resolve-#{base_isa_name}.stamp"].invoke
29-
30-
@archs ||= {}
31-
return @archs[base_isa_name] if @archs.key?(base_isa_name)
32-
33-
@archs[base_isa_name] =
34-
Architecture.new(
35-
base_isa_name,
36-
base,
37-
$root / "gen" / "resolved_arch" / base_isa_name,
38-
)
39-
end
40-
41-
# @param design_name [String] Profile release name for profiles and processor certificate model name for certificates
42-
# @param arch [Architecture] The architecture database
43-
# @param base [Integer] 32 or 64
44-
# @param portfolios [Array<Portfolio>] Portfolios in this design
45-
# @return [PortfolioDesign]
46-
def portfolio_design_for(design_name, arch, base, portfolios)
47-
Rake::Task["#{$root}/.stamps/resolve-#{design_name}.stamp"].invoke
48-
49-
@portfolio_designs ||= {}
50-
return @portfolio_designs[design_name] if @portfolio_designs.key?(design_name)
51-
52-
@portfolio_designs[design_name] =
53-
PortfolioDesign.new(
54-
design_name,
55-
arch,
56-
base,
57-
portfolios
58-
)
59-
end
60-
61-
def cfg_arch_for(config_name, base = nil)
26+
# @param config_name [String] Name of configuration
27+
# @return [ConfiguredArchitecture]
28+
def cfg_arch_for(config_name)
6229
Rake::Task["#{$root}/.stamps/resolve-#{config_name}.stamp"].invoke
6330

6431
@cfg_archs ||= {}
@@ -67,7 +34,6 @@ def cfg_arch_for(config_name, base = nil)
6734
@cfg_archs[config_name] =
6835
ConfiguredArchitecture.new(
6936
config_name,
70-
base,
7137
$root / "gen" / "resolved_arch" / config_name,
7238
overlay_path: $root / "cfgs" / config_name / "arch_overlay"
7339
)
@@ -157,18 +123,18 @@ namespace :test do
157123
end
158124
task schema: "gen:resolved_arch" do
159125
puts "Checking arch files against schema.."
160-
Architecture.new("rv64", nil, "#{$root}/resolved_arch").validate(show_progress: true)
126+
Architecture.new("rv64", "#{$root}/resolved_arch").validate(show_progress: true)
161127
puts "All files validate against their schema"
162128
end
163129
task idl: ["gen:resolved_arch", "#{$root}/.stamps/resolve-rv32.stamp", "#{$root}/.stamps/resolve-rv64.stamp"] do
164130
print "Parsing IDL code for RV32..."
165-
cfg_arch32 = cfg_arch_for("rv32", 32)
131+
cfg_arch32 = cfg_arch_for("rv32")
166132
puts "done"
167133

168134
cfg_arch32.type_check
169135

170136
print "Parsing IDL code for RV64..."
171-
cfg_arch64 = cfg_arch_for("rv64", 64)
137+
cfg_arch64 = cfg_arch_for("rv64")
172138
puts "done"
173139

174140
cfg_arch64.type_check

backends/crd/tasks.rake

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ require "asciidoctor-diagram"
77

88
require_relative "#{$lib}/idl/passes/gen_adoc"
99

10+
puts "UPDATE: Inside crd tasks.rake"
11+
1012
CERT_DOC_DIR = Pathname.new "#{$root}/backends/crd"
1113

1214
Dir.glob("#{$root}/arch/proc_cert_model/*.yaml") do |f|
@@ -15,13 +17,6 @@ Dir.glob("#{$root}/arch/proc_cert_model/*.yaml") do |f|
1517
proc_cert_class_name = File.basename(proc_cert_model_obj['class']['$ref'].split("#")[0], ".yaml")
1618
raise "Ill-formed processor certificate model file #{f}: missing 'class' field" if proc_cert_model_obj['class'].nil?
1719

18-
base = proc_cert_model_obj["base"]
19-
raise "Missing processor certificate model base" if base.nil?
20-
21-
base_isa_name = "rv#{base}"
22-
23-
puts "UPDATE: Extracted base=#{base} from #{f}"
24-
2520
file "#{$root}/gen/crd/adoc/#{proc_cert_model_name}.adoc" => [
2621
__FILE__,
2722
"#{$root}/arch/proc_cert_class/#{proc_cert_class_name}.yaml",
@@ -32,19 +27,22 @@ Dir.glob("#{$root}/arch/proc_cert_model/*.yaml") do |f|
3227
"#{$root}/lib/design.rb",
3328
"#{CERT_DOC_DIR}/templates/crd.adoc.erb"
3429
] do |t|
35-
# Create Architecture object. Function located in top-level Rakefile.
36-
puts "UPDATE: Creating Architecture #{base_isa_name} for #{t}"
37-
arch = arch_for(base_isa_name, base)
30+
# Ensure that unconfigured resolved architecture called "_" exists.
31+
Rake::Task["#{$root}/.stamps/resolve-_.stamp"].invoke
32+
33+
# Create architecture object so we can have it create the ProcCertModel.
34+
# Use the unconfigured resolved architecture called "_".
35+
arch = Architecture.new("RISC-V Architecture", $root / "gen" / "resolved_arch" / "_")
3836

3937
# Create ProcCertModel for specific processor certificate model as specified in its arch YAML file.
4038
# The Architecture object also creates all other portfolio-related class instances from their arch YAML files.
4139
# None of these objects are provided with a Design object when created.
42-
puts "UPDATE: Creating ProcCertModel for #{proc_cert_model_name} using base #{base_isa_name}"
40+
puts "UPDATE: Creating ProcCertModel for #{proc_cert_model_name}"
4341
proc_cert_model = arch.proc_cert_model(proc_cert_model_name)
4442

4543
puts "UPDATE: Creating PortfolioDesign using processor certificate model #{proc_cert_model_name}"
4644
# Create the one PortfolioDesign object required for the ERB evaluation.
47-
portfolio_design = portfolio_design_for(proc_cert_model_name, arch, base, [proc_cert_model])
45+
portfolio_design = PortfolioDesign.new(proc_cert_model_name, arch, [proc_cert_model])
4846

4947
# Create empty binding and then specify explicitly which variables the ERB template can access.
5048
# Seems to use this method name in stack backtraces (hence its name).

backends/profile_doc/tasks.rake

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ require "asciidoctor-diagram"
77

88
require_relative "#{$lib}/idl/passes/gen_adoc"
99

10+
puts "UPDATE: Inside profile_doc tasks.rake"
11+
1012
PROFILE_DOC_DIR = Pathname.new "#{$root}/backends/profile_doc"
1113

1214
Dir.glob("#{$root}/arch/profile_release/*.yaml") do |f|
@@ -22,29 +24,8 @@ Dir.glob("#{$root}/arch/profile_release/*.yaml") do |f|
2224
profile_names = profile_release_obj['profiles'].map {|p| File.basename(p['$ref'].split("#")[0], ".yaml") }
2325
raise "Ill-formed profile release file #{f}: can't parse profile names" if profile_names.nil?
2426

25-
# Find maximum base across all profiles in the profile release.
26-
max_base = nil
27-
profile_names.each do |profile_name|
28-
profile_pathname = "#{$root}/arch/profile/#{profile_name}.yaml"
29-
profile_obj = YAML.load_file(profile_pathname, permitted_classes: [Date])
30-
raise "Can't parse #{profile_name}" if profile_obj.nil?
31-
32-
base = profile_obj["base"]
33-
raise "Missing profile base in #{profile}" if base.nil?
34-
35-
puts "UPDATE: Extracted base=#{base} from #{f}"
36-
37-
max_base = base if (max_base.nil? || base > max_base)
38-
end
39-
raise "Couldn't find max_base in the profiles #{profile_names}" if max_base.nil?
40-
puts "UPDATE: Calculated max_base=#{max_base} across profiles in #{profile_release_name}"
41-
4227
profile_pathnames = profile_names.map {|profile_name| "#{$root}/arch/profile/#{profile_name}.yaml" }
4328

44-
# Just go with maximum base since it is the most inclusive.
45-
base = max_base
46-
base_isa_name = "rv#{base}"
47-
4829
file "#{$root}/gen/profile_doc/adoc/#{profile_release_name}.adoc" => [
4930
__FILE__,
5031
"#{$root}/arch/profile_class/#{profile_class_name}.yaml",
@@ -55,20 +36,23 @@ Dir.glob("#{$root}/arch/profile_release/*.yaml") do |f|
5536
"#{$root}/lib/design.rb",
5637
"#{PROFILE_DOC_DIR}/templates/profile.adoc.erb"
5738
].concat(profile_pathnames) do |t|
58-
# Create Architecture object. Function located in top-level Rakefile.
59-
puts "UPDATE: Creating Architecture #{base_isa_name} for #{t}"
60-
arch = arch_for(base_isa_name, base)
39+
# Ensure that unconfigured resolved architecture called "_" exists.
40+
Rake::Task["#{$root}/.stamps/resolve-_.stamp"].invoke
41+
42+
# Create architecture object so we can have it create the ProcCertModel.
43+
# Use the unconfigured resolved architecture called "_".
44+
arch = Architecture.new("RISC-V Architecture", $root / "gen" / "resolved_arch" / "_")
6145

6246
# Create PortfolioRelease for specific portfolio release as specified in its arch YAML file.
6347
# The Architecture object also creates all other portfolio-related class instances from their arch YAML files.
6448
# None of these objects are provided with a Design object when created.
65-
puts "UPDATE: Creating Profile Release for #{profile_release_name} using #{base_isa_name}"
49+
puts "UPDATE: Creating Profile Release for #{profile_release_name}"
6650
profile_release = arch.profile_release(profile_release_name)
6751

68-
puts "UPDATE: Creating PortfolioDesign using profile release #{profile_release_name}"
6952
# Create the one PortfolioDesign object required for the ERB evaluation.
7053
# Provide it with all the profiles in this ProfileRelease.
71-
portfolio_design = portfolio_design_for(profile_release_name, arch, base, profile_release.profiles)
54+
puts "UPDATE: Creating PortfolioDesign using profile release #{profile_release_name}"
55+
portfolio_design = PortfolioDesign.new(profile_release_name, arch, profile_release.profiles)
7256

7357
# Create empty binding and then specify explicitly which variables the ERB template can access.
7458
# Seems to use this method name in stack backtraces (hence its name).

lib/architecture.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,16 @@ class Architecture
5353
# @return [String] Best name to identify architecture
5454
attr_reader :name
5555

56-
# @return [Integer] 32 for RV32I or 64 for RV64I
57-
attr_reader :base
58-
5956
# @return [Pathname] Path to the directory containing YAML files defining the RISC-V standards
6057
attr_reader :path
6158

6259
# Initialize a new architecture definition
6360
#
6461
# @param name [#to_s] The name associated with this architecture
65-
# @param base [Integer] RISC-V base ISA width (32 for RV32I/RV32E, 64 for RV64I, nil if unknown)
6662
# @param arch_dir [String, Pathname] Path to a directory with a fully merged/resolved architecture definition
67-
def initialize(name, base, arch_dir)
63+
def initialize(name, arch_dir)
6864
@name = name.to_s.freeze
6965

70-
unless base.nil?
71-
raise "Unsupported base ISA value of #{base}. Supported values are 32 or 64." unless base == 32 || base == 64
72-
end
73-
@base = base
74-
@base.freeze
75-
7666
@arch_dir = Pathname.new(arch_dir)
7767
raise "Architecture directory #{arch_dir} not found" unless @arch_dir.exist?
7868

lib/cfg_arch.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,12 @@ class ConfiguredArchitecture < Design
2222
:fully_configured?, :partially_configured?, :unconfigured?, :configured?, :param_values
2323

2424
# @param config_name [#to_s] The configuration name which corresponds to a folder name under cfg_path
25-
# @param base [Integer] RISC-V base ISA width (32 for RV32I/RV32E, 64 for RV64I, nil if unknown)
2625
# @param arch_dir [String,Pathname] Path to a directory with a fully merged/resolved architecture definition
2726
# @param overlay_path [String] Optional path to a directory that overlays the architecture
2827
# @param cfg_path [String] Optional path to where to find configuration file
29-
def initialize(config_name, base, arch_dir, overlay_path: nil, cfg_path: "#{$root}/cfgs")
28+
def initialize(config_name, arch_dir, overlay_path: nil, cfg_path: "#{$root}/cfgs")
3029
@config = Config.create("#{cfg_path}/#{config_name}/cfg.yaml")
31-
@mxlen = @config.mxlen
32-
@mxlen.freeze
33-
34-
arch = Architecture.new(config_name, base, arch_dir)
35-
36-
super(config_name, arch, overlay_path: overlay_path)
30+
super(config_name, Architecture.new(config_name, arch_dir), @config.mxlen, overlay_path: overlay_path)
3731
end
3832

3933
# Returns a string representation of the object, suitable for debugging.
@@ -46,9 +40,6 @@ def inspect = "ConfiguredArchitecture##{name}"
4640
# These raise an error in the base class. #
4741
###########################################
4842

49-
# @return [Integer] 32, 64, or nil if dynamic or undefined.
50-
def mxlen = @mxlen
51-
5243
# Returns whether or not it may be possible to switch XLEN in +mode+ given this definition.
5344
#
5445
# There are three cases when this will return true:

lib/design.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class Design < IDesign
4343
# @return [Architecture] The RISC-V architecture
4444
attr_reader :arch
4545

46+
# @return [Integer] 32, 64, or nil for dynamic
47+
attr_reader :mxlen
48+
4649
# @return [Idl::Compiler] The IDL compiler
4750
attr_reader :idl_compiler
4851

@@ -58,12 +61,17 @@ def hash = @name_sym.hash
5861

5962
# @param name [#to_s] The design name
6063
# @param arch [Architecture] The entire architecture
64+
# @param mxlen [Integer] 32, 64, or nil for dynamic
6165
# @param overlay_path [String] Optional path to a directory that overlays the architecture
62-
def initialize(name, arch, overlay_path: nil)
66+
def initialize(name, arch, mxlen, overlay_path: nil)
6367
super(name)
6468

6569
raise ArgumentError, "arch must be an Architecture but is a #{arch.class}" unless arch.is_a?(Architecture)
6670
@arch = arch
71+
72+
@mxlen = mxlen
73+
@mxlen.freeze
74+
6775
@idl_compiler = Idl::Compiler.new
6876
@symtab = Idl::SymbolTable.new(self)
6977
custom_globals_path = overlay_path.nil? ? Pathname.new("/does/not/exist") : overlay_path / "isa" / "globals.isa"

lib/portfolio_design.rb

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,18 @@ class PortfolioDesign < Design
2121
# @param mxlen [Integer] Comes from portfolio YAML "base" (either 32 or 64)
2222
# @param portfolios [Array<Portfolio>] Portfolios being converted to adoc
2323
# @param overlay_path [String] Optional path to a directory that overlays the architecture
24-
def initialize(base_isa_name, arch, base, portfolios, overlay_path: nil)
25-
raise ArgumentError, "base must be 32 or 64 but is #{base}" unless (base == 32 || base == 64)
24+
def initialize(base_isa_name, arch, portfolios, overlay_path: nil)
2625
raise ArgumentError, "arch must be an Architecture but is a #{arch.class}" unless arch.is_a?(Architecture)
2726
raise ArgumentError, "portfolios must be an Array<Portfolio> but is a #{portfolios.class}" unless portfolios.is_a?(Array)
2827

29-
@mxlen = base
30-
@mxlen.freeze
31-
3228
# The PortfolioGroup has an Array<Portfolio> inside it and forwards common Array methods to its internal Array.
3329
# Can call @portfolio_grp.each or @portfolio_grp.map and they are handled by the normal Array methods.
3430
@portfolio_grp = PortfolioGroup.new(portfolios)
3531

36-
# Sanity check base passed in to me.
3732
max_base = portfolios.map(&:base).max
38-
raise ArgumentError, "Provided base of #{base} but maximum base across all provided portfolios is #{max_base}" unless base == max_base
33+
raise ArgumentError, "Calculated maximum base of #{max_base} across portfolios is not 32 or 64" unless max_base == 32 || max_base == 64
3934

40-
super(base_isa_name, arch, overlay_path: overlay_path)
35+
super(base_isa_name, arch, max_base, overlay_path: overlay_path)
4136
end
4237

4338
# Returns a string representation of the object, suitable for debugging.
@@ -48,9 +43,6 @@ def inspect = "PortfolioDesign##{name}"
4843
# METHODS REQUIRED BY BASE CLASS #
4944
##################################
5045

51-
# @return [Integer] 32 or 64. Might be nil if dynamic (not sure if dynamic required for portfolios).
52-
def mxlen = @mxlen
53-
5446
# Returns whether or not it may be possible to switch XLEN in +mode+ given this definition.
5547
#
5648
# There are three cases when this will return true:

0 commit comments

Comments
 (0)