nvc icon indicating copy to clipboard operation
nvc copied to clipboard

Is it possible to use accent for displaying text with string ?

Open Martoni opened this issue 1 month ago • 6 comments

I'm trying to simulate following simple report program with nvc :

library ieee;
use std.env.finish; --VHDL-08

entity exemples_string is
end exemples_string;

architecture behavioral of exemples_string is
begin
    process
        constant BonjourMonde: string := "Hello, World!";
    begin
        report "Simple affichage de texte";
        REPORT BONJOURMONDE;
        report BonjourMonde&" Quel temps fait-il aujourd'hui ?";
        report "Très beau c'est l'été.";
        finish;
    end process;
end behavioral;

But it's seems to be impossible with nvc because of accents :

$ nvc --std=08 -a exemples_string.vhd 
** Error: no visible declaration for '?'
** Error: invalid character '?' in string literal of type STRING
    > exemples_string.vhd:15
    |
 15 |         report "Trs beau c'est l't.":
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Is there an option to print these froggies characters in NVC ?

This code works with GHDL ;)

Martoni avatar Nov 01 '25 15:11 Martoni

Make sure the encoding of the file is ISO-8859-1 and not UTF-8 and you get the accents. Note the hexdump difference.

ISO-8859-1

00000000  6c 69 62 72 61 72 79 20  69 65 65 65 3b 0a 75 73  |library ieee;.us|
00000010  65 20 73 74 64 2e 65 6e  76 2e 66 69 6e 69 73 68  |e std.env.finish|
00000020  3b 20 2d 2d 56 48 44 4c  2d 30 38 0a 0a 65 6e 74  |; --VHDL-08..ent|
00000030  69 74 79 20 65 78 65 6d  70 6c 65 73 5f 73 74 72  |ity exemples_str|
00000040  69 6e 67 20 69 73 0a 65  6e 64 20 65 78 65 6d 70  |ing is.end exemp|
00000050  6c 65 73 5f 73 74 72 69  6e 67 3b 0a 0a 61 72 63  |les_string;..arc|
00000060  68 69 74 65 63 74 75 72  65 20 62 65 68 61 76 69  |hitecture behavi|
00000070  6f 72 61 6c 20 6f 66 20  65 78 65 6d 70 6c 65 73  |oral of exemples|
00000080  5f 73 74 72 69 6e 67 20  69 73 0a 62 65 67 69 6e  |_string is.begin|
00000090  0a 20 20 20 20 70 72 6f  63 65 73 73 0a 20 20 20  |.    process.   |
000000a0  20 20 20 20 20 63 6f 6e  73 74 61 6e 74 20 42 6f  |     constant Bo|
000000b0  6e 6a 6f 75 72 4d 6f 6e  64 65 3a 20 73 74 72 69  |njourMonde: stri|
000000c0  6e 67 20 3a 3d 20 22 48  65 6c 6c 6f 2c 20 57 6f  |ng := "Hello, Wo|
000000d0  72 6c 64 21 22 3b 0a 20  20 20 20 62 65 67 69 6e  |rld!";.    begin|
000000e0  0a 20 20 20 20 20 20 20  20 72 65 70 6f 72 74 20  |.        report |
000000f0  22 53 69 6d 70 6c 65 20  61 66 66 69 63 68 61 67  |"Simple affichag|
00000100  65 20 64 65 20 74 65 78  74 65 22 3b 0a 20 20 20  |e de texte";.   |
00000110  20 20 20 20 20 52 45 50  4f 52 54 20 42 4f 4e 4a  |     REPORT BONJ|
00000120  4f 55 52 4d 4f 4e 44 45  3b 0a 20 20 20 20 20 20  |OURMONDE;.      |
00000130  20 20 72 65 70 6f 72 74  20 42 6f 6e 6a 6f 75 72  |  report Bonjour|
00000140  4d 6f 6e 64 65 26 22 20  51 75 65 6c 20 74 65 6d  |Monde&" Quel tem|
00000150  70 73 20 66 61 69 74 2d  69 6c 20 61 75 6a 6f 75  |ps fait-il aujou|
00000160  72 64 27 68 75 69 20 3f  22 3b 0a 20 20 20 20 20  |rd'hui ?";.     |
00000170  20 20 20 72 65 70 6f 72  74 20 22 54 72 e8 73 20  |   report "Tr.s |
00000180  62 65 61 75 20 63 27 65  73 74 20 6c 27 e9 74 e9  |beau c'est l'.t.|
00000190  2e 22 3b 0a 20 20 20 20  20 20 20 20 66 69 6e 69  |.";.        fini|
000001a0  73 68 3b 0a 20 20 20 20  65 6e 64 20 70 72 6f 63  |sh;.    end proc|
000001b0  65 73 73 3b 0a 65 6e 64  20 62 65 68 61 76 69 6f  |ess;.end behavio|
000001c0  72 61 6c 3b 0a                                    |ral;.|

