diff options
author | stefan <stefan@s00.xyz> | 2023-05-24 22:29:46 -0400 |
---|---|---|
committer | stefan <stefan@s00.xyz> | 2023-05-24 22:29:46 -0400 |
commit | 20621e073562ee5d423b636fae8b6aa8e38275fa (patch) | |
tree | 4a81bde039e58602e44a213cfb8d91a65f1dadd9 /as/as.go | |
parent | ba2b9c8a1bb1876b6eb4c9783fde798b19de4418 (diff) | |
download | evm-20621e073562ee5d423b636fae8b6aa8e38275fa.tar.gz |
readme and cleanup
Diffstat (limited to 'as/as.go')
-rw-r--r-- | as/as.go | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -2,30 +2,44 @@ package main import ( "fmt" + "os" "strings" "github.com/holiman/uint256" - ) func Assemble(code string) []byte { bytecode := make([]byte, 0) t := strings.Fields(code) + push := byte(0) for i := range t { x, found := OpcodeStrings[t[i]] if found { - bytecode = append(bytecode, x) + push = (&x).IsPush() + fmt.Printf("token: %s, opcode: 0x%x, push = %d\n", t[i], int(x), int(push)) + bytecode = append(bytecode, byte(x)) } else { + if push == 0 { + fmt.Fprintf(os.Stderr, "unexpected token: %s\n", t[i]) + os.Exit(1) + } 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]) } + + if (t[i] == "PUSH") { + push = byte(n.ByteLen()) + } + + b := n.Bytes32() - bytecode = append(bytecode, b[:]...) + fmt.Printf("token: NUMBER, value: %s, push = %d\n", t[i], int(push), b[32 - push:]) + bytecode = append(bytecode, b[32-push:]...) } } return bytecode |