diff options
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() |