summaryrefslogtreecommitdiff
path: root/as/as.go
diff options
context:
space:
mode:
authorstefan <stefan@s00.xyz>2023-05-24 08:32:08 -0400
committerstefan <stefan@s00.xyz>2023-05-24 08:32:08 -0400
commitba2b9c8a1bb1876b6eb4c9783fde798b19de4418 (patch)
tree9b49307112b0f489189cf65c1b50dd281f8e430f /as/as.go
parentc30e7f5f99f9ad4d9552b645d7b89d7385972f99 (diff)
downloadevm-ba2b9c8a1bb1876b6eb4c9783fde798b19de4418.tar.gz
init
Diffstat (limited to 'as/as.go')
-rw-r--r--as/as.go32
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
+}