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

How can I extract the value of a Constant? #727

Open
akcheung opened this issue Jun 11, 2021 · 1 comment
Open

How can I extract the value of a Constant? #727

akcheung opened this issue Jun 11, 2021 · 1 comment
Labels

Comments

@akcheung
Copy link

Is there a way I can retrieve the integer value from a ValueRef? I wrote this code:

from llvmlite import binding as llvm

asm_sum = r"""
define i32 @foo(i32 %arg) #0 {
  %tmp = alloca i32, align 4
  store i32 1, i32* %tmp, align 4
  ret i32 %arg
}
"""

ref = llvm.parse_assembly(asm_sum, None)
fn = ref.get_function("foo")

for b in fn.blocks:
  for i in b.instructions:
    if i.opcode == "store":
      ops = list(i.operands)
      x = ops[0] + 1   # this generates an error

and would like to get the int 1 from it. In llvm's C++ bindings I'd call functions like getZExtValue. Is there a way to do so here? I've also tried ops[0].name but that didn't work either.

@gmarkall
Copy link
Member

Unfortunately I don't think there's a way to do that - a wrapper for getZExtValue would need to be added to the binding layer (in the ffi subdir then the Python layer in llvmlite/binding augmented to be able to access it.

(Marking this as a feature request - is this something you'd potentially be interested in contributing?)

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

No branches or pull requests

2 participants