Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM 5.0 Error Calling Function #45

Open
coffee-cup opened this issue Oct 16, 2017 · 0 comments
Open

LLVM 5.0 Error Calling Function #45

coffee-cup opened this issue Oct 16, 2017 · 0 comments
Assignees

Comments

@coffee-cup
Copy link

coffee-cup commented Oct 16, 2017

I am following along with the tutorial using llvm-hs-5.1.0 and llvm-hs-pure-5.1.0 and with the exception of a few minor issues between the versions, most things are working correctly.

However, I am stuck on an error I am getting when trying to call a previously defined function.

Using the code up to chapter 3 I can do

ready> def foo(a) a;
; ModuleID = 'my cool jit'
source_filename = \"<string>\"

define double @foo(double %a) {
  entry:
  %0 = alloca double
  store double %a, double* %0
  %1 = load double, double* %0
  ret double %1
}

ready> def bar() foo(3);
EncodeException "The serialized GlobalReference has type 

PointerType {
  pointerReferent = FunctionType {
    resultType = FloatingPointType { floatingPointType = DoubleFP }, 
    argumentTypes = [ FloatingPointType { floatingPointType = DoubleFP } ], 
    isVarArg = False
  }, 
  pointerAddrSpace = AddrSpace 0
} 

but should have type 

FloatingPointType { floatingPointType = DoubleFP }"

I believe the problem is from trying to create the constant global reference operand in the externf function.

I can fix the error when supplying a type

-- Codegen.hs
externf :: Type -> Name -> Operand
externf ty nm = ConstantOperand (C.GlobalReference ty nm)

-- Emit.hs
cgen (S.Call fn args) = do
  largs <- mapM cgen args
  let fnT = AST.PointerType { AST.pointerReferent = (AST.FunctionType { AST.resultType = double, AST.argumentTypes = [], AST.isVarArg = False}) , AST.pointerAddrSpace = AddrSpace 0 }
  let oper = externf fnT (AST.Name fn)
  call oper largs

However, this is very specific to this exact function. Preferably, the type would be determined automatically.

So in summary, how can I find the type of the function I am calling so I can pass it into externf?

Note: This error has been added in llvm-hs 5.0 https://github.com/llvm-hs/llvm-hs/blob/4b8269a3be55e84a75de41cdc481c589d161b7f3/llvm-hs/test/LLVM/Test/Regression.hs#L98

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants