📄 00314.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<title>27.4.4 Import declarations</title>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<meta name="generator" content="Doc-O-Matic" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link rel="STYLESHEET" href="default.css" type="text/css" />
<script type="text/javascript" src="scripts.js"></script>
</head>
<body class="Element700" onload="onBodyLoadEx('systemverilog31a.html', 'topic', '00314.html');" onmousedown="onBodyMouseDown();">
<!-- Begin Popups -->
<div class="Element801" id="popup00498">
<div class="Element800">
<div class="Element14">
链接</div>
<div class="Element11">
<div class="Element10">
<a href="00304.html" target="topic">27.4 导入的任务和函数</a></div>
</div>
</div>
</div>
<!-- End Popups -->
<!-- Begin Page Header -->
<div class="Element710" id="areafixed">
<div class="Element92">
<table width="100%" cellspacing="0" cellpadding="0">
<tr><td width="33%">
<div class="Element1">
<a href="#" onmousedown="showPopup(this, 'popup00498');"><img src="seealsolink.png" border="0" alt="" title=""></a> SystemVerilog 3.1a语言参考手册</div>
</td><td width="34%">
<div class="Element2">
</div>
</td><td width="33%">
<div class="Element90">
<a href="00313.html" target="topic"><img src="btn_prev_lightblue.gif" border="0" alt="Previous" title="Previous" onmouseover="switchImage(this, 'btn_prev_lightblue_hover.gif');" onmouseout="switchImage(this, 'btn_prev_lightblue.gif');"></a><a href="00304.html" target="topic"><img src="btn_up_lightblue.gif" border="0" alt="Up" title="Up" onmouseover="switchImage(this, 'btn_up_lightblue_hover.gif');" onmouseout="switchImage(this, 'btn_up_lightblue.gif');"></a><a href="00315.html" target="topic"><img src="btn_next_lightblue.gif" border="0" alt="Next" title="Next" onmouseover="switchImage(this, 'btn_next_lightblue_hover.gif');" onmouseout="switchImage(this, 'btn_next_lightblue.gif');"></a></div>
</td></tr></table><div class="Element5">
27.4.4 Import declarations</div>
</div>
</div>
<!-- End Page Header -->
<!-- Begin Client Area -->
<div class="Element720" id="areascroll">
<div class="Element721">
<!-- Begin Page Content -->
<div class="Element58">
<a name="描述"></a><div class="Element11">
<div class="Element10">
<p class="Element10">
Each imported task or function shall be declared. Such declaration are referred to as import declarations. The syntax of an import declaration is similar to the syntax of SystemVerilog task or function prototypes (see Section 10.5). </p>
<p class="Element10">
</p>
<p class="Element10">
Imported tasks or functions are similar to SystemVerilog tasks or functions. Imported tasks or functions can have zero or more formal input, output, and inout arguments. Imported functions can return a result or be defined as void functions. Imported tasks never return a result, and thus are always declared in foreign code as void functions. </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00966');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00966"><pre class="Element12">dpi_import_export ::= // from Annex A.2.6
<strong><span style="color: #FF0000">import "DPI"</span></strong> [dpi_function_import_property] [c_identifier <strong><span style="color: #FF0000">=</span></strong>] dpi_function_proto<strong><span style="color: #FF0000">;</span></strong>
| <strong><span style="color: #FF0000">import "DPI"</span></strong> [dpi_task_import_property] [c_identifier <strong><span style="color: #FF0000">=</span></strong>] dpi_task_proto<strong><span style="color: #FF0000">;</span></strong>
| <strong><span style="color: #FF0000">export "DPI"</span></strong> [c_identifier <strong><span style="color: #FF0000">=</span></strong>] <strong><span style="color: #FF0000">function</span></strong> function_identifier<strong><span style="color: #FF0000">;</span></strong>
| <strong><span style="color: #FF0000">export "DPI"</span></strong> [c_identifier <strong><span style="color: #FF0000">=</span></strong>] <strong><span style="color: #FF0000">task</span></strong> task_identifier<strong><span style="color: #FF0000">;</span></strong>
dpi_function_import_property ::= <strong><span style="color: #FF0000">context</span></strong> | <strong><span style="color: #FF0000">pure</span></strong>
dpi_task_import_property ::= <strong><span style="color: #FF0000">context</span></strong>
dpi_function_proto<sup>8,9</sup> ::= function_prototype
dpi_task_proto<sup>9</sup> ::= task_prototype
function_prototype ::= <strong><span style="color: #FF0000">function</span></strong> function_data_type function_identifier<strong><span style="color: #FF0000">(</span></strong>[tf_port_list]<strong><span style="color: #FF0000">)</span></strong>
task_prototype ::= <strong><span style="color: #FF0000">task</span></strong> task_identifier<strong><span style="color: #FF0000">(</span></strong>[tf_port_list]<strong><span style="color: #FF0000">) </span></strong>// from Annex A.2.7
NOTES: // from Annex A.10
8) dpi_function_proto return types are restricted to small values, as per 27.4.5.
9) Formals of dpi_function_proto and dpi_task_proto cannot use pass by reference mode
and class types cannot be passed at all; for the complete set of restrictions see
27.4.6.</pre></div></div>
<p class="Element10" style="text-align: center">
<strong>Syntax 27-1—DPI import declaration syntax (excerpt from Annex A)</strong></p><p class="Element10">
</p>
<p class="Element10">
An import declaration specifies the task or function name, function result type, and types and directions of formal arguments. It can also provide optional default values for formal arguments. Formal argument names are optional unless argument passing by name is needed. An import declaration can also specify an optional task or function property. Imported functions can have the properties context or pure; imported tasks can have the property context. </p>
<p class="Element10">
</p>
<p class="Element10">
Note that an import declaration is equivalent to defining a task or function of that name in the SystemVerilog scope in which the import declaration occurs, and thus multiple imports of the same task or function name into the same scope are forbidden. Note that this declaration scope is particularly important in the case of imported context tasks or functions, see Section 27.4.3; for non-context imported tasks or functions the declaration scope has no other implications other than defining the visibility of the task or function. </p>
<p class="Element10">
</p>
<p class="Element10">
c_identifier provides the linkage name for this task or function in the foreign language. If not provided, this defaults to the same identifier as the SystemVerilog task or function name. In either case, this linkage name must conform to C identifier syntax. An error shall occur if the c_identifier, either directly or indirectly, does not conform to these rules. </p>
<p class="Element10">
</p>
<p class="Element10">
For any given c_identifier (whether explicitly defined with c_identifier=, or automatically determined from the task or function name), all declarations, regardless of scope, must have exactly the same type signature. The signature includes the return type and the number, order, direction and types of each and every argument. Type includes dimensions and bounds of any arrays or array dimensions. Signature also includes the pure/context qualifiers that can be associated with an extern definition. </p>
<p class="Element10">
</p>
<p class="Element10">
Note that multiple declarations of the same imported or exported task or function in different scopes can vary argument names and default values, provided the type compatibility constraints are met. </p>
<p class="Element10">
</p>
<p class="Element10">
A formal argument name is required to separate the packed and the unpacked dimensions of an array. </p>
<p class="Element10">
</p>
<p class="Element10">
The qualifier ref cannot be used in import declarations. The actual implementation of argument passing depends solely on the foreign language layer and its implementation and shall be transparent to the SystemVerilog side of the interface. </p>
<p class="Element10">
</p>
<p class="Element10">
The following are examples of external declarations. </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00967');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00967"><pre class="Element12">import "DPI" function void myInit();
// from standard math library
import "DPI" pure function real sin(real);
// from standard C library: memory management
import "DPI" function chandle malloc(int size); // standard C function
import "DPI" function void free(chandle ptr); // standard C function
// abstract data structure: queue
import "DPI" function chandle newQueue(input string name_of_queue);
// Note the following import uses the same foreign function for
// implementation as the prior import, but has different SystemVerilog name
// and provides a default value for the argument.
import "DPI" newQueue=function chandle newAnonQueue(input string s=null);
import "DPI" function chandle newElem(bit [15:0]);
import "DPI" function void enqueue(chandle queue, chandle elem);
import "DPI" function chandle dequeue(chandle queue);
// miscellanea
import "DPI" function bit [15:0] getStimulus();
import "DPI” context function void processTransaction(chandle elem,
output logic [64:1] arr [0:63]);
import "DPI" task checkResults(input string s, bit [511:0] packet);</pre></div></div>
</div>
</div>
<a name="Group"></a><div class="Element14">
<a onclick="toggleVisibilityStored('Group');" class="a_Element14"><img src="sectionminus.png" border="0" alt="" title="" id="imgGroup">Group</a></div>
<div id="divGroup">
<div class="Element11">
<div class="Element10">
<p class="Element10">
<a href="00304.html" target="topic">27.4 导入的任务和函数</a></p></div>
</div>
</div>
<a name="Links"></a><div class="Element14">
<a onclick="toggleVisibilityStored('链接');" class="a_Element14"><img src="sectionminus.png" border="0" alt="" title="" id="img链接">链接</a></div>
<div id="div链接">
<div class="Element11">
<div class="Element10">
<a href="00304.html" target="topic">27.4 导入的任务和函数</a></div>
</div>
</div>
</div>
<!-- End Page Content -->
<!-- Begin Page Footer -->
<hr width="98%" align="center" size="1" color="#CCCCCC" />
<table align="center" cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr height="10">
<td></td>
</tr>
<tr align="center">
<td>
<script type="text/javascript"><!--
google_ad_client = "pub-5266859600380184";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_page_url = document.location;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td>
</tr>
<tr height="15">
<td></td>
</tr>
<tr align="center">
<td>
<font size=2>除非特别声明,原文版权归作者所有,如有转摘请注明原作者以及译者(<a href="http://www.fpgatech.net/" target="_blank">FPGA技术网</a>)信息。<br />
如果您对本主题有何建议或意见,请登陆<a href="http://www.fpgatech.net/forum/forumdisplay.php?fid=18" target="_blank">FPGA开发者家园</a>提交,您的参与是我们前进的动力。</font>
<script language="javascript" type="text/javascript" src="http://js.users.51.la/195685.js"></script>
<noscript><a href="http://www.51.la/?195685" target="_blank"><img alt="我要啦免费统计" src="http://img.users.51.la/195685.asp" style="border:none" /></a></noscript>
</td>
</tr>
</tbody>
</table>
<!-- End Page Footer -->
</div>
</div>
<!-- End Client Area -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -