Skip to content
  • Xavier Leroy's avatar
    Extended asm: print register names according to their types · ed0cfe4b
    Xavier Leroy authored
    When printing an extended asm code fragment, placeholders %n
    are replaced by register names.
    
    Currently we ignore the fact that some assemblers use different
    register names depending on the width of the data that resides
    in the register.
    
    For example, x86_64 uses %rax for a 64-bit quantity and %eax for
    a 32-bit quantity, but CompCert always prints %rax in extended asm
    statements.  This is problematic if we want to use 32-bit integer
    instructions in extended asm, e.g.
    
                 int x, y;
                 asm("addl %1, %0", "=r"(x), "r"(y));
    produces
                 addl %rax, %rdx
    
    which is syntactically incorrect.
    
    Another example is ARM FP registers: D0 is a double-precision float,
    but S0 is a single-precision float.
    
    This commit partially solves this issue by taking into account the
    Cminor type of the asm parameter when printing the corresponding register.
    Continuing the previous example,
    
                 int x, y;
                 asm("addl %1, %0", "=r"(x), "r"(y));
    now produces
                 addl %eax, %edx
    
    This is not perfect yet: we use Cminor types, because this is all we
    have at hand, and not source C types, hence "char" and "short" parameters
    are still printed like "int" parameters, which is not good for x86.
    (I.e. we produce %eax where GCC might have produced %al or %ax.)
    We'll leave this issue open.
    ed0cfe4b