CIRCT 22.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):
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)
98
99 @staticmethod
100 def create(dest, src):
101 return sv.AssignOp(dest=dest, src=src)
102
103
104@_ods_cext.register_operation(_Dialect, replace=True)
106
107 @staticmethod
108 def create(value):
109 value = support.get_value(value)
110 type = support.get_self_or_inner(value.type).element_type
111 return sv.ReadInOutOp(value)
112
113
114@_ods_cext.register_operation(_Dialect, replace=True)
116
117 def __init__(self,
118 sym_name,
119 content,
120 output_file,
121 *,
122 parameters=None,
123 additional_files=None,
124 verilog_name=None,
125 loc=None,
126 ip=None):
127 attributes = {}
128 attributes["sym_name"] = StringAttr.get(str(sym_name))
129 attributes["content"] = StringAttr.get(str(content))
130 attributes["output_file"] = output_file
131
132 if parameters is not None:
133 attributes["parameters"] = parameters
134 else:
135 attributes["parameters"] = ArrayAttr.get([])
136
137 if additional_files is not None:
138 attributes["additional_files"] = additional_files
139
140 if verilog_name is not None:
141 attributes["verilogName"] = StringAttr.get(str(verilog_name))
142 else:
143 # Default to using the symbol name without file extension
144 name = str(sym_name)
145 if name.endswith('.v'):
146 attributes["verilogName"] = StringAttr.get(name[:-2])
147 else:
148 attributes["verilogName"] = StringAttr.get(name)
149
150 OpView.__init__(
151 self,
152 self.build_generic(attributes=attributes,
153 results=[],
154 operands=[],
155 successors=None,
156 regions=0,
157 loc=loc,
158 ip=ip))
159
160
161@_ods_cext.register_operation(_Dialect, replace=True)
163
164 def __init__(self,
165 name,
166 source,
167 input_ports=[],
168 output_ports=[],
169 *,
170 parameters=None,
171 verilog_name=None,
172 attributes={},
173 loc=None,
174 ip=None):
175 attributes = dict(attributes)
176 attributes["source"] = source
177
178 if parameters is not None:
179 attributes["parameters"] = parameters
180 else:
181 attributes["parameters"] = ArrayAttr.get([])
182
183 if verilog_name is not None:
184 attributes["verilogName"] = StringAttr.get(str(verilog_name))
185
187 name,
188 input_ports,
189 output_ports,
190 parameters=parameters if parameters is not None else [],
191 attributes=attributes,
192 body_builder=None,
193 loc=loc,
194 ip=ip)
195
196 def instantiate(self, *args, **kwargs):
197 return hw.ModuleLike.instantiate(self, *args, **kwargs)
198
199 @property
200 def type(self):
201 return hw.ModuleLike.type(self)
202
203 @property
204 def name(self):
205 return hw.ModuleLike.name(self)
206
207 @property
208 def is_external(self):
209 return True
210
211 @property
212 def parameters(self) -> list[hw.ParamDeclAttr]:
213 return hw.ModuleLike.parameters(self)
214
215
216VerbatimSourceOp = SVVerbatimSourceOp
217VerbatimModuleOp = SVVerbatimModuleOp
type(op)
Definition hw.py:192
name(op)
Definition hw.py:196
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
init(op, name, input_ports=[], output_ports=[], *parameters=[], attributes={}, body_builder=None, loc=None, ip=None)
Definition hw.py:128
create(dest, src)
Definition sv.py:100
__init__(self, Attribute cond, *loc=None, ip=None)
Definition sv.py:19
create(value)
Definition sv.py:108
Definition sv.py:70
__init__(self, data_type, name, *sym_name=None, svAttributes=None, loc=None, ip=None)
Definition sv.py:79
is_external(self)
Definition sv.py:208
instantiate(self, *args, **kwargs)
Definition sv.py:196
__init__(self, name, source, input_ports=[], output_ports=[], *parameters=None, verilog_name=None, attributes={}, loc=None, ip=None)
Definition sv.py:174
list[hw.ParamDeclAttr] parameters(self)
Definition sv.py:212
__init__(self, sym_name, content, output_file, *parameters=None, additional_files=None, verilog_name=None, loc=None, ip=None)
Definition sv.py:126
__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