pyevmasm icon indicating copy to clipboard operation
pyevmasm copied to clipboard

Adding label support to assembler

Open lialan opened this issue 6 years ago • 3 comments
trafficstars

I would like to use this little tool to do some easy assembling in my project but found that this does not support label syntax, such as:

    ...
some_label:
    JUMPDEST
    ...
    PUSH some_label
    JUMP

So I just added the labeling syntax.

Another thing is that it seems that EVM memory space address starts with 1 rather than 0. So I changed pc according.

lialan avatar Nov 16 '19 02:11 lialan

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Nov 16 '19 02:11 CLAassistant

Hey @lialan thank you for this. The idea of having labels and other more high level constructs is very interesting. I was secretly expecting for someone to use this in some compiler-ish project.

I gave it a first pass. We may be on the verge of needing a Contract class that contains the more high level stuff. (labels, directives)

I hope we do not loss the filter like structure of the disassembler/assembler. cat bytecode | disassemble | assemble We'll see.

feliam avatar Nov 24 '19 17:11 feliam

hi @feliam, thanks for the reply (and suggestions!), I will update accordingly to your comments later this week.

so I basically am using this assembler in my LLVM project for EVM backend, and I need an easy way to generate some LLVM IR for EVM target, such as https://github.com/etclabscore/evm_llvm/blob/EVM/test/CodeGen/EVM/runtime_tests/fib.ll

Because I have not figured out how to represent contract creation code in LLVM code so here is what I am doing: using a contract template, instantiate it with with generated EVM assembly, then emit a real contract assembly, then use this assembler to emit EVM binary for testing on Geth.

Here is how I integrate it into my testing workflow: https://github.com/etclabscore/evm_llvm/blob/EVM/tools/evm-test/evm_test.py

Yes, this is a real use case of your code, kudo for that, and thanks for this little tool! I will try to see if I can figure out your comments and make proper changes to this pull request.

lialan avatar Nov 28 '19 13:11 lialan