From 7b638d548932eecc0a1af01eba7f57d679b365a8 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Wed, 12 May 2021 16:03:47 +0300 Subject: [PATCH] compiler: emit debug variable info for `_deploy()` --- pkg/compiler/codegen.go | 4 ++++ pkg/compiler/debug.go | 1 + pkg/compiler/debug_test.go | 7 ++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index fb6a23d34..92c56af0d 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -48,6 +48,8 @@ type codegen struct { staticVariables []string // initVariables contains variables local to `_initialize` method. initVariables []string + // deployVariables contains variables local to `_initialize` method. + deployVariables []string // A mapping from label's names to their ids. labels map[labelWithType]uint16 @@ -464,6 +466,8 @@ func (c *codegen) convertFuncDecl(file ast.Node, decl *ast.FuncDecl, pkg *types. if isInit { c.initVariables = append(c.initVariables, f.variables...) + } else if isDeploy { + c.deployVariables = append(c.deployVariables, f.variables...) } f.rng.End = uint16(c.prog.Len() - 1) diff --git a/pkg/compiler/debug.go b/pkg/compiler/debug.go index fb3beae80..2ac735b5d 100644 --- a/pkg/compiler/debug.go +++ b/pkg/compiler/debug.go @@ -169,6 +169,7 @@ func (c *codegen) emitDebugInfo(contract []byte) *DebugInfo { ReturnType: "Void", ReturnTypeSC: smartcontract.VoidType, SeqPoints: c.sequencePoints[manifest.MethodDeploy], + Variables: c.deployVariables, }) } for name, scope := range c.funcs { diff --git a/pkg/compiler/debug_test.go b/pkg/compiler/debug_test.go index 80cb885ed..b5dfbd121 100644 --- a/pkg/compiler/debug_test.go +++ b/pkg/compiler/debug_test.go @@ -63,7 +63,7 @@ func MethodParams(addr interop.Hash160, h interop.Hash256, type MyStruct struct {} func (ms MyStruct) MethodOnStruct() { } func (ms *MyStruct) MethodOnPointerToStruct() { } -func _deploy(data interface{}, isUpdate bool) {} +func _deploy(data interface{}, isUpdate bool) { x := 1; _ = x } ` info, err := getBuildInfo("foo.go", src) @@ -99,8 +99,9 @@ func _deploy(data interface{}, isUpdate bool) {} t.Run("variables", func(t *testing.T) { vars := map[string][]string{ - "Main": {"s,ByteString", "res,Integer"}, - manifest.MethodInit: {"a,Integer", "x,ByteString"}, + "Main": {"s,ByteString", "res,Integer"}, + manifest.MethodInit: {"a,Integer", "x,ByteString"}, + manifest.MethodDeploy: {"x,Integer"}, } for i := range d.Methods { v, ok := vars[d.Methods[i].ID]