LLVM IR:当作为参数传递给函数时,如何在 llvm ir 代码中获取数组的大小?
LLVM IR: How to get size of array, in llvm ir-code, when passed as argument to function?
我有一个将数组作为参数的函数,我需要在函数中首先获取数组的大小。我需要在 LLVM IR 中执行此操作。这可能吗?我可以访问数组,但我不知道大小。
void test(int[] a) {
}
正在翻译成
define void @test(i32* %__p__a) {
entry:
%a = alloca i32*, align 4
store i32* %__p__a , i32** %a, align 4
ret void
}
I need to get the size of the array first thing in the function. I need to do this in LLVM IR. Is this possible?
如果您只有一个 i32*
而没有关于它指向什么的附加信息,那么不,这是不可能的。为了获得数组的大小,您需要将该信息存储在 test
函数可以访问它的地方。
由于这是您自己的语言并且您可以控制生成的 LLVM IR 的外观,例如您可以将数组表示为包含数组大小和指向数据的指针的结构。
我有一个将数组作为参数的函数,我需要在函数中首先获取数组的大小。我需要在 LLVM IR 中执行此操作。这可能吗?我可以访问数组,但我不知道大小。
void test(int[] a) {
}
正在翻译成
define void @test(i32* %__p__a) {
entry:
%a = alloca i32*, align 4
store i32* %__p__a , i32** %a, align 4
ret void
}
I need to get the size of the array first thing in the function. I need to do this in LLVM IR. Is this possible?
如果您只有一个 i32*
而没有关于它指向什么的附加信息,那么不,这是不可能的。为了获得数组的大小,您需要将该信息存储在 test
函数可以访问它的地方。
由于这是您自己的语言并且您可以控制生成的 LLVM IR 的外观,例如您可以将数组表示为包含数组大小和指向数据的指针的结构。