llvm::Value* CallExpression::Codegen(WasmFunction* fct, llvm::IRBuilder<>& builder) { WasmFunction* wfct = GetCallee(fct); llvm::Function* callee = wfct->GetFunction(); assert(callee != nullptr); // Now create the arguments for the call creation. std::vector<Value*> args; if (params_ != nullptr) { for (auto elem : *params_) { args.push_back(elem->Codegen(fct, builder)); } } const char* return_name = ""; if (wfct->GetResult() != VOID) { return_name = "calltmp"; } return builder.CreateCall(callee, args, return_name); }
void WasmAssertReturnNan::Codegen(WasmFile* file) { // Just one thing before we do anything. Find out if the caller was 64-bit or not. ReturnExpression* return_expr = dynamic_cast<ReturnExpression*>(expr_); assert(return_expr != nullptr); IfExpression* if_expr = dynamic_cast<IfExpression*>(return_expr->GetResult()); assert(if_expr!= nullptr); Binop* binop = dynamic_cast<Binop*>(if_expr->GetCondition()); assert(binop != nullptr); CallExpression* call = dynamic_cast<CallExpression*>(binop->GetLeft()); assert(call != nullptr); Variable* var = call->GetVariable(); const char* name = var->GetString(); // Get the function. WasmFunction* fct = file->GetWasmFunction(name); assert(fct != nullptr); ETYPE result = fct->GetResult(); if (result == FLOAT_64) { // We need to just fix the right hand side of the comparison. ValueHolder* vh = new ValueHolder(std::numeric_limits<double>::quiet_NaN()); Const* expr = new Const(FLOAT_64, vh); binop->SetRight(expr); } // Now generate the code... WasmAssertReturn::Codegen(file); }