LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/reps/translator - ccu_rep_reference_manager.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 70.0 % 50 35
Test Date: 2026-07-28 12:11:00 Functions: 78.6 % 14 11

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
       3              :  * Description: ccu rep reference manager implementation file
       4              :  * Create: 2025-02-20
       5              :  */
       6              : 
       7              : #include "ccu_rep_reference_manager_v1.h"
       8              : #include "exception_util.h"
       9              : #include "ccu_api_exception.h"
      10              : 
      11              : namespace hcomm {
      12              : namespace CcuRep {
      13              : 
      14          866 : CcuRepReferenceManager::CcuRepReferenceManager(uint8_t deiId) : dieId(deiId)
      15              : {
      16          866 :     funcInVar.resize(FUNC_ARG_MAX);
      17          866 :     funcOutVar.resize(FUNC_ARG_MAX);
      18          866 :     funcCallVar.resize(1 + FUNC_NEST_MAX + 1); // FUNC_NEST_MAX个xn存放返回地址,1个xn存放block的起始地址和1个xn存放函数地址调用时返回地址
      19          866 : }
      20              : 
      21          864 : CcuResReq CcuRepReferenceManager::GetResReq(uint8_t reqDieId)
      22              : {
      23              :     // xn 资源统一从 continuousXn 池子申请,离散 xn 帐户已废弃
      24          864 :     CcuResReq resReq;
      25          864 :     resReq.continuousXnReq[reqDieId] = FUNC_ARG_MAX + FUNC_ARG_MAX + 1 + FUNC_NEST_MAX + 1;
      26          864 :     return resReq;
      27              : }
      28              : 
      29          864 : void CcuRepReferenceManager::GetRes(CcuRepResource &res)
      30              : {
      31          864 :     res.continuousVariable[dieId].insert(res.continuousVariable[dieId].end(),
      32              :         funcInVar.begin(), funcInVar.end());
      33          864 :     res.continuousVariable[dieId].insert(res.continuousVariable[dieId].end(),
      34              :         funcOutVar.begin(), funcOutVar.end());
      35          864 :     res.continuousVariable[dieId].insert(res.continuousVariable[dieId].end(),
      36              :         funcCallVar.begin(), funcCallVar.end());
      37          864 : }
      38              : 
      39            5 : bool CcuRepReferenceManager::CheckValid(const std::string &label)
      40              : {
      41            5 :     return (referenceMap.find(label) != referenceMap.end());
      42              : }
      43              : 
      44           28 : bool CcuRepReferenceManager::CheckUnique(const std::string &label)
      45              : {
      46           28 :     return (referenceMap.find(label) == referenceMap.end());
      47              : }
      48              : 
      49            5 : std::shared_ptr<CcuRepBlock> CcuRepReferenceManager::GetRefBlock(const std::string &label)
      50              : {
      51            5 :     if (!CheckValid(label)) {
      52            0 :         Hccl::THROW<Hccl::CcuApiException>("Invalid Reference: %s", label.c_str());
      53              :     }
      54            5 :     return referenceMap[label];
      55              : }
      56              : 
      57           28 : void CcuRepReferenceManager::SetRefBlock(const std::string &label, std::shared_ptr<CcuRepBlock> refBlock)
      58              : {
      59           28 :     if (!CheckUnique(label)) {
      60            0 :         Hccl::THROW<Hccl::CcuApiException>("Duplicate Definition: %s", label.c_str());
      61              :     }
      62           28 :     referenceMap[label] = refBlock;
      63           28 : }
      64              : 
      65            0 : uint16_t CcuRepReferenceManager::GetFuncAddr(const std::string &label)
      66              : {
      67            0 :     if (!CheckValid(label)) {
      68            0 :         Hccl::THROW<Hccl::CcuApiException>("Invalid Reference: %s", label.c_str());
      69              :     }
      70              : 
      71            0 :     if (referenceMap[label]->Type() != CcuRepType::FUNC_BLOCK) {
      72            0 :         Hccl::THROW<Hccl::CcuApiException>("Invalid Type, %s Must be FuncBlock", label.c_str());
      73              :     }
      74              : 
      75            0 :     return referenceMap[label]->StartInstrId();
      76              : }
      77              : 
      78           10 : const Variable &CcuRepReferenceManager::GetFuncCall()
      79              : {
      80           10 :     return funcCallVar[0];
      81              : }
      82              : 
      83            9 : const Variable &CcuRepReferenceManager::GetFuncRet(uint16_t callLayer)
      84              : {
      85            9 :     if (callLayer > FUNC_NEST_MAX) {
      86            0 :         Hccl::THROW<Hccl::CcuApiException>("Max Func Call Nest Num is %u, callLayer = %u", FUNC_NEST_MAX, callLayer);
      87              :     }
      88            9 :     return funcCallVar[callLayer + 1];
      89              : }
      90              : 
      91           80 : const std::vector<Variable> &CcuRepReferenceManager::GetFuncIn()
      92              : {
      93           80 :     return funcInVar;
      94              : }
      95              : 
      96            0 : const std::vector<Variable> &CcuRepReferenceManager::GetFuncOut()
      97              : {
      98            0 :     return funcOutVar;
      99              : }
     100              : 
     101            0 : void CcuRepReferenceManager::Dump() const
     102              : {
     103            0 :     for (const auto &kv : referenceMap) {
     104            0 :         HCCL_INFO("refBlock[%s]:", kv.first.c_str());
     105              :     }
     106            0 : }
     107              : 
     108          608 : void CcuRepReferenceManager::ClearRepReference()
     109              : {
     110          608 :     referenceMap.clear();
     111          608 : }
     112              : 
     113              : }; // namespace CcuRep
     114              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1