Skip to content

Commit

Permalink
Set type of function references to function pointers
Browse files Browse the repository at this point in the history
see #15
  • Loading branch information
cocreature committed Feb 7, 2018
1 parent e2dec47 commit 1497273
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
1 change: 1 addition & 0 deletions llvm-hs-quote.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ test-suite test
LLVM.Quote.Test.InlineAssembly
LLVM.Quote.Test.Instructions
LLVM.Quote.Test.Metadata
LLVM.Quote.Test.Module
build-depends: base
, containers
, llvm-hs-pure
Expand Down
2 changes: 1 addition & 1 deletion src/LLVM/Quote/Parser/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ dialect :

callableOperand :: { [A.Type] -> A.CallableOperand }
callableOperand :
type coperand { \ts -> Right ($2 (A.FunctionType $1 ts False)) }
type coperand { \ts -> Right ($2 (A.PointerType (A.FunctionType $1 ts False) (A.AddrSpace 0))) }
| type 'asm' sideeffect alignstack dialect STRING ',' STRING
{ \ts -> Left (A.InlineAssembly (A.FunctionType $1 ts False) (fromString $6) (fromString $8) $3 $4 $5) }

Expand Down
4 changes: 2 additions & 2 deletions test/LLVM/Quote/Test/Instructions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ tests = let a t = LocalReference t . UnName in testGroup "Instructions" [
tailCallKind = Nothing,
callingConvention = CC.C,
returnAttributes = [],
function = Right (ConstantOperand (C.GlobalReference (FunctionType void [i32, float, ptr i32, i64, i1, (VectorType 2 i32), (StructureType False [i32, i32])] False) (UnName 0))),
function = Right (ConstantOperand (C.GlobalReference (ptr (FunctionType void [i32, float, ptr i32, i64, i1, (VectorType 2 i32), (StructureType False [i32, i32])] False)) (UnName 0))),
arguments = [ (LocalReference i32 (UnName 0), [])
, (LocalReference float (UnName 1), [])
, (LocalReference (ptr i32) (UnName 2), [])
Expand Down Expand Up @@ -762,7 +762,7 @@ tests = let a t = LocalReference t . UnName in testGroup "Instructions" [
Do $ Invoke {
callingConvention' = CC.C,
returnAttributes' = [],
function' = Right (ConstantOperand (C.GlobalReference (FunctionType void [i32, i16] False) (UnName 0))),
function' = Right (ConstantOperand (C.GlobalReference (ptr (FunctionType void [i32, i16] False)) (UnName 0))),
arguments' = [
(ConstantOperand (C.Int 32 4), []),
(ConstantOperand (C.Int 16 8), [])
Expand Down
61 changes: 61 additions & 0 deletions test/LLVM/Quote/Test/Module.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module LLVM.Quote.Test.Module
( tests
)where

import Test.Tasty
import Test.Tasty.HUnit

import LLVM.Quote.LLVM

import LLVM.AST
import LLVM.AST.CallingConvention
import LLVM.AST.Constant
import LLVM.AST.Global
import LLVM.AST.Type

tests :: TestTree
tests = testGroup "Module" [
testCase "calls have the proper type" $ do
let s = [llmod|
define void @f() {
entry:
call void @g()
ret void
}
define void @g() {
entry:
ret void
}
|]
let ast = Module "<string>" "<string>" Nothing Nothing
[ GlobalDefinition functionDefaults
{ name = "f"
, returnType = void
, basicBlocks =
[ BasicBlock
"entry"
[Do
(Call
Nothing
C
[]
(Right (ConstantOperand (GlobalReference (ptr (FunctionType void [] False)) (Name "g"))))
[]
[]
[])
]
(Do (Ret Nothing []))
]
}
, GlobalDefinition functionDefaults
{ name = "g"
, returnType = void
, basicBlocks =
[ BasicBlock "entry" [] (Do (Ret Nothing []))
]
}
]
s @?= ast
]
2 changes: 2 additions & 0 deletions test/LLVM/Quote/Test/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import qualified LLVM.Quote.Test.DataLayout as DataLayout
import qualified LLVM.Quote.Test.InlineAssembly as InlineAssembly
import qualified LLVM.Quote.Test.Instructions as Instructions
import qualified LLVM.Quote.Test.Metadata as Metadata
import qualified LLVM.Quote.Test.Module as Module

tests :: TestTree
tests = testGroup "language-llvm-quote"
Expand All @@ -15,4 +16,5 @@ tests = testGroup "language-llvm-quote"
, InlineAssembly.tests
, Instructions.tests
, Metadata.tests
, Module.tests
]

0 comments on commit 1497273

Please sign in to comment.