#406 illegal warnings when mixing asm & C code

None
open
None
5
2013-12-20
2013-03-05
No

In general, SDCC accepts a mixed-use assembly language and C together. But I've the illegal warnings:

void Console_WriteCh_COMPACT_fastcall (void /* Register L */)
{
}

void Console_WriteCh_COMPACT (char ch)
{
__asm
#ifdef __SDCC
ld hl,#2
add hl,sp
ld l,(hl)
#else
ld l,4(ix)
#endif
__endasm;
Console_WriteCh_COMPACT_fastcall();
}

Warning: z80instructionSize() failed to parse line node ld l,(hl)
Warning: z80instructionSize() failed to parse line node ld hl,#2

If you have time, you could see the reason for these warnings, please, because the code that's right here.

If change a case of asm instructions to CAPITAL, we get more warnings:

void Console_WriteCh_COMPACT (char ch)
{
__asm
#ifdef __SDCC
LD HL,#2
ADD HL,SP
LD L,(HL)
#else
LD L,4(IX)
#endif
__endasm;
Console_WriteCh_COMPACT_fastcall();
}

Warning: z80instructionSize() failed to parse line node LD L,(HL)
Warning: z80instructionSize() failed to parse line node ADD HL,SP
Warning: z80instructionSize() failed to parse line node LD HL,#2

This warning is also unacceptable, because the assembler allows keywords in any case.
Thanks.

P.S. I've used SDCC 3.2.1 #8144 and a next command line to launch it:

sdcc -mz80 --code-loc 26000 --data-loc 0xF800 --no-std-crt0 --opt-code-size --funsigned-char --disable-warning 126 -I "." -I %lib% -L %lib%/z80 HelloWorld.c

--
Oleg N. Cher
VEDAsoft Oberon Club
http://zx.oberon2.ru

Discussion

  • Philipp Klaus Krause

    I guess the easiest way to go would be to just disable the emission of warnings in z80instructionSize() when processing inline asm. That might result in some possible optimizations of jp to jr not being done (since every instruction that currently triggers the warning is assumed to be 4 bytes long), but functions containing inline asm should be rare anyway.

    Philipp

     
  • Philipp Klaus Krause

    The issue with ld is fixed in revision #8451. The issue with uppercase asm remains.

    Philipp

     
  • Maarten Brock

    Maarten Brock - 2013-12-19

    I don't quite understand how this bug can be triggered at all. The peepHole() function checks (and has done so for a very long time already) for spl->isInline and then ignores inline assembly lines. Is the z80 back-end forgetting to set this flag for inline assembly?

    Nonetheless the uppercase issue can easily be fixed by using STRNCASECMP instead of strncmp in many places in src/z80/peep.c. But I don't see the point as SDCC doesn't generate uppercase code for Z80 except for the flags.

     
  • Philipp Klaus Krause

    But we can't always ignore inline assembly. Assume there is a jump (jp) next to the inline assembly. The we need to calculate the code size for the inline assembly when looking for the jump target to see if we can replace the jp by jr. And this is what happens here. But since there are some lines we can't parse, we assume the worst in terms of code size for them, and emit a warning (since we might miss a possible optimization of jp into jr).

    Philipp

     
  • Maarten Brock

    Maarten Brock - 2013-12-19
    • assigned_to: Maarten Brock
    • Category: --> Z80
     
  • Maarten Brock

    Maarten Brock - 2013-12-19

    Ah, of course. It's not trying to optimize the inline assembly but the code around it. So I guess this problem is limited to z80instructionSize only. So the search and replace can be limited to this function. I'll look into it.

     
  • Philipp Klaus Krause

    Well, I wouldn't be surprised if the same problem exists in other ports, too.

    Philipp

     
  • Maarten Brock

    Maarten Brock - 2013-12-20
    • status: open --> closed-fixed
     
  • Maarten Brock

    Maarten Brock - 2013-12-20

    Fixed in SDCC 3.3.2 #8920 for Z80. The other ports do not generate warnings at all. They can suffer unrecognized instructions though, but I consider that a feature request to be implemented later. Therefore moved this item to RFE.

    I also think to have fixed a problem in src/z80/peep.c(772). Philipp can you please verify?

    Finally I think it's better to return 999 for totally unrecognized lines as they may represent .ds or something like that.

    Maarten

     
  • Maarten Brock

    Maarten Brock - 2013-12-20

    Ticket moved from /p/sdcc/bugs/2142/

    Can't be converted:

    • _category: Z80
     
  • Maarten Brock

    Maarten Brock - 2013-12-20
    • status: closed-fixed --> open
    • Group: -->
     
  • Philipp Klaus Krause

    The line 772 fix looks good to me.

    Philipp

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks