#jit #dynasm #assembler #dynasm-rs #directasm

dynasm-lib

A pure rust assembler, not a JIT. Used within direct-asm for maximum control over assembly.

1 unstable release

0.1.0-alpha Jul 2, 2020

#90 in Programming languages

Download history 174/week @ 2022-03-09 178/week @ 2022-03-16 160/week @ 2022-03-23 153/week @ 2022-03-30 217/week @ 2022-04-06 157/week @ 2022-04-13 145/week @ 2022-04-20 221/week @ 2022-04-27 195/week @ 2022-05-04 201/week @ 2022-05-11 189/week @ 2022-05-18 99/week @ 2022-05-25 128/week @ 2022-06-01 255/week @ 2022-06-08 239/week @ 2022-06-15 109/week @ 2022-06-22

748 downloads per month
Used in direct-asm

MPL-2.0 license

765KB
16K SLoC

A pure rust assembler, not a JIT. Used within direct-asm for maximum control over assembly.

This crate implements uniform parsing of assembly into directives, labels, expression and backends for some architectures (x86, x86_64, aarch64 WIP). It's not exactly Intel syntax (but somewhat close) since it should be possible to embed expressions from the environment, which we must treat as arbitrary opaque values that we can not manipulate directly.

There is no global state and we don't assume to be executed within a proc-macro but that is one possible embedding. In that case we can combine expressions but not evaluate them. So, e.g. to embed some A: u8 whose three lowest bits give an index into the top three bits of an output byte, we ask the environment to generate a new expression for (A & 0x7) << 5. This yields the right result after const eval without having inspected the value of A ourselves. With enough of these combinators we can do all necessary operations for assembling.

This is a heavy work in progress, any contribution is welcome. Parser, new arch, better diagnostics.

Restriction: Inserting pointers and other relocations from the environment is not easy or outright impossible. We can directly insert a pointer as is which would not permit a pure byte slice as an output and requires an actual struct or complicated enum instead. However, the pointer's location must later be replaced by the linker and it has a replacement value describing the location in MIR const eval so we can inspect its bytes or insert compound arithmetic expressions of it. That must be evaluated at runtime. (In a completely stupid move we would modify the linker script to do that arithmetic but we can't go that crazy yet, the basics should work before that. Another option would be a compiler interface and there is some sympathy for it but nothing official or concrete.)

Dependencies