digitalmars.D - importC: __asm volatile parsing failure - issue or not?
- Denis Feklushkin (63/63) Mar 31 2024 In fact, this is my first time using importC, so maybe I messed
- Denis Feklushkin (3/6) Mar 31 2024 Tried to replace (non-standard?) __asm by \_\_asm\_\_ - nothing
- Denis Feklushkin (2/9) Mar 31 2024 "asm volatile" works as expected, but "asm" isn't C11 keyword
- Walter Bright (4/5) Mar 31 2024 "asm" is a C11 keyword, see C11.j.5.10
- Denis Feklushkin (6/13) Apr 01 2024 Really! I just got confused
- Denis Feklushkin (3/18) Apr 17 2024 Fixed in this PR: https://github.com/dlang/dmd/pull/16386
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
__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?
Mar 31 2024
On Sunday, 31 March 2024 at 08:42:55 UTC, Denis Feklushkin wrote:
```
__asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" (
```
Tried to replace (non-standard?) __asm by \_\_asm\_\_ - nothing
changed
Mar 31 2024
On Sunday, 31 March 2024 at 09:35:01 UTC, Denis Feklushkin wrote:On Sunday, 31 March 2024 at 08:42:55 UTC, Denis Feklushkin wrote:"asm volatile" works as expected, but "asm" isn't C11 keyword``` __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ```Tried to replace (non-standard?) __asm by \_\_asm\_\_ - nothing changed
Mar 31 2024
On 3/31/2024 2:38 AM, Denis Feklushkin wrote:"asm volatile" works as expected, but "asm" isn't C11 keyword"asm" is a C11 keyword, see C11.j.5.10 dmd doesn't support the gcc asm syntax, only the Microsoft & Digital Mars syntaxes. Usually, in header files with asm syntax, it can be disabled with an #ifdef.
Mar 31 2024
On Monday, 1 April 2024 at 00:18:15 UTC, Walter Bright wrote:On 3/31/2024 2:38 AM, Denis Feklushkin wrote:Really! I just got confused Thank you!"asm volatile" works as expected, but "asm" isn't C11 keyword"asm" is a C11 keyword, see C11.j.5.10dmd doesn't support the gcc asm syntax, only the Microsoft & Digital Mars syntaxes. Usually, in header files with asm syntax, it can be disabled with an #ifdef.This is just the opposite case: FreeRTOS code is full of asm entries which isn't be able to disabled. But, preliminarily, a simple mass replacement to "asm volatile" works for me
Apr 01 2024
On Monday, 1 April 2024 at 18:02:33 UTC, Denis Feklushkin wrote:On Monday, 1 April 2024 at 00:18:15 UTC, Walter Bright wrote:Fixed in this PR: https://github.com/dlang/dmd/pull/16386 Please review!On 3/31/2024 2:38 AM, Denis Feklushkin wrote:Really! I just got confused Thank you!"asm volatile" works as expected, but "asm" isn't C11 keyword"asm" is a C11 keyword, see C11.j.5.10dmd doesn't support the gcc asm syntax, only the Microsoft & Digital Mars syntaxes. Usually, in header files with asm syntax, it can be disabled with an #ifdef.This is just the opposite case: FreeRTOS code is full of asm entries which isn't be able to disabled. But, preliminarily, a simple mass replacement to "asm volatile" works for me
Apr 17 2024








Denis Feklushkin <feklushkin.denis gmail.com>