diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-11-08 16:38:30 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-11-08 16:38:30 +0100 |
commit | db0654fa48ddc07e6bcaaaeddfa301a32806dadc (patch) | |
tree | ea611c24a41ea8d9dc1e2116b64b9760f26708e0 /cpp.cpp | |
parent | dd2a994fbbe946fa751b689e92c85696469e5e5c (diff) |
Prepare encoding and linking
Diffstat (limited to 'cpp.cpp')
-rw-r--r-- | cpp.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
@@ -1,9 +1,10 @@ #include "cpp.h" -#include "flowgraph/node.h" +#include "asm/encode.h" #include "bnf.h" #include "cppbnf.h" #include "debug.h" +#include "flowgraph/node.h" #include "lexer.h" #include "grammer.h" #include "minicc.h" @@ -101,7 +102,7 @@ std::string CPP::valueOfNode(index_t node_index) const if (!pos0) throw std::runtime_error("ICE: Node value not available"); - return m_code.substr(*pos0, m_tokens[last_index].location.pos - *pos0) + m_tokens[last_index].value; + return m_source.substr(*pos0, m_tokens[last_index].location.pos - *pos0) + m_tokens[last_index].value; }; std::string CPP::typeOfNode(index_t node_id) const @@ -572,25 +573,36 @@ void CPP::translate() // Phase 8: Instantiate objects void CPP::instantiate() { - // TODO + // TODO: template instantiation + + Asm::toMachineCode(mCPPContext.graph, mSegment); } // Phase 9: Link libraries void CPP::link() { // TODO + + // mSegment -> elf +#if 0 + return { + 0x48, 0xc7, 0xc0, 0x3c, 0x00, 0x00, 0x00, // mov $0x3c,%rax # syscall 60 + 0x48, 0x31, 0xff, // xor %rdi,%rdi # exit code 0 + 0x0f, 0x05, // syscall + }; +#endif } // phases of translation, according to standard -void CPP::compile(const std::string& code) +void CPP::compile(const std::string& source) { - m_code = code; + m_source = source; source_charset_map(); // phase 1 backslash_escape(); // phase 2 - auto pp_tokens = preprocessing_tokenize(code); // phase 3 + auto pp_tokens = preprocessing_tokenize(m_source); // phase 3 preprocess(); // phase 4 @@ -609,12 +621,7 @@ void CPP::compile(const std::string& code) std::vector<uint8_t> CPP::getCode() { - // TODO - return { - 0x48, 0xc7, 0xc0, 0x3c, 0x00, 0x00, 0x00, // mov $0x3c,%rax # syscall 60 - 0x48, 0x31, 0xff, // xor %rdi,%rdi # exit code 0 - 0x0f, 0x05, // syscall - }; + return mCode; } std::vector<uint8_t> CPP::getData() |