importC: __asm volatile parsing failure - issue or not?

Denis Feklushkin feklushkin.denis at gmail.com
Sun Mar 31 08:42:55 UTC 2024


In fact, this is my first time using importC, so maybe I messed 
something up

This is real piece of FreeRTOS header. It contains ARM assembler 
instruction and attended to use with GCC:
```
$ cat test.h
__attribute__( ( always_inline ) ) static inline uint8_t 
ucPortCountLeadingZeros( uint32_t ulBitmap )
{
     uint8_t ucReturn;

     __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( 
ulBitmap ) : "memory" );

     return ucReturn;
}
```
Preprocessing this C header:
```
$ arm-none-eabi-gcc -std=c11 -E test.h -o test_gcc.i
$ cat test_gcc.i
# 0 "test.h"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "test.h"
__attribute__( ( always_inline ) ) static inline uint8_t 
ucPortCountLeadingZeros( uint32_t ulBitmap )
{
     uint8_t ucReturn;

     __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( 
ulBitmap ) : "memory" );

     return ucReturn;
}
```

Trying to use it from D:
```
$ dmd test_gcc.i -Hf=test.di
test.h(5): Error: found `volatile` when expecting `;` following 
statement
test.h(5): Error: found `:` when expecting `)`
test.h(5): Error: found `"=r"` when expecting `;` following 
statement
test.h(5): Error: found `:` when expecting `;` following statement
test.h(5): Error: found `"r"` instead of statement

$ dmd --version
DMD64 D Compiler v2.107.1
Copyright (C) 1999-2024 by The D Language Foundation, All Rights 
Reserved written by Walter Bright
```
```
$ ldc2 --mtriple=thumbv7em-unknown-none-eabi test_gcc.i 
-Hf=test.di
test.h(5): Error: found `volatile` when expecting `;` following 
statement
test.h(5): Error: found `:` when expecting `)`
test.h(5): Error: found `"=r"` when expecting `;` following 
statement
test.h(5): Error: found `:` when expecting `;` following statement
test.h(5): Error: found `"r"` instead of statement

$ ldc2 --version
LDC - the LLVM D compiler (1.37.0):
   based on DMD v2.107.1 and LLVM 17.0.6
   built with LDC - the LLVM D compiler (1.37.0)
```

Something went wrong with "__asm volatile" syntax?


More information about the Digitalmars-d mailing list