diff options
-rw-r--r-- | src/gc.cpp | 1 | ||||
-rw-r--r-- | src/llvm.cpp | 36 | ||||
-rw-r--r-- | src/tuplr.hpp | 4 |
3 files changed, 26 insertions, 15 deletions
@@ -79,6 +79,7 @@ GC::collect(const Roots& roots) if ((*i)->marked()) { (*i)->mark(false); + assert(!(*i)->marked()); } else { if ((*i)->tag() == Object::AST) ((AST*)*i)->~AST(); diff --git a/src/llvm.cpp b/src/llvm.cpp index fa4e99e..5010775 100644 --- a/src/llvm.cpp +++ b/src/llvm.cpp @@ -92,16 +92,16 @@ struct LLVMEngine : public Engine { LLVMEngine() : module(new Module("tuplr")) , engine(ExecutionEngine::create(module)) - , emp(module) - , opt(&emp) + , emp(new ExistingModuleProvider(module)) + , opt(new FunctionPassManager(emp)) { // Set up optimiser pipeline const TargetData* target = engine->getTargetData(); - opt.add(new TargetData(*target)); // Register target arch - opt.add(createInstructionCombiningPass()); // Simple optimizations - opt.add(createReassociatePass()); // Reassociate expressions - opt.add(createGVNPass()); // Eliminate Common Subexpressions - opt.add(createCFGSimplificationPass()); // Simplify control flow + opt->add(new TargetData(*target)); // Register target arch + opt->add(createInstructionCombiningPass()); // Simple optimizations + opt->add(createReassociatePass()); // Reassociate expressions + opt->add(createGVNPass()); // Eliminate Common Subexpressions + opt->add(createCFGSimplificationPass()); // Simplify control flow // Declare host provided allocation primitive std::vector<const Type*> argsT(1, Type::Int32Ty); // unsigned size @@ -110,6 +110,14 @@ struct LLVMEngine : public Engine { "tuplr_gc_allocate", module); } + ~LLVMEngine() + { + emp->releaseModule(); + delete engine; + delete opt; + delete emp; + } + CFunc startFunction(CEnv& cenv, const std::string& name, const AType* retT, const ATuple& argsT, const vector<string> argNames) @@ -153,7 +161,7 @@ struct LLVMEngine : public Engine { verifyFunction(*static_cast<Function*>(f)); if (cenv.args.find("-g") == cenv.args.end()) - opt.run(*static_cast<Function*>(f)); + opt->run(*static_cast<Function*>(f)); } void eraseFunction(CEnv& cenv, CFunc f) { @@ -201,12 +209,12 @@ struct LLVMEngine : public Engine { return ss.str(); } - Module* module; - ExecutionEngine* engine; - IRBuilder<> builder; - Function* alloc; - ExistingModuleProvider emp; - FunctionPassManager opt; + Module* module; + ExecutionEngine* engine; + IRBuilder<> builder; + Function* alloc; + ExistingModuleProvider* emp; + FunctionPassManager* opt; }; Engine* diff --git a/src/tuplr.hpp b/src/tuplr.hpp index 0385533..787355b 100644 --- a/src/tuplr.hpp +++ b/src/tuplr.hpp @@ -158,7 +158,7 @@ struct Object { inline Tag tag() const { return (Tag)header()->tag; } inline void tag(Tag t) { header()->tag = t; } inline bool marked() const { return header()->mark != 0; } - inline void mark(bool b) const { header()->mark = 1; } + inline void mark(bool b) const { header()->mark = (b ? 1 : 0); } static void* operator new(size_t size) { return pool.alloc(size); } static void operator delete(void* ptr) {} @@ -638,6 +638,8 @@ Subst unify(const Constraints& c); /// Compiler backend struct Engine { + virtual ~Engine() {} + virtual CFunc startFunction( CEnv& cenv, const std::string& name, |