Ejemplo n.º 1
0
SN_TYPE(string) ml_sn_get_type_name_from_id(unsigned int type_id) 
{
  SN_TYPE(string) result;
  ENTER_DEBUG_MSG("ml_sn_get_type_name_from_id","type_id = %d",type_id);
  result = provided_tray->get_type_name_from_id_ptr(sn_uvm_ml_adapter_id,type_id);
  EXIT_DEBUG_MSG("ml_sn_get_type_name_from_id","result = %d",result);
  return result;
}
Ejemplo n.º 2
0
static int sn_bp_create_child_junction_node(const char * component_type_name,
					    const char * instance_name,
					    const char * parent_full_name,
					    int          parent_framework_id,
					    int          parent_junction_node_id) 
{
  int result;
  SN_TYPE(string) component_type_name_copy = SN_STRING_NEW(strlen(component_type_name)+1);
  SN_TYPE(string) instance_name_copy = SN_STRING_NEW(strlen(instance_name)+1);
  SN_TYPE(string) parent_full_name_copy = SN_STRING_NEW(strlen(parent_full_name)+1);

  strcpy(component_type_name_copy,component_type_name);
  strcpy(instance_name_copy,instance_name);
  strcpy(parent_full_name_copy,parent_full_name);
  
  ENTER_DEBUG_MSG("sn_bp_create_child_junction_node","component_type_name = %s, instance_name = %s, parent_full_name = %s, parent_framework_id = %d, parent_junction_node_id = %d",
		  component_type_name,instance_name,parent_full_name,parent_framework_id,parent_junction_node_id);
  result = SN_DISPATCH(sn_ml_create_child,UVM_ML_ADAPTER,sn_ML_LIB_adapter,(UVM_ML_ADAPTER,component_type_name_copy,instance_name_copy,parent_full_name_copy,parent_framework_id,parent_junction_node_id));
  EXIT_DEBUG_MSG("sn_bp_create_child_junction_node","result = %d",result);
  return result;
}
Ejemplo n.º 3
0
static int sn_bp_tlm2_b_transport_request(unsigned target_connector_id,
					  unsigned call_id, 
					  unsigned callback_adapter_id,
					  unsigned stream_size, 
					  uvm_ml_stream_t stream, 
					  uvm_ml_time_unit delay_unit, 
					  double delay_value,
					  uvm_ml_time_unit time_unit, 
					  double time_value)
{
  int result;
  SN_TYPE(real) time;
  ENTER_DEBUG_MSG("sn_bp_tlm2_b_transport_request","target_connector_id = %d, call_id = %d, callback_adapter_id = %d, stream_size = %d, stream = %p, delay_unit = %d, delay_value = %f, time_unit = %d, time_value = %f",
		  target_connector_id,call_id,callback_adapter_id,stream_size,stream,delay_unit,delay_value,time_unit,time_value);
  time = SN_REAL_NEW(delay_value);
  result = SN_DISPATCH(sn_ml_tlm2_b_transport_request,UVM_ML_ADAPTER,sn_ML_LIB_adapter,(UVM_ML_ADAPTER,target_connector_id,call_id,callback_adapter_id,stream_size,stream,delay_unit,time));
  EXIT_DEBUG_MSG("sn_bp_tlm2_b_transport_request","result = %d",result);
  return result;
}
Ejemplo n.º 4
0
static uvm_ml_tlm_sync_enum sn_bp_tlm2_nb_transport_bw(unsigned target_connector_id, 
						       unsigned *stream_size, 
						       uvm_ml_stream_t *stream, 
						       uvm_ml_tlm_phase *phase,
						       unsigned transaction_id,
						       uvm_ml_time_unit *delay_unit,
						       double *delay_value,
						       uvm_ml_time_unit time_unit, 
						       double time_value)
{
  SN_TYPE(real) time;
  uvm_ml_tlm_sync_enum result;
  time = SN_REAL_NEW(*delay_value);
  ENTER_DEBUG_MSG("sn_bp_tlm2_nb_transport_bw","target_connector_id  = %d, stream_size_ptr = %p, stream = %p, phase_ptr = %p, transaction_id = %d, delay_unit_ptr = %p, delay_value_ptr = %p, time_unit = %d, time_value = %f",
		  target_connector_id,stream_size,stream,phase,transaction_id,delay_unit,delay_value,time_unit,time_value);
  result = SN_DISPATCH(sn_ml_tlm2_nb_transport_bw,UVM_ML_ADAPTER,sn_ML_LIB_adapter,(UVM_ML_ADAPTER,target_connector_id,stream_size,stream,phase,transaction_id,delay_unit,&time));
  *delay_value = SN_REAL_GET(time);
  EXIT_DEBUG_MSG("sn_bp_tlm2_nb_transport_bw","result = %d, stream_size = %d, stream = %p, phase = %d, delay_unit = %d, delay_value = %f",
		 result,*stream_size,stream,*phase,*delay_unit,*delay_value);
  return result;
}
Ejemplo n.º 5
0
  ENTER_DEBUG_MSG("ml_sn_get_type_id_from_name","type_name = %s",type_name);
  result = provided_tray->get_type_id_from_name_ptr(sn_uvm_ml_adapter_id,type_name);
  EXIT_DEBUG_MSG("ml_sn_get_type_id_from_name","result = %d",result);
  return result;
}

