Skip to content

Commit a6911d2

Browse files
committed
Fixed a few ast sytnax errors
Signed-off-by: Luke Quinn <[email protected]>
1 parent c8b3ba7 commit a6911d2

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

backends/cpp_hart_gen/lib/gen_cpp.rb

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

backends/cpp_hart_gen/templates/csrs.cxx.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CsrFieldType <%= name_of(:csr_field, cfg_arch, csr.name, field.name) %>::type(co
2929
<%- if field.defined_in_all_bases? && cfg_arch.multi_xlen? -%>
3030
if (xlen == 32) {
3131
<%= field.type_to_cpp(32) %>
32-
} else if (xlen == 64) {
32+
} else { // if (xlen == 64)
3333
<%= field.type_to_cpp(64) %>
3434
}
3535
<%- else -%>

backends/cpp_hart_gen/templates/inst.hxx.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ namespace udb {
7878
#define __UDB_PC m_parent->pc()
7979
#define __UDB_MUTABLE_GLOBAL(x) m_parent->x
8080
#define __UDB_CONSTEXPR_FUNC_CALL <%= name_of(:hart, cfg_arch)%>::
81+
#define __UDB_CONST_GLOBAL(F) <%= name_of(:hart, cfg_arch)%>:: F
8182

8283
void execute() override {
8384

8485
<%- if inst.operation_ast(cfg_arch.symtab).nil? -%>
85-
m_parent->udb_assert(false, "There is no operation() defined for this instruction");
86+
m_parent->assert(false, "There is no operation() defined for this instruction");
8687
<%- else -%>
8788
<%- if !inst.base.nil? -%>
8889
<%- pruned_ast = inst.pruned_operation_ast(cfg_arch.symtab, inst.base) -%>
@@ -115,6 +116,7 @@ namespace udb {
115116
#undef __UDB_PC
116117
#undef __UDB_CONSTEXPR_FUNC_CALL
117118
#undef __UDB_SET_PC
119+
#undef __UDB_CONST_GLOBAL
118120

119121

120122
private:

0 commit comments

Comments
 (0)