Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyfah committed Sep 13, 2023
1 parent 6e70833 commit cff88a2
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 976 deletions.
8 changes: 0 additions & 8 deletions CodeGen/include/Codegen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include "SemanticAnalysis/include/SymbolTable.hpp"
#include "Register.hpp"

#include <vector>
#include <string>
#include <sstream>

class CodeGen
{
Expand All @@ -25,17 +22,12 @@ class CodeGen

void perform_operation(LexerTokenType op, int reg_idx1, int reg_idx2);

std::string output() {
return output_stream.str();
}

private:
RegisterAllocator reg;
int last_reg;
symbolTable::Table _symboltable;
std::unordered_map<std::string, int> _staked_var;
int sp = -4;
std::stringstream output_stream;
};

#endif
10 changes: 3 additions & 7 deletions CodeGen/src/Codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ nlohmann::json CodeGen::convert(const std::vector<std::shared_ptr<Node>> &compou
{
nlohmann::json jArray = nlohmann::json::array();
// Traverse the AST in postfix order
for (auto &node : compound)
{
jArray.push_back(traverse(node));
}
for (auto &node : compound) { jArray.push_back(traverse(node)); }

return jArray;
}
Expand Down Expand Up @@ -138,7 +135,6 @@ nlohmann::json CodeGen::traverse(const std::shared_ptr<Node> node)
reg.free_register(last_reg);
last_reg = reg_idx;
break;

}

case LexerTokenType::MinusToken:
Expand Down Expand Up @@ -189,14 +185,14 @@ nlohmann::json CodeGen::traverse(const std::shared_ptr<Node> node)
case LexerTokenType::PrintToken:
instruction.clear();
instruction["command"] = "print";
instruction["registers"] = { ""};
instruction["registers"] = { "" };
instructions.push_back(instruction);
traverse(node->left);
nlohmann::json leftInstructions = traverse(node->left);
instructions.insert(instructions.end(), leftInstructions.begin(), leftInstructions.end());
int reg_idx = reg.alloc_register();
instruction["command"] = "bl";
instruction["registers"] = { ""};
instruction["registers"] = { "" };
instruction["value"] = "printf";
instructions.push_back(instruction);

Expand Down
12 changes: 0 additions & 12 deletions SemanticAnalysis/include/SymbolTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,6 @@ namespace symbolTable {
return "UNKNOWN";
}

// prints symbol table
std::stringstream printTable()
{
std::stringstream _output;
for (const auto &node : nodes)
{
_output << node.node.value << " " << to_string(std::get<InferredType>(node.inferredType));
_output << std::endl;
}
return _output;
}

nlohmann::json tableToJson()
{
nlohmann::json jArray = nlohmann::json::array();
Expand Down
8 changes: 0 additions & 8 deletions SyntaxAnalysis/src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,3 @@ std::shared_ptr<Node> Parser::Print()

return makeUnary(left, type);
}








258 changes: 0 additions & 258 deletions Utils/FileHandler.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions Utils/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22695,7 +22695,7 @@ if no parse error occurred.
@since version 1.0.0
*/
JSON_HEDLEY_NON_NULL(1)
inline nlohmann::json operator "" _json(const char* s, std::size_t n)
inline nlohmann::json operator ""_json(const char* s, std::size_t n)
{
return nlohmann::json::parse(s, s + n);
}
Expand All @@ -22714,7 +22714,7 @@ object if no parse error occurred.
@since version 2.0.0
*/
JSON_HEDLEY_NON_NULL(1)
inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n)
inline nlohmann::json::json_pointer operator ""_json_pointer(const char* s, std::size_t n)
{
return nlohmann::json::json_pointer(std::string(s, n));
}
Expand Down
Loading

0 comments on commit cff88a2

Please sign in to comment.