{-# LANGUAGE ExistentialQuantification, NoMonomorphismRestriction, FlexibleInstances #-} -- Interpretation of Symantics on top of programmatic LLVM library -- bindings. -- module SymLLVM where import LLVM.Core import LLVM.ExecutionEngine import LLVM.Util.Arithmetic import Data.Word import Control.Monad import LLVM.Util.File(writeCodeGenModule) square x = mul x x cube x = do xx <- mul x x mul x xx broem x = x^2 - 1 (.=) = (==) (.?) = (==) mLift' = createFunction ExternalLinkage mLift1 fn = mLift' $ (fn >=> ret) mLift2 fn = mLift' $ \x -> fn x >=> ret type GenFun f = CodeGenModule (Function f) type GenFun1 t = GenFun (t -> IO t) type GenFun2 t = GenFun (t -> t -> IO t) -- Passing these to simpleFunction below requires the type to be -- specified. Just lifting makes them too general. mFun1 :: GenFun1 Word32 mFun1 = mLift1 (broem . return) -- (square >=> square >=> square) mFun2 :: GenFun2 Word32 mFun2 = mLift2 mul {- main = do initializeNativeTarget -- Otherwise: error: Interpreter not linked in. fun1 <- simpleFunction $ mFun1 r1 <- fun1 3 print r1 fun1 <- simpleFunction $ mFun1 r1 <- fun1 3 print r1 fun2 <- simpleFunction $ mFun2 r2 <- fun2 3 4 print r2 writeCodeGenModule "fun2.bc" mFun2 -}