Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String add ops, optional test point naming #309

Merged
merged 4 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/pr-scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ jobs:
with:
python-version: '3.10'
- name: install dependencies
run: |
pip install protobuf sexpdata Deprecated

run: pip install -r requirements.txt
- name: sbt test
run: cd compiler && sbt -v +test

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/main/scala/edg/compiler/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class AssignNamer() {
}

object Compiler {
final val kExpectedProtoVersion = 2
final val kExpectedProtoVersion = 3
}

/** Compiler for a particular design, with an associated library to elaborate references from.
Expand Down
1 change: 1 addition & 0 deletions compiler/src/main/scala/edg/compiler/ExprEvaluate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ object ExprEvaluate {
case (FloatValue(lhs), FloatPromotable(rhs)) => FloatValue(lhs + rhs)
case (FloatPromotable(lhs), FloatValue(rhs)) => FloatValue(lhs + rhs)
case (IntValue(lhs), IntValue(rhs)) => IntValue(lhs + rhs)
case (TextValue(lhs), TextValue(rhs)) => TextValue(lhs + rhs)
case _ =>
throw new ExprEvaluateException(s"Unknown binary operand types in $lhs ${binary.op} $rhs from $binary")
}
Expand Down
2 changes: 1 addition & 1 deletion edg_core/Binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def __repr__(self) -> str:
def __init__(self,
lhs: ConstraintExpr,
rhs: ConstraintExpr,
op: Union[NumericOp,BoolOp,EqOp,OrdOp,RangeSetOp]):
op: Union[NumericOp, BoolOp, EqOp, OrdOp, RangeSetOp]):
self.op_map = {
# Numeric
NumericOp.add: edgir.BinaryExpr.ADD,
Expand Down
12 changes: 11 additions & 1 deletion edg_core/ConstraintExpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def _create_unary_op(cls,
def _create_binary_op(cls,
lhs: SelfType,
rhs: SelfType,
op: Union[NumericOp,RangeSetOp]) -> SelfType:
op: Union[NumericOp, RangeSetOp]) -> SelfType:
"""Creates a new expression that is the result of a binary operation on inputs"""
if type(lhs) != type(rhs):
raise TypeError(f"op args must be of same type, "
Expand Down Expand Up @@ -473,6 +473,16 @@ def _is_lit(self) -> bool:
assert self._is_bound()
return isinstance(self.binding, StringLiteralBinding)

def __add__(self, rhs: StringLike) -> StringExpr:
rhs_typed = self._to_expr_type(rhs)
assert self._is_bound() and rhs_typed._is_bound()
return self._new_bind(BinaryOpBinding(self, rhs_typed, NumericOp.add))

def __radd__(self, lhs: StringLike) -> StringExpr:
lhs_typed = self._to_expr_type(lhs)
assert lhs_typed._is_bound() and self._is_bound()
return self._new_bind(BinaryOpBinding(self, lhs_typed, NumericOp.add))


class AssignExpr(ConstraintExpr[None, None]):
"""Assignment expression, should be an internal type"""
Expand Down
Binary file modified edg_core/resources/edg-compiler-precompiled.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion edg_hdl_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from edg_core.Core import NonLibraryProperty


EDG_PROTO_VERSION = 2
EDG_PROTO_VERSION = 3


class LibraryElementIndexer:
Expand Down
72 changes: 51 additions & 21 deletions electronics_abstract_parts/AbstractTestPoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,38 @@ def __init__(self, name: StringLike = "") -> None:
self.tp_name = self.ArgParameter(name)


class VoltageTestPoint(TypedTestPoint, Block):
"""Test point with a VoltageSink port."""
def __init__(self):
@non_library
class BaseTypedTestPoint(TypedTestPoint, Block):
"""Base class with utility infrastructure for typed test points"""
@init_in_parent
def __init__(self, name: StringLike = "") -> None:
super().__init__()
self.io: Port
self.tp_name = self.ArgParameter(name)
self.tp = self.Block(TestPoint(name=StringExpr()))

def contents(self):
super().contents()
self.assign(self.tp.tp_name, (self.tp_name == "").then_else(self.io.link().name(), self.tp_name))


class VoltageTestPoint(BaseTypedTestPoint, Block):
"""Test point with a VoltageSink port."""
def __init__(self, *args):
super().__init__(*args)
self.io = self.Port(VoltageSink.empty(), [InOut])
self.tp = self.Block(TestPoint(name=self.io.link().name()))
self.connect(self.io, self.tp.io.adapt_to(VoltageSink()))

def connected(self, io: Port[VoltageLink]) -> 'VoltageTestPoint':
cast(Block, builder.get_enclosing_block()).connect(io, self.io)
return self


class DigitalTestPoint(TypedTestPoint, Block):
class DigitalTestPoint(BaseTypedTestPoint, Block):
"""Test point with a DigitalSink port."""
def __init__(self):
super().__init__()
def __init__(self, *args):
super().__init__(*args)
self.io = self.Port(DigitalSink.empty(), [InOut])
self.tp = self.Block(TestPoint(name=self.io.link().name()))
self.connect(self.io, self.tp.io.adapt_to(DigitalSink()))

def connected(self, io: Port[DigitalLink]) -> 'DigitalTestPoint':
Expand All @@ -45,25 +58,30 @@ def connected(self, io: Port[DigitalLink]) -> 'DigitalTestPoint':

class DigitalArrayTestPoint(TypedTestPoint, GeneratorBlock):
"""Creates an array of Digital test points, sized from the port array's connections."""
def __init__(self):
@init_in_parent
def __init__(self, name: StringLike = ''):
super().__init__()
self.io = self.Port(Vector(DigitalSink.empty()), [InOut])
self.generator_param(self.io.requested())
self.tp_name = self.ArgParameter(name)
self.generator_param(self.io.requested(), self.tp_name)

def generate(self):
super().generate()
self.tp = ElementDict[DigitalTestPoint]()
for requested in self.get(self.io.requested()):
tp = self.tp[requested] = self.Block(DigitalTestPoint())
# TODO: link() on Vector is not supported, so we leave the naming to the leaf link in the leaf test point
if self.get(self.tp_name) == '':
tp = self.tp[requested] = self.Block(DigitalTestPoint())
else:
tp = self.tp[requested] = self.Block(DigitalTestPoint(self.tp_name + f'.{requested}'))
self.connect(self.io.append_elt(DigitalSink.empty(), requested), tp.io)


class AnalogTestPoint(TypedTestPoint, Block):
class AnalogTestPoint(BaseTypedTestPoint, Block):
"""Test point with a AnalogSink port."""
def __init__(self):
super().__init__()
def __init__(self, *args):
super().__init__(*args)
self.io = self.Port(AnalogSink.empty(), [InOut])
self.tp = self.Block(TestPoint(name=self.io.link().name()))
self.connect(self.io, self.tp.io.adapt_to(AnalogSink()))

def connected(self, io: Port[AnalogLink]) -> 'AnalogTestPoint':
Expand All @@ -73,12 +91,18 @@ def connected(self, io: Port[AnalogLink]) -> 'AnalogTestPoint':

class I2cTestPoint(TypedTestPoint, Block):
"""Two test points for I2C SDA and SCL"""
def __init__(self):
@init_in_parent
def __init__(self, name: StringLike = ""):
super().__init__()
self.io = self.Port(I2cTarget(DigitalBidir.empty()), [InOut])
self.tp_scl = self.Block(DigitalTestPoint())
self.tp_name = self.ArgParameter(name)

def contents(self):
super().contents()
name_prefix = (self.tp_name == '').then_else(self.io.link().name(), self.tp_name)
self.tp_scl = self.Block(DigitalTestPoint(name_prefix + '.scl'))
self.tp_sda = self.Block(DigitalTestPoint(name_prefix + '.sda'))
self.connect(self.tp_scl.io, self.io.scl)
self.tp_sda = self.Block(DigitalTestPoint())
self.connect(self.tp_sda.io, self.io.sda)

def connected(self, io: Port[I2cLink]) -> 'I2cTestPoint':
Expand All @@ -88,12 +112,18 @@ def connected(self, io: Port[I2cLink]) -> 'I2cTestPoint':

class CanControllerTestPoint(TypedTestPoint, Block):
"""Two test points for CAN controller-side TXD and RXD"""
def __init__(self):
@init_in_parent
def __init__(self, name: StringLike = ""):
super().__init__()
self.io = self.Port(CanPassivePort(DigitalBidir.empty()), [InOut])
self.tp_txd = self.Block(DigitalTestPoint())
self.tp_name = self.ArgParameter(name)

def contents(self):
super().contents()
name_prefix = (self.tp_name == '').then_else(self.io.link().name(), self.tp_name)
self.tp_txd = self.Block(DigitalTestPoint(name_prefix + '.txd'))
self.tp_rxd = self.Block(DigitalTestPoint(name_prefix + '.rxd'))
self.connect(self.tp_txd.io, self.io.txd)
self.tp_rxd = self.Block(DigitalTestPoint())
self.connect(self.tp_rxd.io, self.io.rxd)

def connected(self, io: Port[CanLogicLink]) -> 'CanControllerTestPoint':
Expand Down
2 changes: 1 addition & 1 deletion examples/BldcController/BldcController.net
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
(sheetpath (names "/i2c_tp/") (tstamps "/07770242/"))
(tstamps "08f50286"))
(comp (ref "i2c_tp.tp_sda")
(value "i2c_tp._io_sda_link")
(value "_mcu_i2c_i2c_link.sda")
(footprint "edg:TestPoint_TE_RCT_0805")
(property (name "Sheetname") (value "i2c_tp"))
(property (name "Sheetfile") (value "electronics_abstract_parts.AbstractTestPoint.I2cTestPoint"))
Expand Down
2 changes: 1 addition & 1 deletion examples/IotKnob/IotKnob.net
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
(sheetpath (names "/i2c_tp/") (tstamps "/07770242/"))
(tstamps "08f50286"))
(comp (ref "i2c_tp.tp_sda")
(value "i2c_tp._io_sda_link")
(value "i2c_chain_0.sda")
(footprint "edg:TestPoint_TE_RCT_0805")
(property (name "Sheetname") (value "i2c_tp"))
(property (name "Sheetfile") (value "electronics_abstract_parts.AbstractTestPoint.I2cTestPoint"))
Expand Down
2 changes: 1 addition & 1 deletion examples/RobotCrawler/RobotCrawler.net
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@
(sheetpath (names "/i2c_tp/") (tstamps "/07770242/"))
(tstamps "08f50286"))
(comp (ref "i2c_tp.tp_sda")
(value "i2c_tp._io_sda_link")
(value "i2c_chain_0.sda")
(footprint "edg:TestPoint_TE_RCT_0805")
(property (name "Sheetname") (value "i2c_tp"))
(property (name "Sheetfile") (value "electronics_abstract_parts.AbstractTestPoint.I2cTestPoint"))
Expand Down
2 changes: 1 addition & 1 deletion examples/RobotDriver/RobotDriver.net
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@
(sheetpath (names "/i2c_tp/") (tstamps "/07770242/"))
(tstamps "08f50286"))
(comp (ref "i2c_tp.tp_sda")
(value "i2c_tp._io_sda_link")
(value "i2c_chain_0.sda")
(footprint "edg:TestPoint_TE_RCT_0805")
(property (name "Sheetname") (value "i2c_tp"))
(property (name "Sheetfile") (value "electronics_abstract_parts.AbstractTestPoint.I2cTestPoint"))
Expand Down
2 changes: 1 addition & 1 deletion examples/RobotDriver3/RobotDriver3.net
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
(sheetpath (names "/i2c_tp/") (tstamps "/07770242/"))
(tstamps "08f50286"))
(comp (ref "i2c_tp.tp_sda")
(value "i2c_tp._io_sda_link")
(value "i2c_chain_0.sda")
(footprint "edg:TestPoint_TE_RCT_0805")
(property (name "Sheetname") (value "i2c_tp"))
(property (name "Sheetfile") (value "electronics_abstract_parts.AbstractTestPoint.I2cTestPoint"))
Expand Down
2 changes: 1 addition & 1 deletion examples/SevenSegment/SevenSegment.net
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@
(sheetpath (names "/i2c_tp/") (tstamps "/07770242/"))
(tstamps "08f50286"))
(comp (ref "i2c_tp.tp_sda")
(value "i2c_tp._io_sda_link")
(value "i2c_chain_0.sda")
(footprint "edg:TestPoint_TE_RCT_0805")
(property (name "Sheetname") (value "i2c_tp"))
(property (name "Sheetfile") (value "electronics_abstract_parts.AbstractTestPoint.I2cTestPoint"))
Expand Down
2 changes: 1 addition & 1 deletion examples/TofArray/TofArray.net
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@
(sheetpath (names "/i2c_tp/") (tstamps "/07770242/"))
(tstamps "08f50286"))
(comp (ref "i2c_tp.tp_sda")
(value "i2c_tp._io_sda_link")
(value "i2c_chain_0.sda")
(footprint "TestPoint:TestPoint_Keystone_5015_Micro-Minature")
(property (name "Sheetname") (value "i2c_tp"))
(property (name "Sheetfile") (value "electronics_abstract_parts.AbstractTestPoint.I2cTestPoint"))
Expand Down
Loading