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.cpp51
1 files changed, 40 insertions, 11 deletions
diff --git a/c_compiler/src/function.cpp b/c_compiler/src/function.cpp
index 420c782..a132280 100644
--- a/c_compiler/src/function.cpp
+++ b/c_compiler/src/function.cpp
@@ -1,18 +1,47 @@
#include "ast.hpp"
-Function::Function(const std::string& _id, const BaseList* _param_list,
- const BaseNode* _comp_statement)
- : BaseNode(_param_list, _comp_statement), id(_id) {}
-void Function::printxml() const {
+// Function definition
+
+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;
+
+ if(parameter_list != nullptr)
+ parameter_list->print();
+
+ if(statement != nullptr)
+ statement->print();
+}
+
+void Function::printxml() const
+{
std::cout << "<Function id=\"" << id << "\">" << std::endl;
- leftNode->printxml();
- rightNode->printxml();
+
+ Declaration* parameter = parameter_list;
+ std::vector<std::string> parameter_vec;
+
+ while(parameter != nullptr) {
+ if(parameter->getId() != "")
+ parameter_vec.push_back(parameter->getId());
+ parameter = parameter->getNext();
+ }
+
+ for(std::vector<std::string>::reverse_iterator itr = parameter_vec.rbegin();
+ itr != parameter_vec.rend(); ++itr) {
+
+ std::cout << "<Parameter id=\"" << *itr << "\" />" << std::endl;
+ }
+
+ if(statement != nullptr)
+ statement->printxml();
+
std::cout << "</Function>" << std::endl;
}
-void Function::printasm() const {
- std::cout << id << ":\n\taddiu\t$sp,$sp,-24\n\tsw\t$fp,20($sp)\n\tmove\t$fp,$sp" << std::endl;
- rightNode->printasm();
- std::cout << "\tmove\t$sp,$fp\n\tlw\t$fp,20($sp)\n\taddiu\t$sp,$sp,24\n\tjr\t$31\n\tnop" << std::endl;
-}
+void Function::printasm() const
+{}