forked from TrueCloudLab/neoneo-go
compiler: remove CompileWithDebugInfo
It is a simple wrapper over `CompileWithOptions` which we don't really
need. Custom options can be specified explicitly instead of using some
random default. This default was introduced in 1578904da
, however tests
written there use `CompileWithOptions` and all other tests
pass on that commit even without this default.
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
46f623a48f
commit
8af9c870b1
14 changed files with 26 additions and 33 deletions
|
@ -55,7 +55,7 @@ func NewDeployTx(bc blockchainer.Blockchainer, name string, sender util.Uint160,
|
||||||
// nef.NewFile() cares about version a lot.
|
// nef.NewFile() cares about version a lot.
|
||||||
config.Version = "0.90.0-test"
|
config.Version = "0.90.0-test"
|
||||||
|
|
||||||
ne, di, err := compiler.CompileWithDebugInfo(name, r)
|
ne, di, err := compiler.CompileWithOptions(name, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, util.Uint160{}, nil, err
|
return nil, util.Uint160{}, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,7 @@ func getBuildInfo(name string, src interface{}) (*buildInfo, error) {
|
||||||
// If `r != nil`, `name` is interpreted as a filename, and `r` as file contents.
|
// If `r != nil`, `name` is interpreted as a filename, and `r` as file contents.
|
||||||
// Otherwise `name` is either file name or name of the directory containing source files.
|
// Otherwise `name` is either file name or name of the directory containing source files.
|
||||||
func Compile(name string, r io.Reader) ([]byte, error) {
|
func Compile(name string, r io.Reader) ([]byte, error) {
|
||||||
f, _, err := CompileWithDebugInfo(name, r)
|
f, _, err := CompileWithOptions(name, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -168,13 +168,6 @@ func Compile(name string, r io.Reader) ([]byte, error) {
|
||||||
return f.Script, nil
|
return f.Script, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompileWithDebugInfo compiles a Go program into bytecode and emits debug info.
|
|
||||||
func CompileWithDebugInfo(name string, r io.Reader) (*nef.File, *DebugInfo, error) {
|
|
||||||
return CompileWithOptions(name, r, &Options{
|
|
||||||
NoEventsCheck: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// CompileWithOptions compiles a Go program into bytecode with provided compiler options.
|
// CompileWithOptions compiles a Go program into bytecode with provided compiler options.
|
||||||
func CompileWithOptions(name string, r io.Reader, o *Options) (*nef.File, *DebugInfo, error) {
|
func CompileWithOptions(name string, r io.Reader, o *Options) (*nef.File, *DebugInfo, error) {
|
||||||
ctx, err := getBuildInfo(name, r)
|
ctx, err := getBuildInfo(name, r)
|
||||||
|
|
|
@ -36,7 +36,7 @@ func TestCompiler(t *testing.T) {
|
||||||
name: "TestCompileDirectory",
|
name: "TestCompileDirectory",
|
||||||
function: func(t *testing.T) {
|
function: func(t *testing.T) {
|
||||||
const multiMainDir = "testdata/multi"
|
const multiMainDir = "testdata/multi"
|
||||||
_, di, err := compiler.CompileWithDebugInfo(multiMainDir, nil)
|
_, di, err := compiler.CompileWithOptions(multiMainDir, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
m := map[string]bool{}
|
m := map[string]bool{}
|
||||||
for i := range di.Methods {
|
for i := range di.Methods {
|
||||||
|
@ -93,7 +93,7 @@ func compileFile(src string) error {
|
||||||
|
|
||||||
func TestOnPayableChecks(t *testing.T) {
|
func TestOnPayableChecks(t *testing.T) {
|
||||||
compileAndCheck := func(t *testing.T, src string) error {
|
compileAndCheck := func(t *testing.T, src string) error {
|
||||||
_, di, err := compiler.CompileWithDebugInfo("payable", strings.NewReader(src))
|
_, di, err := compiler.CompileWithOptions("payable", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = compiler.CreateManifest(di, &compiler.Options{})
|
_, err = compiler.CreateManifest(di, &compiler.Options{})
|
||||||
return err
|
return err
|
||||||
|
@ -129,7 +129,7 @@ func TestSafeMethodWarnings(t *testing.T) {
|
||||||
src := `package payable
|
src := `package payable
|
||||||
func Main() int { return 1 }`
|
func Main() int { return 1 }`
|
||||||
|
|
||||||
_, di, err := compiler.CompileWithDebugInfo("eventTest", strings.NewReader(src))
|
_, di, err := compiler.CompileWithOptions("eventTest", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = compiler.CreateManifest(di, &compiler.Options{SafeMethods: []string{"main"}})
|
_, err = compiler.CreateManifest(di, &compiler.Options{SafeMethods: []string{"main"}})
|
||||||
|
@ -144,7 +144,7 @@ func TestEventWarnings(t *testing.T) {
|
||||||
import "github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
import "github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||||
func Main() { runtime.Notify("Event", 1) }`
|
func Main() { runtime.Notify("Event", 1) }`
|
||||||
|
|
||||||
_, di, err := compiler.CompileWithDebugInfo("eventTest", strings.NewReader(src))
|
_, di, err := compiler.CompileWithOptions("eventTest", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Run("event it missing from config", func(t *testing.T) {
|
t.Run("event it missing from config", func(t *testing.T) {
|
||||||
|
@ -188,7 +188,7 @@ func TestEventWarnings(t *testing.T) {
|
||||||
return notify.Value
|
return notify.Value
|
||||||
}`
|
}`
|
||||||
|
|
||||||
_, di, err := compiler.CompileWithDebugInfo("eventTest", strings.NewReader(src))
|
_, di, err := compiler.CompileWithOptions("eventTest", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = compiler.CreateManifest(di, &compiler.Options{NoEventsCheck: true})
|
_, err = compiler.CreateManifest(di, &compiler.Options{NoEventsCheck: true})
|
||||||
|
@ -202,7 +202,7 @@ func TestEventWarnings(t *testing.T) {
|
||||||
return 42
|
return 42
|
||||||
}`
|
}`
|
||||||
|
|
||||||
_, di, err := compiler.CompileWithDebugInfo("eventTest", strings.NewReader(src))
|
_, di, err := compiler.CompileWithOptions("eventTest", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = compiler.CreateManifest(di, &compiler.Options{})
|
_, err = compiler.CreateManifest(di, &compiler.Options{})
|
||||||
|
|
|
@ -67,7 +67,7 @@ func (ms *MyStruct) MethodOnPointerToStruct() { }
|
||||||
func _deploy(data interface{}, isUpdate bool) { x := 1; _ = x }
|
func _deploy(data interface{}, isUpdate bool) { x := 1; _ = x }
|
||||||
`
|
`
|
||||||
|
|
||||||
buf, d, err := CompileWithOptions("foo.go", strings.NewReader(src), nil)
|
ne, d, err := CompileWithOptions("foo.go", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, d)
|
require.NotNil(t, d)
|
||||||
|
|
||||||
|
@ -162,8 +162,8 @@ func _deploy(data interface{}, isUpdate bool) { x := 1; _ = x }
|
||||||
// basic check that last instruction of every method is indeed RET
|
// basic check that last instruction of every method is indeed RET
|
||||||
for i := range d.Methods {
|
for i := range d.Methods {
|
||||||
index := d.Methods[i].Range.End
|
index := d.Methods[i].Range.End
|
||||||
require.True(t, int(index) < len(buf))
|
require.True(t, int(index) < len(ne.Script))
|
||||||
require.EqualValues(t, opcode.RET, buf[index])
|
require.EqualValues(t, opcode.RET, ne.Script[index])
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("convert to Manifest", func(t *testing.T) {
|
t.Run("convert to Manifest", func(t *testing.T) {
|
||||||
|
@ -365,7 +365,7 @@ func TestManifestOverload(t *testing.T) {
|
||||||
return 4
|
return 4
|
||||||
}`
|
}`
|
||||||
|
|
||||||
_, di, err := CompileWithDebugInfo("foo", strings.NewReader(src))
|
_, di, err := CompileWithOptions("foo", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
m, err := di.ConvertToManifest(&Options{Overloads: map[string]string{"add3Aux": "add3"}})
|
m, err := di.ConvertToManifest(&Options{Overloads: map[string]string{"add3Aux": "add3"}})
|
||||||
|
|
|
@ -302,7 +302,7 @@ func TestJumpOptimize(t *testing.T) {
|
||||||
func Main() int {
|
func Main() int {
|
||||||
return Get3()
|
return Get3()
|
||||||
}`
|
}`
|
||||||
b, di, err := compiler.CompileWithDebugInfo("", strings.NewReader(src))
|
b, di, err := compiler.CompileWithOptions("", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 6, len(di.Methods))
|
require.Equal(t, 6, len(di.Methods))
|
||||||
for _, mi := range di.Methods {
|
for _, mi := range di.Methods {
|
||||||
|
|
|
@ -131,7 +131,7 @@ func TestContractWithNoMain(t *testing.T) {
|
||||||
someLocal := 2
|
someLocal := 2
|
||||||
return someGlobal + someLocal + a
|
return someGlobal + someLocal + a
|
||||||
}`
|
}`
|
||||||
b, di, err := compiler.CompileWithDebugInfo("foo.go", strings.NewReader(src))
|
b, di, err := compiler.CompileWithOptions("foo.go", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
v := vm.New()
|
v := vm.New()
|
||||||
invokeMethod(t, "Add3", b.Script, v, di)
|
invokeMethod(t, "Add3", b.Script, v, di)
|
||||||
|
|
|
@ -128,7 +128,7 @@ func TestAbort(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func spawnVM(t *testing.T, ic *interop.Context, src string) *vm.VM {
|
func spawnVM(t *testing.T, ic *interop.Context, src string) *vm.VM {
|
||||||
b, di, err := compiler.CompileWithDebugInfo("foo.go", strings.NewReader(src))
|
b, di, err := compiler.CompileWithOptions("foo.go", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
v := core.SpawnVM(ic)
|
v := core.SpawnVM(ic)
|
||||||
invokeMethod(t, testMainIdent, b.Script, v, di)
|
invokeMethod(t, testMainIdent, b.Script, v, di)
|
||||||
|
@ -141,7 +141,7 @@ func TestAppCall(t *testing.T) {
|
||||||
func Get42() int {
|
func Get42() int {
|
||||||
return 42
|
return 42
|
||||||
}`
|
}`
|
||||||
barCtr, di, err := compiler.CompileWithDebugInfo("bar.go", strings.NewReader(srcDeep))
|
barCtr, di, err := compiler.CompileWithOptions("bar.go", strings.NewReader(srcDeep), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
mBar, err := di.ConvertToManifest(&compiler.Options{Name: "Bar"})
|
mBar, err := di.ConvertToManifest(&compiler.Options{Name: "Bar"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -167,7 +167,7 @@ func TestAppCall(t *testing.T) {
|
||||||
srcInner = fmt.Sprintf(srcInner,
|
srcInner = fmt.Sprintf(srcInner,
|
||||||
fmt.Sprintf("%#v", cinterop.Hash160(barH.BytesBE())))
|
fmt.Sprintf("%#v", cinterop.Hash160(barH.BytesBE())))
|
||||||
|
|
||||||
inner, di, err := compiler.CompileWithDebugInfo("foo.go", strings.NewReader(srcInner))
|
inner, di, err := compiler.CompileWithOptions("foo.go", strings.NewReader(srcInner), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
m, err := di.ConvertToManifest(&compiler.Options{
|
m, err := di.ConvertToManifest(&compiler.Options{
|
||||||
Name: "Foo",
|
Name: "Foo",
|
||||||
|
|
|
@ -251,7 +251,7 @@ func runNativeTestCase(t *testing.T, ctr interop.ContractMD, name, method string
|
||||||
|
|
||||||
v := vm.New()
|
v := vm.New()
|
||||||
v.GasLimit = -1
|
v.GasLimit = -1
|
||||||
b, di, err := compiler.CompileWithDebugInfo("foo.go", strings.NewReader(src))
|
b, di, err := compiler.CompileWithOptions("foo.go", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
result := getTestStackItem(md.MD.ReturnType)
|
result := getTestStackItem(md.MD.ReturnType)
|
||||||
|
|
|
@ -139,7 +139,7 @@ func runSyscallTestCase(t *testing.T, ic *interop.Context, goName string, tc sys
|
||||||
}
|
}
|
||||||
ss := strings.Split(goName, ".")
|
ss := strings.Split(goName, ".")
|
||||||
src := fmt.Sprintf(srcTmpl, ss[0], goName, strings.Join(tc.params, ", "))
|
src := fmt.Sprintf(srcTmpl, ss[0], goName, strings.Join(tc.params, ", "))
|
||||||
b, _, err := compiler.CompileWithDebugInfo("foo", strings.NewReader(src))
|
b, _, err := compiler.CompileWithOptions("foo", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
v := ic.SpawnVM()
|
v := ic.SpawnVM()
|
||||||
|
@ -198,7 +198,7 @@ func TestNotify(t *testing.T) {
|
||||||
runtime.Notify("long event12345678901234567890123")
|
runtime.Notify("long event12345678901234567890123")
|
||||||
}`
|
}`
|
||||||
|
|
||||||
_, _, err := compiler.CompileWithDebugInfo("foo.go", strings.NewReader(src))
|
_, _, err := compiler.CompileWithOptions("foo.go", strings.NewReader(src), nil)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ func vmAndCompileInterop(t *testing.T, src string) (*vm.VM, *storagePlugin) {
|
||||||
vm.GasLimit = -1
|
vm.GasLimit = -1
|
||||||
vm.SyscallHandler = storePlugin.syscallHandler
|
vm.SyscallHandler = storePlugin.syscallHandler
|
||||||
|
|
||||||
b, di, err := compiler.CompileWithDebugInfo("foo.go", strings.NewReader(src))
|
b, di, err := compiler.CompileWithOptions("foo.go", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
storePlugin.info = di
|
storePlugin.info = di
|
||||||
|
|
|
@ -187,7 +187,7 @@ func TestBug1728(t *testing.T) {
|
||||||
func _deploy(_ interface{}, isUpdate bool) {
|
func _deploy(_ interface{}, isUpdate bool) {
|
||||||
runtime.Log("Deploy")
|
runtime.Log("Deploy")
|
||||||
}`
|
}`
|
||||||
nf, di, err := compiler.CompileWithDebugInfo("foo", strings.NewReader(src))
|
nf, di, err := compiler.CompileWithOptions("foo", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
m, err := di.ConvertToManifest(&compiler.Options{Name: "TestContract"})
|
m, err := di.ConvertToManifest(&compiler.Options{Name: "TestContract"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -29,7 +29,7 @@ func CompileSource(t *testing.T, sender util.Uint160, src io.Reader, opts *compi
|
||||||
// nef.NewFile() cares about version a lot.
|
// nef.NewFile() cares about version a lot.
|
||||||
config.Version = "neotest"
|
config.Version = "neotest"
|
||||||
|
|
||||||
ne, di, err := compiler.CompileWithDebugInfo(opts.Name, src)
|
ne, di, err := compiler.CompileWithOptions(opts.Name, src, opts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
m, err := compiler.CreateManifest(di, opts)
|
m, err := compiler.CreateManifest(di, opts)
|
||||||
|
@ -51,7 +51,7 @@ func CompileFile(t *testing.T, sender util.Uint160, srcPath string, configPath s
|
||||||
// nef.NewFile() cares about version a lot.
|
// nef.NewFile() cares about version a lot.
|
||||||
config.Version = "neotest"
|
config.Version = "neotest"
|
||||||
|
|
||||||
ne, di, err := compiler.CompileWithDebugInfo(srcPath, nil)
|
ne, di, err := compiler.CompileWithOptions(srcPath, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
conf, err := smartcontract.ParseContractConfig(configPath)
|
conf, err := smartcontract.ParseContractConfig(configPath)
|
||||||
|
|
|
@ -394,7 +394,7 @@ func handleLoadGo(c *ishell.Context) {
|
||||||
c.Err(fmt.Errorf("%w: <file>", ErrMissingParameter))
|
c.Err(fmt.Errorf("%w: <file>", ErrMissingParameter))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
b, di, err := compiler.CompileWithDebugInfo(c.Args[0], nil)
|
b, di, err := compiler.CompileWithOptions(c.Args[0], nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Err(err)
|
c.Err(err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -243,7 +243,7 @@ func TestLoad(t *testing.T) {
|
||||||
t.Run("loadnef", func(t *testing.T) {
|
t.Run("loadnef", func(t *testing.T) {
|
||||||
config.Version = "0.92.0-test"
|
config.Version = "0.92.0-test"
|
||||||
|
|
||||||
nefFile, di, err := compiler.CompileWithDebugInfo("test", strings.NewReader(src))
|
nefFile, di, err := compiler.CompileWithOptions("test", strings.NewReader(src), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
filename := filepath.Join(tmpDir, "vmtestcontract.nef")
|
filename := filepath.Join(tmpDir, "vmtestcontract.nef")
|
||||||
rawNef, err := nefFile.Bytes()
|
rawNef, err := nefFile.Bytes()
|
||||||
|
|
Loading…
Reference in a new issue