This ugly construction has come very close to what I want:
    
    
    # chained field modify
    template GPIOAEN*(regVal: RCC_AHB1ENR_Val, fieldVal: uint32): 
RCC_AHB1ENR_Val =
      {.emit: ["asm (\"BFI %0, %1, #0, #1\"\n\t: \"=r\" (", regVal, ")\n\t: 
\"r\" (", fieldVal, "));\n"].}
      regVal
    
    
    Run

but it causes an error in the C that Nim generates, `error: redeclaration of 
'resX60gensym1_' with no linkage`:
    
    
    N_LIB_PRIVATE N_NIMCALL(void, main__main9556_u45)(void) {
            NU32 resX60gensym1_;
            NU32 resX60gensym1_;
            resX60gensym1_ = (NU32)0;
            resX60gensym1_ = (*(NU32 volatile*)((NU32*)1073887280));
            asm ("BFI %0, %1, #0, #1"
            : "=r" (resX60gensym1_)
            : "r" (((NU32)1)));
    
    
    Run

The manual makes strong recommendations against the emit pragma, so I'll keep 
looking for other solutions.

Reply via email to