UTF-8

00000000  6c 69 62 72 61 72 79 20  69 65 65 65 3b 0a 75 73  |library ieee;.us|
00000010  65 20 73 74 64 2e 65 6e  76 2e 66 69 6e 69 73 68  |e std.env.finish|
00000020  3b 20 2d 2d 56 48 44 4c  2d 30 38 0a 0a 65 6e 74  |; --VHDL-08..ent|
00000030  69 74 79 20 65 78 65 6d  70 6c 65 73 5f 73 74 72  |ity exemples_str|
00000040  69 6e 67 20 69 73 0a 65  6e 64 20 65 78 65 6d 70  |ing is.end exemp|
00000050  6c 65 73 5f 73 74 72 69  6e 67 3b 0a 0a 61 72 63  |les_string;..arc|
00000060  68 69 74 65 63 74 75 72  65 20 62 65 68 61 76 69  |hitecture behavi|
00000070  6f 72 61 6c 20 6f 66 20  65 78 65 6d 70 6c 65 73  |oral of exemples|
00000080  5f 73 74 72 69 6e 67 20  69 73 0a 62 65 67 69 6e  |_string is.begin|
00000090  0a 20 20 20 20 70 72 6f  63 65 73 73 0a 20 20 20  |.    process.   |
000000a0  20 20 20 20 20 63 6f 6e  73 74 61 6e 74 20 42 6f  |     constant Bo|
000000b0  6e 6a 6f 75 72 4d 6f 6e  64 65 3a 20 73 74 72 69  |njourMonde: stri|
000000c0  6e 67 20 3a 3d 20 22 48  65 6c 6c 6f 2c 20 57 6f  |ng := "Hello, Wo|
000000d0  72 6c 64 21 22 3b 0a 20  20 20 20 62 65 67 69 6e  |rld!";.    begin|
000000e0  0a 20 20 20 20 20 20 20  20 72 65 70 6f 72 74 20  |.        report |
000000f0  22 53 69 6d 70 6c 65 20  61 66 66 69 63 68 61 67  |"Simple affichag|
00000100  65 20 64 65 20 74 65 78  74 65 22 3b 0a 20 20 20  |e de texte";.   |
00000110  20 20 20 20 20 52 45 50  4f 52 54 20 42 4f 4e 4a  |     REPORT BONJ|
00000120  4f 55 52 4d 4f 4e 44 45  3b 0a 20 20 20 20 20 20  |OURMONDE;.      |
00000130  20 20 72 65 70 6f 72 74  20 42 6f 6e 6a 6f 75 72  |  report Bonjour|
00000140  4d 6f 6e 64 65 26 22 20  51 75 65 6c 20 74 65 6d  |Monde&" Quel tem|
00000150  70 73 20 66 61 69 74 2d  69 6c 20 61 75 6a 6f 75  |ps fait-il aujou|
00000160  72 64 27 68 75 69 20 3f  22 3b 0a 20 20 20 20 20  |rd'hui ?";.     |
00000170  20 20 20 72 65 70 6f 72  74 20 22 54 72 c3 a8 73  |   report "Tr..s|
00000180  20 62 65 61 75 20 63 27  65 73 74 20 6c 27 c3 a9  | beau c'est l'..|
00000190  74 c3 a9 2e 22 3b 0a 20  20 20 20 20 20 20 20 66  |t...";.        f|
000001a0  69 6e 69 73 68 3b 0a 20  20 20 20 65 6e 64 20 70  |inish;.    end p|
000001b0  72 6f 63 65 73 73 3b 0a  65 6e 64 20 62 65 68 61  |rocess;.end beha|
000001c0  76 69 6f 72 61 6c 3b 0a                           |vioral;.|

bpadalino avatar Nov 01 '25 19:11 bpadalino

I changed the encoding to ISO-8859 but It's not working :

$ file exemples_string.vhd 
exemples_string.vhd: ISO-8859 text
$ nvc --std=08 -a exemples_string.vhd 
** Error: no visible declaration for '?'
** Error: no visible declaration for '?'
** Error: invalid character '?' in string literal of type STRING
    > exemples_string.vhd:15
    |
 15 |         report "Trs beau c'est l't.";
    |                ^^^^^^^^^^^^^^^^^^^^^^^^