SN_TYPE(string) ml_sn_get_type_name_from_id(unsigned int type_id) 
{
  SN_TYPE(string) result;
  ENTER_DEBUG_MSG("ml_sn_get_type_name_from_id","type_id = %d",type_id);
  result = provided_tray->get_type_name_from_id_ptr(sn_uvm_ml_adapter_id,type_id);
  EXIT_DEBUG_MSG("ml_sn_get_type_name_from_id","result = %d",result);
  return result;
}

unsigned int ml_sn_connect_names(SN_TYPE(string) path1,
				 SN_TYPE(string) path2) 
{
  unsigned int result;
  ENTER_DEBUG_MSG("ml_sn_connect_names","path1 = %s, path2 = %s",path1,path2);
  result = provided_tray->connect_ptr(sn_uvm_ml_adapter_id,path1,path2);
  EXIT_DEBUG_MSG("ml_sn_connect_names","result = %d",result);
  return result;
}

SN_TYPE(bool) ml_sn_can_get(unsigned int connector_id) 
{
  uvm_ml_time_unit dummy_time_unit = TIME_UNIT_UNDEFINED;
  double           dummy_time_value = 0;
  SN_TYPE(bool) result;
Ejemplo n.º 6
0
bool
LCovSource::writeScript(JSScript* script)
{
    numFunctionsFound_++;
    outFN_.printf("FN:%d,", script->lineno());
    if (!writeScriptName(outFN_, script))
        return false;
    outFN_.put("\n", 1);

    uint64_t hits = 0;
    ScriptCounts* sc = nullptr;
    if (script->hasScriptCounts()) {
        sc = &script->getScriptCounts();
        numFunctionsHit_++;
        const PCCounts* counts = sc->maybeGetPCCounts(script->pcToOffset(script->main()));
        outFNDA_.printf("FNDA:%" PRIu64 ",", counts->numExec());
        if (!writeScriptName(outFNDA_, script))
            return false;
        outFNDA_.put("\n", 1);

        // Set the hit count of the pre-main code to 1, if the function ever got
        // visited.
        hits = 1;
    }

    jsbytecode* snpc = script->code();
    jssrcnote* sn = script->notes();
    if (!SN_IS_TERMINATOR(sn))
        snpc += SN_DELTA(sn);

    size_t lineno = script->lineno();
    jsbytecode* end = script->codeEnd();
    size_t branchId = 0;
    size_t tableswitchExitOffset = 0;
    for (jsbytecode* pc = script->code(); pc != end; pc = GetNextPc(pc)) {
        JSOp op = JSOp(*pc);
        bool jump = IsJumpOpcode(op) || op == JSOP_TABLESWITCH;
        bool fallsthrough = BytecodeFallsThrough(op) && op != JSOP_GOSUB;

        // If the current script & pc has a hit-count report, then update the
        // current number of hits.
        if (sc) {
            const PCCounts* counts = sc->maybeGetPCCounts(script->pcToOffset(pc));
            if (counts)
                hits = counts->numExec();
        }

        // If we have additional source notes, walk all the source notes of the
        // current pc.
        if (snpc <= pc) {
            size_t oldLine = lineno;
            while (!SN_IS_TERMINATOR(sn) && snpc <= pc) {
                SrcNoteType type = (SrcNoteType) SN_TYPE(sn);
                if (type == SRC_SETLINE)
                    lineno = size_t(GetSrcNoteOffset(sn, 0));
                else if (type == SRC_NEWLINE)
                    lineno++;
                else if (type == SRC_TABLESWITCH)
                    tableswitchExitOffset = GetSrcNoteOffset(sn, 0);

                sn = SN_NEXT(sn);
                snpc += SN_DELTA(sn);
            }

            if (oldLine != lineno && fallsthrough) {
                outDA_.printf("DA:%d,%" PRIu64 "\n", lineno, hits);

                // Count the number of lines instrumented & hit.
                numLinesInstrumented_++;
                if (hits)
                    numLinesHit_++;
            }
        }

        // If the current instruction has thrown, then decrement the hit counts
        // with the number of throws.
        if (sc) {
            const PCCounts* counts = sc->maybeGetThrowCounts(script->pcToOffset(pc));
            if (counts)
                hits -= counts->numExec();
        }

        // If the current pc corresponds to a conditional jump instruction, then reports
        // branch hits.
        if (jump && fallsthrough) {
            jsbytecode* fallthroughTarget = GetNextPc(pc);
            uint64_t fallthroughHits = 0;
            if (sc) {
                const PCCounts* counts = sc->maybeGetPCCounts(script->pcToOffset(fallthroughTarget));
                if (counts)
                    fallthroughHits = counts->numExec();
            }

            uint64_t taken = hits - fallthroughHits;
            outBRDA_.printf("BRDA:%d,%d,0,", lineno, branchId);
            if (taken)
                outBRDA_.printf("%d\n", taken);
            else
                outBRDA_.put("-\n", 2);

            outBRDA_.printf("BRDA:%d,%d,1,", lineno, branchId);
            if (fallthroughHits)
                outBRDA_.printf("%d\n", fallthroughHits);
            else
                outBRDA_.put("-\n", 2);

            // Count the number of branches, and the number of branches hit.
            numBranchesFound_ += 2;
            if (hits)
                numBranchesHit_ += !!taken + !!fallthroughHits;
            branchId++;
        }

        // If the current pc corresponds to a pre-computed switch case, then
        // reports branch hits for each case statement.
        if (jump && op == JSOP_TABLESWITCH) {
            MOZ_ASSERT(tableswitchExitOffset != 0);

            // Get the default and exit pc
            jsbytecode* exitpc = pc + tableswitchExitOffset;
            jsbytecode* defaultpc = pc + GET_JUMP_OFFSET(pc);
            MOZ_ASSERT(defaultpc > pc && defaultpc <= exitpc);

            // Get the low and high from the tableswitch
            int32_t low = GET_JUMP_OFFSET(pc + JUMP_OFFSET_LEN * 1);
            int32_t high = GET_JUMP_OFFSET(pc + JUMP_OFFSET_LEN * 2);
            MOZ_ASSERT(high - low + 1 >= 0);
            size_t numCases = high - low + 1;
            jsbytecode* jumpTable = pc + JUMP_OFFSET_LEN * 3;

            jsbytecode* firstcasepc = exitpc;
            for (size_t j = 0; j < numCases; j++) {
                jsbytecode* testpc = pc + GET_JUMP_OFFSET(jumpTable + JUMP_OFFSET_LEN * j);
                if (testpc < firstcasepc)
                    firstcasepc = testpc;
            }

            // Count the number of hits of the default branch, by subtracting
            // the number of hits of each cases.
            uint64_t defaultHits = hits;

            // Count the number of hits of the previous case entry.
            uint64_t fallsThroughHits = 0;

            // Record branches for each cases.
            size_t caseId = 0;
            for (size_t i = 0; i < numCases; i++) {
                jsbytecode* casepc = pc + GET_JUMP_OFFSET(jumpTable + JUMP_OFFSET_LEN * i);
                // The case is not present, and jumps to the default pc if used.
                if (casepc == pc)
                    continue;

                // PCs might not be in increasing order of case indexes.
                jsbytecode* lastcasepc = firstcasepc - 1;
                for (size_t j = 0; j < numCases; j++) {
                    jsbytecode* testpc = pc + GET_JUMP_OFFSET(jumpTable + JUMP_OFFSET_LEN * j);
                    if (lastcasepc < testpc && (testpc < casepc || (j < i && testpc == casepc)))
                        lastcasepc = testpc;
                }

                if (casepc != lastcasepc) {
                    // Case (i + low)
                    uint64_t caseHits = 0;
                    if (sc) {
                        const PCCounts* counts = sc->maybeGetPCCounts(script->pcToOffset(casepc));
                        if (counts)
                            caseHits = counts->numExec();

                        // Remove fallthrough.
                        fallsThroughHits = 0;
                        if (casepc != firstcasepc) {
                            jsbytecode* endpc = lastcasepc;
                            while (GetNextPc(endpc) < casepc)
                                endpc = GetNextPc(endpc);

                            if (BytecodeFallsThrough(JSOp(*endpc)))
                                fallsThroughHits = script->getHitCount(endpc);
                        }

                        caseHits -= fallsThroughHits;
                    }

                    outBRDA_.printf("BRDA:%d,%d,%d,", lineno, branchId, caseId);
                    if (caseHits)
                        outBRDA_.printf("%d\n", caseHits);
                    else
                        outBRDA_.put("-\n", 2);

                    numBranchesFound_++;
                    numBranchesHit_ += !!caseHits;
                    defaultHits -= caseHits;
                    caseId++;
                }
            }

            // Compute the number of hits of the default branch, if it has its
            // own case clause.
            bool defaultHasOwnClause = true;
            if (defaultpc != exitpc) {
                defaultHits = 0;

                // Look for the last case entry before the default pc.
                jsbytecode* lastcasepc = firstcasepc - 1;
                for (size_t j = 0; j < numCases; j++) {
                    jsbytecode* testpc = pc + GET_JUMP_OFFSET(jumpTable + JUMP_OFFSET_LEN * j);
                    if (lastcasepc < testpc && testpc <= defaultpc)
                        lastcasepc = testpc;
                }

                if (lastcasepc == defaultpc)
                    defaultHasOwnClause = false;

                // Look if the last case entry fallthrough to the default case,
                // in which case we have to remove the number of fallthrough
                // hits out of the default case hits.
                if (sc && lastcasepc != pc) {
                    jsbytecode* endpc = lastcasepc;
                    while (GetNextPc(endpc) < defaultpc)
                        endpc = GetNextPc(endpc);

                    if (BytecodeFallsThrough(JSOp(*endpc)))
                        fallsThroughHits = script->getHitCount(endpc);
                }

                if (sc) {
                    const PCCounts* counts = sc->maybeGetPCCounts(script->pcToOffset(defaultpc));
                    if (counts)
                        defaultHits = counts->numExec();
                }
                defaultHits -= fallsThroughHits;
            }

            if (defaultHasOwnClause) {
                outBRDA_.printf("BRDA:%d,%d,%d,", lineno, branchId, caseId);
                if (defaultHits)
                    outBRDA_.printf("%d\n", defaultHits);
                else
                    outBRDA_.put("-\n", 2);
                numBranchesFound_++;
                numBranchesHit_ += !!defaultHits;
            }

            // Increment the branch identifier, and go to the next instruction.
            branchId++;
            tableswitchExitOffset = 0;
        }
    }

    // Report any new OOM.
    if (outFN_.hadOutOfMemory() ||
        outFNDA_.hadOutOfMemory() ||
        outBRDA_.hadOutOfMemory() ||
        outDA_.hadOutOfMemory())
    {
        return false;
    }

    // If this script is the top-level script, then record it such that we can
    // assume that the code coverage report is complete, as this script has
    // references on all inner scripts.
    if (script->isTopLevel())
        hasTopLevelScript_ = true;

    return true;
}