Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Implementation of Programming Languages / Transpiler / src / main.cpp
diff options
context:
space:
mode:
1 files changed, 15 insertions, 0 deletions
-rw-r--r--Year 2/Implementation of Programming Languages/Transpiler/src/main.cpp15
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/main.cpp b/Year 2/Implementation of Programming Languages/Transpiler/src/main.cpp
index cc5d771..bc651e6 100644
--- a/Year 2/Implementation of Programming Languages/Transpiler/src/main.cpp
+++ b/Year 2/Implementation of Programming Languages/Transpiler/src/main.cpp
@@ -2,6 +2,18 @@
#include <deque>
#include "LLVMVisitor/LLVMVisitor.h"
+void freeNodes(Value* v) {
+ if (dynamic_cast<Funcall*>(v) != nullptr) {
+ for (Value* val : static_cast<Funcall*>(v)->get_args())
+ freeNodes(val);
+ }
+ else if (dynamic_cast<List*>(v) != nullptr) {
+ for (Value* val : static_cast<List*>(v)->get_value())
+ freeNodes(val);
+ }
+ delete v;
+}
+
int main() {
LLVMVisitor visitor("testout.ll");
std::deque<Value*> nodes = {
@@ -32,4 +44,7 @@ int main() {
n->Visit(visitor);
}
visitor.insertMain();
+
+ for (Value* n : nodes)
+ freeNodes(n);
}