aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Notes.org43
-rw-r--r--c_compiler/GPATHbin0 -> 16384 bytes
-rw-r--r--c_compiler/GRTAGSbin0 -> 98304 bytes
-rw-r--r--c_compiler/GTAGSbin0 -> 57344 bytes
-rw-r--r--c_compiler/TAGS113
-rw-r--r--c_compiler/include/ast.hpp4
-rw-r--r--c_compiler/include/declaration.hpp9
-rw-r--r--c_compiler/include/expression.hpp10
-rw-r--r--c_compiler/include/function.hpp11
-rw-r--r--c_compiler/include/node.hpp21
-rw-r--r--c_compiler/include/statement.hpp17
-rw-r--r--c_compiler/include/translation_unit.hpp10
-rw-r--r--c_compiler/include/type.hpp4
-rw-r--r--c_compiler/src/c_parser.y15
-rw-r--r--c_compiler/src/compiler_main.cpp5
-rw-r--r--c_compiler/src/declaration.cpp2
-rw-r--r--c_compiler/src/expression.cpp8
-rw-r--r--c_compiler/src/function.cpp11
-rw-r--r--c_compiler/src/statement.cpp22
-rw-r--r--c_compiler/src/translation_unit.cpp4
-rw-r--r--c_compiler/src/type.cpp2
22 files changed, 197 insertions, 115 deletions
diff --git a/.gitignore b/.gitignore
index fe302c9..44b4cf2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,4 @@ c_compiler/build/
.#*
*.log
.vagrant
+test/
diff --git a/Notes.org b/Notes.org
index 6766d99..8b2d525 100644
--- a/Notes.org
+++ b/Notes.org
@@ -3,6 +3,7 @@
#+AUTHOR: Yann Herklotz
#+EMAIL: ymherklotz@gmail.com
#+DESCRIPTION: These are notes about the Compiler project.
+#+DATE: <2017-03-09 Thu>
* Lexer
@@ -89,11 +90,43 @@
- move :: Pseudo instruction interpreted as (add $rt, $rs, $zero)
- nop :: No Operation
- sw :: Store Word
+*** TODOs
+**** Expression
-*** TODOs
+***** void evaluate(VariableStackBindings binding)
+
+ Statements evaluate the expression by writing it out and printing the resulting asm
+ onto the command line. I will also have to pass the bindings to the evaluate function
+
+ examples:
+
+ z = a + b + c, will be calculated as $2 = b + c, and then $2 = a + $2
+
+ This should happen automatically because of recursion.
+ Have to be careful because of the way the expressions are parsed.
+ Constant expressions will just output li $2, 6 for example
+
+**** Function class
+
+**** Statement class
+
+ - Need function that prints declaration bits and expression bits, as well as connected
+ statements
+
+**** Definition class
+
+ - need function that will print the code for declaration. Basic code should be:
+
+ li $2, 6
+ sw $2, 4($fp)
+
+ - Before that is executed it should evaluate the expression.
+
+ - The expression should be the thing doing: li $2, 6
+ That is if we want a 6 stored in the variable.
- - Analyse tree with map including "name", and struct with "type" and "stack
- position", and a counter passed by reference.
- - This function will be called by printasm() in the base class and will only be
- implemented by function.
+ - The declaration class should only be in charge of storing it in the right location in
+ the stack.
+
+
diff --git a/c_compiler/GPATH b/c_compiler/GPATH
new file mode 100644
index 0000000..1af534b
--- /dev/null
+++ b/c_compiler/GPATH
Binary files differ
diff --git a/c_compiler/GRTAGS b/c_compiler/GRTAGS
new file mode 100644
index 0000000..c1933dc
--- /dev/null
+++ b/c_compiler/GRTAGS
Binary files differ
diff --git a/c_compiler/GTAGS b/c_compiler/GTAGS
new file mode 100644
index 0000000..4128c61
--- /dev/null
+++ b/c_compiler/GTAGS
Binary files differ
diff --git a/c_compiler/TAGS b/c_compiler/TAGS
index 97375a9..77480fc 100644
--- a/c_compiler/TAGS
+++ b/c_compiler/TAGS
@@ -4,22 +4,22 @@ include/node.hpp,96
class Node {Node7,64
virtual ~Node() {}~Node9,85
-include/statement.hpp,783
+include/statement.hpp,786
#define AST_STATEMENT_HPPAST_STATEMENT_HPP2,26
class Statement : public Node {Statement7,74
Statement* next_statement;next_statement9,117
-class CompoundStatement : public Statement {CompoundStatement24,435
- Declaration* m_decl;m_decl26,491
- Statement* m_statement;m_statement27,516
-class SelectionStatement : public Statement {SelectionStatement41,855
- Statement* m_if;m_if43,912
- Statement* m_else;m_else44,933
-class ExpressionStatement : public Statement {ExpressionStatement56,1211
- Expression* m_expr;m_expr58,1269
-class JumpStatement : public Statement {JumpStatement70,1523
- Expression* m_expr;m_expr72,1575
-class IterationStatement : public Statement {IterationStatement84,1823
- Statement* m_statement;m_statement86,1880
+class CompoundStatement : public Statement {CompoundStatement26,524
+ Declaration* m_decl;m_decl28,580
+ Statement* m_statement;m_statement29,605
+class SelectionStatement : public Statement {SelectionStatement45,1029
+ Statement* m_if;m_if47,1086
+ Statement* m_else;m_else48,1107
+class ExpressionStatement : public Statement {ExpressionStatement62,1470
+ Expression* m_expr;m_expr64,1528
+class JumpStatement : public Statement {JumpStatement78,1867
+ Expression* m_expr;m_expr80,1919
+class IterationStatement : public Statement {IterationStatement94,2252
+ Statement* m_statement;m_statement96,2309
include/function.hpp,363
#define AST_FUNCTION_HPPAST_FUNCTION_HPP2,25
@@ -35,10 +35,10 @@ class Function : public Node {Function13,142
include/expression.hpp,286
#define AST_EXPRESSION_HPPAST_EXPRESSION_HPP2,27
class Expression : public Node {Expression6,75
-class Identifier : public Expression {Identifier15,232
- std::string m_id;m_id17,280
-class Constant : public Expression {Constant25,390
- int32_t m_constant;m_constant27,436
+class Identifier : public Expression {Identifier16,267
+ std::string m_id;m_id18,315
+class Constant : public Expression {Constant26,425
+ int32_t m_constant;m_constant28,471
include/translation_unit.hpp,163
#define EXTERNAL_HPPEXTERNAL_HPP2,21
@@ -65,11 +65,11 @@ typedef std::map<std::string, VarLocation> VariableStack;VariableStack12,145
include/declaration.hpp,297
#define AST_DECLARATION_HPPAST_DECLARATION_HPP2,28
class Declaration : public Node {Declaration8,127
- Type* type;type10,172
- std::string id;id11,188
- Expression* init;init12,208
- Declaration* next_decl;next_decl13,230
- Declaration* list_next_decl;list_next_decl14,258
+ Type* type;type10,170
+ std::string id;id11,186
+ Expression* init;init12,206
+ Declaration* next_decl;next_decl13,228
+ Declaration* list_next_decl;list_next_decl14,256
src/c_parser.tab.cpp,9030
#define YYBISON YYBISON44,2037
@@ -461,7 +461,7 @@ void Identifier::printasm() constprintasm19,212
Constant::Constant(const int32_t& constant)Constant25,275
void Constant::printasm() constprintasm29,350
-src/statement.cpp,1960
+src/statement.cpp,2074
Statement::Statement(Statement* statement)Statement6,59
void Statement::addStatement(Statement* _next)addStatement10,138
CompoundStatement::CompoundStatement(Declaration* decl, Statement* statement)CompoundStatement18,253
@@ -470,26 +470,27 @@ void CompoundStatement::print() constprint26,483
void CompoundStatement::printxml() constprintxml35,629
void CompoundStatement::printasm() constprintasm51,945
void CompoundStatement::count_variables(int32_t& var_count) constcount_variables62,1154
-SelectionStatement::SelectionStatement(Statement* _if, Statement* _else)SelectionStatement90,1751
-void SelectionStatement::print() constprint93,1872
-void SelectionStatement::printxml() constprintxml99,1956
-void SelectionStatement::printasm() constprintasm109,2156
-void SelectionStatement::count_variables(int32_t& var_count) constcount_variables112,2202
-ExpressionStatement::ExpressionStatement(Expression* expr)ExpressionStatement127,2514
-void ExpressionStatement::print() constprint131,2609
-void ExpressionStatement::printxml() constprintxml134,2653
-void ExpressionStatement::printasm() constprintasm137,2700
-void ExpressionStatement::count_variables(int32_t& var_count) constcount_variables140,2747
-JumpStatement::JumpStatement(Expression* expr)JumpStatement149,2930
-void JumpStatement::print() constprint153,3000
-void JumpStatement::printxml() constprintxml156,3038
-void JumpStatement::printasm() constprintasm162,3143
-void JumpStatement::count_variables(int32_t& var_count) constcount_variables167,3209
-IterationStatement::IterationStatement(Statement* statement)IterationStatement176,3391
-void IterationStatement::print() constprint180,3485
-void IterationStatement::printxml() constprintxml183,3528
-void IterationStatement::printasm() constprintasm191,3695
-void IterationStatement::count_variables(int32_t& var_count) constcount_variables194,3741
+void CompoundStatement::make_variables(VariableStack var_stack, int32_t& var_count) constmake_variables87,1715
+SelectionStatement::SelectionStatement(Statement* _if, Statement* _else)SelectionStatement95,1851
+void SelectionStatement::print() constprint98,1972
+void SelectionStatement::printxml() constprintxml104,2056
+void SelectionStatement::printasm() constprintasm114,2256
+void SelectionStatement::count_variables(int32_t& var_count) constcount_variables117,2302
+ExpressionStatement::ExpressionStatement(Expression* expr)ExpressionStatement132,2614
+void ExpressionStatement::print() constprint136,2709
+void ExpressionStatement::printxml() constprintxml139,2753
+void ExpressionStatement::printasm() constprintasm142,2800
+void ExpressionStatement::count_variables(int32_t& var_count) constcount_variables145,2847
+JumpStatement::JumpStatement(Expression* expr)JumpStatement154,3030
+void JumpStatement::print() constprint158,3100
+void JumpStatement::printxml() constprintxml161,3138
+void JumpStatement::printasm() constprintasm167,3243
+void JumpStatement::count_variables(int32_t& var_count) constcount_variables172,3309
+IterationStatement::IterationStatement(Statement* statement)IterationStatement181,3491
+void IterationStatement::print() constprint185,3585
+void IterationStatement::printxml() constprintxml188,3628
+void IterationStatement::printasm() constprintasm196,3795
+void IterationStatement::count_variables(int32_t& var_count) constcount_variables199,3841
src/c_parser.tab.hpp,2446
# define YY_YY_C_COMPILER_SRC_C_PARSER_TAB_HPP_INCLUDEDYY_YY_C_COMPILER_SRC_C_PARSER_TAB_HPP_INCLUDED34,1569
@@ -561,18 +562,18 @@ typedef union YYSTYPE YYSTYPE;YYSTYPE135,3582
src/compiler_main.cpp,43
int main(int argc, char *argv[])main5,41
-src/declaration.cpp,651
+src/declaration.cpp,654
Declaration::Declaration(const std::string& _id)Declaration6,48
void Declaration::print() constprint10,115
void Declaration::printxml() constprintxml19,255
void Declaration::printasm() constprintasm32,504
-void Declaration::addDeclaration(Declaration* _next_decl)addDeclaration35,543
-void Declaration::addList(Declaration* _next_decl)addList40,634
-void Declaration::setType(Type* _type)setType45,723
-Declaration* Declaration::getNext() constgetNext50,785
-Declaration* Declaration::getNextListItem() constgetNextListItem55,854
-std::string Declaration::getId() constgetId60,936
-std::string Declaration::getType() constgetType65,995
+void Declaration::addDeclaration(Declaration* _next_decl)addDeclaration42,746
+void Declaration::addList(Declaration* _next_decl)addList47,837
+void Declaration::setType(Type* _type)setType52,926
+Declaration* Declaration::getNext() constgetNext57,988
+Declaration* Declaration::getNextListItem() constgetNextListItem62,1057
+std::string Declaration::getId() constgetId67,1139
+std::string Declaration::getType() constgetType72,1198
src/translation_unit.cpp,276
TranslationUnit::TranslationUnit(Node* decl)TranslationUnit6,53
@@ -653,12 +654,18 @@ test/out/04.s,28
main:main3,20
f:f14,153
+test/out/05.s,0
+
test/out/02.s,16
main:main3,20
test/in/02.c,22
int main() {main1,0
+test/in/05.c,44
+char *glob;glob1,0
+int main() {main3,13
+
test/in/01.c,22
int main() {main1,0
@@ -679,5 +686,9 @@ test/ref/04.s,30
main:main15,207
f:f47,695
+test/ref/05.s,36
+$LC0:$LC012,145
+main:main21,267
+
test/ref/02.s,18
main:main15,207
diff --git a/c_compiler/include/ast.hpp b/c_compiler/include/ast.hpp
index 4bcd523..88ef36b 100644
--- a/c_compiler/include/ast.hpp
+++ b/c_compiler/include/ast.hpp
@@ -9,7 +9,7 @@
struct VarLocation;
-typedef std::map<std::string, VarLocation> VariableStack;
+typedef std::map<std::string, VarLocation> VariableStackBindings;
#include "node.hpp"
#include "type.hpp"
@@ -19,6 +19,6 @@ typedef std::map<std::string, VarLocation> VariableStack;
#include "function.hpp"
#include "translation_unit.hpp"
-TranslationUnit* parseAST();
+Node* parseAST();
#endif
diff --git a/c_compiler/include/declaration.hpp b/c_compiler/include/declaration.hpp
index 7f862a5..8226090 100644
--- a/c_compiler/include/declaration.hpp
+++ b/c_compiler/include/declaration.hpp
@@ -1,12 +1,13 @@
#ifndef AST_DECLARATION_HPP
#define AST_DECLARATION_HPP
-#include "ast.hpp"
+#include "node.hpp"
+
+class Expression;
-// Declaration that holds a list of declarations
class Declaration : public Node {
-protected:
+private:
Type* type;
std::string id;
Expression* init;
@@ -18,7 +19,7 @@ public:
virtual void print() const;
virtual void printxml() const;
- virtual void printasm() const;
+ virtual VariableStackBindings printasm(VariableStackBindings bindings) const;
void addDeclaration(Declaration* _next_decl);
void addList(Declaration* _next_decl);
diff --git a/c_compiler/include/expression.hpp b/c_compiler/include/expression.hpp
index 71d993f..d446972 100644
--- a/c_compiler/include/expression.hpp
+++ b/c_compiler/include/expression.hpp
@@ -1,14 +1,14 @@
#ifndef AST_EXPRESSION_HPP
#define AST_EXPRESSION_HPP
-#include "ast.hpp"
+#include "node.hpp"
+
class Expression : public Node {
public:
- virtual void printasm() const = 0;
-
virtual void print() const;
virtual void printxml() const;
+ virtual VariableStackBindings printasm(VariableStackBindings bindings) const = 0;
};
@@ -18,7 +18,7 @@ private:
public:
Identifier(const std::string& id);
- virtual void printasm() const;
+ virtual VariableStackBindings printasm(VariableStackBindings bindings) const;
};
@@ -28,7 +28,7 @@ private:
public:
Constant(const int32_t& constant);
- virtual void printasm() const;
+ virtual VariableStackBindings printasm(VariableStackBindings bindings) const;
};
diff --git a/c_compiler/include/function.hpp b/c_compiler/include/function.hpp
index d608531..77d1372 100644
--- a/c_compiler/include/function.hpp
+++ b/c_compiler/include/function.hpp
@@ -1,13 +1,10 @@
#ifndef AST_FUNCTION_HPP
#define AST_FUNCTION_HPP
-#include "ast.hpp"
+#include "node.hpp"
-
-struct VarLocation {
- Type* type;
- int32_t stack_position;
-};
+class Declaration;
+class Statement;
class Function : public Node {
@@ -22,7 +19,7 @@ public:
virtual void print() const;
virtual void printxml() const;
- virtual void printasm() const;
+ virtual VariableStackBindings printasm(VariableStackBindings bindings) const;
};
diff --git a/c_compiler/include/node.hpp b/c_compiler/include/node.hpp
index 940a948..584ed32 100644
--- a/c_compiler/include/node.hpp
+++ b/c_compiler/include/node.hpp
@@ -1,7 +1,20 @@
-#ifndef AST_BASE_HPP
-#define AST_BASE_HPP
+#ifndef NODE_HPP
+#define NODE_HPP
-#include "ast.hpp"
+#include <cstdint>
+#include <map>
+#include <string>
+
+struct VarLocation;
+class Type;
+
+typedef std::map<std::string, VarLocation> VariableStackBindings;
+
+
+struct VarLocation {
+ Type* type;
+ int32_t stack_position;
+};
class Node {
@@ -10,7 +23,7 @@ public:
virtual void print() const = 0;
virtual void printxml() const = 0;
- virtual void printasm() const = 0;
+ virtual VariableStackBindings printasm(VariableStackBindings bindings) const = 0;
};
diff --git a/c_compiler/include/statement.hpp b/c_compiler/include/statement.hpp
index 17a5153..b5f7e9c 100644
--- a/c_compiler/include/statement.hpp
+++ b/c_compiler/include/statement.hpp
@@ -1,7 +1,10 @@
#ifndef AST_STATEMENT_HPP
#define AST_STATEMENT_HPP
-#include "ast.hpp"
+#include "node.hpp"
+
+class Declaration;
+class Expression;
class Statement : public Node {
@@ -13,7 +16,7 @@ public:
virtual void print() const = 0;
virtual void printxml() const = 0;
- virtual void printasm() const = 0;
+ virtual VariableStackBindings printasm(VariableStackBindings bindings) const = 0;
virtual void count_variables(int32_t& var_count) const = 0;
@@ -32,7 +35,7 @@ public:
virtual void print() const;
virtual void printxml() const;
- virtual void printasm() const;
+ virtual VariableStackBindings printasm(VariableStackBindings bindings) const;
virtual void count_variables(int32_t& var_count) const;
};
@@ -47,7 +50,7 @@ public:
virtual void print() const;
virtual void printxml() const;
- virtual void printasm() const;
+ virtual VariableStackBindings printasm(VariableStackBindings bindings) const;
virtual void count_variables(int32_t& var_count) const;
};
@@ -61,7 +64,7 @@ public:
virtual void print() const;
virtual void printxml() const;
- virtual void printasm() const;
+ virtual VariableStackBindings printasm(VariableStackBindings bindings) const;
virtual void count_variables(int32_t& var_count) const;
};
@@ -75,7 +78,7 @@ public:
virtual void print() const;
virtual void printxml() const;
- virtual void printasm() const;
+ virtual VariableStackBindings printasm(VariableStackBindings bindings) const;
virtual void count_variables(int32_t& var_count) const;
};
@@ -89,7 +92,7 @@ public:
virtual void print() const;
virtual void printxml() const;
- virtual void printasm() const;
+ virtual VariableStackBindings printasm(VariableStackBindings bindings) const;
virtual void count_variables(int32_t& var_count) const;
};
diff --git a/c_compiler/include/translation_unit.hpp b/c_compiler/include/translation_unit.hpp
index 42822f9..c290163 100644
--- a/c_compiler/include/translation_unit.hpp
+++ b/c_compiler/include/translation_unit.hpp
@@ -1,7 +1,9 @@
-#ifndef EXTERNAL_HPP
-#define EXTERNAL_HPP
+#ifndef TRANSLATION_UNIT_HPP
+#define TRANSLATION_UNIT_HPP
-#include "ast.hpp"
+#include "node.hpp"
+
+#include <vector>
class TranslationUnit : public Node {
@@ -13,7 +15,7 @@ public:
virtual void print() const;
virtual void printxml() const;
- virtual void printasm() const;
+ virtual VariableStackBindings printasm(VariableStackBindings bindings) const;
void push(Node* decl);
};
diff --git a/c_compiler/include/type.hpp b/c_compiler/include/type.hpp
index 8727ee0..3deca58 100644
--- a/c_compiler/include/type.hpp
+++ b/c_compiler/include/type.hpp
@@ -1,14 +1,14 @@
#ifndef TYPE_HPP
#define TYPE_HPP
-#include "ast.hpp"
+#include "node.hpp"
class Type : public Node {
public:
virtual void print() const;
virtual void printxml() const;
- virtual void printasm() const;
+ virtual VariableStackBindings printasm(VariableStackBindings bindings) const;
virtual std::string getType() const = 0;
};
diff --git a/c_compiler/src/c_parser.y b/c_compiler/src/c_parser.y
index 5866c57..a42463c 100644
--- a/c_compiler/src/c_parser.y
+++ b/c_compiler/src/c_parser.y
@@ -1,8 +1,15 @@
%code requires{
-#include "ast.hpp"
+#include "node.hpp"
+#include "translation_unit.hpp"
+#include "function.hpp"
+#include "declaration.hpp"
+#include "statement.hpp"
+#include "expression.hpp"
+#include "type.hpp"
-extern TranslationUnit* g_root; // A way of getting the AST out
+
+extern Node* g_root; // A way of getting the AST out
//! This is to fix problems when generating C++
// We are declaring the functions provided by Flex, so
@@ -338,9 +345,9 @@ Constant:
%%
-TranslationUnit* g_root; // Definition of variable (to match declaration earlier)
+Node* g_root; // Definition of variable (to match declaration earlier)
-TranslationUnit* parseAST() {
+Node* parseAST() {
g_root = 0;
yyparse();
return g_root;
diff --git a/c_compiler/src/compiler_main.cpp b/c_compiler/src/compiler_main.cpp
index 2ba8e3d..a7d7eb3 100644
--- a/c_compiler/src/compiler_main.cpp
+++ b/c_compiler/src/compiler_main.cpp
@@ -5,8 +5,11 @@
int main(int argc, char *argv[])
{
Node* ast = parseAST();
+
+ VariableStackBindings bindings;
+ int32_t var_count;
- ast->printasm();
+ ast->printasm(bindings, var_count);
return 0;
}
diff --git a/c_compiler/src/declaration.cpp b/c_compiler/src/declaration.cpp
index 7b924b3..0f125b0 100644
--- a/c_compiler/src/declaration.cpp
+++ b/c_compiler/src/declaration.cpp
@@ -29,7 +29,7 @@ void Declaration::printxml() const
std::cout << "<Variable id=\""<< id << "\" />" << std::endl;
}
-void Declaration::printasm() const
+void Declaration::printasm(VariableStackBindings bindings, int32_t& var_count) const
{
if(init == nullptr)
std::cout << "\t.comm\t" << id << ",4,4" << std::endl;
diff --git a/c_compiler/src/expression.cpp b/c_compiler/src/expression.cpp
index 76a6c43..11fa66e 100644
--- a/c_compiler/src/expression.cpp
+++ b/c_compiler/src/expression.cpp
@@ -1,5 +1,6 @@
-#include "ast.hpp"
+#include "expression.hpp"
+#include <iostream>
// Expression definition
@@ -16,7 +17,7 @@ Identifier::Identifier(const std::string& id)
: m_id(id)
{}
-void Identifier::printasm() const
+void Identifier::printasm(VariableStackBindings bindings) const
{}
@@ -26,7 +27,8 @@ Constant::Constant(const int32_t& constant)
: m_constant(constant)
{}
-void Constant::printasm() const
+void Constant::printasm(VariableStackBindings bindings) const
{
std::cout << "\tli\t$2," << m_constant << std::endl;
}
+
diff --git a/c_compiler/src/function.cpp b/c_compiler/src/function.cpp
index 5475ec9..090e070 100644
--- a/c_compiler/src/function.cpp
+++ b/c_compiler/src/function.cpp
@@ -1,4 +1,9 @@
-#include "ast.hpp"
+#include "function.hpp"
+#include "statement.hpp"
+#include "declaration.hpp"
+
+#include <iostream>
+#include <vector>
// Function definition
@@ -43,7 +48,7 @@ void Function::printxml() const
std::cout << "</Function>" << std::endl;
}
-void Function::printasm() const
+VariableStackBindings Function::printasm(VariableStackBindings bindings) const
{
// Counting all the variables being declared in the function
int32_t count = 0;
@@ -60,7 +65,7 @@ void Function::printasm() const
// TODO print asm for parameters
// Prints the asm for the compound statement in the function
- statement->printasm();
+ statement->printasm(bindings);
std::cout << "\tmove\t$sp,$fp\n\tlw\t$fp," << memory_needed-4 << "($sp)\n\taddiu\t$sp,$sp,"
<< memory_needed << "\n\tjr\t$31\n\tnop" << std::endl;
diff --git a/c_compiler/src/statement.cpp b/c_compiler/src/statement.cpp
index 99b2879..7b98631 100644
--- a/c_compiler/src/statement.cpp
+++ b/c_compiler/src/statement.cpp
@@ -1,4 +1,8 @@
-#include "ast.hpp"
+#include "statement.hpp"
+#include "declaration.hpp"
+#include "expression.hpp"
+
+#include <iostream>
// General base Statement definition
@@ -48,15 +52,15 @@ void CompoundStatement::printxml() const
std::cout << "</Scope>" << std::endl;
}
-void CompoundStatement::printasm() const
+VariableStackBindings CompoundStatement::printasm(VariableStackBindings bindings, int32_t& var_count) const
{
if(next_statement != nullptr)
- next_statement->printasm();
+ next_statement->printasm(bindings, var_count);
// TODO printasm for the declaration
if(m_statement != nullptr)
- m_statement->printasm();
+ m_statement->printasm(bindings, var_count);
}
void CompoundStatement::count_variables(int32_t& var_count) const
@@ -106,7 +110,7 @@ void SelectionStatement::printxml() const
m_else->printxml();
}
-void SelectionStatement::printasm() const
+VariableStackBindings SelectionStatement::printasm(VariableStackBindings bindings, int32_t& var_count) const
{}
void SelectionStatement::count_variables(int32_t& var_count) const
@@ -134,7 +138,7 @@ void ExpressionStatement::print() const
void ExpressionStatement::printxml() const
{}
-void ExpressionStatement::printasm() const
+VariableStackBindings ExpressionStatement::printasm(VariableStackBindings bindings, int32_t& var_count) const
{}
void ExpressionStatement::count_variables(int32_t& var_count) const
@@ -159,9 +163,9 @@ void JumpStatement::printxml() const
next_statement->printxml();
}
-void JumpStatement::printasm() const
+VariableStackBindings JumpStatement::printasm(VariableStackBindings bindings, int32_t& var_count) const
{
- m_expr->printasm();
+ m_expr->printasm(bindings, var_count);
}
void JumpStatement::count_variables(int32_t& var_count) const
@@ -188,7 +192,7 @@ void IterationStatement::printxml() const
m_statement->printxml();
}
-void IterationStatement::printasm() const
+VariableStackBindings IterationStatement::printasm(VariableStackBindings bindings, int32_t& var_count) const
{}
void IterationStatement::count_variables(int32_t& var_count) const
diff --git a/c_compiler/src/translation_unit.cpp b/c_compiler/src/translation_unit.cpp
index a3566d7..e85237b 100644
--- a/c_compiler/src/translation_unit.cpp
+++ b/c_compiler/src/translation_unit.cpp
@@ -24,10 +24,10 @@ void TranslationUnit::printxml() const
std::cout << "</Program>" << std::endl;
}
-void TranslationUnit::printasm() const
+void TranslationUnit::printasm(VariableStackBindings bindings, int32_t& var_count) const
{
for(auto& node : translation_unit) {
- node->printasm();
+ node->printasm(bindings, var_count);
}
}
diff --git a/c_compiler/src/type.cpp b/c_compiler/src/type.cpp
index b7c3fec..13496e9 100644
--- a/c_compiler/src/type.cpp
+++ b/c_compiler/src/type.cpp
@@ -11,7 +11,7 @@ void Type::print() const
void Type::printxml() const
{}
-void Type::printasm() const
+void Type::printasm(VariableStackBindings bindings, int32_t& var_count) const
{}