LLVMBlockAddress() 第一个参数是什么?
What's LLVMBlockAddress() first argument?
我正在玩 LLVM C-API,但不知何故我被 LLVMBuildIndirectBr() 困住了,或者更确切地说是 LLVMBlockAddress() 因为我不知道它的第一个参数是什么等等重要的是我该如何创建它。这是一个 LLVMValueRef 应该代表 'the function' 但我找到的文档并没有说明更多。
根据its code, this function is just a C wrapper for BlockAddress::get()。所以,第一个参数是包含 BB 的 Function
,我想。
BlockAddress::get()
重载没有 C API 只接受 BB 参数,所以你必须先在那个 BB 上调用 LLVMGetBasicBlockParent() 以获得对 [=10= 的引用] 它属于,然后将它作为第一个参数传递给 LLVMBlockAddress()
.
根据经验,在这种情况下,请尝试弄清楚 "native" 您正在使用的 C++ 方法,然后查找其文档。
显然是通过 LLVMFunctionType() 和 LLVMAddFunction()。
尝试:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(int arg_count, char **args)
{
label0:
if (arg_count < 2)
{
uint32_t addr1 = &&label1 - &&label0;
uint32_t addr2 = &&label2 - &&label0;
printf("label1=%d label2=%d\n", addr1, addr2);
return 0;
}
else
{
uint32_t addr = strtol(args[1], NULL, 0);
printf("goto address = %d\n", addr);
void *indirect_addr = &&label0 + addr;
goto *indirect_addr;
}
label1:
printf("label1\n");
return 1;
label2:
printf("label2\n");
return 2;
}
clang ind_br.c -emit-llvm -S
查看输出
块地址(@main, %10) = LLVMBlockAddress
indirectbr i8* %36,[标签 %29,标签 %10,标签 %31,标签 %10,标签 %10] = LLVMBuildIndirectBr + LLVMAddDestination
所以 LLVMBuildIndirectBr 的第一个参数是 LLVMBlockAddress()
之一的结果
我正在玩 LLVM C-API,但不知何故我被 LLVMBuildIndirectBr() 困住了,或者更确切地说是 LLVMBlockAddress() 因为我不知道它的第一个参数是什么等等重要的是我该如何创建它。这是一个 LLVMValueRef 应该代表 'the function' 但我找到的文档并没有说明更多。
根据its code, this function is just a C wrapper for BlockAddress::get()。所以,第一个参数是包含 BB 的 Function
,我想。
BlockAddress::get()
重载没有 C API 只接受 BB 参数,所以你必须先在那个 BB 上调用 LLVMGetBasicBlockParent() 以获得对 [=10= 的引用] 它属于,然后将它作为第一个参数传递给 LLVMBlockAddress()
.
根据经验,在这种情况下,请尝试弄清楚 "native" 您正在使用的 C++ 方法,然后查找其文档。
显然是通过 LLVMFunctionType() 和 LLVMAddFunction()。
尝试:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(int arg_count, char **args)
{
label0:
if (arg_count < 2)
{
uint32_t addr1 = &&label1 - &&label0;
uint32_t addr2 = &&label2 - &&label0;
printf("label1=%d label2=%d\n", addr1, addr2);
return 0;
}
else
{
uint32_t addr = strtol(args[1], NULL, 0);
printf("goto address = %d\n", addr);
void *indirect_addr = &&label0 + addr;
goto *indirect_addr;
}
label1:
printf("label1\n");
return 1;
label2:
printf("label2\n");
return 2;
}
clang ind_br.c -emit-llvm -S
查看输出
块地址(@main, %10) = LLVMBlockAddress
indirectbr i8* %36,[标签 %29,标签 %10,标签 %31,标签 %10,标签 %10] = LLVMBuildIndirectBr + LLVMAddDestination
所以 LLVMBuildIndirectBr 的第一个参数是 LLVMBlockAddress()
之一的结果