From 795fc872e603cc359ec6e307969ac925c3b5dc4d Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Sun, 19 May 2019 14:23:31 +0100 Subject: [PATCH] Generate code for call expressions In order to call a function in LLVM IR, we need to grab a GlobalReference to it. Currently we just make it ourselves, inferring the type of it based on what arguments the caller provided and the fact that all functions return a double. --- Main.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Main.hs b/Main.hs index f32003b..2a5a7e0 100644 --- a/Main.hs +++ b/Main.hs @@ -7,6 +7,7 @@ import Control.Monad.IO.Class import Data.String import qualified Data.Map as Map import qualified Data.Text.Lazy.IO as Text +import LLVM.AST.AddrSpace import LLVM.AST.Constant import LLVM.AST.Float import LLVM.AST.FloatingPointPredicate hiding (False, True) @@ -80,3 +81,12 @@ buildExpr (BinOp op a b) = do K.Cmp LT -> fcmp OLT K.Cmp GT -> fcmp OGT K.Cmp EQ -> fcmp OEQ + +buildExpr (Call callee params) = do + paramOps <- mapM buildExpr params + let nam = fromString callee + -- get a pointer to the function + typ = FunctionType Type.double (replicate (length params) Type.double) False + ptrTyp = Type.PointerType typ (AddrSpace 0) + ref = GlobalReference ptrTyp nam + call (ConstantOperand ref) (zip paramOps (repeat [])) -- 2.30.2