Commit 9cab866a authored by zygzagZ's avatar zygzagZ

WIP tworzenie asm

parent 3bc2b0ce
Pipeline #13 failed with stages
#include "Compiler.h"
#include <filesystem>
Compiler::Compiler(std::string f)
: TypeCheck(), file(f), buf()
{
};
extern std::filesystem::path binaryPath;
const std::string Compiler::extension = "s";
void Compiler::externalCommand(std::filesystem::path lat) {
......@@ -20,5 +25,14 @@ void Compiler::externalCommand(std::filesystem::path lat) {
std::string Compiler::compile(Visitable *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
#define COMPILER_HEADER
/* You might want to change the above name. */
#include "TypeCheck.h"
#include <filesystem>
......@@ -8,8 +7,7 @@
class Compiler : public TypeCheck
{
public:
Compiler(std::string f) : file(f) {};
Compiler(std::string f);
std::string compile(Visitable *v);
static const std::string extension;
......@@ -17,6 +15,7 @@ public:
private:
std::filesystem::path file;
std::stringstream buf;
// enum State {
// initialized,
// findClasses,
......
......@@ -75,7 +75,7 @@ int main(int argc, char ** argv)
binaryPath = argv[0];
std::filesystem::path file(filename ? filename : "Latte");
try {
Compiler c(file);
Compiler c(file.string());
std::string out = c.compile(parse_tree);
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