Class CoverageProbePlacer
java.lang.Object
org.ek9lang.compiler.phase7.generation.CoverageProbePlacer
Places coverage probes at control flow points during IR generation.
Coverage probes are inserted at:
- Function/method entry (FUNCTION_ENTRY)
- If-then branch taken (BRANCH_TRUE)
- Else/else-if branch taken (BRANCH_FALSE)
- Switch case entry (SWITCH_CASE)
- Catch block entry (CATCH_BLOCK)
- Loop body entry (LOOP_BODY)
Each probe has a unique ID within its module, enabling precise coverage tracking. The placer tracks all probes for a module to generate module metadata at the end.
Note: BLOCK and FUNCTION_EXIT probes are intentionally omitted as they are redundant in EK9 - explicit branch tracking already identifies paths taken, and EK9 functions have exactly one exit point (no return statement).
-
Constructor Summary
ConstructorsConstructorDescriptionCoverageProbePlacer(CompilerFlags compilerFlags, long moduleId, String moduleName) Create a coverage probe placer for a module. -
Method Summary
Modifier and TypeMethodDescriptioncreateBranchFalseProbe(DebugInfo debugInfo) Create a branch-false (else) probe instruction.createBranchTrueProbe(DebugInfo debugInfo) Create a branch-true (if/then) probe instruction.createCatchBlockProbe(String exceptionType, DebugInfo debugInfo) Create a catch block probe instruction.createCoverageFinalization(DebugInfo debugInfo) Create a coverage finalization instruction.createFunctionEntryProbe(DebugInfo debugInfo) Create a function entry probe instruction.createLoopBodyProbe(DebugInfo debugInfo) Create a loop body probe instruction.createModuleRegistration(DebugInfo debugInfo) Create a module registration instruction.createSwitchCaseProbe(String caseLabel, DebugInfo debugInfo) Create a switch case probe instruction.voidenterFunction(String functionName, String simpleName, String sourceFile, int startLine) Enter a function/method context for probe tracking.voidexitFunction(int endLine) Exit the current function/method context.Get all probe details for this module (for testing/verification).Get function details for this module (for testing/verification).longGet the module ID.intGet the current probe count for this module.booleanCheck if coverage instrumentation is enabled.Serialize probe and function metadata to JSON for runtime coverage computation.
-
Constructor Details
-
CoverageProbePlacer
Create a coverage probe placer for a module.- Parameters:
compilerFlags- Compiler flags to check if coverage is enabledmoduleId- Unique identifier for this modulemoduleName- Human-readable module name
-
-
Method Details
-
isCoverageEnabled
public boolean isCoverageEnabled()Check if coverage instrumentation is enabled. -
enterFunction
Enter a function/method context for probe tracking. Call this when starting to generate IR for a function/method.- Parameters:
functionName- Fully qualified function/method namesimpleName- Simple function/method name (e.g., "_add")sourceFile- Source file containing this functionstartLine- Starting line number of the function
-
exitFunction
public void exitFunction(int endLine) Exit the current function/method context. Records function-level coverage metadata.- Parameters:
endLine- Ending line number of the function
-
createFunctionEntryProbe
-
createBranchTrueProbe
-
createBranchFalseProbe
-
createSwitchCaseProbe
Create a switch case probe instruction.- Parameters:
caseLabel- Label or description of the case (for logging purposes)debugInfo- Source location information- Returns:
- Coverage probe instruction, or null if coverage disabled
-
createCatchBlockProbe
Create a catch block probe instruction.- Parameters:
exceptionType- Type of exception being caught (for logging purposes)debugInfo- Source location information- Returns:
- Coverage probe instruction, or null if coverage disabled
-
createLoopBodyProbe
-
createModuleRegistration
-
createCoverageFinalization
-
getProbeCount
public int getProbeCount()Get the current probe count for this module. -
getModuleId
public long getModuleId()Get the module ID. -
getAllProbes
Get all probe details for this module (for testing/verification). -
getFunctionDetails
Get function details for this module (for testing/verification). -
toMetadataJson
Serialize probe and function metadata to JSON for runtime coverage computation.The JSON format is:
{ "probes": [ {"id": 0, "type": "FUNCTION_ENTRY", "line": 10, "functionId": 0}, {"id": 1, "type": "BRANCH_TRUE", "line": 15, "functionId": 0} ], "functions": [ {"id": 0, "name": "myFunction", "startLine": 10, "endLine": 20, "probeCount": 3} ] }- Returns:
- JSON string with coverage metadata, or null if no probes
-