bool assembler::compile(binary * bin) { FKLOG("[assembler] compile binary %p", bin); #ifndef FK64 // 32位目前不支持 return true; #endif if (!m_isopen) { return true; } for (const fkhashmap<variant, funcunion>::ele * p = m_fk->fm.m_shh.first(); p != 0; p = m_fk->fm.m_shh.next()) { const funcunion & f = *p->t; if (f.havefb && FUNC_BINARY_FRESH(f.fb)) { const func_binary & fb = f.fb; if (FUNC_BINARY_BACKUP(fb)) { const func_binary & bkfb = *FUNC_BINARY_BACKUP(fb); if (!compile_func(bkfb)) { FKERR("[assembler] compile compile_func %s fail", FUNC_BINARY_NAME(bkfb)); return false; } FUNC_BINARY_FRESH(bkfb)--; } else { if (!compile_func(fb)) { FKERR("[assembler] compile compile_func %s fail", FUNC_BINARY_NAME(fb)); return false; } FUNC_BINARY_FRESH(fb)--; } } } FKLOG("[assembler] compile binary %d ok \n%s", bin, m_native->dump().c_str()); return true; }
static HRESULT create_function(compile_ctx_t *ctx, function_decl_t *decl, function_t **ret) { function_t *func; HRESULT hres; if(lookup_dim_decls(ctx, decl->name) || lookup_funcs_name(ctx, decl->name)) { FIXME("%s: redefinition\n", debugstr_w(decl->name)); return E_FAIL; } func = compiler_alloc(ctx->code, sizeof(*func)); if(!func) return E_OUTOFMEMORY; func->name = compiler_alloc_string(ctx->code, decl->name); if(!func->name) return E_OUTOFMEMORY; func->vars = NULL; func->var_cnt = 0; func->code_ctx = ctx->code; func->type = decl->type; func->is_public = decl->is_public; func->arg_cnt = 0; if(decl->args) { arg_decl_t *arg; unsigned i; for(arg = decl->args; arg; arg = arg->next) func->arg_cnt++; func->args = compiler_alloc(ctx->code, func->arg_cnt * sizeof(arg_desc_t)); if(!func->args) return E_OUTOFMEMORY; for(i = 0, arg = decl->args; arg; arg = arg->next, i++) { func->args[i].name = compiler_alloc_string(ctx->code, arg->name); if(!func->args[i].name) return E_OUTOFMEMORY; func->args[i].by_ref = arg->by_ref; } }else { func->args = NULL; } hres = compile_func(ctx, decl->body, func); if(FAILED(hres)) return hres; *ret = func; return S_OK; }
void host::compile( shader_object_ptr& obj, shader_log_ptr& log, string const& code, shader_profile const& prof, vector<external_function_desc> const& funcs ) { if(!compile_func) { load_function(); } assert(compile_func); if(!compile_func) return; compile_func(obj, log, code, prof, funcs); }
bool compiler::compile_body() { myflexer * mf = m_mf; func_desc_list & funclist = mf->get_func_list(); FKLOG("[compiler] compile_body funclist %d", funclist.size()); for (int i = 0; i < (int)funclist.size(); i++) { func_desc_node * funcnode = funclist[i]; if (!compile_func(funcnode)) { FKERR("[compiler] compile_body %s fail", funcnode->funcname.c_str()); return false; } } FKLOG("[compiler] compile_body funclist %d ok dump \n%s", funclist.size(), m_fk->bin.dump().c_str()); FKLOG("[compiler] compile_body funcmap %d ok dump \n%s", m_fk->fm.size(), m_fk->fm.dump().c_str()); return true; }