static void emit_typecheck(Value *x, jl_value_t *type, const std::string &msg, jl_codectx_t *ctx) { Value *istype = builder.CreateICmpEQ(emit_typeof(x), literal_pointer_val(type)); BasicBlock *failBB = BasicBlock::Create(getGlobalContext(),"fail",ctx->f); BasicBlock *passBB = BasicBlock::Create(getGlobalContext(),"pass"); builder.CreateCondBr(istype, passBB, failBB); builder.SetInsertPoint(failBB); emit_type_error(x, type, msg, ctx); builder.CreateBr(passBB); ctx->f->getBasicBlockList().push_back(passBB); builder.SetInsertPoint(passBB); }
static void emit_cpointercheck(Value *x, const std::string &msg, jl_codectx_t *ctx) { Value *t = emit_typeof(x); emit_typecheck(t, (jl_value_t*)jl_datatype_type, msg, ctx); Value *istype = builder.CreateICmpEQ(emit_nthptr(t, offsetof(jl_datatype_t,name)/sizeof(char*)), literal_pointer_val((jl_value_t*)jl_pointer_type->name)); BasicBlock *failBB = BasicBlock::Create(getGlobalContext(),"fail",ctx->f); BasicBlock *passBB = BasicBlock::Create(getGlobalContext(),"pass"); builder.CreateCondBr(istype, passBB, failBB); builder.SetInsertPoint(failBB); emit_type_error(x, (jl_value_t*)jl_pointer_type, msg, ctx); builder.CreateBr(passBB); ctx->f->getBasicBlockList().push_back(passBB); builder.SetInsertPoint(passBB); }
static void emit_func_check(Value *x, jl_codectx_t *ctx) { Value *xty = emit_typeof(x); Value *isfunc = builder. CreateOr(builder. CreateICmpEQ(xty, literal_pointer_val((jl_value_t*)jl_function_type)), builder. CreateICmpEQ(xty, literal_pointer_val((jl_value_t*)jl_struct_kind))); BasicBlock *elseBB1 = BasicBlock::Create(getGlobalContext(),"notf", ctx->f); BasicBlock *mergeBB1 = BasicBlock::Create(getGlobalContext(),"isf"); builder.CreateCondBr(isfunc, mergeBB1, elseBB1); builder.SetInsertPoint(elseBB1); emit_type_error(x, (jl_value_t*)jl_function_type, "apply", ctx); builder.CreateBr(mergeBB1); ctx->f->getBasicBlockList().push_back(mergeBB1); builder.SetInsertPoint(mergeBB1); }