-
Notifications
You must be signed in to change notification settings - Fork 78
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
ir.InlineAsm does not implement value.Named #33
Comments
@driusan good catch. The This has been fixed, and now both constructors use value.Value. Cheers |
I think this got broken again at some point? I get an error telling me that the Lines 344 to 355 in f20e2cd
|
There are many special cases to consider in LLVM IR, I keep learning of new ones even after years of playing with these things. Thanks for re-opening the issue. It seem, the proper solution is to do a type switch and allow a function type directly (to cater for inline asm values). |
To be honest, another solution could be to have inline asm values have pointer to function type, instead of function type. How does the official LLVM distribution treat inline asm types? As func type or pointer to func type? |
A simple test program that should produce the return code package main
import (
"fmt"
"github.com/llir/llvm/ir"
"github.com/llir/llvm/ir/constant"
"github.com/llir/llvm/ir/types"
)
func main() {
m := ir.NewModule()
// inline asm
funcType := types.NewFunc(types.I32, types.I32)
asm := ir.NewInlineAsm(funcType, "add $1,$0", "=Q,Q,~{dirflag},~{fpsr},~{flags}")
// main
main := m.NewFunc("main", types.I32)
entry := main.NewBlock("")
result := entry.NewCall(asm, constant.NewInt(types.I32, 21))
entry.NewRet(result)
fmt.Println(m)
}
|
Prior to this commit, the callee had to be of pointer to function type (as is the type of functions declared in the global scope of the module). However, to allow inline asm values to have function type instead of pointer to function type, the type checking of NewCall is relaxed. Fixes llir#33.
Hmm, I'm uncertain whether my complaint was valid or not. Part of the issue was that I didn't understand how to use inline asm properly. With what you've written above and #74 I'm now happily able to use it. I don't have any strong feelings about how this should work. |
Before closing this issue, I still wish we could evaluate how the official LLVM distribution treats the type of inline asm, and then decide to be consistent with that. This would follow the Principle of Least Surprise, for any user coming from official LLVM to llir/llvm. @pwaller, do you have the LLVM C++ distribution installed, and if so, could you write a minimal test just to verify if inline asm has |
Do not have a computer to try now, but I guess https://stackoverflow.com/questions/29184031/how-to-get-llvm-inline-asm-operands-type would help? |
@dannypsnl, thanks! From https://stackoverflow.com/questions/29184031/how-to-get-llvm-inline-asm-operands-type:
So, we can close this issue. And let users create inline asm values with type pointer to function type. |
I added a bullet to the typechecking issue #65 - we should type-check the arg to |
Note sure when you'd want to call a null function, but since its valid LLVM IR we should ensure that the null constant has the correct type, which is pointer to function type for all callees. An old but related issue #33.
The documentation for NewCall says it may have one of the following types:
However, ir.InlineAsm doesn't implement the value.Named interface, so trying to use it as the callee parameter results in a compile time error about *ir.InlineAsm not implementing GetName()
The text was updated successfully, but these errors were encountered: