7 ms·
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
by poincaredisk 2y ago
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.
- deleted 2y ago[deleted]
- 9rx 2y ago> 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.
- PittleyDunkin 2y ago> 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.
- 9rx 2y agoIt 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.
- deleted 2y ago[deleted]
- jcranmer 2y agoI'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.
- steveklabnik 2y ago&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.
- uecker 2y agoWhy would you target a language that is less portable and less stable?
- jcranmer 2y agoFor 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!
- uecker 2y agoI don't think any weird edge case is a problem when targeting C. You just do not produce such cases when emitting the code.
- pjmlp 2y agoHence why Macro Assemblers have existed for almost as long as raw Assembly. MASM and TASM, were already far beyond the features in K&R C, if we overlook the issue of being bound to 80x86 Assembly. TI has some DSPs where their Assembly is basically bare bones C like, in a SSA kind of approach.