Skip to content

Commit

Permalink
feat(IR): add overloaded form of IRBuilder.CreateCall
Browse files Browse the repository at this point in the history
  • Loading branch information
ApsarasX committed Oct 22, 2021
1 parent a07a1fe commit d150d2c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion include/Util/ErrMsg.h
Expand Up @@ -109,7 +109,8 @@ namespace ErrMsg {
static const char *CreateAlloca = "IRBuilder.CreateAlloca needs to be called with: (type: Type, arraySize?: Value, name?: string)";
static const char *CreateBr = "IRBuilder.CreateBr needs to be called with: (destBB: BasicBlock)";
static const char *CreateCall = "IRBuilder.CreateCall needs to be called with:"
"\n\t - (callee: Value, args: Value[], name?: string)"
"\n\t - (callee: Function)"
"\n\t - (callee: Function, args: Value[], name?: string)"
"\n\t - (funcType: FunctionType, callee: Value, args: Value[], name?: string)";
static const char *CreateCondBr = "IRBuilder.createCondBr needs to be called with: (cond: Value, thenBB: BasicBlock, elseBB: BasicBlock)";
static const char *CreateLoad = "IRBuilder.CreateLoad needs to be called with: (type: Type, ptr: Value, name?: string)";
Expand Down
3 changes: 2 additions & 1 deletion llvm-bindings.d.ts
Expand Up @@ -651,6 +651,8 @@ declare namespace llvm {

public CreateBr(destBB: BasicBlock): BranchInst;

// customized
public CreateCall(callee: Function): CallInst;
public CreateCall(callee: Function, args: Value[], name?: string): CallInst;
public CreateCall(funcType: FunctionType, callee: Value, args: Value[], name?: string): CallInst;

Expand Down Expand Up @@ -1065,7 +1067,6 @@ declare namespace llvm {
function getDeclaration(module: Module, id: number, types?: Type[]): Function;
}


function verifyFunction(func: Function): boolean;

function verifyModule(module: Module): boolean;
Expand Down
5 changes: 4 additions & 1 deletion src/IR/IRBuilder.cpp
Expand Up @@ -189,7 +189,10 @@ Napi::Value IRBuilder::createCall(const Napi::CallbackInfo &info) {
int argsLen = info.Length();
llvm::CallInst *call = nullptr;
std::vector<llvm::Value *> calleeArgs;
if (argsLen >= 2 && Function::IsClassOf(info[0]) && info[1].IsArray() && (argsLen == 2 || argsLen >= 3 && info[2].IsString())) {
if (argsLen == 1 && Function::IsClassOf(info[0])) {
llvm::Function *callee = Function::Extract(info[0]);
call = builder->CreateCall(callee);
} else if (argsLen >= 2 && Function::IsClassOf(info[0]) && info[1].IsArray() && (argsLen == 2 || argsLen >= 3 && info[2].IsString())) {
llvm::Function *callee = Function::Extract(info[0]);
if (assembleValueArray(info[1].As<Napi::Array>(), calleeArgs)) {
std::string name = argsLen >= 3 ? std::string(info[2].As<Napi::String>()) : "";
Expand Down

0 comments on commit d150d2c

Please sign in to comment.