aboutsummaryrefslogtreecommitdiffstats
path: root/src/tuplr_llvm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tuplr_llvm.cpp')
-rw-r--r--src/tuplr_llvm.cpp45
1 files changed, 19 insertions, 26 deletions
diff --git a/src/tuplr_llvm.cpp b/src/tuplr_llvm.cpp
index dfd4c9d..e2f7f1a 100644
--- a/src/tuplr_llvm.cpp
+++ b/src/tuplr_llvm.cpp
@@ -43,12 +43,6 @@ using namespace llvm;
using namespace std;
using boost::format;
-// Backend shared library interface
-extern "C" {
- Engine* tuplr_new_engine();
- void tuplr_free_engine(Engine* engine);
-}
-
static inline Value* llVal(CValue v) { return static_cast<Value*>(v); }
static inline Function* llFunc(CFunction f) { return static_cast<Function*>(f); }
@@ -166,6 +160,8 @@ struct LLVMEngine : public Engine {
}
void liftCall(CEnv& cenv, AFn* fn, const AType& argsT);
+
+ CValue compileLiteral(CEnv& cenv, AST* lit);
CValue compilePrimitive(CEnv& cenv, APrimitive* prim);
CValue compileIf(CEnv& cenv, AIf* aif);
@@ -200,36 +196,33 @@ struct LLVMEngine : public Engine {
FunctionPassManager opt;
};
-extern "C" {
-
-/// Create a new Engine (shared library entry point)
Engine*
-tuplr_new_engine()
+tuplr_new_llvm_engine()
{
return new LLVMEngine();
}
-/// Free an Engine (shared library entry point)
-void
-tuplr_free_engine(Engine* engine)
-{
- delete (LLVMEngine*)engine;
-}
-
-}
-
-
/***************************************************************************
* Code Generation *
***************************************************************************/
-#define COMPILE_LITERAL(CT, COMPILED) \
-template<> CValue ALiteral<CT>::compile(CEnv& cenv) { return (COMPILED); }
+CValue
+LLVMEngine::compileLiteral(CEnv& cenv, AST* lit)
+{
+ ALiteral<int32_t>* ilit = dynamic_cast<ALiteral<int32_t>*>(lit);
+ if (ilit)
+ return ConstantInt::get(Type::Int32Ty, ilit->val, true);
+
+ ALiteral<float>* flit = dynamic_cast<ALiteral<float>*>(lit);
+ if (flit)
+ return ConstantFP::get(Type::FloatTy, flit->val);
-// Literal template instantiations
-COMPILE_LITERAL(int32_t, ConstantInt::get(Type::Int32Ty, val, true))
-COMPILE_LITERAL(float, ConstantFP::get(Type::FloatTy, val))
-COMPILE_LITERAL(bool, ConstantInt::get(Type::Int1Ty, val, false))
+ ALiteral<bool>* blit = dynamic_cast<ALiteral<bool>*>(lit);
+ if (blit)
+ return ConstantFP::get(Type::FloatTy, blit->val);
+
+ throw Error(lit->loc, "Unknown literal type");
+}
void
LLVMEngine::liftCall(CEnv& cenv, AFn* fn, const AType& argsT)