Esempio n. 1
0
from py_hcl.core.expr import ExprHolder
from py_hcl.core.expr.bundle_holder import BundleHolder
from py_hcl.core.expr.error import ExprError
from py_hcl.core.hcl_ops import op_register
from py_hcl.core.stmt.connect import ConnSide
from py_hcl.core.type import HclType
from py_hcl.core.type.bundle import BundleT, Dir
from py_hcl.utils import json_serialize

field_accessor = op_register('.')


@json_serialize
class FieldAccess(object):
    def __init__(self, expr, item):
        self.operation = "field_access"
        self.item = item
        self.ref_expr_id = expr.id


@field_accessor(BundleT)
def _(bd, item):
    # TODO: Accurate Error Message
    assert item in bd.hcl_type.fields
    if isinstance(bd, BundleHolder):
        return bd.assoc_value[item]

    # build connect side
    sd = bd.conn_side
    f = bd.hcl_type.fields[item]
    dr, tpe = f["dir"], f["hcl_type"]
Esempio n. 2
0
from py_hcl.core.type.bundle import BundleT, Dir
from py_hcl.core.type.sint import SIntT
from py_hcl.core.type.uint import UIntT
from py_hcl.core.type.vector import VectorT
from py_hcl.utils import json_serialize


@json_serialize
class And(object):
    def __init__(self, left, right):
        self.operation = 'and'
        self.left_expr_id = left.id
        self.right_expr_id = right.id


ander = op_register('&')


@ander(UIntT, UIntT)
@assert_right_side
def _(lf, rt):
    w = max(lf.hcl_type.width, rt.hcl_type.width)
    t = UIntT(w)
    return ExprHolder(t, ConnSide.RT, And(lf, rt))


@ander(SIntT, SIntT)
@assert_right_side
def _(lf, rt):
    w = max(lf.hcl_type.width, rt.hcl_type.width)
    t = UIntT(w)
Esempio n. 3
0
from py_hcl.core.expr import ExprHolder
from py_hcl.core.expr.utils import assert_right_side
from py_hcl.core.hcl_ops import op_register
from py_hcl.core.stmt.connect import ConnSide
from py_hcl.core.type.sint import SIntT
from py_hcl.core.type.uint import UIntT
from py_hcl.utils import json_serialize

extend = op_register('extend')


@json_serialize
class Extend(object):
    def __init__(self, expr):
        self.operation = 'extend'
        self.ref_expr_id = expr.id


@extend(UIntT)
@assert_right_side
def _(uint, size):
    return ExprHolder(UIntT(size), ConnSide.RT, Extend(uint))


@extend(SIntT)
@assert_right_side
def _(sint, size):
    return ExprHolder(SIntT(size), ConnSide.RT, Extend(sint))
Esempio n. 4
0
from py_hcl.core.type.bundle import BundleT, Dir
from py_hcl.core.type.sint import SIntT
from py_hcl.core.type.uint import UIntT
from py_hcl.core.type.vector import VectorT
from py_hcl.utils import json_serialize


@json_serialize
class Or(object):
    def __init__(self, left, right):
        self.operation = 'or'
        self.left_expr_id = left.id
        self.right_expr_id = right.id


orer = op_register('|')


@orer(UIntT, UIntT)
@assert_right_side
def _(lf, rt):
    w = max(lf.hcl_type.width, rt.hcl_type.width)
    t = UIntT(w)
    return ExprHolder(t, ConnSide.RT, Or(lf, rt))


@orer(SIntT, SIntT)
@assert_right_side
def _(lf, rt):
    w = max(lf.hcl_type.width, rt.hcl_type.width)
    t = UIntT(w)
Esempio n. 5
0
from py_hcl.core.expr import ExprHolder
from py_hcl.core.expr.error import ExprError
from py_hcl.core.expr.utils import assert_right_side
from py_hcl.core.hcl_ops import op_register
from py_hcl.core.stmt.connect import ConnSide
from py_hcl.core.type import HclType
from py_hcl.core.type.sint import SIntT
from py_hcl.core.type.uint import UIntT
from py_hcl.utils import json_serialize

to_bool = op_register('to_bool')
to_uint = op_register('to_uint')
to_sint = op_register('to_sint')


@json_serialize
class ToSInt(object):
    def __init__(self, expr):
        self.operation = "to_sint"
        self.ref_expr_id = expr.id


@json_serialize
class ToUInt(object):
    def __init__(self, expr):
        self.operation = "to_uint"
        self.ref_expr_id = expr.id


