compiler: support sequence points in debug info

Sequence points is a way to map a specific instruction offset
from a compiled contract to a text span in a source file.

This commit implements mapping only for `return` statements.
Further improvements are straight-forward.
This commit is contained in:
Evgenii Stratonikov 2020-03-31 16:57:35 +03:00
parent 24fef35ead
commit 5d3da26e1e
3 changed files with 52 additions and 1 deletions

View file

@ -76,6 +76,19 @@ type DebugParam struct {
Type string
}
func (c *codegen) saveSequencePoint(n ast.Node) {
fset := c.buildInfo.program.Fset
start := fset.Position(n.Pos())
end := fset.Position(n.End())
c.sequencePoints[c.scope.name] = append(c.sequencePoints[c.scope.name], DebugSeqPoint{
Opcode: c.prog.Len(),
StartLine: start.Line,
StartCol: start.Offset,
EndLine: end.Line,
EndCol: end.Offset,
})
}
func (c *codegen) emitDebugInfo() *DebugInfo {
d := &DebugInfo{
EntryPoint: mainIdent,
@ -108,6 +121,7 @@ func (c *codegen) methodInfoFromScope(name string, scope *funcScope) *MethodDebu
Range: scope.rng,
Parameters: params,
ReturnType: c.scReturnTypeFromScope(scope),
SeqPoints: c.sequencePoints[name],
}
}