Open jameysharp opened 8 years ago
@jdub has expressed interest in working on this.
And, here's a nice blog post from someone else who was trying to work out how Rust inline assembly compares to GCC: http://embed.rs/articles/2016/arm-inline-assembly-rust/
The
CAsm
constructor ofCStatement
, and theCAssemblyStatement
it contains, are almost easy to translate to Rust'sasm!
macro.At a high level, both syntaxes deliberately have the same semantics: Rust borrows LLVM's, which exists to support Clang's attempts to exactly match GCC. However, I'm not sure the details actually agree. I'd like someone who has some experience with inline assembly to take this on.
A correct implementation probably starts like this:
If
volatile
, then the"volatile"
option should be added as the last parameter to theasm!
macro.The template expression can be extracted using something like the code that would run for
interpretExpr True (CConst (CStrConst expr node))
(try factoring out the code that handlesCStringLiteral
expressions) except that theasm!
macro probably doesn't expect byte strings, so it should be expanded as a Unicode string instead. Similar string extraction is needed inside the operands and clobbers.I'm stuck trying to figure out how to map operands and clobbers. Some cases will probably work if they're copied through unchanged, but maybe others are more complicated?