# Passing VHDL string generic with spaces via Modelsim command line

Given the following code:

entity foo is
generic
(
VAL : string
);
end entity foo;

architecture behav of foo is
begin
end architecture behav;


How can I set VAL via the command line using Modelsim, if VAL contains spaces. For example, there's no problem doing something like this:

entity tb is
end entity tb;

architecture behav of tb is
begin
foo_inst : entity work.foo
generic map
(
STRING_VAL => "a b c d"
);
end architecture behav;


But if I want to do something like:

vsim -c work.foo -gVAL="a b c d"


I get:

# ** Warning: (vsim-3351) Invalid value "a b c d" for generic "VAL".  Not using this value.


I've tried several variants:

  vsim -c work.foo -gVAL="a\ b\ c\ d"
vsim -c work.foo -gVAL='a\ b\ c\ d'
vsim -c work.foo -gVAL='a b c d'
vsim -c work.foo -gVAL={a b c d}
vsim -c work.foo -gVAL="{a b c d}"
vsim -c work.foo -gVAL={"a b c d"}


I'm using Modelsim 10.7c on Linux and Windows, and it fails with the same error on both.

Based on your error message, it looks like spaces aren't the issue, but actually the quotes themselves are not being included in the value being passed to the generic, and need to be escaped. The warning put quotes around a b c d like "a b c d" and around VAL like "VAL". This means the value it received is what is in quotes, meaning it is trying to assign just a b c d to VAL. What it really needs is to assign "a b c d" (including quotes) to VAL, the same way you showed in pure VHDL.

Pg. 423 of the ModelSim 10.5 Command Reference Manual (Sorry, couldn't find one for 10.7 off-hand) has notes about limitations of using -g. It suggests wrapping the whole -g command in curly braces {-gVAL="a b c d"} or using escaped quotes -gVAL=\"a b c d\"

EDIT

Since I only have Questa 10.5c, I couldn't exactly duplicate your scenario, but I tried the same ways you did and included the two suggested from the Command Reference Manual and a few extras.

These did not work:

vsim ... -gVAL="a b c d"


Warning: (vsim-3351) Invalid value "a b c d" for generic "VAL"

vsim ... -gVAL='a\ b\ c\ d'


Warning: (vsim-3351) Invalid value "'a b c d'" for generic "VAL"

vsim ... -gVAL='a b c d' ;# Error, not just warning


Error: (vsim-3170) Could not find 'b'.

vsim ... -gVAL={a b c d}


Warning: (vsim-3351) Invalid value "a b c d" for generic "VAL"

vsim ... -gVAL="{a b c d}"


Warning: (vsim-3351) Invalid value "{a b c d}" for generic "VAL"

vsim ... -gVAL=\"a b c d\" ;# Suggested by ref. manual


Warning: (vsim-3351) Invalid value "a b c d" for generic "VAL"

These did work for me:

vsim ... -gVAL="a\ b\ c\ d"  ;# Worked for me and not you...strange
vsim ... -gVAL={"a b c d"}   ;# Worked for me and not you...strange
vsim ... {-gVAL="a b c d"}   ;# Suggested by ref. manual
vsim ... -gVAL="\"a b c d\"" ;# Added additional quotes w/ escaped quotes
vsim ... -gVAL=""a b c d""   ;# Or just quotes within quotes

• Your suggestions helped. The case vsim -c -gVAL=\"a\ b\ c\ d\" worked. – PlayDough Jun 12 '19 at 21:45

Your command line translates to these parameters:

1. "vsim"
2. "-c"
3. "work.foo"
4. "-gVAL=\"a"
5. "b"
6. "c"
7. "d\""

You need to enclose the wohle parameter in quotes:

vsim -c work.foo "-gVAL=a b c d"


The application will see these parameters:

1. "vsim"
2. "-c"
3. "work.foo"
4. "-gVAL=a b c d"
• The message from Modelsim doesn't indicate that is the case. If it saw "-gVAL=a", then I would expect the message to say Invalid value "a" for generic "VAL". But to further test this case, I did, within Modelsim, both in a .do file and at the TCL command line, and got the same error. – PlayDough Jan 28 '19 at 23:18
• @PlayDough I assumed with command line you meant a real command line a.k.a. shell but not the integrated Tcl console in ModelSim ... – Paebbels Jan 29 '19 at 19:26