Skip to content

Commit

Permalink
Perform type checking on config-indpendent IDL code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhower-qc committed Aug 20, 2024
1 parent be96f79 commit 0ecdb6a
Show file tree
Hide file tree
Showing 123 changed files with 1,190 additions and 783 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gem "base64"
gem "bigdecimal"
gem "json_schemer", "~> 1.0"
gem "minitest"
gem "ruby-progressbar", "~> 1.13"
gem "pygments.rb"
gem "rake", "~> 13.0"
gem "rouge"
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ DEPENDENCIES
rouge
rubocop-minitest
ruby-prof
ruby-progressbar (~> 1.13)
solargraph
treetop (= 1.6.12)
webrick
Expand Down
42 changes: 41 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$root = Pathname.new(__FILE__).dirname.realpath
$lib = $root / "lib"

require "ruby-progressbar"
require "yard"
require "minitest/test_task"

Expand Down Expand Up @@ -64,10 +65,48 @@ end
desc "Validate the arch docs"
task validate: "gen:arch" do
validator = Validator.instance
Dir.glob("#{$root}/arch/**/*.yaml") do |f|
puts "Checking arch files against schema.."
arch_files = Dir.glob("#{$root}/arch/**/*.yaml")
progressbar = ProgressBar.create(total: arch_files.size)
arch_files.each do |f|
progressbar.increment
validator.validate(f)
end
puts "All files validate against their schema"

puts "Type checking IDL code..."
arch_def = arch_def_for("_")
progressbar = ProgressBar.create(title: "Instructions", total: arch_def.instructions.size)
arch_def.instructions.each do |inst|
progressbar.increment
inst.type_checked_operation_ast(arch_def.idl_compiler, arch_def.sym_table_32, 32) if inst.rv32?
inst.type_checked_operation_ast(arch_def.idl_compiler, arch_def.sym_table_64, 64) if inst.rv64?
# also need to check for an RV64 machine running with effective XLEN of 32
inst.type_checked_operation_ast(arch_def.idl_compiler, arch_def.sym_table_64, 32) if inst.rv64? && inst.rv32?
end
progressbar = ProgressBar.create(title: "CSRs", total: arch_def.csrs.size)
arch_def.csrs.each do |csr|
progressbar.increment
if csr.has_custom_sw_read?
csr.type_checked_sw_read_ast(arch_def.sym_table_32) if csr.defined_in_base32?
csr.type_checked_sw_read_ast(arch_def.sym_table_64) if csr.defined_in_base64?
end
csr.fields.each do |field|
unless field.type_ast(arch_def.idl_compiler).nil?
field.type_checked_type_ast(arch_def.sym_table_32) if csr.defined_in_base32? && field.defined_in_base32?
field.type_checked_type_ast(arch_def.sym_table_64) if csr.defined_in_base64? && field.defined_in_base64?
end
unless field.reset_value_ast(arch_def.idl_compiler).nil?
field.type_checked_reset_value_ast(arch_def.sym_table_32) if csr.defined_in_base32? && field.defined_in_base32?
field.type_checked_reset_value_ast(arch_def.sym_table_64) if csr.defined_in_base64? && field.defined_in_base64?
end
unless field.sw_write_ast(arch_def.idl_compiler).nil?
field.type_checked_sw_write_ast(arch_def.sym_table_32, 32) if csr.defined_in_base32? && field.defined_in_base32?
field.type_checked_sw_write_ast(arch_def.sym_table_64, 64) if csr.defined_in_base64? && field.defined_in_base64?
end
end
end
puts "All IDL passed type checking"
end

def insert_warning(str, from)
Expand All @@ -76,6 +115,7 @@ def insert_warning(str, from)
first_line = lines.shift
lines.unshift(first_line, "\n# WARNING: This file is auto-generated from #{Pathname.new(from).relative_path_from($root)}\n\n").join("")
end
private :insert_warning

