Commit 9cab866a authored by zygzagZ's avatar zygzagZ

WIP tworzenie asm

parent 3bc2b0ce
Pipeline #13 failed with stages
#include "Compiler.h" #include "Compiler.h"
#include <filesystem> #include <filesystem>
Compiler::Compiler(std::string f)
: TypeCheck(), file(f), buf()
{
};
extern std::filesystem::path binaryPath; extern std::filesystem::path binaryPath;
const std::string Compiler::extension = "s"; const std::string Compiler::extension = "s";
void Compiler::externalCommand(std::filesystem::path lat) { void Compiler::externalCommand(std::filesystem::path lat) {
...@@ -20,5 +25,14 @@ void Compiler::externalCommand(std::filesystem::path lat) { ...@@ -20,5 +25,14 @@ void Compiler::externalCommand(std::filesystem::path lat) {
std::string Compiler::compile(Visitable *v) { std::string Compiler::compile(Visitable *v) {
check(v); check(v);
return "empty\n"; for (auto i : {"printStr", "printInt", "readInt", "readStr", "error", "exit", "_start"}) {
buf << ".globl " << i << "\n";
}
buf << "_start:\n"
"pushl %%ebp\n"
"movl %%esp, %%ebp\n"
"call main\n"
"pushl %%eax\n"
"call exit\n";
return buf.str();
} }
\ No newline at end of file
#ifndef COMPILER_HEADER #ifndef COMPILER_HEADER
#define COMPILER_HEADER #define COMPILER_HEADER
/* You might want to change the above name. */
#include "TypeCheck.h" #include "TypeCheck.h"
#include <filesystem> #include <filesystem>
...@@ -8,8 +7,7 @@ ...@@ -8,8 +7,7 @@
class Compiler : public TypeCheck class Compiler : public TypeCheck
{ {
public: public:
Compiler(std::string f);
Compiler(std::string f) : file(f) {};
std::string compile(Visitable *v); std::string compile(Visitable *v);
static const std::string extension; static const std::string extension;
...@@ -17,6 +15,7 @@ public: ...@@ -17,6 +15,7 @@ public:
private: private:
std::filesystem::path file; std::filesystem::path file;
std::stringstream buf;
// enum State { // enum State {
// initialized, // initialized,
// findClasses, // findClasses,
......
...@@ -75,7 +75,7 @@ int main(int argc, char ** argv) ...@@ -75,7 +75,7 @@ int main(int argc, char ** argv)
binaryPath = argv[0]; binaryPath = argv[0];
std::filesystem::path file(filename ? filename : "Latte"); std::filesystem::path file(filename ? filename : "Latte");
try { try {
Compiler c(file); Compiler c(file.string());
std::string out = c.compile(parse_tree); std::string out = c.compile(parse_tree);
if (!filename) { if (!filename) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment