Skip to content

Commit 1cf5061

Browse files
committed
Fixup for AryDeref and typos in auto gen
Signed-off-by: Luke Quinn <[email protected]>
1 parent 0771491 commit 1cf5061

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

backends/cpp_hart_gen/lib/csr_template_helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def type_to_cpp(xlen)
2424
symtab = fill_symtab_for_type(xlen, pruned_ast)
2525
value_result = pruned_ast.value_try do
2626
type_value = pruned_ast.return_value(symtab)
27-
cpp = "return CsfFieldType::#{TYPE_VALUE_TO_CPP_NAME[type_value]};"
27+
cpp = "return CsrFieldType::#{TYPE_VALUE_TO_CPP_NAME[type_value]};"
2828
end
2929
pruned_ast.value_else(value_result) do
3030
cpp = pruned_ast.gen_cpp(symtab)

backends/cpp_hart_gen/lib/gen_cpp.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ class AryElementAccessAst
409409
def gen_cpp(symtab, indent = 0, indent_spaces: 2)
410410
if var.text_value.start_with?("X")
411411
#"#{' '*indent}#{var.gen_cpp(symtab, 0, indent_spaces:)}[#{index.gen_cpp(symtab, 0, indent_spaces:)}]"
412-
"#{' '*indent} __UDB__FUNC__OBJ xregRef(#{index.gen_cpp(symtab, 0, indent_spaces:)})"
412+
"#{' '*indent} __UDB_FUNC_CALL xregRef(#{index.gen_cpp(symtab, 0, indent_spaces:)})"
413413
else
414414
if var.type(symtab).integral?
415415
"#{' '*indent}extract<#{index.gen_cpp(symtab, 0)}, 1, #{var.type(symtab).width}>(#{var.gen_cpp(symtab, 0, indent_spaces:)})"
@@ -442,7 +442,7 @@ class AryElementAssignmentAst
442442
def gen_cpp(symtab, indent = 0, indent_spaces: 2)
443443
if lhs.text_value.start_with?("X")
444444
#"#{' '*indent} #{lhs.gen_cpp(symtab, 0, indent_spaces:)}[#{idx.gen_cpp(symtab, 0, indent_spaces:)}] = #{rhs.gen_cpp(symtab, 0, indent_spaces:)}"
445-
"#{' '*indent} __UDB__FUNC__OBJ xregRef ( #{idx.gen_cpp(symtab, 0, indent_spaces:)} ) = #{rhs.gen_cpp(symtab, 0, indent_spaces:)}"
445+
"#{' '*indent} __UDB_FUNC_CALL xregRef ( #{idx.gen_cpp(symtab, 0, indent_spaces:)} ) = #{rhs.gen_cpp(symtab, 0, indent_spaces:)}"
446446
else
447447
"#{' '*indent}#{lhs.gen_cpp(symtab, 0, indent_spaces:)}[#{idx.gen_cpp(symtab, 0, indent_spaces:)}] = #{rhs.gen_cpp(symtab, 0, indent_spaces:)}"
448448
end

backends/cpp_hart_gen/templates/csrs.cxx.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ using namespace udb;
1212
#define __UDB_STATIC_PARAM(param_name) <%= name_of(:params, cfg_arch) %>::param_name
1313
#define __UDB_FUNC_CALL m_hart->
1414
#define __UDB_CONSTEXPR_FUNC_CALL <%= name_of(:hart, cfg_arch) %>::
15+
#define __UDB_CSR_BY_ADDR(addr) m_hart->csr(addr)
16+
#define __UDB_CSR_BY_NAME(csr_name) m_hart->m_csrs.csr_name
1517

1618
<%- fields.each do |field| -%>
1719
<%- max_width = cfg_arch.possible_xlens.map { |xlen| field.defined_in_base?(xlen) ? field.location(xlen).size : 0 }.max -%>
@@ -65,6 +67,8 @@ void <%= name_of(:csr_field, cfg_arch, csr.name, field.name) %>::reset() {
6567
#undef __UDB_STATIC_PARAM
6668
#undef __UDB_CONSTEXPR_FUNC_CALL
6769
#undef __UDB_FUNC_CALL
70+
#undef __UDB_CSR_BY_NAME
71+
#undef __UDB_CSR_BY_ADDR
6872

6973
#define __UDB_RUNTIME_PARAM(param_name) m_parent->m_params.param_name
7074
#define __UDB_STATIC_PARAM(param_name) <%= name_of(:params, cfg_arch) %>::param_name
@@ -74,6 +78,7 @@ void <%= name_of(:csr_field, cfg_arch, csr.name, field.name) %>::reset() {
7478
#define __UDB_FUNC_CALL m_parent->
7579
#define __UDB_CONSTEXPR_FUNC_CALL <%= name_of(:hart, cfg_arch) %>::
7680
#define __UDB_XLEN m_parent->xlen()
81+
#define __UDB_ENCODING m_parent->m_curr_insn.encoding()
7782

7883
// constructor
7984
<%- fields_for_xlen = fields.select { |f| cfg_arch.possible_xlens.any? { |xlen| f.defined_in_base?(xlen) } } -%>

backends/cpp_hart_gen/templates/hart.hxx.erb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,28 @@ namespace udb {
113113
// return it->second;
114114
}
115115

116+
CsrBase* csr(const std::string& address) override {
117+
return nullptr;
118+
// auto it = m_csr_map.find(address);
119+
// if (it == m_csr_map.end()) {
120+
// return nullptr;
121+
// }
122+
// return it->second;
123+
}
124+
125+
const CsrBase* csr(const std::string& address) const override {
126+
return nullptr;
127+
// auto it = m_csr_map.find(address);
128+
// if (it == m_csr_map.end()) {
129+
// return nullptr;
130+
// }
131+
// return it->second;
132+
}
133+
116134
private:
117135
XReg m_pc;
118136
XReg m_next_pc;
137+
InstBase* m_curr_insn;
119138
std::array<XRegister<MXLEN>, 32> m_xregs;
120139

121140
<%= name_of(:params, cfg_arch) %> m_params;

backends/cpp_hart_gen/templates/inst.hxx.erb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ namespace udb {
6767
<%- end -%>
6868
<%- end -%>
6969

70-
#define __UDB__FUNC__OBJ m_parent->
70+
#define __UDB_FUNC_CALL m_parent->
71+
#define __UDB_CSR_BY_ADDR(addr) m_parent->csr(addr)
72+
#define __UDB_CSR_BY_NAME(csr_name) m_parent->m_csrs.csr_name
7173

7274

7375
void execute() override {
@@ -97,7 +99,9 @@ namespace udb {
9799
<%- end -%>
98100
}
99101

100-
#undef __UDB__FUNC__OBJ
102+
#undef __UDB__FUNC__CALL
103+
#undef __UDB_CSR_BY_ADDR
104+
#undef __UDB_CSR_BY_NAME
101105

102106
private:
103107
<%= name_of(:hart, cfg_arch) %> * const m_parent;

0 commit comments

Comments
 (0)