@to_bool(UIntT)
@assert_right_side
Esempio n. 6
0
from py_hcl.core.expr import ExprHolder
from py_hcl.core.expr.error import ExprError
from py_hcl.core.expr.utils import assert_right_side
from py_hcl.core.expr.vec_holder import VecHolder
from py_hcl.core.hcl_ops import op_register
from py_hcl.core.type import HclType
from py_hcl.core.type.sint import SIntT
from py_hcl.core.type.uint import UIntT
from py_hcl.core.type.vector import VectorT
from py_hcl.utils import json_serialize

index = op_register('[i]')


@json_serialize
class VecIndex(object):
    def __init__(self, expr, idx: int):
        self.operation = "vec_index"
        self.index = idx
        self.ref_expr_id = expr.id


@index(UIntT)
@assert_right_side
def _(uint, i: int):
    return uint[i:i]


@index(SIntT)
@assert_right_side
def _(sint, i: int):
Esempio n. 7
0
from py_hcl.core.expr import ExprHolder
from py_hcl.core.expr.error import ExprError
from py_hcl.core.expr.utils import assert_right_side
from py_hcl.core.expr.vec_holder import VecHolder
from py_hcl.core.hcl_ops import op_register
from py_hcl.core.stmt.connect import ConnSide
from py_hcl.core.type import HclType
from py_hcl.core.type.sint import SIntT
from py_hcl.core.type.uint import UIntT
from py_hcl.core.type.vector import VectorT
from py_hcl.utils import json_serialize

slice_ = op_register('[i:j]')


@json_serialize
class Bits(object):
    def __init__(self, expr, high, low):
        self.operation = 'bits'
        self.high = high
        self.low = low
        self.ref_expr_id = expr.id


@slice_(UIntT)
@assert_right_side
def _(uint, high: int, low: int):
    check_bit_width(uint, high, low)
    t = UIntT(high - low + 1)
    return ExprHolder(t, ConnSide.RT, Bits(uint, high, low))
Esempio n. 8
0
from py_hcl.core.type.bundle import BundleT, Dir
from py_hcl.core.type.sint import SIntT
from py_hcl.core.type.uint import UIntT
from py_hcl.core.type.vector import VectorT
from py_hcl.utils import json_serialize


@json_serialize
class Add(object):
    def __init__(self, left, right):
        self.operation = 'add'
        self.left_expr_id = left.id
        self.right_expr_id = right.id


adder = op_register('+')


@adder(UIntT, UIntT)
@assert_right_side
def _(lf, rt):
    w = max(lf.hcl_type.width, rt.hcl_type.width) + 1
    t = UIntT(w)
    return ExprHolder(t, ConnSide.RT, Add(lf, rt))


@adder(SIntT, SIntT)
@assert_right_side
def _(lf, rt):
    w = max(lf.hcl_type.width, rt.hcl_type.width) + 1
    t = SIntT(w)
Esempio n. 9
0
class ConnSide(Enum):
    UNKNOWN = 0
    LF = 1
    RT = 2
    BOTH = 3


@json_serialize
class Connect(object):
    def __init__(self, left, right):
        self.stmt_type = 'connect'
        self.left_expr_id = left.id
        self.right_expr_id = right.id


connector = op_register('<<=')


@connector(UIntT, UIntT)
def _(left, right):
    check_connect_dir(left, right)

    if left.hcl_type.width < right.hcl_type.width:
        msg = 'connect(): connecting {} to {} will truncate the bits'.format(
            right.hcl_type, left.hcl_type)
        logging.warning(msg)
        right = right[left.hcl_type.width - 1:0]

    if left.hcl_type.width > right.hcl_type.width:
        right = op_apply('extend')(right, left.hcl_type.width)
Esempio n. 10
0
from py_hcl.core.type.bundle import BundleT, Dir
from py_hcl.core.type.sint import SIntT
from py_hcl.core.type.uint import UIntT
from py_hcl.core.type.vector import VectorT
from py_hcl.utils import json_serialize


@json_serialize
class Xor(object):
    def __init__(self, left, right):
        self.operation = 'xor'
        self.left_expr_id = left.id
        self.right_expr_id = right.id


xorer = op_register('^')


@xorer(UIntT, UIntT)
@assert_right_side
def _(lf, rt):
    w = max(lf.hcl_type.width, rt.hcl_type.width)
    t = UIntT(w)
    return ExprHolder(t, ConnSide.RT, Xor(lf, rt))


@xorer(SIntT, SIntT)
@assert_right_side
def _(lf, rt):
    w = max(lf.hcl_type.width, rt.hcl_type.width)
    t = UIntT(w)