30.04.2013 Views

BSV by Example - Computation Structures Group

BSV by Example - Computation Structures Group

BSV by Example - Computation Structures Group

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

the repetition of the declaration in each of the implementation modules. All modules which share a<br />

common interface have the same methods, and therefore the same number and types of inputs and<br />

outputs.<br />

It is important to distinguish between interface declarations and interface instances. A design may<br />

contain one or more interface declarations, and each of these may have multiple instances. An<br />

interface declaration can be thought of as declaring a new type similar to a struct type, where the<br />

members are all method prototypes. The declaration states the new type, while the definition of how<br />

the methods are implemented is contained within the module that contains the interface instance.<br />

A method can be thought of like a function, i.e., it is a procedure that takes zero or more arguments<br />

and returns a result. Thus, method declarations inside interface declarations look a lot like function<br />

prototypes, the only difference being the use of the keyword method instead of the keyword function.<br />

Each method represents one kind of transaction between a module and its clients. When translated<br />

into RTL, each method becomes a bundle of wires. The definition of how a method is implemented<br />

is contained in the interface definition within the module and may be different in each module where<br />

the common interface is used. However the wires making up the interface, that is the inputs, outputs<br />

and inouts, and the methods defined, will be the same in all instances.<br />

Let’s look at the definition of interface Ifc_type. Interface names always start with an upper-case<br />

letter, because they are a data type, in this case a user-defined data type. The interface declares a<br />

value method named the_answer with three int arguments returning an int result. How the result<br />

is calculated is left to the method definition.<br />

interface Ifc_type;<br />

method int the_answer (int x, int y, int z);<br />

endinterface: Ifc_type<br />

The module mkModuleDeepThought provides an interface of type Ifc_type, as shown in the module<br />

definition statement:<br />

module mkModuleDeepThought (Ifc_type);<br />

To instantiate a module and obtain a handle on its interface, use a statement of the form:<br />

Interface type identifier

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!