@@ -232,10 +232,20 @@ def gen_cpp(symtab, indent, indent_spaces: 2)
232232
233233 class CsrFieldAssignmentAst
234234 def gen_cpp ( symtab , indent , indent_spaces : 2 )
235- if csr_field . idx . is_a? ( AstNode )
236- "#{ ' ' *indent } __UDB_CSR_BY_ADDR(#{ csr_field . idx . gen_cpp ( symtab , 0 ) } )._hw_write(#{ write_value . gen_cpp ( symtab , 0 , indent_spaces :) } )"
235+
236+ field = csr_field . field_def ( symtab )
237+ if symtab . cfg_arch . multi_xlen? && field . dynamic_location?
238+ if csr_field . idx . is_a? ( AstNode )
239+ "#{ ' ' *indent } __UDB_CSR_BY_ADDR(#{ csr_field . idx . gen_cpp ( symtab , 0 ) } ).#{ field . name } ()._hw_write(#{ write_value . gen_cpp ( symtab , 0 , indent_spaces :) } , __UDB_XLEN)"
240+ else
241+ "#{ ' ' *indent } __UDB_CSR_BY_NAME(#{ csr_field . csr_name ( symtab ) } ).#{ field . name } ()._hw_write(#{ write_value . gen_cpp ( symtab , 0 , indent_spaces :) } , __UDB_XLEN)"
242+ end
237243 else
238- "#{ ' ' *indent } __UDB_CSR_BY_NAME(#{ csr_field . csr_name ( symtab ) } )._hw_write(#{ write_value . gen_cpp ( symtab , 0 , indent_spaces :) } )"
244+ if csr_field . idx . is_a? ( AstNode )
245+ "#{ ' ' *indent } __UDB_CSR_BY_ADDR(#{ csr_field . idx . gen_cpp ( symtab , 0 ) } ).#{ field . name } ()._hw_write(#{ write_value . gen_cpp ( symtab , 0 , indent_spaces :) } )"
246+ else
247+ "#{ ' ' *indent } __UDB_CSR_BY_NAME(#{ csr_field . csr_name ( symtab ) } ).#{ field . name } ()._hw_write(#{ write_value . gen_cpp ( symtab , 0 , indent_spaces :) } )"
248+ end
239249 end
240250 end
241251 end
@@ -301,8 +311,8 @@ def gen_cpp(symtab, indent = 0, indent_spaces: 2)
301311 else
302312 "#{ ' ' * indent } __UDB_MUTABLE_GLOBAL(#{ text_value } )"
303313 end
304- elsif text_value == "imm"
305- "#{ ' ' * indent } imm ()"
314+ elsif ! var . nil? && var . decode_var?
315+ "#{ ' ' * indent } #{ text_value } ()"
306316 else
307317 "#{ ' ' * indent } #{ text_value } "
308318 end
@@ -428,12 +438,16 @@ def gen_cpp(symtab, indent = 0, indent_spaces: 2)
428438
429439 class AryElementAccessAst
430440 def gen_cpp ( symtab , indent = 0 , indent_spaces : 2 )
431- if var . text_value . start_with? ( "X" )
432- #"#{' '*indent}#{var.gen_cpp(symtab, 0, indent_spaces:)}[#{index.gen_cpp(symtab, 0, indent_spaces:)}]"
433- "#{ ' ' *indent } __UDB_FUNC_CALL xregRef(#{ index . gen_cpp ( symtab , 0 , indent_spaces :) } )"
434- else
435- if var . type ( symtab ) . integral?
441+ if var . type ( symtab ) . integral?
442+ if index . constexpr? ( symtab )
436443 "#{ ' ' *indent } extract<#{ index . gen_cpp ( symtab , 0 ) } , 1, #{ var . type ( symtab ) . width } >(#{ var . gen_cpp ( symtab , 0 , indent_spaces :) } )"
444+ else
445+ "#{ ' ' *indent } extract( #{ var . gen_cpp ( symtab , 0 , indent_spaces :) } , #{ index . gen_cpp ( symtab , 0 ) } , 1)"
446+ end
447+ else
448+ if var . text_value . start_with? ( "X" )
449+ #"#{' '*indent}#{var.gen_cpp(symtab, 0, indent_spaces:)}[#{index.gen_cpp(symtab, 0, indent_spaces:)}]"
450+ "#{ ' ' *indent } __UDB_FUNC_CALL xregRef(#{ index . gen_cpp ( symtab , 0 , indent_spaces :) } )"
437451 else
438452 "#{ ' ' *indent } #{ var . gen_cpp ( symtab , 0 , indent_spaces :) } [#{ index . gen_cpp ( symtab , 0 , indent_spaces :) } ]"
439453 end
0 commit comments