From ba2b9c8a1bb1876b6eb4c9783fde798b19de4418 Mon Sep 17 00:00:00 2001 From: stefan Date: Wed, 24 May 2023 08:32:08 -0400 Subject: init --- as/as.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 as/as.go (limited to 'as/as.go') 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 +} -- cgit v1.2.3