| 2308 | } |
| 2309 | |
| 2310 | bool CompileHelper::compileFunction(DesignComponent* component, |
| 2311 | const FileContent* fC, NodeId nodeId, |
| 2312 | CompileDesign* compileDesign, Reduce reduce, |
| 2313 | ValuedComponentI* instance, bool isMethod) { |
| 2314 | UHDM::Serializer& s = compileDesign->getSerializer(); |
| 2315 | std::vector<UHDM::task_func*>* task_funcs = component->getTask_funcs(); |
| 2316 | if (task_funcs == nullptr) { |
| 2317 | component->setTask_funcs(s.MakeTask_funcVec()); |
| 2318 | task_funcs = component->getTask_funcs(); |
| 2319 | } |
| 2320 | std::string name; |
| 2321 | NodeId func_decl = setFuncTaskQualifiers(fC, nodeId, nullptr); |
| 2322 | VObjectType func_decl_type = fC->Type(func_decl); |
| 2323 | bool constructor = false; |
| 2324 | if (func_decl_type == VObjectType::paClass_constructor_declaration || |
| 2325 | func_decl_type == VObjectType::paClass_constructor_prototype) { |
| 2326 | constructor = true; |
| 2327 | } |
| 2328 | NodeId Tf_port_list; |
| 2329 | if (constructor) { |
| 2330 | Tf_port_list = fC->Child(func_decl); |
| 2331 | name = "new"; |
| 2332 | } else { |
| 2333 | NodeId Function_body_declaration; |
| 2334 | if (fC->Type(func_decl) == VObjectType::paFunction_body_declaration) |
| 2335 | Function_body_declaration = func_decl; |
| 2336 | else |
| 2337 | Function_body_declaration = fC->Child(func_decl); |
| 2338 | NodeId Function_data_type_or_implicit = |
| 2339 | fC->Child(Function_body_declaration); |
| 2340 | NodeId Function_name = fC->Sibling(Function_data_type_or_implicit); |
| 2341 | if (fC->Type(Function_name) == VObjectType::slStringConst) { |
| 2342 | name = fC->SymName(Function_name); |
| 2343 | Tf_port_list = fC->Sibling(Function_name); |
| 2344 | } else if (fC->Type(Function_name) == VObjectType::paClass_scope) { |
| 2345 | NodeId Class_type = fC->Child(Function_name); |
| 2346 | NodeId suffixname = fC->Sibling(Function_name); |
| 2347 | name.assign(fC->SymName(fC->Child(Class_type))) |
| 2348 | .append("::") |
| 2349 | .append(fC->SymName(suffixname)); |
| 2350 | Tf_port_list = fC->Sibling(suffixname); |
| 2351 | } |
| 2352 | } |
| 2353 | UHDM::function* func = nullptr; |
| 2354 | for (auto f : *component->getTask_funcs()) { |
| 2355 | if (f->VpiName() == name) { |
| 2356 | func = any_cast<UHDM::function*>(f); |
| 2357 | break; |
| 2358 | } |
| 2359 | } |
| 2360 | if (func == nullptr) { |
| 2361 | // make placeholder first |
| 2362 | func = s.MakeFunction(); |
| 2363 | func->VpiName(name); |
| 2364 | fC->populateCoreMembers(nodeId, nodeId, func); |
| 2365 | task_funcs->push_back(func); |
| 2366 | return true; |
| 2367 | } |
no test coverage detected