blob: bcc7cf8548ede6602d42fee4f1ccb497120cecf2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package main
import (
"fmt"
"strings"
"github.com/holiman/uint256"
)
func Assemble(code string) []byte {
bytecode := make([]byte, 0)
t := strings.Fields(code)
for i := range t {
x, found := OpcodeStrings[t[i]]
if found {
bytecode = append(bytecode, x)
} else {
var n *uint256.Int = nil
if len(t[i]) > 1 && t[i][1] == 'x' {
n, _ = uint256.FromHex(t[i])
} else {
n, _ = uint256.FromDecimal(t[i])
}
b := n.Bytes32()
bytecode = append(bytecode, b[:]...)
}
}
return bytecode
}
|