Skip to content

Commit 2ed7c27

Browse files
authored
Merge pull request #135 from riscv-software-src/csr_link
Ensure that CSR links are not applied when the index is a variable
2 parents 1a3adb8 + 828d3c4 commit 2ed7c27

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/idl/ast.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5682,6 +5682,7 @@ def freeze_tree(symtab)
56825682
@value = nil
56835683
end
56845684
@type = calc_type(symtab)
5685+
@archdef = symtab.archdef # remember archdef, used in gen_adoc pass
56855686
freeze
56865687
end
56875688
@@ -5813,6 +5814,12 @@ def initialize(input, interval, idx)
58135814
@idx = idx
58145815
end
58155816
5817+
def freeze_tree(symtab)
5818+
@archdef = symtab.archdef # remember archdef, used by gen_adoc pass
5819+
@idx.freeze_tree(symtab)
5820+
freeze
5821+
end
5822+
58165823
# @!macro type
58175824
def type(symtab)
58185825
archdef = symtab.archdef

lib/idl/passes/gen_adoc.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ def gen_adoc(indent = 0, indent_spaces: 2)
295295
if idx_text =~ /[0-9]+/
296296
"#{' '*indent}#{csr_text}"
297297
else
298-
"#{' '*indent}%%LINK%csr_field;#{idx_text}.#{@field_name};#{csr_text}%%"
298+
if @archdef.csr(csr_text).nil?
299+
"#{' '*indent}#{csr_text}"
300+
else
301+
"#{' '*indent}%%LINK%csr_field;#{idx_text}.#{@field_name};#{csr_text}%%"
302+
end
299303
end
300304
end
301305
end
@@ -314,7 +318,11 @@ def gen_adoc(indent = 0, indent_spaces: 2)
314318
# we don't have the symtab to map this to a csr name
315319
"#{' '*indent}#{csr_text}"
316320
else
317-
"#{' '*indent}%%LINK%csr;#{idx_text};#{csr_text}%%"
321+
if @archdef.csr(csr_text).nil?
322+
"#{' '*indent}#{csr_text}"
323+
else
324+
"#{' '*indent}%%LINK%csr;#{idx_text};#{csr_text}%%"
325+
end
318326
end
319327
end
320328
end

0 commit comments

Comments
 (0)