aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CodeGen.cc7
-rw-r--r--lib/CodeGen/StatementGen.cc2
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/CodeGen/CodeGen.cc b/lib/CodeGen/CodeGen.cc
index 30b6131..641b424 100644
--- a/lib/CodeGen/CodeGen.cc
+++ b/lib/CodeGen/CodeGen.cc
@@ -6,6 +6,7 @@
#include "cps/ExceptionHandler.h"
#include "Builtins.h"
#include "cps/TypeAST.h"
+#include "cps/TemplateAST.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Verifier.h"
#include <cstdarg>
@@ -209,7 +210,11 @@ void CodeGen::compile(const std::vector<SourceUnit> &Sources) {
for (const auto &S : Sources[I].Statements) {
SaveAndRestore<int> Location(DiagnosticLine, S->getLine());
std::string TypeName;
- if (auto *F = dynamic_cast<FunctionDefAST*>(S.get())) {
+ if (auto *T = dynamic_cast<TemplateDeclAST*>(S.get())) {
+ auto *Function = T->getFunction();
+ Reserve(T->getName(), Function != nullptr, Function && Function->getProto()->isOverload());
+ Templates[T->getName()].push_back({T, I});
+ } else if (auto *F = dynamic_cast<FunctionDefAST*>(S.get())) {
Reserve(F->getProto()->getName(), true, F->getProto()->isOverload());
if (sameIdentifier(F->getProto()->getName(), "MAIN")) {
if (Entry) reportError("Multiple MAIN definitions in %s and %s",
diff --git a/lib/CodeGen/StatementGen.cc b/lib/CodeGen/StatementGen.cc
index 5b60d29..6bc4ec4 100644
--- a/lib/CodeGen/StatementGen.cc
+++ b/lib/CodeGen/StatementGen.cc
@@ -5,6 +5,7 @@
#include "cps/MemoryHandler.h"
#include "cps/ExceptionHandler.h"
#include "cps/TypeAST.h"
+#include "cps/TemplateAST.h"
using namespace llvm;
using namespace cps;
@@ -18,6 +19,7 @@ void CodeGen::emitStmt(StmtAST *Stmt) {
void CodeGen::emitStmtImpl(StmtAST *Stmt) {
SaveAndRestore<int> Location(DiagnosticLine, Stmt && Stmt->getLine() ? Stmt->getLine() : DiagnosticLine);
if (!Stmt) return;
+ if (dynamic_cast<TemplateDeclAST*>(Stmt)) return;
if (dynamic_cast<IncludeStmtAST*>(Stmt)) return;
if (dynamic_cast<GlobalBlockAST*>(Stmt)) return;