CIRCT 24.0.0git
Loading...
Searching...
No Matches
sv.py
Go to the documentation of this file.
1# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2# See https://llvm.org/LICENSE.txt for license information.
3# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5from . import sv, hw
6from .. import support
7from .._mlir_libs._circt._sv import *
8from ..dialects._ods_common import _cext as _ods_cext
9from ..ir import ArrayAttr, Attribute, FlatSymbolRefAttr, OpView, StringAttr
10from ._sv_ops_gen import *
11from ._sv_ops_gen import _Dialect
12
13from typing import List, Optional
14
15
16@_ods_cext.register_operation(_Dialect, replace=True)
18
19 def __init__(self, cond: Attribute, *, loc=None, ip=None):
20 operands = []
21 results = []
22 attributes = {"cond": cond}
23 regions = 2
24 super().__init__(
25 self.build_generic(attributes=attributes,
26 results=results,
27 operands=operands,
28 successors=None,
29 regions=regions,
30 loc=loc,
31 ip=ip))
32 self.regions[0].blocks.append()
33 self.regions[1].blocks.append()
34
35
36@_ods_cext.register_operation(_Dialect, replace=True)
38
39 def __init__(self,
40 data_type,
41 name,
42 *,
43 sym_name=None,
44 svAttributes=None,
45 loc=None,
46 ip=None):
47 attributes = {"name": StringAttr.get(name)}
48 if sym_name is not None:
49 attributes["inner_sym"] = hw.InnerSymAttr.get(StringAttr.get(sym_name))
50 if svAttributes is not None:
51 attributes["svAttributes"] = ArrayAttr.get(svAttributes)
52 OpView.__init__(
53 self,
54 self.build_generic(attributes=attributes,
55 results=[data_type],
56 operands=[],
57 successors=None,
58 regions=0,
59 loc=loc,
60 ip=ip))
61
62 @staticmethod
63 def create(data_type, name=None, sym_name=None):
64 if not isinstance(data_type, (hw.InOutType, sv.NetType)):
65 data_type = hw.InOutType.get(data_type)
66 return sv.WireOp(data_type, name, sym_name=sym_name)
67
68
69@_ods_cext.register_operation(_Dialect, replace=True)
70class RegOp(RegOp):
71
72 def __init__(self,
73 data_type,
74 name,
75 *,
76 sym_name=None,
77 svAttributes=None,
78 loc=None,
79 ip=None):
80 attributes = {"name": StringAttr.get(name)}
81 if sym_name is not None:
82 attributes["inner_sym"] = hw.InnerSymAttr.get(StringAttr.get(sym_name))
83 if svAttributes is not None:
84 attributes["svAttributes"] = ArrayAttr.get(svAttributes)
85 OpView.__init__(
86 self,
87 self.build_generic(attributes=attributes,
88 results=[data_type],
89 operands=[],
90 successors=None,
91 regions=0,
92 loc=loc,
93 ip=ip))
94
95
96@_ods_cext.register_operation(_Dialect, replace=True)
97class VarOp(VarOp):
98
99 def __init__(self,
100 data_type,
101 name,
102 *,
103 sym_name=None,
104 svAttributes=None,
105 loc=None,
106 ip=None):
107 if name is None:
108 name = ""
109 attributes = {"name": StringAttr.get(name)}
110 if sym_name is not None:
111 attributes["inner_sym"] = hw.InnerSymAttr.get(StringAttr.get(sym_name))
112 if svAttributes is not None:
113 attributes["svAttributes"] = ArrayAttr.get(svAttributes)
114 OpView.__init__(
115 self,
116 self.build_generic(attributes=attributes,
117 results=[data_type],
118 operands=[],
119 successors=None,
120 regions=0,
121 loc=loc,
122 ip=ip))
123
124 @staticmethod
125 def create(data_type, name=None, sym_name=None):
126 if not isinstance(data_type, sv.VarType):
127 data_type = sv.VarType.get(data_type)
128 return sv.VarOp(data_type, name, sym_name=sym_name)
129
130
131@_ods_cext.register_operation(_Dialect, replace=True)
133
134 @staticmethod
135 def create(dest, src):
136 return sv.AssignOp(dest=dest, src=src)
137
138
139@_ods_cext.register_operation(_Dialect, replace=True)
141
142 @staticmethod
143 def create(dest, src):
144 return sv.VarAssignOp(dest=dest, src=src)
145
146
147@_ods_cext.register_operation(_Dialect, replace=True)
149
150 @staticmethod
151 def create(value):
152 value = support.get_value(value)
153 type = support.get_self_or_inner(value.type).element_type
154 return sv.ReadInOutOp(value)
155
156
157@_ods_cext.register_operation(_Dialect, replace=True)
159
160 def __init__(self,
161 sym_name,
162 content,
163 output_file,
164 *,
165 parameters=None,
166 additional_files=None,
167 verilog_name=None,
168 loc=None,
169 ip=None):
170 attributes = {}
171 attributes["sym_name"] = StringAttr.get(str(sym_name))
172 attributes["content"] = StringAttr.get(str(content))
173 attributes["output_file"] = output_file
174
175 if parameters is not None:
176 attributes["parameters"] = parameters
177 else:
178 attributes["parameters"] = ArrayAttr.get([])
179
180 if additional_files is not None:
181 attributes["additional_files"] = additional_files
182
183 if verilog_name is not None:
184 attributes["verilogName"] = StringAttr.get(str(verilog_name))
185 else:
186 # Default to using the symbol name without file extension
187 name = str(sym_name)
188 if name.endswith('.v'):
189 attributes["verilogName"] = StringAttr.get(name[:-2])
190 else:
191 attributes["verilogName"] = StringAttr.get(name)
192
193 OpView.__init__(
194 self,
195 self.build_generic(attributes=attributes,
196 results=[],
197 operands=[],
198 successors=None,
199 regions=0,
200 loc=loc,
201 ip=ip))
202
203
204@_ods_cext.register_operation(_Dialect, replace=True)
206
207 def __init__(self,
208 name,
209 source,
210 input_ports=[],
211 output_ports=[],
212 *,
213 parameters=None,
214 verilog_name=None,
215 attributes={},
216 loc=None,
217 ip=None):
218 attributes = dict(attributes)
219 attributes["source"] = source
220
221 if parameters is not None:
222 attributes["parameters"] = parameters
223 else:
224 attributes["parameters"] = ArrayAttr.get([])
225
226 if verilog_name is not None:
227 attributes["verilogName"] = StringAttr.get(str(verilog_name))
228
230 name,
231 input_ports,
232 output_ports,
233 parameters=parameters if parameters is not None else [],
234 attributes=attributes,
235 body_builder=None,
236 loc=loc,
237 ip=ip)
238
239 def instantiate(self, *args, **kwargs):
240 return hw.ModuleLike.instantiate(self, *args, **kwargs)
241
242 @property
243 def type(self):
244 return hw.ModuleLike.type(self)
245
246 @property
247 def name(self):
248 return hw.ModuleLike.name(self)
249
250 @property
251 def is_external(self):
252 return True
253
254 @property
255 def parameters(self) -> list[hw.ParamDeclAttr]:
256 return hw.ModuleLike.parameters(self)
257
258
259VerbatimSourceOp = SVVerbatimSourceOp
260VerbatimModuleOp = SVVerbatimModuleOp
type(op)
Definition hw.py:192
name(op)
Definition hw.py:196
init(op, name, input_ports=[], output_ports=[], *, parameters=[], attributes={}, body_builder=None, loc=None, ip=None)
Definition hw.py:128
list[ParamDeclAttr] parameters(op)
Definition hw.py:204
instantiate(op, str name, Dict[str, object] parameters={}, results=None, sym_name=None, loc=None, ip=None, **kwargs)
Definition hw.py:215
create(dest, src)
Definition sv.py:135
__init__(self, Attribute cond, *, loc=None, ip=None)
Definition sv.py:19
create(value)
Definition sv.py:151
Definition sv.py:70
__init__(self, data_type, name, *, sym_name=None, svAttributes=None, loc=None, ip=None)
Definition sv.py:79
__init__(self, name, source, input_ports=[], output_ports=[], *, parameters=None, verilog_name=None, attributes={}, loc=None, ip=None)
Definition sv.py:217
is_external(self)
Definition sv.py:251
instantiate(self, *args, **kwargs)
Definition sv.py:239
list[hw.ParamDeclAttr] parameters(self)
Definition sv.py:255
__init__(self, sym_name, content, output_file, *, parameters=None, additional_files=None, verilog_name=None, loc=None, ip=None)
Definition sv.py:169
create(dest, src)
Definition sv.py:143
Definition sv.py:97
create(data_type, name=None, sym_name=None)
Definition sv.py:125
__init__(self, data_type, name, *, sym_name=None, svAttributes=None, loc=None, ip=None)
Definition sv.py:106
__init__(self, data_type, name, *, sym_name=None, svAttributes=None, loc=None, ip=None)
Definition sv.py:46
create(data_type, name=None, sym_name=None)
Definition sv.py:63