And characters are not displayed correctly in ghdl :(

$ ghdl -a --std=08 exemples_string.vhd 
$ ghdl -r --std=08 exemples_string
exemples_string.vhd:12:9:@0ms:(report note): Simple affichage de texte
exemples_string.vhd:13:9:@0ms:(report note): Hello, World!
exemples_string.vhd:14:9:@0ms:(report note): Hello, World! Quel temps fait-il aujourd'hui ?
exemples_string.vhd:15:9:@0ms:(report note): Tr�s beau c'est l'�t�.
simulation finished @0ms

Martoni avatar Nov 01 '25 21:11 Martoni

What does the hexdump look like for the file? Does it match what I had above?

$ nvc -a accent.vhdl -e exemples_string -r
** Note: 0ms+0: Simple affichage de texte
   Process :exemples_string:_p0 at accent.vhdl:9
** Note: 0ms+0: Hello, World!
   Process :exemples_string:_p0 at accent.vhdl:9
** Note: 0ms+0: Hello, World! Quel temps fait-il aujourd'hui ?
   Process :exemples_string:_p0 at accent.vhdl:9
** Note: 0ms+0: Très beau c'est l'été.
   Process :exemples_string:_p0 at accent.vhdl:9
** Note: 0ms+0: FINISH called
   Procedure FINISH [] at ../lib/std.08/env-body.vhd:42
   Process :exemples_string:_p0 at accent.vhdl:16

bpadalino avatar Nov 01 '25 21:11 bpadalino

Hex dump following :

$ file exemples_string.vhd 
exemples_string.vhd: ISO-8859 text
$ hexdump -C exemples_string.vhd 
00000000  6c 69 62 72 61 72 79 20  69 65 65 65 3b 0a 75 73  |library ieee;.us|
00000010  65 20 73 74 64 2e 65 6e  76 2e 66 69 6e 69 73 68  |e std.env.finish|
00000020  3b 20 2d 2d 56 48 44 4c  2d 30 38 0a 0a 65 6e 74  |; --VHDL-08..ent|
00000030  69 74 79 20 65 78 65 6d  70 6c 65 73 5f 73 74 72  |ity exemples_str|
00000040  69 6e 67 20 69 73 0a 65  6e 64 20 65 78 65 6d 70  |ing is.end exemp|
00000050  6c 65 73 5f 73 74 72 69  6e 67 3b 0a 0a 61 72 63  |les_string;..arc|
00000060  68 69 74 65 63 74 75 72  65 20 62 65 68 61 76 69  |hitecture behavi|
00000070  6f 72 61 6c 20 6f 66 20  65 78 65 6d 70 6c 65 73  |oral of exemples|
00000080  5f 73 74 72 69 6e 67 20  69 73 0a 62 65 67 69 6e  |_string is.begin|
00000090  0a 20 20 20 20 70 72 6f  63 65 73 73 0a 20 20 20  |.    process.   |
000000a0  20 20 20 20 20 63 6f 6e  73 74 61 6e 74 20 42 6f  |     constant Bo|
000000b0  6e 6a 6f 75 72 4d 6f 6e  64 65 3a 20 73 74 72 69  |njourMonde: stri|
000000c0  6e 67 20 3a 3d 20 22 48  65 6c 6c 6f 2c 20 57 6f  |ng := "Hello, Wo|
000000d0  72 6c 64 21 22 3b 0a 20  20 20 20 62 65 67 69 6e  |rld!";.    begin|
000000e0  0a 20 20 20 20 20 20 20  20 72 65 70 6f 72 74 20  |.        report |
000000f0  22 53 69 6d 70 6c 65 20  61 66 66 69 63 68 61 67  |"Simple affichag|
00000100  65 20 64 65 20 74 65 78  74 65 22 3b 0a 20 20 20  |e de texte";.   |
00000110  20 20 20 20 20 52 45 50  4f 52 54 20 42 4f 4e 4a  |     REPORT BONJ|
00000120  4f 55 52 4d 4f 4e 44 45  3b 0a 20 20 20 20 20 20  |OURMONDE;.      |
00000130  20 20 72 65 70 6f 72 74  20 42 6f 6e 6a 6f 75 72  |  report Bonjour|
00000140  4d 6f 6e 64 65 26 22 20  51 75 65 6c 20 74 65 6d  |Monde&" Quel tem|
00000150  70 73 20 66 61 69 74 2d  69 6c 20 61 75 6a 6f 75  |ps fait-il aujou|
00000160  72 64 27 68 75 69 20 3f  22 3b 0a 20 20 20 20 20  |rd'hui ?";.     |
00000170  20 20 20 72 65 70 6f 72  74 20 22 54 72 e8 73 20  |   report "Tr.s |
00000180  62 65 61 75 20 63 27 65  73 74 20 6c 27 e9 74 e9  |beau c'est l'.t.|
00000190  2e 22 3b 0a 20 20 20 20  20 20 20 20 66 69 6e 69  |.";.        fini|
000001a0  73 68 3b 0a 20 20 20 20  65 6e 64 20 70 72 6f 63  |sh;.    end proc|
000001b0  65 73 73 3b 0a 65 6e 64  20 62 65 68 61 76 69 6f  |ess;.end behavio|
000001c0  72 61 6c 3b 0a                                    |ral;.|
000001c5
$ nvc -a exemples_string.vhd -e exemples_string -r
** Error: unit STD.ENV not found in library STD
   > exemples_string.vhd:2
   |
 2 | use std.env.finish; --VHDL-08
   | ^^^^^^^^^^^^^^^^^^
** Error: design unit depends on WORK.EXEMPLES_STRING which was analysed with errors
   > exemples_string.vhd:7
   |
 7 | architecture behavioral of exemples_string is
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
** Error: invalid character '?' in string literal of type STRING
    > exemples_string.vhd:15
    |
 15 |         report "Trs beau c'est l't.";
    |                ^^^^^^^^^^^^^^^^^^^^^^^^
** Error: no visible subprogram declaration for FINISH
    > exemples_string.vhd:16
    |
 16 |         finish;

Martoni avatar Nov 02 '25 14:11 Martoni

In fact it was an old version of nvc, I just recompiled git repository and get the same messages than yours:

$  nvc --version
nvc 1.19-devel (1.18.0.r66.g3a60d57b6) (Using LLVM 14.0.0)
Copyright (C) 2011-2025  Nick Gasson
This program comes with ABSOLUTELY NO WARRANTY. This is free software, and
you are welcome to redistribute it under certain conditions. See the GNU
General Public Licence for details.

$ file exemples_string.vhd 
exemples_string.vhd: ISO-8859 text
$ nvc -a exemples_string.vhd -e exemples_string -r
** Note: 0ms+0: Simple affichage de texte
   Process :exemples_string:_p0 at exemples_string.vhd:9
** Note: 0ms+0: Hello, World!
   Process :exemples_string:_p0 at exemples_string.vhd:9
** Note: 0ms+0: Hello, World! Quel temps fait-il aujourd'hui ?
   Process :exemples_string:_p0 at exemples_string.vhd:9
** Note: 0ms+0: Très beau c'est l'été.
   Process :exemples_string:_p0 at exemples_string.vhd:9
** Note: 0ms+0: FINISH called
   Procedure FINISH [] at ../lib/std.08/env-body.vhd:42
   Process :exemples_string:_p0 at exemples_string.vhd:16

And it works with utf-8 but with bad characters display:

$ file exemples_string.vhd 
exemples_string.vhd: Unicode text, UTF-8 text
$ nvc -a exemples_string.vhd -e exemples_string -r
** Note: 0ms+0: Simple affichage de texte
   Process :exemples_string:_p0 at exemples_string.vhd:9
** Note: 0ms+0: Hello, World!
   Process :exemples_string:_p0 at exemples_string.vhd:9
** Note: 0ms+0: Hello, World! Quel temps fait-il aujourd'hui ?
   Process :exemples_string:_p0 at exemples_string.vhd:9
** Note: 0ms+0: Très beau c'est l'été.
   Process :exemples_string:_p0 at exemples_string.vhd:9
** Note: 0ms+0: FINISH called
   Procedure FINISH [] at ../lib/std.08/env-body.vhd:42
   Process :exemples_string:_p0 at exemples_string.vhd:16

Thanks for the help

Martoni avatar Nov 02 '25 14:11 Martoni

The LRM requires all source files are encoded with ISO-8859-1 as @bpadalino mentions above. So if you use UTF-8 then each byte of a multi-byte unicode character gets interpreted as a single ISO-8859 character. I think it appears to work with GHDL because you are just printing the string and GHDL does no character set conversion on output, but if you try 'length on that string, or access individual characters, it will behave unexpectedly.

NVC assumes all input text is ISO-8859-1 encoded and then converts to UTF-8 if the output terminal is unicode. That allows the accents to display properly in the ISO-8859 encoded example above, but obviously produces nonsense if the input was UTF-8 originally.

I guess we could add a --utf8 analysis option that would do the conversion internally and then error on any codepoints that can't be mapped ton ISO-8859.

nickg avatar Nov 11 '25 05:11 nickg