aboutsummaryrefslogtreecommitdiffstats
path: root/c_compiler/src/function.cpp
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-03-03 16:24:07 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-03-03 16:24:07 +0000
commit522cc9d286c5d35ca25ebaa85374f5f9214a7f6e (patch)
treee4c944cce2fcd736834e35d8e5d06f984b57a976 /c_compiler/src/function.cpp
parent446c2394ec8970198d645bbbb462c67b9e3f1b1e (diff)
downloadCompiler-522cc9d286c5d35ca25ebaa85374f5f9214a7f6e.tar.gz
Compiler-522cc9d286c5d35ca25ebaa85374f5f9214a7f6e.zip
Still working on ast
Diffstat (limited to 'c_compiler/src/function.cpp')
-rw-r--r--c_compiler/src/function.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/c_compiler/src/function.cpp b/c_compiler/src/function.cpp
new file mode 100644
index 0000000..420c782
--- /dev/null
+++ b/c_compiler/src/function.cpp
@@ -0,0 +1,18 @@
+#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 {
+ std::cout << "<Function id=\"" << id << "\">" << std::endl;
+ leftNode->printxml();
+ rightNode->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;
+}