mirror of https://github.com/ethereum/go-ethereum
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
1.4 KiB
83 lines
1.4 KiB
10 years ago
|
package vm
|
||
10 years ago
|
|
||
|
import (
|
||
10 years ago
|
"math"
|
||
10 years ago
|
"math/big"
|
||
|
|
||
10 years ago
|
"github.com/ethereum/go-ethereum/common"
|
||
10 years ago
|
"github.com/ethereum/go-ethereum/logger"
|
||
10 years ago
|
)
|
||
|
|
||
10 years ago
|
var vmlogger = logger.NewLogger("VM")
|
||
10 years ago
|
|
||
10 years ago
|
// Global Debug flag indicating Debug VM (full logging)
|
||
|
var Debug bool
|
||
|
|
||
10 years ago
|
type Type byte
|
||
10 years ago
|
|
||
|
const (
|
||
10 years ago
|
StdVmTy Type = iota
|
||
10 years ago
|
JitVmTy
|
||
10 years ago
|
MaxVmTy
|
||
10 years ago
|
|
||
|
MaxCallDepth = 1025
|
||
|
|
||
|
LogTyPretty byte = 0x1
|
||
|
LogTyDiff byte = 0x2
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
Pow256 = common.BigPow(2, 256)
|
||
|
|
||
|
U256 = common.U256
|
||
|
S256 = common.S256
|
||
|
|
||
|
Zero = common.Big0
|
||
|
|
||
|
max = big.NewInt(math.MaxInt64)
|
||
10 years ago
|
)
|
||
|
|
||
10 years ago
|
func NewVm(env Environment) VirtualMachine {
|
||
|
switch env.VmType() {
|
||
|
case JitVmTy:
|
||
|
return NewJitVm(env)
|
||
|
default:
|
||
|
vmlogger.Infoln("unsupported vm type %d", env.VmType())
|
||
|
fallthrough
|
||
|
case StdVmTy:
|
||
|
return New(env)
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
func calcMemSize(off, l *big.Int) *big.Int {
|
||
10 years ago
|
if l.Cmp(common.Big0) == 0 {
|
||
|
return common.Big0
|
||
10 years ago
|
}
|
||
|
|
||
|
return new(big.Int).Add(off, l)
|
||
|
}
|
||
|
|
||
|
// Simple helper
|
||
|
func u256(n int64) *big.Int {
|
||
|
return big.NewInt(n)
|
||
|
}
|
||
|
|
||
|
// Mainly used for print variables and passing to Print*
|
||
|
func toValue(val *big.Int) interface{} {
|
||
|
// Let's assume a string on right padded zero's
|
||
|
b := val.Bytes()
|
||
|
if b[0] != 0 && b[len(b)-1] == 0x0 && b[len(b)-2] == 0x0 {
|
||
|
return string(b)
|
||
|
}
|
||
|
|
||
|
return val
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
func getData(data []byte, start, size *big.Int) []byte {
|
||
|
dlen := big.NewInt(int64(len(data)))
|
||
10 years ago
|
|
||
10 years ago
|
s := common.BigMin(start, dlen)
|
||
|
e := common.BigMin(new(big.Int).Add(s, size), dlen)
|
||
|
return common.RightPadBytes(data[s.Uint64():e.Uint64()], int(size.Uint64()))
|
||
10 years ago
|
}
|