diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-03-29 20:15:52 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-03-29 20:15:52 +0200 |
commit | 2eb2383387d16fc919c07e1a6b9211406576b893 (patch) | |
tree | 83e5c5feb3b337552590d1ce7a4730d91081327f | |
parent | 12c12ebbdd3f843c87ba12c29727003f1f78a7ff (diff) |
Fix compiler structure
-rw-r--r-- | cpp.cpp | 15 | ||||
-rw-r--r-- | cpp.h | 8 | ||||
-rw-r--r-- | grammer.cpp | 2 | ||||
-rw-r--r-- | mcc.cpp | 2 |
4 files changed, 15 insertions, 12 deletions
@@ -182,7 +182,7 @@ namespace { } // Phase 7.a: Create tokens from preprocessing tokens -std::vector<Token> CPP::tokens_from_pptokens(std::vector<Token> pp_tokens) +std::vector<Token> CPP::tokens_from_pptokens(const std::vector<Token>& pp_tokens) { std::vector<Token> result; @@ -213,7 +213,7 @@ std::vector<Token> CPP::tokens_from_pptokens(std::vector<Token> pp_tokens) } // Phase 7.b: Grammar Analysis -std::vector<Gram::TreeNode> CPP::analysis(std::vector<Token> tokens) +std::vector<Gram::TreeNode> CPP::analysis(const std::vector<Token>& tokens) { auto bnf = SubBNF(CPPBNF::GetCppBNFGram(), "translation-unit"); @@ -223,9 +223,12 @@ std::vector<Gram::TreeNode> CPP::analysis(std::vector<Token> tokens) } // Phase 7.c: Translate -void CPP::translate() +void CPP::translate(const std::vector<Gram::TreeNode>& tree) { - // TODO + if (tree.size() == 0) + throw std::runtime_error("ICE: Tree is empty"); + + //traverse(i, ); } // Phase 8: Instantiate objects @@ -241,7 +244,7 @@ void CPP::link() } // phases of translation, according to standard -void CPP::translate(const std::string& code) +void CPP::compile(const std::string& code) { source_charset_map(); @@ -257,7 +260,7 @@ void CPP::translate(const std::string& code) auto tokens = tokens_from_pptokens(pp_tokens); auto nodes = analysis(tokens); - translate(); + translate(nodes); instantiate(); @@ -21,14 +21,14 @@ std::vector<Token> preprocessing_tokenize(const std::string& s); // phase 3 void preprocess(); // phase 4 void execution_charset_map(); // phase 5 void concatenate_strings(); // phase 6 -std::vector<Token> tokens_from_pptokens(std::vector<Token> pp_tokens); // phase 7.a -std::vector<Gram::TreeNode> analysis(std::vector<Token>); // phase 7.b -void translate(); // phase 7.c +std::vector<Token> tokens_from_pptokens(const std::vector<Token>& pp_tokens); // phase 7.a +std::vector<Gram::TreeNode> analysis(const std::vector<Token>&); // phase 7.b +void translate(const std::vector<Gram::TreeNode>& tree); // phase 7.c void instantiate(); // phase 8 void link(); // phase 9 // all phases of translation -void translate(const std::string& code); +void compile(const std::string& code); std::vector<uint8_t> getCode(); std::vector<uint8_t> getData(); diff --git a/grammer.cpp b/grammer.cpp index 40775ef..8b6f01b 100644 --- a/grammer.cpp +++ b/grammer.cpp @@ -313,7 +313,7 @@ std::vector<TreeNode> Compiler::compile(std::vector<Token> p_tokens) if (!match(m_top, 0, tokens.size())) throw std::runtime_error("Compile error"); - //DumpTree(); + DumpTree(); return nodes; } @@ -38,7 +38,7 @@ int main(int argc, char* argv[]) std::string unit_string(reinterpret_cast<char*>(unit.data()), unit.size()); - cpp.translate(unit_string); + cpp.compile(unit_string); Elf::Write(out_filename, cpp.getCode(), cpp.getData()); } catch (const std::exception& ex) { |