From 490e88686a46f7228f9eec45a726ff1808a863f2 Mon Sep 17 00:00:00 2001 From: harrand Date: Sun, 5 May 2024 02:09:37 +0100 Subject: [PATCH] [cpp] skeleton code for the parser --- cpp/CMakeLists.txt | 5 +++++ cpp/src/ast.cpp | 2 ++ cpp/src/ast.hpp | 9 +++++++++ cpp/src/parse.cpp | 12 ++++++++++++ cpp/src/parse.hpp | 16 ++++++++++++++++ cpp/src/psyc_main.cpp | 19 +++++++++++++++++++ 6 files changed, 63 insertions(+) create mode 100644 cpp/src/ast.cpp create mode 100644 cpp/src/ast.hpp create mode 100644 cpp/src/parse.cpp create mode 100644 cpp/src/parse.hpp diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 13579a5..6c4ce72 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -32,10 +32,15 @@ separate_arguments(llvm_definitions_list NATIVE_COMMAND ${LLVM_DEFINITIONS}) add_executable(psyc src/psyc_main.cpp + src/ast.cpp + src/ast.hpp + src/config.hpp src/diag.hpp src/error.hpp src/lex.cpp src/lex.hpp + src/parse.cpp + src/parse.hpp src/srcloc.hpp src/timer.cpp src/timer.hpp diff --git a/cpp/src/ast.cpp b/cpp/src/ast.cpp new file mode 100644 index 0000000..0dc5800 --- /dev/null +++ b/cpp/src/ast.cpp @@ -0,0 +1,2 @@ +#include "ast.hpp" + diff --git a/cpp/src/ast.hpp b/cpp/src/ast.hpp new file mode 100644 index 0000000..6b202cc --- /dev/null +++ b/cpp/src/ast.hpp @@ -0,0 +1,9 @@ +#ifndef PSYC_AST_HPP +#define PSYC_AST_HPP + +struct ast +{ + +}; + +#endif // PSYC_AST_HPP \ No newline at end of file diff --git a/cpp/src/parse.cpp b/cpp/src/parse.cpp new file mode 100644 index 0000000..97fadda --- /dev/null +++ b/cpp/src/parse.cpp @@ -0,0 +1,12 @@ +#include "parse.hpp" +#include "lex.hpp" + +namespace parse +{ + ast tokens(lex::const_token_view toks) + { + ast ret; + + return ret; + } +} \ No newline at end of file diff --git a/cpp/src/parse.hpp b/cpp/src/parse.hpp new file mode 100644 index 0000000..c6044e3 --- /dev/null +++ b/cpp/src/parse.hpp @@ -0,0 +1,16 @@ +#ifndef PSYC_PARSE_HPP +#define PSYC_PARSE_HPP +#include "ast.hpp" +#include "lex.hpp" + +namespace parse +{ + ast tokens(lex::const_token_view toks); + + struct state + { + std::unordered_map parsed_input_files = {}; + }; +} + +#endif // PSYC_PARSE_HPP \ No newline at end of file diff --git a/cpp/src/psyc_main.cpp b/cpp/src/psyc_main.cpp index 3594795..7029e8e 100644 --- a/cpp/src/psyc_main.cpp +++ b/cpp/src/psyc_main.cpp @@ -1,5 +1,6 @@ #include "config.hpp" #include "lex.hpp" +#include "parse.hpp" #include "timer.hpp" #include "diag.hpp" #include @@ -16,6 +17,7 @@ struct timers std::uint64_t parsing = 0u; std::uint64_t semal = 0u; std::uint64_t codegen = 0u; + std::uint64_t link = 0u; void print() { constexpr int width = 16; @@ -23,6 +25,7 @@ struct timers std::cout << std::setw(width) << "parser:" << std::setw(6) << std::setprecision(3) << (this->parsing / 1000.0f) << " seconds" << std::endl; std::cout << std::setw(width) << "semal:" << std::setw(6) << std::setprecision(3) << (this->semal / 1000.0f) << " seconds" << std::endl; std::cout << std::setw(width) << "codegen:" << std::setw(6) << std::setprecision(3) << (this->codegen / 1000.0f) << " seconds" << std::endl; + std::cout << std::setw(width) << "link:" << std::setw(6) << std::setprecision(3) << (this->link / 1000.0f) << " seconds" << std::endl; } }; @@ -32,6 +35,7 @@ int main(int argc, char** argv) config::compiler_args args = parse_args(cli_args); timers t; + // lex timer::start(); lex::state lex; for(const std::filesystem::path input_file : args.input_files) @@ -40,6 +44,21 @@ int main(int argc, char** argv) } t.lexing = timer::elapsed_millis(); + // parse + timer::start(); + parse::state parse; + for(const std::filesystem::path input_file : args.input_files) + { + parse.parsed_input_files[input_file] = parse::tokens(lex.tokenised_input_files[input_file].tokens); + } + t.parsing = timer::elapsed_millis(); + + // semal + + // codegen + + // link + t.print(); return 0; }