MichaReiser / llvm-node

LLVM 9.0+ Node Bindings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't found LLVM API: GetElementPtrInst

mohanson opened this issue · comments

I want declare a number array and give it a value.

I can do this with clang, and the corresponding IR is

int a[3];
a[0] = 1;
%1 = alloca i32, align 4
%2 = alloca [3 x i32], align 4
store i32 0, i32* %1, align 4
%3 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
store i32 1, i32* %3, align 4

But don't know how to implement it in llvm-node , because I cant' found getelementptr api in llvm-node

commented

You can use the IRBuilder's createInBoundsGEP:

createInBoundsGEP(ptr: Value, idxList: Value[], name?: string): Value;

Thanks, I understand how to implement an array.