static void write_sample_server(definition *def) { version_list *vp; proc_list *proc; for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { for (proc = vp->procs; proc != NULL; proc = proc->next) { f_print(fout, "\n"); if (!mtflag) { return_type(proc); f_print(fout, "*\n"); } else f_print(fout, "bool_t\n"); pvname_svc(proc->proc_name, vp->vers_num); printarglist(proc, "result", RQSTP, "struct svc_req *"); f_print(fout, "{\n"); if (!mtflag) { f_print(fout, "\tstatic "); if(!streq(proc->res_type, "void")) return_type(proc); else f_print(fout, "char *"); /* cannot have void type */ f_print(fout, " result;\n"); } else f_print(fout, "\tbool_t retval;\n"); f_print(fout, "\n\t/*\n\t * insert server code here\n\t */\n\n"); if (!mtflag) if(!streq(proc->res_type, "void")) f_print(fout, "\treturn (&result);\n}\n"); else /* cast back to void * */ f_print(fout, "\treturn((void *) &result);\n}\n"); else f_print(fout, "\treturn (retval);\n}\n"); } /* put in sample freeing routine */ if (mtflag) { f_print(fout, "\nint\n"); pvname(def->def_name, vp->vers_num); f_print(fout,"_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result)\n"); f_print(fout, "{\n"); f_print(fout, "\t(void) xdr_free(xdr_result, result);\n"); f_print(fout, "\n\t/*\n\t * Insert additional freeing code here, if needed\n\t */\n"); f_print(fout, "\n}\n"); } } }
int main() { impala::init(); std::unique_ptr<impala::TypeTable> typetable; auto module = std::make_unique<impala::Module>("dummy.impala"); check(typetable, module.get(), false); llvm::LLVMContext context; int num = llvm::Intrinsic::num_intrinsics - 1; std::cout << "extern \"device\" {" << thorin::up; for (int i = 1; i != num; ++i) { auto id = (llvm::Intrinsic::ID) i; std::string llvm_name; if (llvm::Intrinsic::isOverloaded(id)) llvm_name = IntrinsicNameTable[i]; else llvm_name = llvm::Intrinsic::getName(id); // skip "experimental" intrinsics if (llvm_name.find("experimental")!=std::string::npos) continue; assert(llvm_name.substr(0, 5) == "llvm."); std::string name = llvm_name.substr(5); // remove 'llvm.' prefix // replace '.' with '_' std::transform(name.begin(), name.end(), name.begin(), [] (char c) { return c == '.' ? '_' : c; }); if (llvm::Intrinsic::isOverloaded(id)) { std::cout << thorin::endl; std::cout << "// fn \"" << llvm_name << "\" " << name; std::cout << " (...) -> (...); // is overloaded"; } else { if (auto itype = llvm2impala(*typetable, llvm::Intrinsic::getType(context, id))) { std::cout << thorin::endl; auto fn = itype->as<impala::FnType>(); std::cout << "fn \"" << llvm_name << "\" " << name << "("; for (size_t i = 0, e = fn->num_params()-1; i != e; ++i) { std::cout << fn->param(i); if (i != e-1) std::cout << ", "; } if (fn->return_type()->isa<impala::NoRetType>()) std::cout << ") -> !;"; else std::cout << ") -> " << fn->return_type() << ';'; } } } std::cout << thorin::down << thorin::endl << '}' << thorin::endl; }
void CodeTypeInference::on_visit(CodeBinaryOperatorExpression *object) { auto ret = CodeResolver::resolve(object); if (ret != nullptr) this->m_result = ret->return_type(); else this->m_result = nullptr; }
exparser::return_type exparser::parse_variable(const std::string& s) { if (!isalpha(s[0])) return return_false; auto it = std::find_if_not(s.begin(), s.end(), isalnum); if (it != s.end()) return return_false; return return_type(make_variable(s)); }
void ffi_call(/*@dependent@*/ ffi_cif *cif, void (*fn)(), /*@out@*/ void *rvalue, /*@dependent@*/ void **avalue) { extended_cif ecif; UINT64 trvalue; ecif.cif = cif; ecif.avalue = avalue; /* If the return value is a struct and we don't have a return */ /* value address then we need to make one */ if (cif->rtype->type == FFI_TYPE_STRUCT && return_type (cif->rtype) != FFI_TYPE_STRUCT) ecif.rvalue = &trvalue; else if ((rvalue == NULL) && (cif->rtype->type == FFI_TYPE_STRUCT)) { /*@-sysunrecog@*/ ecif.rvalue = alloca(cif->rtype->size); /*@=sysunrecog@*/ } else ecif.rvalue = rvalue; switch (cif->abi) { case FFI_SYSV: /*@-usedef@*/ ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes, cif->flags, ecif.rvalue, fn); /*@=usedef@*/ break; default: FFI_ASSERT(0); break; } if (rvalue && cif->rtype->type == FFI_TYPE_STRUCT && return_type (cif->rtype) != FFI_TYPE_STRUCT) memcpy (rvalue, &trvalue, cif->rtype->size); }
exparser::return_type exparser::parse_function(const std::string& s) { if (s[s.length() - 1] != ')') return return_false; std::size_t pos = s.find_first_of("("); if (pos == std::string::npos || !pos) return return_false; auto inner = loop(s.substr(pos, std::string::npos)); if (!inner) return return_false; if (s.substr(0, pos) == "sin") return return_type(sin(inner.get())); else if (s.substr(0, pos) == "cos") return return_type(cos(inner.get())); else if (s.substr(0, pos) == "tan") return return_type(tan(inner.get())); else if (s.substr(0, pos) == "log") return return_type(log(inner.get())); else return return_false; }
be_operation::be_operation ( AST_Type * rt, AST_Operation::Flags fl, UTL_ScopedName * n, const UTL_Pragmas & p ) : AST_Decl (AST_Decl::NT_op, n, p), UTL_Scope (AST_Decl::NT_op, n, p), AST_Operation (rt, fl, n, p), returnType (0), n_InArgs (0), n_OutArgs (0), n_InOutArgs (0), n_Args (0) { assert (return_type ()); isAtModuleScope (pbfalse); if (return_type ()) { returnType = (be_DispatchableType *) return_type ()-> narrow ((long) &be_DispatchableType::type_id); const char * typeName = returnType->TypeName (); if (typeName && strcmp (typeName, "DDS::Any") == 0) { BE_Globals::inc_any = pbtrue; } } else { DDSError ((DDS_StdString) "unknown return type for operation " + LocalName ()); } enclosingScope = be_Type::EnclosingScopeString (this); stubClassname = enclosingScope + DDSStubExtension; opKey = NameToString (name (), "_"); }
bool SLFunctionSignature::operator==(SLFunctionSignature other) const { if (*return_type() != *other.return_type() || arg_types().size() != other.arg_types().size()) { return false; } for (size_t i = 0; i < arg_types().size(); ++i) { if (*(arg_types()[i]) != *(other.arg_types()[i])) { return false; } } return true; }
static void write_sample_server(definition * def) { version_list *vp; proc_list *proc; for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { for (proc = vp->procs; proc != NULL; proc = proc->next) { f_print(fout, "\n"); /* if( Cflag ) f_print( fout, "extern \"C\"{\n"); */ return_type(proc); f_print(fout, "* \n"); if (Cflag) pvname_svc(proc->proc_name, vp->vers_num); else pvname(proc->proc_name, vp->vers_num); printarglist(proc, RQSTP, "struct svc_req *"); f_print(fout, "{\n"); f_print(fout, "\n\tstatic "); if (!streq(proc->res_type, "void")) return_type(proc); else f_print(fout, "char*"); /* cannot have void type */ /* f_print(fout, " result;\n", proc->res_type); */ f_print(fout, " result;\n"); f_print(fout, "\n\t/*\n\t * insert server code here\n\t */\n\n"); if (!streq(proc->res_type, "void")) f_print(fout, "\treturn(&result);\n}\n"); else /* cast back to void * */ f_print(fout, "\treturn((void*) &result);\n}\n"); /* if( Cflag) f_print( fout, "};\n"); */ } } }
exparser::return_type exparser::parse_constant(const std::string& s) { try { std::size_t pos = 0; auto c = stod(s, &pos); if (pos == s.length()) return return_type(make_constant(c)); else return return_false; } catch (std::invalid_argument e) { return return_false; } catch (std::out_of_range e) { throw e; } }
void Type::toJson(ostream& os) const { os << "{\"type\":\"" << getJsonName() << "\""; if (is_function()) { os << ",\"args\":["; for (unsigned t = 0; t < arguments().size(); ++t) { if (t > 0) os << ","; argument(t).toJson(os); } os << "]"; os << ",\"return\":"; return_type().toJson(os); } os << "}"; }
// // visit_operation // int Provides_Svnt_Impl::visit_operation (AST_Operation * node) { const char * local_name = node->local_name ()->get_string (); Operation_Return_Type return_type (this->hfile_, this->sfile_); node->return_type ()->ast_accept (&return_type); this->hfile_ << " " << local_name << " ("; this->sfile_ << " " << this->servant_name_ << "::" << local_name << " ("; // Build the signature int arg_count = node->argument_count (); if (arg_count == 0) { this->hfile_ << "void"; this->sfile_ << "void"; } else { Operation_Argument_List arg_list (this->hfile_, this->sfile_); arg_list.visit_scope (node); } this->hfile_ << ");"; this->sfile_ << "){"; // Start passthrough to impl if (arg_count != 0) this->sfile_ << "return "; this->sfile_ << "this->impl_->" << local_name << " ("; // Build the passthrough args if (arg_count != 0) { Operation_Impl_Args impl_args (this->sfile_); impl_args.visit_scope (node); } this->sfile_ << ");}"; return 0; }
void be_operation::GenerateVirtual ( be_Source & source, const DDS_StdString & implclassname ) { ostream & os = source.Stream (); be_Tab tab (source); be_Type *rettype = (be_Type *) return_type ()->narrow ((long) &be_Type::type_id); (void) rettype; assert (rettype); os << tab << "virtual " << BaseSignature (implclassname); os << " = 0;" << nl; }
exparser::return_type exparser::parse_plus(const std::string& s) { int par = 0; for (std::size_t i = s.length() - 1; i > 0; --i) { if ('(' == s[i]) ++par; else if (')' == s[i]) --par; else if (!par && '+' == s[i]) { auto lhs = loop(s.substr(0, i)); auto rhs = loop(s.substr(i+1, std::string::npos)); if (lhs && rhs) return return_type(lhs.get() + rhs.get()); else return return_false; } } return return_false; }
exparser::return_type exparser::parse_power(const std::string& s) { int par = 0; for (std::size_t i = 0; i < s.length(); ++i) { if ('(' == s[i]) ++par; else if (')' == s[i]) --par; else if (!par && '^' == s[i]) { auto lhs = loop(s.substr(0, i)); auto rhs = loop(s.substr(i+1, std::string::npos)); if (lhs && rhs) return return_type(pow(lhs.get(), rhs.get())); else return return_false; } } return return_false; }
// token builders static constexpr token_type e_number(const char *s, size_t index, size_t end) { // a small strtof float value = 0; size_t i = index; for (; s[i] != '.' && i < end; ++i) value = value * 10 + (s[i] - '0'); if (s[i] == '.') { float cpow = 10; for (size_t j = i + 1; j < end; ++j) { value += float(s[j] - '0') / cpow; cpow *= 10; } } return token_type {e_token_type::tok_number, return_type(value), s, index, end}; }
bool generate_functions(std::ostream& o) const { for (const auto& fn : export_fns) { const auto fn_type = fn->fn_type(); std::string return_pref, return_suf; if (!ctype_from_impala(fn_type->return_type(), return_pref, return_suf)) { error(fn, "function return type not exportable"); return false; } // We cannot return definite or indefinite arrays from Impala if (return_suf != "") { error(fn, "function returning an array"); return false; } o << return_pref << ' ' << fn->symbol() << '('; // Generate all arguments except the last one which is the implicit continuation for (size_t i = 0, e = fn_type->num_params() - 1; i != e; ++i) { std::string ctype_pref, ctype_suf; if (!ctype_from_impala(fn_type->param(i), ctype_pref, ctype_suf)) { error(fn, "function argument type not exportable"); return false; } o << ctype_pref << ' ' << fn->param(i)->symbol() << ctype_suf; if (i < fn_type->num_params() - 2) o << ", "; } // Generate void functions when the function takes no argument to be C89 compatible if (fn_type->num_params() == 1) { o << "void"; } o << ");" << std::endl; } return true; }
ffi_status ffi_prep_closure_loc (ffi_closure* closure, ffi_cif* cif, void (*fun)(ffi_cif*, void*, void**, void*), void *user_data, void *codeloc) { unsigned int *tramp; unsigned int insn; if (cif->abi != FFI_SYSV) return FFI_BAD_ABI; tramp = (unsigned int *) &closure->tramp[0]; /* Set T bit if the function returns a struct pointed with R2. */ insn = (return_type (cif->rtype) == FFI_TYPE_STRUCT ? 0x0018 /* sett */ : 0x0008 /* clrt */); #ifdef __LITTLE_ENDIAN__ tramp[0] = 0xd301d102; tramp[1] = 0x0000412b | (insn << 16); #else tramp[0] = 0xd102d301; tramp[1] = 0x412b0000 | insn; #endif *(void **) &tramp[2] = (void *)codeloc; /* ctx */ *(void **) &tramp[3] = (void *)ffi_closure_SYSV; /* funaddr */ closure->cif = cif; closure->fun = fun; closure->user_data = user_data; #if defined(__SH4__) /* Flush the icache. */ __ic_invalidate(codeloc); #endif return FFI_OK; }
Expr* primitive_desc::return_klass(PReg* p, Node* n) const { return convertToKlass(return_type(), p, n); }
// The type call slot. static PyObject *pyqtMethodProxy_call(PyObject *self, PyObject *args, PyObject *kw_args) { qpycore_pyqtMethodProxy *mp = (qpycore_pyqtMethodProxy *)self; const char *py_name = mp->py_name->constData(); // Check for keyword arguments. if (kw_args) { PyErr_Format(PyExc_TypeError, "%s() does not support keyword arguments", py_name); return 0; } QMetaMethod method = mp->qobject->metaObject()->method(mp->method_index); QList<QByteArray> arg_types = method.parameterTypes(); if (PyTuple_Size(args) != arg_types.size()) { PyErr_Format(PyExc_TypeError, "%s() called with %zd arguments but %d expected", py_name, PyTuple_Size(args), arg_types.size()); return 0; } // Parse the return type and the arguments. QGenericReturnArgument ret; QGenericArgument a0, a1, a2, a3, a4, a5, a6, a7, a8, a9; Chimera::Storage *return_storage, *storage[10]; QByteArray return_type(method.typeName()); bool failed = false; return_storage = 0; if (!return_type.isEmpty()) { const Chimera *ct = Chimera::parse(return_type); if (!ct) { PyErr_Format(PyExc_TypeError, "unable to convert return value of %s from '%s' to a Python object", py_name, return_type.constData()); return 0; } return_storage = ct->storageFactory(); ret = QGenericReturnArgument(return_type.constData(), return_storage->address()); } parse_arg(args, 0, arg_types, a0, storage, failed, py_name); parse_arg(args, 1, arg_types, a1, storage, failed, py_name); parse_arg(args, 2, arg_types, a2, storage, failed, py_name); parse_arg(args, 3, arg_types, a3, storage, failed, py_name); parse_arg(args, 4, arg_types, a4, storage, failed, py_name); parse_arg(args, 5, arg_types, a5, storage, failed, py_name); parse_arg(args, 6, arg_types, a6, storage, failed, py_name); parse_arg(args, 7, arg_types, a7, storage, failed, py_name); parse_arg(args, 8, arg_types, a8, storage, failed, py_name); parse_arg(args, 9, arg_types, a9, storage, failed, py_name); // Invoke the method. PyObject *result = 0; if (!failed) { failed = !method.invoke(mp->qobject, ret, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); if (failed) { PyErr_Format(PyExc_TypeError, "invocation of %s() failed", py_name); } else if (return_storage) { result = return_storage->toPyObject(); } else { result = Py_None; Py_INCREF(result); } } // Release any storage. if (return_storage) { delete return_storage->type(); delete return_storage; } for (int i = 0; i < 10; ++i) { Chimera::Storage *st = storage[i]; if (st) { delete st->type(); delete st; } } return result; }
inline summation() : sum(return_type()) { // Strategy supports only 2D areas assert_dimension<PointOfSegment, 2>(); }
void CodeTypeInference::on_visit(CodeMethodInvokeExpression *object) { auto method = CodeResolver::resolve(object); this->m_result = method->return_type(); }
void ffi_prep_args(char *stack, extended_cif *ecif) { register unsigned int i; register int tmp; register unsigned int avn; register void **p_argv; register char *argp; register ffi_type **p_arg; int greg, ireg; #if defined(__SH4__) int freg = 0; #endif tmp = 0; argp = stack; if (return_type (ecif->cif->rtype) == FFI_TYPE_STRUCT) { *(void **) argp = ecif->rvalue; argp += 4; ireg = STRUCT_VALUE_ADDRESS_WITH_ARG ? 1 : 0; } else ireg = 0; /* Set arguments for registers. */ greg = ireg; avn = ecif->cif->nargs; p_argv = ecif->avalue; for (i = 0, p_arg = ecif->cif->arg_types; i < avn; i++, p_arg++, p_argv++) { size_t z; z = (*p_arg)->size; if (z < sizeof(int)) { if (greg++ >= NGREGARG) continue; z = sizeof(int); switch ((*p_arg)->type) { case FFI_TYPE_SINT8: *(signed int *) argp = (signed int)*(SINT8 *)(* p_argv); break; case FFI_TYPE_UINT8: *(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv); break; case FFI_TYPE_SINT16: *(signed int *) argp = (signed int)*(SINT16 *)(* p_argv); break; case FFI_TYPE_UINT16: *(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv); break; case FFI_TYPE_STRUCT: *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv); break; default: FFI_ASSERT(0); } argp += z; } else if (z == sizeof(int)) { #if defined(__SH4__) if ((*p_arg)->type == FFI_TYPE_FLOAT) { if (freg++ >= NFREGARG) continue; } else #endif { if (greg++ >= NGREGARG) continue; } *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv); argp += z; } #if defined(__SH4__) else if ((*p_arg)->type == FFI_TYPE_DOUBLE) { if (freg + 1 >= NFREGARG) continue; freg = (freg + 1) & ~1; freg += 2; memcpy (argp, *p_argv, z); argp += z; } #endif else { int n = (z + sizeof (int) - 1) / sizeof (int); #if defined(__SH4__) if (greg + n - 1 >= NGREGARG) continue; #else if (greg >= NGREGARG) continue; #endif greg += n; memcpy (argp, *p_argv, z); argp += n * sizeof (int); } } /* Set arguments on stack. */ greg = ireg; #if defined(__SH4__) freg = 0; #endif p_argv = ecif->avalue; for (i = 0, p_arg = ecif->cif->arg_types; i < avn; i++, p_arg++, p_argv++) { size_t z; z = (*p_arg)->size; if (z < sizeof(int)) { if (greg++ < NGREGARG) continue; z = sizeof(int); switch ((*p_arg)->type) { case FFI_TYPE_SINT8: *(signed int *) argp = (signed int)*(SINT8 *)(* p_argv); break; case FFI_TYPE_UINT8: *(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv); break; case FFI_TYPE_SINT16: *(signed int *) argp = (signed int)*(SINT16 *)(* p_argv); break; case FFI_TYPE_UINT16: *(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv); break; case FFI_TYPE_STRUCT: *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv); break; default: FFI_ASSERT(0); } argp += z; } else if (z == sizeof(int)) { #if defined(__SH4__) if ((*p_arg)->type == FFI_TYPE_FLOAT) { if (freg++ < NFREGARG) continue; } else #endif { if (greg++ < NGREGARG) continue; } *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv); argp += z; } #if defined(__SH4__) else if ((*p_arg)->type == FFI_TYPE_DOUBLE) { if (freg + 1 < NFREGARG) { freg = (freg + 1) & ~1; freg += 2; continue; } memcpy (argp, *p_argv, z); argp += z; } #endif else { int n = (z + sizeof (int) - 1) / sizeof (int); if (greg + n - 1 < NGREGARG) { greg += n; continue; } #if (! defined(__SH4__)) else if (greg < NGREGARG) { greg = NGREGARG; continue; } #endif memcpy (argp, *p_argv, z); argp += n * sizeof (int); } } return; }
void openGL_function_info:: output_to_source(ostream &sourceFile) { int i; if(!m_newDeclaration) { // cerr << "Warning: " << function_name() << " in list twice not putting into source file!\n"; return; } //typedef for function pointer type sourceFile << "\ntypedef " << return_type() << "( APIENTRY* " << function_pointer_type() << " )(" << full_arg_list_withoutnames() << ");\n"; if(m_use_function_pointer) { //declare prototypes: sourceFile << front_material() << " " << do_nothing_function_name() << "(" << full_arg_list_withoutnames() << ");\n"; sourceFile << "int " << m_existsFunctionName << "(void);\n"; sourceFile << front_material() << " " << local_function_name() << "(" << full_arg_list_with_names() << ");\n"; sourceFile << front_material() << " " << do_nothing_function_name() << "(" << full_arg_list_withoutnames() << ");\n" << function_pointer_type() << " " << m_getFunctionName << "(void);\n"; //init the pointer for the function! sourceFile << function_pointer_type() << " " << function_pointer_name() << "=" << local_function_name() << ";\n\n\n"; //first the function which holds the initial value of the function pointer: sourceFile << front_material() << " " << local_function_name() << "(" << full_arg_list_with_names() << ")\n{\n\t" << m_getFunctionName << "();\n\t"; if(returns_value()) { sourceFile << "return "; } sourceFile << function_pointer_name() << "(" << argument_list_names_only() << ");\n}\n\n"; //thirdly the do nothing function: sourceFile << front_material() << " " << do_nothing_function_name() << "(" << full_arg_list_withoutnames() << ")\n{\n\t"; if(returns_value()) { sourceFile << return_type() << " retval = 0;\n\t"; } sourceFile << "return"; if(returns_value()) { sourceFile << " retval"; } sourceFile << ";\n}\n"; //fourthly the getFunction, which does the loading. sourceFile << function_pointer_type() << " " << m_getFunctionName << "(void)\n{\n\t" << "if(" << function_pointer_name() << "==" << local_function_name() << ")\n\t{\n\t\t" << function_pointer_name() << "=(" << function_pointer_type() << ")" << function_loader() << "(\"" << function_name() << "\");\n\t\tif(" << function_pointer_name() << "==NULL)\n\t\t{\n\t\t\t"<< function_error_loading() << "(\"" << function_name() << "\");\n\t\t\t" << function_pointer_name() << "=" << do_nothing_function_name() << ";\n\t\t}\n\t}\n\t" << "return " << function_pointer_name() << ";\n}\n\n"; //lastly the exists function: sourceFile << "int " << m_existsFunctionName << "(void)\n{\n\t" << m_getFunctionName << "();\n\t" << "return " << function_pointer_name() << "!=" << do_nothing_function_name() << ";\n}\n\n"; } else { sourceFile << function_pointer_type() << " " << function_pointer_name() << "=" << m_functionName << ";\n\n\n"; } //second the debug function. sourceFile << "#ifdef GL_DEBUG\n" << return_type() << " " << debug_function_name() << "("; if(number_arguments()!=0) { sourceFile << full_arg_list_with_names() << ", "; } sourceFile << "const char *file, int line, const char *call"; for(int i=0;i<number_arguments();++i) { sourceFile << ", const char *argumentName_" << i; } sourceFile << ")\n{\n\tstd::ostringstream call_stream;\n\t" << "std::string call_string;\n\t"; if(returns_value()) { sourceFile << return_type() << " retval;\n\t"; } if(function_name()=="glBegin") { sourceFile << inside_begin_end_pair_counter() << "=1;\n\t"; } sourceFile << "call_stream << \"" << function_name() << "(\" "; for(i=0;i<number_arguments();++i) { if(i!=0) { sourceFile << " << \",\" "; } sourceFile << "<< argumentName_" << i << " "; if(!arg_type_is_pointer(i)) { sourceFile << "<< \"=0x\" "; } else { sourceFile << "<< \"=\" "; } sourceFile << "<< std::hex << argument_" << i << " "; } sourceFile << "<< \")\";\n\tcall_string=call_stream.str();\n\t"; sourceFile << function_pregl_error() << "(call_string.c_str(),call,\"" << function_name() << "\",file,line,(void*)" << function_pointer_name() << ");\n\t"; if(returns_value()) { sourceFile << "retval="; } sourceFile << function_pointer_name() << "(" << argument_list_names_only() << ");\n\t" << function_gl_error() << "(call_string.c_str(),call,\"" << function_name() << "\",file,line,(void*)" << function_pointer_name() << ");\n\t"; if(function_name()=="glEnd") { sourceFile << inside_begin_end_pair_counter() << "=0;\n\t"; } if(returns_value()) { sourceFile << "return retval;"; } else { sourceFile << "//no return value"; } sourceFile << "\n}\n#endif\n\n"; }
void openGL_function_info:: output_to_header(ostream &headerFile) { if(!m_newDeclaration) { // cerr << "Warning: " << function_name() << " in list twice not putting into header file!\n"; return; } headerFile << "\ntypedef " << return_type() << "( APIENTRY* " << function_pointer_type() << " )(" << full_arg_list_withoutnames() << ");\n"; headerFile << "extern " << function_pointer_type() << " " << function_pointer_name() << ";\n"; if(m_use_function_pointer) { headerFile << "int " << m_existsFunctionName << "(void);\n" << function_pointer_type() << " " << m_getFunctionName << "(void);\n"; } else { headerFile << "inline int " << m_existsFunctionName << "(void) { return 1; }\n" << "inline " << function_pointer_type() << " " << m_getFunctionName << "(void) { return " << m_functionName << "; }\n"; } headerFile << "#ifdef GL_DEBUG\n"; headerFile << return_type() << " " << debug_function_name() << "("; if(number_arguments()!=0) { headerFile << full_arg_list_with_names() << ", " ; } headerFile << "const char *file, int line, const char *call"; for(int i=0;i<number_arguments();++i) { headerFile << ", const char *argumentName_" << i; } headerFile << ");\n" << "#define " << function_name() << "(" << argument_list_names_only() << ") " << sm_namespace << "::" << debug_function_name() << "("; if(number_arguments()!=0) { headerFile << argument_list_names_only() << "," ; } headerFile << " __FILE__, __LINE__, \"" << function_name() << "(\""; for(int i=0;i<number_arguments();++i) { if(i!=0) headerFile << "\",\""; headerFile << "#" << argument_name() << i; } headerFile << "\")\""; for(int i=0;i<number_arguments();++i) { headerFile << ", #" << argument_name() << i; } headerFile << ")\n" << "#else\n" << "#define " << function_name() << "(" << argument_list_names_only() << ") " << sm_namespace << "::" << function_pointer_name() << "(" << argument_list_names_only() << ")\n#endif\n\n"; }
int ffi_closure_helper_SYSV (ffi_closure *closure, void *rvalue, unsigned long *pgr, unsigned long *pfr, unsigned long *pst) { void **avalue; ffi_type **p_arg; int i, avn; int ireg, greg = 0; #if defined(__SH4__) int freg = 0; #endif ffi_cif *cif; cif = closure->cif; avalue = alloca(cif->nargs * sizeof(void *)); /* Copy the caller's structure return value address so that the closure returns the data directly to the caller. */ if (cif->rtype->type == FFI_TYPE_STRUCT && STRUCT_VALUE_ADDRESS_WITH_ARG) { rvalue = (void *) *pgr++; ireg = 1; } else ireg = 0; cif = closure->cif; greg = ireg; avn = cif->nargs; /* Grab the addresses of the arguments from the stack frame. */ for (i = 0, p_arg = cif->arg_types; i < avn; i++, p_arg++) { size_t z; z = (*p_arg)->size; if (z < sizeof(int)) { if (greg++ >= NGREGARG) continue; z = sizeof(int); switch ((*p_arg)->type) { case FFI_TYPE_SINT8: case FFI_TYPE_UINT8: avalue[i] = (((char *)pgr) + OFS_INT8); break; case FFI_TYPE_SINT16: case FFI_TYPE_UINT16: avalue[i] = (((char *)pgr) + OFS_INT16); break; case FFI_TYPE_STRUCT: avalue[i] = pgr; break; default: FFI_ASSERT(0); } pgr++; } else if (z == sizeof(int)) { #if defined(__SH4__) if ((*p_arg)->type == FFI_TYPE_FLOAT) { if (freg++ >= NFREGARG) continue; avalue[i] = pfr; pfr++; } else #endif { if (greg++ >= NGREGARG) continue; avalue[i] = pgr; pgr++; } } #if defined(__SH4__) else if ((*p_arg)->type == FFI_TYPE_DOUBLE) { if (freg + 1 >= NFREGARG) continue; if (freg & 1) pfr++; freg = (freg + 1) & ~1; freg += 2; avalue[i] = pfr; pfr += 2; } #endif else { int n = (z + sizeof (int) - 1) / sizeof (int); #if defined(__SH4__) if (greg + n - 1 >= NGREGARG) continue; #else if (greg >= NGREGARG) continue; #endif greg += n; avalue[i] = pgr; pgr += n; } } greg = ireg; #if defined(__SH4__) freg = 0; #endif for (i = 0, p_arg = cif->arg_types; i < avn; i++, p_arg++) { size_t z; z = (*p_arg)->size; if (z < sizeof(int)) { if (greg++ < NGREGARG) continue; z = sizeof(int); switch ((*p_arg)->type) { case FFI_TYPE_SINT8: case FFI_TYPE_UINT8: avalue[i] = (((char *)pst) + OFS_INT8); break; case FFI_TYPE_SINT16: case FFI_TYPE_UINT16: avalue[i] = (((char *)pst) + OFS_INT16); break; case FFI_TYPE_STRUCT: avalue[i] = pst; break; default: FFI_ASSERT(0); } pst++; } else if (z == sizeof(int)) { #if defined(__SH4__) if ((*p_arg)->type == FFI_TYPE_FLOAT) { if (freg++ < NFREGARG) continue; } else #endif { if (greg++ < NGREGARG) continue; } avalue[i] = pst; pst++; } #if defined(__SH4__) else if ((*p_arg)->type == FFI_TYPE_DOUBLE) { if (freg + 1 < NFREGARG) { freg = (freg + 1) & ~1; freg += 2; continue; } avalue[i] = pst; pst += 2; } #endif else { int n = (z + sizeof (int) - 1) / sizeof (int); if (greg + n - 1 < NGREGARG) { greg += n; continue; } #if (! defined(__SH4__)) else if (greg < NGREGARG) { greg += n; pst += greg - NGREGARG; continue; } #endif avalue[i] = pst; pst += n; } } (closure->fun) (cif, rvalue, avalue, closure->user_data); /* Tell ffi_closure_SYSV how to perform return type promotions. */ return return_type (cif->rtype); }
/* Perform machine dependent cif processing */ ffi_status ffi_prep_cif_machdep(ffi_cif *cif) { int i, j; int size, type; int n, m; int greg; #if defined(__SH4__) int freg = 0; #endif cif->flags = 0; greg = ((return_type (cif->rtype) == FFI_TYPE_STRUCT) && STRUCT_VALUE_ADDRESS_WITH_ARG) ? 1 : 0; #if defined(__SH4__) for (i = j = 0; i < cif->nargs && j < 12; i++) { type = (cif->arg_types)[i]->type; switch (type) { case FFI_TYPE_FLOAT: if (freg >= NFREGARG) continue; freg++; cif->flags += ((cif->arg_types)[i]->type) << (2 * j); j++; break; case FFI_TYPE_DOUBLE: if ((freg + 1) >= NFREGARG) continue; freg = (freg + 1) & ~1; freg += 2; cif->flags += ((cif->arg_types)[i]->type) << (2 * j); j++; break; default: size = (cif->arg_types)[i]->size; n = (size + sizeof (int) - 1) / sizeof (int); if (greg + n - 1 >= NGREGARG) continue; greg += n; for (m = 0; m < n; m++) cif->flags += FFI_TYPE_INT << (2 * j++); break; } } #else for (i = j = 0; i < cif->nargs && j < 4; i++) { size = (cif->arg_types)[i]->size; n = (size + sizeof (int) - 1) / sizeof (int); if (greg >= NGREGARG) continue; else if (greg + n - 1 >= NGREGARG) n = NGREGARG - greg; greg += n; for (m = 0; m < n; m++) cif->flags += FFI_TYPE_INT << (2 * j++); } #endif /* Set the return type flag */ switch (cif->rtype->type) { case FFI_TYPE_STRUCT: cif->flags += (unsigned) (return_type (cif->rtype)) << 24; break; case FFI_TYPE_VOID: case FFI_TYPE_FLOAT: case FFI_TYPE_DOUBLE: case FFI_TYPE_SINT64: case FFI_TYPE_UINT64: cif->flags += (unsigned) cif->rtype->type << 24; break; default: cif->flags += FFI_TYPE_INT << 24; break; } return FFI_OK; }