mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
* Implement the ewasm module and the EEI. * Add an ewasm standalone binary to test standalone files * use reflection to declare EEI module exports * check the module name when importing EEI functions * make eeiFuncs a function to avoid an init loop issue in call * Add a reference to the ewasm tests * wagon implementation of the Interpreter interface * update to wagon's PR #59 and uses the Process structure * Adapt to endianness change * All tests but 1 passing * CanRun only checks for the header * Add a "debug" module to support "printHex" in contracts Notes: * There are very little checks, e.g. of the call depths and so on.
64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
// Copyright 2017 The go-interpreter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package wasm
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"io"
|
|
|
|
"github.com/go-interpreter/wagon/wasm/leb128"
|
|
)
|
|
|
|
func readBytes(r io.Reader, n int) ([]byte, error) {
|
|
bytes := make([]byte, n)
|
|
_, err := io.ReadFull(r, bytes)
|
|
if err != nil {
|
|
return bytes, err
|
|
}
|
|
|
|
return bytes, nil
|
|
}
|
|
|
|
func readBytesUint(r io.Reader) ([]byte, error) {
|
|
n, err := leb128.ReadVarUint32(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return readBytes(r, int(n))
|
|
}
|
|
|
|
func readString(r io.Reader, n int) (string, error) {
|
|
bytes, err := readBytes(r, n)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(bytes), nil
|
|
}
|
|
|
|
func readStringUint(r io.Reader) (string, error) {
|
|
n, err := leb128.ReadVarUint32(r)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return readString(r, int(n))
|
|
}
|
|
|
|
func readU32(r io.Reader) (uint32, error) {
|
|
var buf [4]byte
|
|
_, err := io.ReadFull(r, buf[:])
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return binary.LittleEndian.Uint32(buf[:]), nil
|
|
}
|
|
|
|
func readU64(r io.Reader) (uint64, error) {
|
|
var buf [8]byte
|
|
_, err := io.ReadFull(r, buf[:])
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return binary.LittleEndian.Uint64(buf[:]), nil
|
|
}
|