hlorenzi / customasm

💻 An assembler for custom, user-defined instruction sets! https://hlorenzi.github.io/customasm/web/
Apache License 2.0
704 stars 55 forks source link

Are there any stability guarantees if I use customasm as a library? #153

Closed mainrs closed 1 year ago

mainrs commented 2 years ago

I am looking for a cross-platform way to describe instruction sets. Your custom language might be a nice fit.

I wanted to ask if the AST/Expr tree is stable API.

hlorenzi commented 2 years ago

Hmm, it is stable up to a point. 😅 I believe we've got a good basis here, and I don't intend to change it anymore, but there are still some open questions which might affect you.

For example, the assembler currently ignores whitespace in instruction names (so ld a and lda cannot be disambiguated) and I've been working to fix this -- mostly fixed already, but there are some contrived cases where I can't get it to work correctly, so it's not been pushed to the main branch yet.

Moreover, in the past, people have raised issues which prompted a change to the default behavior in some other areas, like the ?: ternary operator precedence.

So I've been avoiding going v1.0 for these kinds of reasons -- I get good feedback from users, which lets the syntax improve! v0.11.0 brought the biggest overhaul to the overall syntax, after a couple of years of user feedback. But I don't think a big overhaul is going to happen again.

Do you think these open questions would prove too problematic for you? I'd be glad if you chose to use customasm for your project, and I'd love to hear your feedback on actual usage!

mainrs commented 2 years ago

I am looking into implementing some emulators for simple chipsets of the attiny family. My idea was to somehow express the instruction set in a format that I can parse and automatically use to generate code. This would additionally provide means for others to re-use these definition files for other projects.

I thought about using JSON to express this. But your custom language just makes more sense and feels more natural to be honest.

parasyte commented 1 year ago

I guess one distinction that could be made here is that customasm is not intended to be an intermediate representation as you might see used for code generation (think in terms of LLVM or cranelift).

What customasm is really quite good at, IMHO, is describing the human-readable assembly instructions (mnemonics and operands) with a metalanguage. You can of course use the AST to compose the metalanguage itself, but that is still pretty far away from being an intermediate language.

It is very possible that I've misunderstood what you meant by automatically generating code from the AST. Presumably it's because you have some higher-level abstraction in mind (a programming language for example). And also, presumably it either maps almost directly to the ISA in question, or you need an intermediate representation to perform steps like register spilling and optimizations... (All things that are outside of the scope of this crate, FWIW.) For the former case where your higher-level language maps directly to the ISA, you might be better just creating your own AST in the form of a strongly typed DSL and state machine.

I still think this is a good question worth exploring, just for different reasons, it seems.