CIRCT  20.0.0git
handshake.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 
5 from __future__ import annotations
6 from typing import Dict, List, Tuple, Union
7 
8 from . import handshake
9 from ._handshake_ops_gen import *
10 from ._handshake_ops_gen import _Dialect
11 
12 from ..dialects._ods_common import _cext as _ods_cext
13 from ..ir import ArrayAttr, Attribute, FunctionType, StringAttr, Type, TypeAttr
14 
15 from ._ods_common import (
16  equally_sized_accessor as _ods_equally_sized_accessor,
17  get_default_loc_context as _ods_get_default_loc_context,
18  get_op_result_or_op_results as _get_op_result_or_op_results,
19  get_op_result_or_value as _get_op_result_or_value,
20  get_op_results_or_values as _get_op_results_or_values,
21  segmented_accessor as _ods_segmented_accessor,
22 )
23 
24 _ods_ir = _ods_cext.ir
25 
26 
27 @_ods_cext.register_operation(_Dialect, replace=True)
28 class FuncOp(FuncOp):
29 
30  @staticmethod
31  def create(sym_name: Union[StringAttr, str],
32  args: List[Tuple[str, Type]],
33  results: List[Tuple[str, Type]],
34  attributes: Dict[str, Attribute] = {},
35  loc=None,
36  ip=None) -> FuncOp:
37  if isinstance(sym_name, str):
38  sym_name = StringAttr.get(sym_name)
39  input_types = [t for _, t in args]
40  res_types = [t for _, t in results]
41  func_type = FunctionType.get(input_types, res_types)
42  func_type_attr = TypeAttr.get(func_type)
43  funcop = FuncOp(func_type_attr, loc=loc, ip=ip)
44  for k, v in attributes.items():
45  funcop.attributes[k] = v
46  funcop.attributes["sym_name"] = sym_name
47  funcop.attributes["argNames"] = ArrayAttr.get(
48  [StringAttr.get(name) for name, _ in args])
49  funcop.attributes["resNames"] = ArrayAttr.get(
50  [StringAttr.get(name) for name, _ in results])
51  return funcop
52 
53  def add_entry_block(self):
54  self.body.blocks.append(*self.function_type.value.inputs)
55  return self.body.blocks[0]
def add_entry_block(self)
Definition: handshake.py:53
FuncOp create(Union[StringAttr, str] sym_name, List[Tuple[str, Type]] args, List[Tuple[str, Type]] results, Dict[str, Attribute] attributes={}, loc=None, ip=None)
Definition: handshake.py:36