I really like this! Some feedback:
- Some architectures use special characters in register name, so it might be better to put register names in quotes:
in("eax").- x86 uses
st(1),st(2) - MIPS uses
$0,$1
- x86 uses
- Figuring out a short name for some constraints is not trivial, it might be easier to just stick with the existing GCC single-letter contraints. In particular some constraints can be very complex:
- (PowerPC) P: An immediate integer constant whose negation is a signed 16-bit constant.
- Have you considered simply using a bare
volatileinstead offlags(volatile)? Additional flags can be added after that. - An
asm!with no outputs is meaningless if thevolatileflag isn’t specified. It should be a compile-time error for a non-volatileasm!to have no outputs. Previous discussion. - Template argument modifiers are absolutely required in practice. I make heavy use of them in my code (ARM64 assembly). I think that we can just reuse LLVM’s single-letter modifiers here since these are used in the format string:
mov {0:w}, {1:x} - The RFC should specify the rules for the clobber list. I think we should follow LLVM here: a register can’t both be an output and clobbered. However it is fine for a register to be an input and clobbered. (This only applies to explicit register inputs/outputs).
- I suggest adding an additional direction specification
tmpto deal with temporary registers and clobbered inputs:- An input value may be specified, or
_can be used to indicate that the temporary register has no initial value. - This is equivalent to an
inout(with initial value) orout(without initial value) where the output value is simply discarded after theasm!. This is how it is done is C but this is very unintuitive.
- An input value may be specified, or
- You might want to specify that, like format strings, you can escape braces with
{{and}}. This is needed for certain ARM instructions.
Regarding your questions:
-
Clobbers: LLVM recognizes
memoryandccon all architectures. Other values are architecture-specific, search forGCCRegNamesin https://github.com/llvm-mirror/clang/tree/master/lib/Basic/Targets. -
Flags: I don’t really have a preference for either
volatileorsideeffect.