Class SmapGenerator

java.lang.Object
org.ek9lang.compiler.backend.jvm.SmapGenerator

final class SmapGenerator extends Object
Generates JSR-45 SMAP (Source Map) for debugging non-Java languages on the JVM.

SMAP format enables debuggers to map JVM bytecode back to original .ek9 source files. This is critical for proper debugging support - without SMAP, debuggers expect .java files.

SMAP Structure:

SMAP
GeneratedFileName
LanguageName
*S LanguageName
*F
+ FileID FileName
  FilePath
*L
InputStartLine#FileID,InputLineCount:OutputStartLine,OutputLineIncrement
*E
See Also:
  • Constructor Details

    • SmapGenerator

      public SmapGenerator(String generatedFileName)
      Create SMAP generator for a specific generated class.
      Parameters:
      generatedFileName - The name of the generated .class file (without .class extension)
  • Method Details

    • addMapping

      public void addMapping(DebugInfo debugInfo, int outputLineNumber)
      Add debug information from an IR instruction to the SMAP.
      Parameters:
      debugInfo - Debug information from IR
      outputLineNumber - JVM bytecode line number
    • collectFromIRConstruct

      public void collectFromIRConstruct(IRConstruct construct)
      Collect all debug information from IR construct operations.

      Walks EVERY executed instruction of each operation through THE shared IR walk, IRConstruct.allInstructionsOf(OperationInstr) - so a line that exists only inside a nested body (a for-range loop body, an if/switch/try arm) is in the SMAP too. Before this (S14, 2026-10-07) only the operation body's top-level instructions were read: the LineNumberTable carried the loop-body lines but the EK9 stratum did not, so locationsOfLine("EK9", file, line) was empty for them and no breakpoint could bind on total += step inside a for.

      Parameters:
      construct - IR construct containing operations with debug info
    • generate

      public String generate()
      Generate complete SMAP string in JSR-45 format.
      Returns:
      SMAP string for SourceDebugExtension attribute