|
6 | 6 |
|
7 | 7 | from dataclasses import dataclass
|
8 | 8 | from enum import Enum
|
9 |
| -from typing import Callable |
| 9 | +from typing import Callable, List, Optional |
10 | 10 |
|
| 11 | +from inputgen.argument.type import ArgType |
11 | 12 | from inputgen.attribute.model import Attribute
|
12 | 13 |
|
13 | 14 |
|
@@ -63,3 +64,86 @@ class ConstraintProducer:
|
63 | 64 | Rank = ConstraintAttributeSuffixes(Attribute.RANK)
|
64 | 65 | Size = ConstraintAttributeSuffixes(Attribute.SIZE)
|
65 | 66 | Value = ConstraintAttributeSuffixes(Attribute.VALUE)
|
| 67 | + |
| 68 | + |
| 69 | +class BaseArg: |
| 70 | + def __init__( |
| 71 | + self, |
| 72 | + argtype: ArgType, |
| 73 | + name: str, |
| 74 | + deps: Optional[List[int]] = None, |
| 75 | + constraints: Optional[List[Constraint]] = None, |
| 76 | + ): |
| 77 | + self.name: str = name |
| 78 | + self.type: ArgType = argtype |
| 79 | + self.deps = () if deps is None else tuple(deps) |
| 80 | + self.constraints = [] if constraints is None else constraints |
| 81 | + self._kw: bool = False |
| 82 | + self._out: bool = False |
| 83 | + self._ret: bool = False |
| 84 | + |
| 85 | + @property |
| 86 | + def kw(self): |
| 87 | + return self._kw |
| 88 | + |
| 89 | + @kw.setter |
| 90 | + def kw(self, v): |
| 91 | + if not isinstance(v, bool): |
| 92 | + raise ValueError("kw property should be boolean") |
| 93 | + self._kw = v |
| 94 | + |
| 95 | + @property |
| 96 | + def out(self): |
| 97 | + return self._out |
| 98 | + |
| 99 | + @out.setter |
| 100 | + def out(self, v): |
| 101 | + if not isinstance(v, bool): |
| 102 | + raise ValueError("out property should be boolean") |
| 103 | + self._out = v |
| 104 | + |
| 105 | + @property |
| 106 | + def ret(self): |
| 107 | + return self._ret |
| 108 | + |
| 109 | + @ret.setter |
| 110 | + def ret(self, v): |
| 111 | + if not isinstance(v, bool): |
| 112 | + raise ValueError("ret property should be boolean") |
| 113 | + self._ret = v |
| 114 | + |
| 115 | + |
| 116 | +class InArg(BaseArg): |
| 117 | + def __init__(self, *args, **kwargs): |
| 118 | + BaseArg.__init__(self, *args, **kwargs) |
| 119 | + |
| 120 | + |
| 121 | +class InPosArg(InArg): |
| 122 | + def __init__(self, *args, **kwargs): |
| 123 | + BaseArg.__init__(self, *args, **kwargs) |
| 124 | + |
| 125 | + |
| 126 | +class InKwArg(InArg): |
| 127 | + def __init__(self, *args, **kwargs): |
| 128 | + BaseArg.__init__(self, *args, **kwargs) |
| 129 | + self._kw = True |
| 130 | + |
| 131 | + |
| 132 | +class OutArg(BaseArg): |
| 133 | + def __init__(self, argtype: ArgType, name: str = "out", *args, **kwargs): |
| 134 | + BaseArg.__init__(self, argtype, name, *args, **kwargs) |
| 135 | + self._kw = True |
| 136 | + self._out = True |
| 137 | + |
| 138 | + |
| 139 | +class Return(BaseArg): |
| 140 | + def __init__(self, argtype: ArgType, name: str = "__ret", *args, **kwargs): |
| 141 | + BaseArg.__init__(self, argtype, name, *args, **kwargs) |
| 142 | + self._ret = True |
| 143 | + |
| 144 | + |
| 145 | +class Spec: |
| 146 | + def __init__(self, op: str, inspec: List[InArg], outspec: List[OutArg]): |
| 147 | + self.op = op |
| 148 | + self.inspec = inspec |
| 149 | + self.outspec = outspec |
0 commit comments