How to invoke an Objective-C Block via the LLVM C++ API?

Posted by smokris on Stack Overflow See other posts from Stack Overflow or by smokris
Published on 2010-12-31T06:48:52Z Indexed on 2010/12/31 6:53 UTC
Read the original article Hit count: 253

Filed under:
|

Say, for example, I have an Objective-C compiled Module that contains something like the following:

typedef bool (^BoolBlock)(void);
BoolBlock returnABlock(void)
{
    return Block_copy(^bool(void){
        printf("Block executing.\n");
        return YES;
    });
}

...then, using the LLVM C++ API, I load that Module and create a CallInst to call the returnABlock() function:

Function *returnABlockFunction = returnABlockModule->getFunction(std::string("returnABlock"));
CallInst *returnABlockCall = CallInst::Create(returnABlockFunction, "returnABlockCall", entryBlock);

How can I then invoke the Block returned via the returnABlockCall object?

© Stack Overflow or respective owner

Related posts about llvm

Related posts about objective-c-blocks