(3..31).each do |hpm_num|
file "#{$root}/arch/csr/Zihpm/mhpmcounter#{hpm_num}.yaml" => [
Expand Down
2 changes: 1 addition & 1 deletion arch/csr/H/hcounteren.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ hcounteren:
Together with `scounteren`, delegates control of the hardware performance-monitoring counters
to VS/VU-mode
See `cycle` for a table of how exceptions occur across all modes.
See `cycle` for a table describing how exceptions occur.
definedBy: H
fields:
CY:
Expand Down
12 changes: 6 additions & 6 deletions arch/csr/I/mcounteren.layout
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ mcounteren:
When `hcounteren.CY` && `scounteren.CY` are both set, `cycle` is futher accessible to VU-mode.
<%%- end -%>
type(): |
if (COUNTENABLE_EN[2]) {
if (MCOUNTENABLE_EN[2]) {
return CsrFieldType::RW;
} else {
return CsrFieldType::RO;
}
reset_value(): |
if (COUNTENABLE_EN[2]) {
if (MCOUNTENABLE_EN[2]) {
return UNDEFINED_LEGAL;
} else {
return 0;
Expand Down Expand Up @@ -140,13 +140,13 @@ mcounteren:
When `hcounteren.IR` && `scounteren.IR` are both set, `instret` is futher accessible to VU-mode.
<%%- end -%>
type(): |
if (COUNTENABLE_EN[2]) {
if (MCOUNTENABLE_EN[2]) {
return CsrFieldType::RW;
} else {
return CsrFieldType::RO;
}
reset_value(): |
if (COUNTENABLE_EN[2]) {
if (MCOUNTENABLE_EN[2]) {
return UNDEFINED_LEGAL;
} else {
return 0;
Expand All @@ -172,13 +172,13 @@ mcounteren:
When `hcounteren.HPM<%= hpm_num %>` && `scounteren.HPM<%= hpm_num %>` are both set, `hpmcounter<%= hpm_num %>` is futher accessible to VU-mode.
<%%- end -%>
type(): |
if (COUNTENABLE_EN[<%= hpm_num %>]) {
if (MCOUNTENABLE_EN[<%= hpm_num %>]) {
return CsrFieldType::RW;
} else {
return CsrFieldType::RO;
}
reset_value(): |
if (COUNTENABLE_EN[<%= hpm_num %>]) {
if (MCOUNTENABLE_EN[<%= hpm_num %>]) {
return UNDEFINED_LEGAL;
} else {
return 0;
Expand Down
38 changes: 7 additions & 31 deletions arch/csr/I/mcounteren.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# yaml-language-server: $schema=../../../schemas/csr_schema.json
# yaml-language-server: $schema=../../schemas/csr_schema.json

# WARNING: This file is auto-generated from arch/csr/I/mcounteren.layout

Expand Down Expand Up @@ -105,48 +105,24 @@ mcounteren:
When `hcounteren.CY` && `scounteren.CY` are both set, `cycle` is futher accessible to VU-mode.
<%- end -%>
type(): |
if (MCOUNTENABLE_EN[0]) {
if (MCOUNTENABLE_EN[2]) {
return CsrFieldType::RW;
} else {
return CsrFieldType::RO;
}
reset_value(): |
if (MCOUNTENABLE_EN[0]) {
if (MCOUNTENABLE_EN[2]) {
return UNDEFINED_LEGAL;
} else {
return 0;
}
TM:
location: 1
description: |
When set, the `time` CSR (an alias of the `mtime` memory-mapped CSR) is accessible to
<%- if ext?(:S) -%>
S-mode.
<%- else -%>
U-mode.
<%- end -%>
<%- if ext?(:S) -%>
When `scounteren.TM` is also set, `time` is futher accessible to U-mode.
<%- end -%>
<%- if ext?(:H) -%>
When `hcounteren.TM` is also set, `time` is futher accessible to VS-mode.
When `hcounteren.TM` && `scounteren.TM` are both set, `time` is futher accessible to VU-mode.
<%- end -%>
type(): |
if (MCOUNTENABLE_EN[1]) {
return CsrFieldType::RW;
} else {
return CsrFieldType::RO;
}
reset_value(): |
if (MCOUNTENABLE_EN[1]) {
return UNDEFINED_LEGAL;
} else {
return 0;
}
Placeholder for delegating `time` to less-privileged modes; however, since `time`
is memory-mapped rather than a CSR, this field is always read-only zero.
type: RO
reset_value: 0
IR:
location: 2
description: |
Expand Down
6 changes: 3 additions & 3 deletions arch/csr/Zihpm/mhpmcounter10h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mhpmcounter10h:
alias: mhpmcounter.COUNT10[63:32]
description: |
Upper bits of counter.
type(): 'return (NUM_HPM_COUNTERS > 7) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (NUM_HPM_COUNTERS > 7) ? UNDEFINED_LEGAL : 0;'
type(): 'return (HPM_COUNTER_EN[10]) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (HPM_COUNTER_EN[10]) ? UNDEFINED_LEGAL : 0;'
sw_read(): |
if (NUM_HPM_COUNTERS <= 7) {
if (HPM_COUNTER_EN[10]) {
return read_hpm_counter(10)[63:32];
} else {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/csr/Zihpm/mhpmcounter11h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mhpmcounter11h:
alias: mhpmcounter.COUNT11[63:32]
description: |
Upper bits of counter.
type(): 'return (NUM_HPM_COUNTERS > 8) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (NUM_HPM_COUNTERS > 8) ? UNDEFINED_LEGAL : 0;'
type(): 'return (HPM_COUNTER_EN[11]) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (HPM_COUNTER_EN[11]) ? UNDEFINED_LEGAL : 0;'
sw_read(): |
if (NUM_HPM_COUNTERS <= 8) {
if (HPM_COUNTER_EN[11]) {
return read_hpm_counter(11)[63:32];
} else {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/csr/Zihpm/mhpmcounter12h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mhpmcounter12h:
alias: mhpmcounter.COUNT12[63:32]
description: |
Upper bits of counter.
type(): 'return (NUM_HPM_COUNTERS > 9) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (NUM_HPM_COUNTERS > 9) ? UNDEFINED_LEGAL : 0;'
type(): 'return (HPM_COUNTER_EN[12]) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (HPM_COUNTER_EN[12]) ? UNDEFINED_LEGAL : 0;'
sw_read(): |
if (NUM_HPM_COUNTERS <= 9) {
if (HPM_COUNTER_EN[12]) {
return read_hpm_counter(12)[63:32];
} else {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/csr/Zihpm/mhpmcounter13h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mhpmcounter13h:
alias: mhpmcounter.COUNT13[63:32]
description: |
Upper bits of counter.
type(): 'return (NUM_HPM_COUNTERS > 10) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (NUM_HPM_COUNTERS > 10) ? UNDEFINED_LEGAL : 0;'
type(): 'return (HPM_COUNTER_EN[13]) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (HPM_COUNTER_EN[13]) ? UNDEFINED_LEGAL : 0;'
sw_read(): |
if (NUM_HPM_COUNTERS <= 10) {
if (HPM_COUNTER_EN[13]) {
return read_hpm_counter(13)[63:32];
} else {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/csr/Zihpm/mhpmcounter14h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mhpmcounter14h:
alias: mhpmcounter.COUNT14[63:32]
description: |
Upper bits of counter.
type(): 'return (NUM_HPM_COUNTERS > 11) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (NUM_HPM_COUNTERS > 11) ? UNDEFINED_LEGAL : 0;'
type(): 'return (HPM_COUNTER_EN[14]) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (HPM_COUNTER_EN[14]) ? UNDEFINED_LEGAL : 0;'
sw_read(): |
if (NUM_HPM_COUNTERS <= 11) {
if (HPM_COUNTER_EN[14]) {
return read_hpm_counter(14)[63:32];
} else {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/csr/Zihpm/mhpmcounter15h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mhpmcounter15h:
alias: mhpmcounter.COUNT15[63:32]
description: |
Upper bits of counter.
type(): 'return (NUM_HPM_COUNTERS > 12) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (NUM_HPM_COUNTERS > 12) ? UNDEFINED_LEGAL : 0;'
type(): 'return (HPM_COUNTER_EN[15]) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (HPM_COUNTER_EN[15]) ? UNDEFINED_LEGAL : 0;'
sw_read(): |
if (NUM_HPM_COUNTERS <= 12) {
if (HPM_COUNTER_EN[15]) {
return read_hpm_counter(15)[63:32];
} else {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/csr/Zihpm/mhpmcounter16h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mhpmcounter16h:
alias: mhpmcounter.COUNT16[63:32]
description: |
Upper bits of counter.
type(): 'return (NUM_HPM_COUNTERS > 13) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (NUM_HPM_COUNTERS > 13) ? UNDEFINED_LEGAL : 0;'
type(): 'return (HPM_COUNTER_EN[16]) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (HPM_COUNTER_EN[16]) ? UNDEFINED_LEGAL : 0;'
sw_read(): |
if (NUM_HPM_COUNTERS <= 13) {
if (HPM_COUNTER_EN[16]) {
return read_hpm_counter(16)[63:32];
} else {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/csr/Zihpm/mhpmcounter17h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mhpmcounter17h:
alias: mhpmcounter.COUNT17[63:32]
description: |
Upper bits of counter.
type(): 'return (NUM_HPM_COUNTERS > 14) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (NUM_HPM_COUNTERS > 14) ? UNDEFINED_LEGAL : 0;'
type(): 'return (HPM_COUNTER_EN[17]) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (HPM_COUNTER_EN[17]) ? UNDEFINED_LEGAL : 0;'
sw_read(): |
if (NUM_HPM_COUNTERS <= 14) {
if (HPM_COUNTER_EN[17]) {
return read_hpm_counter(17)[63:32];
} else {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/csr/Zihpm/mhpmcounter18h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mhpmcounter18h:
alias: mhpmcounter.COUNT18[63:32]
description: |
Upper bits of counter.
type(): 'return (NUM_HPM_COUNTERS > 15) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (NUM_HPM_COUNTERS > 15) ? UNDEFINED_LEGAL : 0;'
type(): 'return (HPM_COUNTER_EN[18]) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (HPM_COUNTER_EN[18]) ? UNDEFINED_LEGAL : 0;'
sw_read(): |
if (NUM_HPM_COUNTERS <= 15) {
if (HPM_COUNTER_EN[18]) {
return read_hpm_counter(18)[63:32];
} else {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/csr/Zihpm/mhpmcounter19h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mhpmcounter19h:
alias: mhpmcounter.COUNT19[63:32]
description: |
Upper bits of counter.
type(): 'return (NUM_HPM_COUNTERS > 16) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (NUM_HPM_COUNTERS > 16) ? UNDEFINED_LEGAL : 0;'
type(): 'return (HPM_COUNTER_EN[19]) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (HPM_COUNTER_EN[19]) ? UNDEFINED_LEGAL : 0;'
sw_read(): |
if (NUM_HPM_COUNTERS <= 16) {
if (HPM_COUNTER_EN[19]) {
return read_hpm_counter(19)[63:32];
} else {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/csr/Zihpm/mhpmcounter20h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mhpmcounter20h:
alias: mhpmcounter.COUNT20[63:32]
description: |
Upper bits of counter.
type(): 'return (NUM_HPM_COUNTERS > 17) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (NUM_HPM_COUNTERS > 17) ? UNDEFINED_LEGAL : 0;'
type(): 'return (HPM_COUNTER_EN[20]) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (HPM_COUNTER_EN[20]) ? UNDEFINED_LEGAL : 0;'
sw_read(): |
if (NUM_HPM_COUNTERS <= 17) {
if (HPM_COUNTER_EN[20]) {
return read_hpm_counter(20)[63:32];
} else {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/csr/Zihpm/mhpmcounter21h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mhpmcounter21h:
alias: mhpmcounter.COUNT21[63:32]
description: |
Upper bits of counter.
type(): 'return (NUM_HPM_COUNTERS > 18) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (NUM_HPM_COUNTERS > 18) ? UNDEFINED_LEGAL : 0;'
type(): 'return (HPM_COUNTER_EN[21]) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (HPM_COUNTER_EN[21]) ? UNDEFINED_LEGAL : 0;'
sw_read(): |
if (NUM_HPM_COUNTERS <= 18) {
if (HPM_COUNTER_EN[21]) {
return read_hpm_counter(21)[63:32];
} else {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/csr/Zihpm/mhpmcounter22h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mhpmcounter22h:
alias: mhpmcounter.COUNT22[63:32]
description: |
Upper bits of counter.
type(): 'return (NUM_HPM_COUNTERS > 19) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (NUM_HPM_COUNTERS > 19) ? UNDEFINED_LEGAL : 0;'
type(): 'return (HPM_COUNTER_EN[22]) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (HPM_COUNTER_EN[22]) ? UNDEFINED_LEGAL : 0;'
sw_read(): |
if (NUM_HPM_COUNTERS <= 19) {
if (HPM_COUNTER_EN[22]) {
return read_hpm_counter(22)[63:32];
} else {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/csr/Zihpm/mhpmcounter23h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mhpmcounter23h:
alias: mhpmcounter.COUNT23[63:32]
description: |
Upper bits of counter.
type(): 'return (NUM_HPM_COUNTERS > 20) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (NUM_HPM_COUNTERS > 20) ? UNDEFINED_LEGAL : 0;'
type(): 'return (HPM_COUNTER_EN[23]) ? CsrFieldType::RWH : CsrFieldType::RO;'
reset_value(): 'return (HPM_COUNTER_EN[23]) ? UNDEFINED_LEGAL : 0;'
sw_read(): |
if (NUM_HPM_COUNTERS <= 20) {
if (HPM_COUNTER_EN[23]) {
return read_hpm_counter(23)[63:32];
} else {
return 0;
Expand Down
Loading

0 comments on commit 0ecdb6a

Please sign in to comment.