Skip to content

Commit

Permalink
[cpp] skeleton code for the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed May 5, 2024
1 parent d254f4b commit 490e886
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/ast.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "ast.hpp"

9 changes: 9 additions & 0 deletions cpp/src/ast.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef PSYC_AST_HPP
#define PSYC_AST_HPP

struct ast
{

};

#endif // PSYC_AST_HPP
12 changes: 12 additions & 0 deletions cpp/src/parse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "parse.hpp"
#include "lex.hpp"

namespace parse
{
ast tokens(lex::const_token_view toks)
{
ast ret;

return ret;
}
}
16 changes: 16 additions & 0 deletions cpp/src/parse.hpp
Original file line number Diff line number Diff line change
@@ -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<std::filesystem::path, ast> parsed_input_files = {};
};
}

#endif // PSYC_PARSE_HPP
19 changes: 19 additions & 0 deletions cpp/src/psyc_main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "config.hpp"
#include "lex.hpp"
#include "parse.hpp"
#include "timer.hpp"
#include "diag.hpp"
#include <filesystem>
Expand All @@ -16,13 +17,15 @@ 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;
std::cout << std::setw(width) << "lexer:" << std::setw(6) << std::setprecision(3) << (this->lexing / 1000.0f) << " seconds" << std::endl;
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;
}
};

Expand All @@ -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)
Expand All @@ -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;
}
Expand Down

0 comments on commit 490e886

Please sign in to comment.