Hacker News new | past | comments | ask | show | jobs | submit login

No. Assembly is not portable, not typed and not structured (as in structured programming).

Another usecase for microC: most decompilers decompile to a custom C-like language. It pretends to be C, but in reality this is just a representation of a recovered AST that is often-but not always-a valid C code. MicroC would be a better target, because it would supposedly have less weird edge cases.






I don't think any weird edge case is a problem when targeting C. You just do not produce such cases when emitting the code.

I'd argue that unsafe Rust is a better target here (although I don't know if &raw has made it into stable Rust yet, which you need for doing an address-of that doesn't have a risk of UB like & does). Rust's typesystem is less silly (there's only one multiple-types-for-same-value, namely usize), there's no implicit conversions, the core CFG primitives are a little bit richer (labeled break/continue, although those are now added in C2y), and there's a decent usable intrinsic class for common operators-not-in-C like rotations or popcount.

If your goal is a simple language to compile, well, Rust won't ever fit the bill; but as a target for a decompiler, I think the unsafe subset is worth exploring.


&raw landed in the release just before this latest one.

And even before that release, there were macros the poly fill it, so you could have used those to target an earlier version.


Why would you target a language that is less portable and less stable?

For the specific question of decompiling, as noted in the GP comment, you're already forced to decompile to a not-quite-C language because C's semantics just aren't conducive to accurately representing the hardware semantics. Not that Rust doesn't have its own foibles, but I suspect its core semantics are easier to map to than C's semantics without having to resort as much to a not-quite-Rust target.

It's definitely something I would like to see at least explored!


I am pretty sure somebody will do this. My guess is that it will make basically no difference, but the end result is likely less useful...

> Assembly [...] not typed and not structured (as in structured programming).

That depends on the assembly language. Some have structure constructs, some are typed. Portability is out.

But if you accept a slightly higher abstraction, WebAssembly is portable, typed, and structured.


> But if you accept a slightly higher abstraction, WebAssembly is portable, typed, and structured.

Does WebAssembly support AOT compilation to native binaries? I thought it was just a VM.


It does if you implement it! You can do anything if you get around to doing it.

Or use an existing implement like wasmedge, I guess.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: