corrode icon indicating copy to clipboard operation
corrode copied to clipboard

implement inline assembly

Open jameysharp opened this issue 8 years ago • 1 comments

The CAsm constructor of CStatement, and the CAssemblyStatement it contains, are almost easy to translate to Rust's asm! 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:

interpretStatement stmt@(CAsm (CAsmStmt qual expr outops inops clobbers node) _) = do
    volatile <- case qual of
        Just (CVolatQual _) -> True
        Nothing -> False
        _ -> badSource stmt "qualifier on inline assembly"

If volatile, then the "volatile" option should be added as the last parameter to the asm! 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 handles CStringLiteral expressions) except that the asm! 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?

jameysharp avatar Jul 25 '16 07:07 jameysharp

@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/

jameysharp avatar Oct 18 '16 22:10 jameysharp