Implement division
This commit is contained in:
@ -2,15 +2,15 @@
|
||||
#include "elna/backend/riscv.hpp"
|
||||
#include <elfio/elfio.hpp>
|
||||
|
||||
namespace elna::backend
|
||||
namespace elna::riscv
|
||||
{
|
||||
void riscv32_elf(source::block *ast, const std::filesystem::path& out_file)
|
||||
{
|
||||
auto visitor = std::make_unique<RiscVVisitor>();
|
||||
visitor->visit(ast);
|
||||
auto _visitor = std::make_unique<visitor>();
|
||||
_visitor->visit(ast);
|
||||
|
||||
ELFIO::elfio writer;
|
||||
const ELFIO::Elf_Word instructions_size = visitor->instructions.size() * sizeof(Instruction);
|
||||
const ELFIO::Elf_Word instructions_size = _visitor->instructions.size() * sizeof(instruction);
|
||||
|
||||
writer.create(ELFIO::ELFCLASS32, ELFIO::ELFDATA2LSB);
|
||||
|
||||
@ -23,7 +23,7 @@ namespace elna::backend
|
||||
text_sec->set_type(ELFIO::SHT_PROGBITS);
|
||||
text_sec->set_flags(ELFIO::SHF_ALLOC | ELFIO::SHF_EXECINSTR);
|
||||
text_sec->set_addr_align(0x1);
|
||||
text_sec->set_data(reinterpret_cast<const char *>(visitor->instructions.data()),
|
||||
text_sec->set_data(reinterpret_cast<const char *>(_visitor->instructions.data()),
|
||||
instructions_size);
|
||||
|
||||
// Create string table section
|
||||
@ -71,12 +71,12 @@ namespace elna::backend
|
||||
// Create relocation table writer
|
||||
ELFIO::relocation_section_accessor rela(writer, rel_sec);
|
||||
// Add relocation entry (adjust address at offset 11)
|
||||
rela.add_entry(visitor->references[0].offset, label_sym, 26 /* ELFIO::R_RISCV_HI20 */);
|
||||
rela.add_entry(visitor->references[0].offset, label_sym, 51 /* ELFIO::R_RISCV_RELAX */);
|
||||
rela.add_entry(visitor->references[1].offset, label_sym, 27 /* ELFIO::R_RISCV_LO12_I */);
|
||||
rela.add_entry(visitor->references[1].offset, label_sym, 51 /* ELFIO::R_RISCV_RELAX */);
|
||||
rela.add_entry(visitor->references[2].offset, printf_sym, 18 /* ELFIO::R_RISCV_CALL */);
|
||||
rela.add_entry(visitor->references[2].offset, printf_sym, 51 /* ELFIO::R_RISCV_RELAX */);
|
||||
rela.add_entry(_visitor->references[0].offset, label_sym, 26 /* ELFIO::R_RISCV_HI20 */);
|
||||
rela.add_entry(_visitor->references[0].offset, label_sym, 51 /* ELFIO::R_RISCV_RELAX */);
|
||||
rela.add_entry(_visitor->references[1].offset, label_sym, 27 /* ELFIO::R_RISCV_LO12_I */);
|
||||
rela.add_entry(_visitor->references[1].offset, label_sym, 51 /* ELFIO::R_RISCV_RELAX */);
|
||||
rela.add_entry(_visitor->references[2].offset, printf_sym, 18 /* ELFIO::R_RISCV_CALL */);
|
||||
rela.add_entry(_visitor->references[2].offset, printf_sym, 51 /* ELFIO::R_RISCV_RELAX */);
|
||||
|
||||
// Create ELF object file
|
||||
writer.save(out_file);
|
||||
|
Reference in New Issue
Block a user