aboutsummaryrefslogtreecommitdiffstats
path: root/c_compiler/src/function.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c_compiler/src/function.cpp')
-rw-r--r--c_compiler/src/function.cpp43
1 files changed, 20 insertions, 23 deletions
diff --git a/c_compiler/src/function.cpp b/c_compiler/src/function.cpp
index 1d9db33..2152c71 100644
--- a/c_compiler/src/function.cpp
+++ b/c_compiler/src/function.cpp
@@ -1,7 +1,4 @@
#include "function.hpp"
-#include "statement.hpp"
-#include "declaration.hpp"
-#include "bindings.hpp"
#include <iostream>
#include <vector>
@@ -9,26 +6,26 @@
// Function definition
-Function::Function(const std::string& _id, Declaration* _parameter_list, Statement* _statement)
- : id(_id), parameter_list(_parameter_list), statement(_statement)
+Function::Function(const std::string& id, Declaration* parameter_list, Statement* statement)
+ : id_(id), parameter_list_(parameter_list), statement_(statement)
{}
void Function::print() const
{
- std::cout << id << std::endl;
+ std::cout << id_ << std::endl;
- if(parameter_list != nullptr)
- parameter_list->print();
+ if(parameter_list_ != nullptr)
+ parameter_list_->print();
- if(statement != nullptr)
- statement->print();
+ if(statement_ != nullptr)
+ statement_->print();
}
-void Function::printxml() const
+void Function::printXml() const
{
- std::cout << "<Function id=\"" << id << "\">" << std::endl;
+ std::cout << "<Function id=\"" << id_ << "\">" << std::endl;
- DeclarationPtr parameter = parameter_list;
+ DeclarationPtr parameter = parameter_list_;
std::vector<std::string> parameter_vec;
while(parameter != nullptr) {
@@ -43,30 +40,30 @@ void Function::printxml() const
std::cout << "<Parameter id=\"" << *itr << "\" />" << std::endl;
}
- if(statement != nullptr)
- statement->printxml();
+ if(statement_ != nullptr)
+ statement_->printXml();
std::cout << "</Function>" << std::endl;
}
-VariableStackBindings Function::printasm(VariableStackBindings bindings) const
+VariableStackBindings Function::printAsm(VariableStackBindings bindings) const
{
// Counting all the variables being declared in the function
- int32_t count = 0;
- if(statement != nullptr)
- statement->count_variables(count);
-
+ unsigned count = 0;
+ if(statement_ != nullptr)
+ statement_->countVariables(count);
+
// This includes the space for the old frame counter and (return address)?
- int32_t memory_needed = 4*count+8;
+ unsigned memory_needed = 4*count+8;
- std::cout << "\t.text\n\t.globl\t" << id << std::endl << id << ":\n\taddiu\t$sp,$sp,-"
+ std::cout << "\t.text\n\t.globl\t" << id_ << std::endl << id_ << ":\n\taddiu\t$sp,$sp,-"
<< memory_needed << "\n\tsw\t$fp," << memory_needed-4 << "($sp)\n\tmove\t$fp,$sp"
<< std::endl;
// TODO print asm for parameters
// Prints the asm for the compound statement in the function
- statement->printasm(bindings);
+ 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;