Yesterday was Halloween and candies are around every corner, even in my code. But do you think it compiles?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | `define candy function void candy; endfunction module candy( input candy ); initial begin (* candy *) bit candy; end endmodule package candy; function void candy; endfunction endpackage |
It will! This is because each candy is in different name spaces. SystemVerilog has eight name spaces for identifiers (names).
- Global
- Definitions name space —
module
,primitive
,program
, andinterface
names defined outside all other declarations. - Package name space —
package
names.
- Definitions name space —
- Global to the compilation unit
- Compilation-unit name space —
function
,task
, and other names defined outside themodule
,interface
,package
, etc. - Text macro name space — text macro names.
- Compilation-unit name space —
- Local
- Module name space — names defined within the
module
,interface
,package
, etc. - Block name space — names defined in blocks,
function
,task
, etc. - Port name space — port names of
module
,interface
, etc. - Attribute name space — attribute names.
- Module name space — names defined within the
These are the name spaces each candy belongs to. Since they are in different name spaces, they do not conflict each other.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | `define candy // This candy is in the text macro name space. function void candy; // This candy is in the compilation-unit scope name space. endfunction module candy( // This candy is in the definitions name space. input candy ); // This candy is in the port name space. initial begin (* candy *) // This candy is in the attribute name space. bit candy; // This candy is in the block name space. end endmodule package candy; // This candy is in the package name space. function void candy; // This candy is in the module name space. endfunction endpackage |
You can view and run the code on EDA Playground.
VCS 2014.12 gives the below compilation error.
———————————————————————————————–
Parsing design file ‘design.sv’
Error-[SV-PPD] Package previously declared
design.sv, 18
candy
Identifier ‘candy’ is already declared in file “design.sv”, line 10.
———————————————————————————————–
Using questasim the compilation goes through fine (expected).
What is (* candy *) at line number 9 in above code
It is an attribute that specifies a property about
bit candy
. Tools such as simulators and logic synthesizers can use the attribute to control their operation or behavior. Probably no tools understand thecandy
attribute, though.Can you give an example which type of property you are talking about??
You could specify
(* do_not_optimize *)
attribute to thebit candy
to control the operation of a logic synthesis tool if the tool supports such an attribute, for example.Hi Keisuke,
Since you mentioned name space, I have some questions about name space and parameter type. Would you please tell any good material or paper written by you or other about it?
1. Are A1, A2, A4 the same? What is the different between A2 and A3.
2. Will the parameter data have any conflict for method_1? Is there a better way to handle it?
3. Is this a legal way to program parameter. Will the parameter Data have different copy? How could we access each parameter Data
4. What is the difference between local, private and protected parameters.
Thanks you very much. Sorry for so many questions
Best,
A2
andA3
,A2
is available to anyone who has access to it because it is a public class method. On the other hand,A3
is visible to classB
and its subclasses only, because it is a protected class method.Data
is a class property, taskA
and taskB
can access it. It is caller’s responsibility when to update it.Data
. However, since theData
exists only in the task, you cannot access the updatedData
from outside of the task.local
(private) class property is available only inside the class. Aprotected
class property is visible to subclasses, too.Hi Keisuke,
Thanks for your explanation, Please correct me if I am wrong.
For my understanding, property in the class is accessible to task. by if the parameter is defined inside the task, it is only accessible inside the task.
Best,
Kevin
That is correct.