mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-05 22:38:44 +00:00
basic compiler integration (with errors, without check)
This commit is contained in:
parent
7c3ff04573
commit
26d2eaa8b3
5 changed files with 31 additions and 3 deletions
|
|
@ -6,12 +6,14 @@
|
||||||
(:parser src/parser.cpp)
|
(:parser src/parser.cpp)
|
||||||
(:analyzer src/analyzer.cpp)
|
(:analyzer src/analyzer.cpp)
|
||||||
(:module_manager src/module_manager.cpp)
|
(:module_manager src/module_manager.cpp)
|
||||||
|
(:sm_parser src/sm_parser.cpp)
|
||||||
|
(:compiler src/compiler.cpp)
|
||||||
(:obj types.o interpreter.o)
|
(:obj types.o interpreter.o)
|
||||||
(:runtime ../runtime/runtime.a))
|
(:runtime ../runtime/runtime.a))
|
||||||
(mode
|
(mode
|
||||||
(promote (until-clean)))
|
(promote (until-clean)))
|
||||||
(action
|
(action
|
||||||
(run g++ -Wall -Wextra -O3 -std=c++20 -DWITH_CHECK -Iinclude/ %{main} %{parser} %{analyzer} %{module_manager} %{runtime} %{obj} -o %{target})))
|
(run g++ -Wall -Wextra -O3 -std=c++20 -DWITH_CHECK -Iinclude/ %{main} %{parser} %{analyzer} %{module_manager} %{sm_parser} %{compiler} %{runtime} %{obj} -o %{target})))
|
||||||
|
|
||||||
(rule
|
(rule
|
||||||
(target types.o)
|
(target types.o)
|
||||||
|
|
|
||||||
6
byterun/include/compiler.hpp
Normal file
6
byterun/include/compiler.hpp
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "sm_parser.hpp"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
std::vector<std::string> compile_to_code(const std::vector<SMInstr> &code);
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "analyzer.hpp"
|
#include "analyzer.hpp"
|
||||||
|
#include "compiler.hpp"
|
||||||
#include "parser.hpp"
|
#include "parser.hpp"
|
||||||
#include "sm_parser.hpp"
|
#include "sm_parser.hpp"
|
||||||
|
|
||||||
|
|
@ -24,7 +25,7 @@ int main(int argc, char **argv) {
|
||||||
bool do_print = false;
|
bool do_print = false;
|
||||||
if (strcmp(argv[1], "-i") == 0) {
|
if (strcmp(argv[1], "-i") == 0) {
|
||||||
do_interpretation = true;
|
do_interpretation = true;
|
||||||
} else if (strcmp(argv[1], "-sm") == 0) { // TODO: TMP, FOR CHECKS
|
} else if (strcmp(argv[1], "-ds") == 0) { // TODO: TMP, FOR CHECKS
|
||||||
std::ifstream file(argv[2]);
|
std::ifstream file(argv[2]);
|
||||||
std::cout << "-- parse\n";
|
std::cout << "-- parse\n";
|
||||||
auto instrs = parse_sm(file);
|
auto instrs = parse_sm(file);
|
||||||
|
|
@ -33,6 +34,13 @@ int main(int argc, char **argv) {
|
||||||
std::cout << print_sm(instr) << "\n";
|
std::cout << print_sm(instr) << "\n";
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
} else if (strcmp(argv[1], "-s") == 0) {
|
||||||
|
std::ifstream file(argv[2]);
|
||||||
|
auto instrs = compile_to_code(parse_sm(file));
|
||||||
|
for (auto &instr : instrs) {
|
||||||
|
std::cout << instr << "\n";
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#ifdef WITH_CHECK
|
#ifdef WITH_CHECK
|
||||||
else if (strcmp(argv[1], "-vi") == 0) {
|
else if (strcmp(argv[1], "-vi") == 0) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "../../runtime/runtime.h"
|
#include "../../runtime/runtime.h"
|
||||||
|
|
||||||
|
#include "compiler.hpp"
|
||||||
#include "sm_parser.hpp"
|
#include "sm_parser.hpp"
|
||||||
|
|
||||||
#include <format>
|
#include <format>
|
||||||
|
|
@ -2115,3 +2116,15 @@ std::vector<Instr> compile(const Options &cmd, Env &env,
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> compile_to_code(const std::vector<SMInstr> &code) {
|
||||||
|
Options cmd{.topname = "byterun", .filename = "byterun"}; // TODO TMP
|
||||||
|
Env env(Mode{.is_debug = true, .target_os = OS::LINUX});
|
||||||
|
|
||||||
|
auto asm_code = compile(cmd, env, {/*imports (TODO TMP)*/}, code);
|
||||||
|
std::vector<std::string> res;
|
||||||
|
std::transform(asm_code.begin(), asm_code.end(), std::back_inserter(res),
|
||||||
|
[&env](const auto &instr) { return to_code(env, instr); });
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ target("byterun")
|
||||||
add_includedirs("include")
|
add_includedirs("include")
|
||||||
add_files("../runtime/**.c", "../runtime/**.S")
|
add_files("../runtime/**.c", "../runtime/**.S")
|
||||||
add_files("src/**.cpp", "src/**.c")
|
add_files("src/**.cpp", "src/**.c")
|
||||||
remove_files("src/compiler.cpp")
|
|
||||||
set_warnings("allextra")
|
set_warnings("allextra")
|
||||||
set_rundir("$(projectdir)")
|
set_rundir("$(projectdir)")
|
||||||
add_defines("WITH_CHECK")
|
add_defines("WITH_CHECK")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue