diff options
Diffstat (limited to 'as/as.go')
-rw-r--r-- | as/as.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/as/as.go b/as/as.go new file mode 100644 index 0000000..bcc7cf8 --- /dev/null +++ b/as/as.go @@ -0,0 +1,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 +} |