To solve!!! Compilation and operation of SystemVerilog in Modelsim

Source: Internet
Author: User

is in the process of learning SV, run the book on the examples, encountered problems.
function: The function returns an array.

Code1:
/ * Examples provided in the book, there are errors, not running
function void init (ref int f[5], int start);//main function definition without declaring automatic property
foreach (f)
F= i + start;
Endfunction

Initial begin
int fa[5];
FA = init (fa,5);
foreach (FA)
$display ("fa[%0d] =%0d", I, FA);
End
*/


#-----------------------------------------------------------------------------------
Code2:
The following code will run successfully under Modelsim. (Automatic is added when defining function)
Module Enum_name;
int fa[5];
Initial begin
FA = init (FA, 5);
Init (FA, 5);
foreach (FA)
$display ("fa[%0d] =%0d", I, FA);
End

function automatic void init (ref int f[5], input int start);
foreach (f)//Initialize array
F= i + start;
Endfunction
Endmodule
#-----------------------------------------------------------------------------------

Question:
In the 16th chapter of LRM, the following structure is provided when explaining program results:
Code3:
ModuleTest (...)
intShared Variable shared by programs P1 and P1
ProgramP1;
...
Endprogram
Program p2;
...
Endprogram //P1 and P2 is implicitly instantiated once in module test
endmodule

to ask, how can the function of Code2 in the Program...endprogram inside, form the Code3 form of code structure.
among them, Code4 is I try to change, but in Modelsim compile can pass, but run times wrong.

Code4:
Module Enum_name;
int fa[5];
Initial begin

FA = init (FA, 5);
Test.init (FA, 5); The 61st line of the prompt in the corresponding error message
foreach (FA
       $display ("fa[%0d") =%0d ", I, Fa  end
//------------------------------------------------------------;
  program automatic test;
    function automatic void init (ref int f[5], input int start);
      foreach (f)//initialize array
        f = i + start;< BR style= "Word-wrap:break-word" >   endfunction
  endprogram< BR style= "Word-wrap:break-word" >endmodule


run the wrong content of the Times:
# Compile of ENUM_NAME.SV is successful with warnings.
Vsim-gui Work.enum_name
# Vsim-gui Work.enum_name
# Loading SV_STD.STD
# Loading Work.enum_name
# * * Error: (vsim-3927) D:/MODELSIM/SYSVERILOG/ENUM/ENUM_NAME.SV () Accessing program item '/enum_name/test/init ' From a Non-program design unit enum_name is illegal.

# region:/enum_name
# * * Error: (vsim-3927) D:/MODELSIM/SYSVERILOG/ENUM/ENUM_NAME.SV () Accessing program item '/enum_name/test/init ' From a Non-program design unit enum_name is illegal.

# region:/enum_name
# * * Error: (vsim-3927) D:/MODELSIM/SYSVERILOG/ENUM/ENUM_NAME.SV () Accessing program item '/enum_name/test/init ' From a Non-program design unit enum_name is illegal.

# region:/enum_name
# Error Loading Design



To solve!!! Compilation and operation of SystemVerilog in Modelsim

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.