Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Implementation of Programming Languages / Transpiler / src / main.cpp
blob: e38216108caf1f7ca8acfdd03c798d9846f42580 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#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 = {
		new Funcall("defvar", { new Name("myvar"), new Float(4.956) })
	};
	for (Value* n : nodes) {
		n->Visit(visitor);
	}
	// visitor.insertMain();

	for (Value* n : nodes)
		freeNodes(n);
}