Skip to content

Commit

Permalink
* Added the pytest plugin for poetry run
Browse files Browse the repository at this point in the history
* Updated the create valve code to use the mintdevice method instead of using parchmint api
* Autoformatted `mintcompler.py` code
  • Loading branch information
rkrishnasanka committed Oct 23, 2023
1 parent 3da7cf6 commit dc4959b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 49 deletions.
74 changes: 25 additions & 49 deletions pymint/mintcompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pymint.antlrgen.mintParser import mintParser
from pymint.mintdevice import MINTDevice
from pymint.mintlayer import MINTLayerType
from parchmint.device import ValveType


class MINTCompiler(mintListener):
Expand All @@ -33,9 +34,7 @@ def exitNetlist(self, ctx: mintParser.NetlistContext):

def enterHeader(self, ctx: mintParser.HeaderContext):
if self.current_device is None:
raise Exception(
"Error Initializing the device. Could not find the current device"
)
raise Exception("Error Initializing the device. Could not find the current device")

if ctx.device_name is None:
raise Exception("Could not find Device Name")
Expand All @@ -47,9 +46,7 @@ def exitLayerBlock(self, ctx: mintParser.LayerBlockContext):

def enterFlowBlock(self, ctx: mintParser.FlowBlockContext):
if self.current_device is None:
raise Exception(
"Error Initializing the device. Could not find the current device"
)
raise Exception("Error Initializing the device. Could not find the current device")
layer = self.current_device.create_mint_layer(
str(self.current_layer_id),
str(self.flow_layer_count),
Expand All @@ -62,9 +59,7 @@ def enterFlowBlock(self, ctx: mintParser.FlowBlockContext):

def enterControlBlock(self, ctx: mintParser.ControlBlockContext):
if self.current_device is None:
raise Exception(
"Error Initializing the device. Could not find the current device"
)
raise Exception("Error Initializing the device. Could not find the current device")

layer = self.current_device.create_mint_layer(
str(self.current_layer_id),
Expand All @@ -78,9 +73,7 @@ def enterControlBlock(self, ctx: mintParser.ControlBlockContext):

def enterIntegrationBlock(self, ctx: mintParser.IntegrationBlockContext):
if self.current_device is None:
raise Exception(
"Error Initializing the device. Could not find the current device"
)
raise Exception("Error Initializing the device. Could not find the current device")

layer = self.current_device.create_mint_layer(
str(self.current_layer_id),
Expand Down Expand Up @@ -141,9 +134,7 @@ def enterControlStat(self, ctx: mintParser.ControlStatContext):

def exitPrimitiveStat(self, ctx: mintParser.PrimitiveStatContext):
if self.current_device is None:
raise Exception(
"Error Initializing the device. Could not find the current device"
)
raise Exception("Error Initializing the device. Could not find the current device")

entity = self.current_entity
if entity is None:
Expand All @@ -153,9 +144,7 @@ def exitPrimitiveStat(self, ctx: mintParser.PrimitiveStatContext):
for ufname in ctx.ufnames().ufname(): # type: ignore
if self._current_layer is None:
raise Exception("Current layer is set to None")
if not (
self._current_layer is not None and self._current_layer.ID is not None
):
if not (self._current_layer is not None and self._current_layer.ID is not None):
raise AssertionError
self.current_device.create_mint_component(
ufname.getText(),
Expand Down Expand Up @@ -200,19 +189,15 @@ def exitBankGenStat(self, ctx: mintParser.BankGenStatContext):
component_name = name + "_" + str(i)
if self._current_layer is None:
raise Exception("Current Layer not Set")
if not (
self._current_layer is not None and self._current_layer.ID is not None
):
if not (self._current_layer is not None and self._current_layer.ID is not None):
raise AssertionError
self.current_device.create_mint_component(
component_name, entity, self.current_params, [self._current_layer.ID]
)

def exitGridDeclStat(self, ctx: mintParser.GridDeclStatContext):
if self.current_device is None:
raise Exception(
"Error Initializing the device. Could not find the current device"
)
raise Exception("Error Initializing the device. Could not find the current device")

entity = self.current_entity
if entity is None:
Expand All @@ -233,9 +218,7 @@ def exitGridDeclStat(self, ctx: mintParser.GridDeclStatContext):

def exitChannelStat(self, ctx: mintParser.ChannelStatContext):
if self.current_device is None:
raise Exception(
"Error Initializing the device. Could not find the current device"
)
raise Exception("Error Initializing the device. Could not find the current device")

entity = self.current_entity
if entity is None:
Expand Down Expand Up @@ -326,9 +309,7 @@ def exitNetStat(self, ctx: mintParser.NetStatContext):

def exitSpanStat(self, ctx: mintParser.SpanStatContext):
if self.current_device is None:
raise Exception(
"Error Initializing the device. Could not find the current device"
)
raise Exception("Error Initializing the device. Could not find the current device")

entity = self.current_entity
if entity is None:
Expand Down Expand Up @@ -356,9 +337,7 @@ def exitSpanStat(self, ctx: mintParser.SpanStatContext):
def exitNodeStat(self, ctx: mintParser.NodeStatContext):
entity = "NODE"
if self.current_device is None:
raise Exception(
"Error Initializing the device. Could not find the current device"
)
raise Exception("Error Initializing the device. Could not find the current device")

# Loop for each of the components that need to be created with this param
if not (self._current_layer is not None and self._current_layer.ID is not None):
Expand All @@ -373,9 +352,7 @@ def exitNodeStat(self, ctx: mintParser.NodeStatContext):

def exitValveStat(self, ctx: mintParser.ValveStatContext):
if self.current_device is None:
raise Exception(
"Error Initializing the device. Could not find the current device"
)
raise Exception("Error Initializing the device. Could not find the current device")

entity = self.current_entity
if entity is None:
Expand All @@ -384,12 +361,8 @@ def exitValveStat(self, ctx: mintParser.ValveStatContext):
valve_name = ctx.ufname()[0].getText() # type: ignore
if not (self._current_layer is not None and self._current_layer.ID is not None):
raise AssertionError
valve_component = self.current_device.create_mint_component(
valve_name,
entity,
self.current_params,
[self._current_layer.ID],
)

# Get the connection information
connection_name = ctx.ufname()[1].getText() # type: ignore
valve_connection = self.current_device.device.get_connection(connection_name)
if valve_connection is None:
Expand All @@ -399,22 +372,25 @@ def exitValveStat(self, ctx: mintParser.ValveStatContext):
)
)

self.current_device.device.map_valve(valve_component, valve_connection)
self.current_device.create_valve(
name=valve_name,
technology=entity,
params=self.current_params,
layer_ids=[self._current_layer.ID],
connection=valve_connection,
valve_type=ValveType.NORMALLY_OPEN,
)

def enterViaStat(self, ctx: mintParser.ViaStatContext):
if self.current_device is None:
raise Exception(
"Error Initializing the device. Could not find the current device"
)
raise Exception("Error Initializing the device. Could not find the current device")

for ufname in ctx.ufnames().ufname():
self.current_device.add_via(ufname.getText(), [])

def enterTerminalStat(self, ctx: mintParser.TerminalStatContext):
if self.current_device is None:
raise Exception(
"Error Initializing the device. Could not find the current device"
)
raise Exception("Error Initializing the device. Could not find the current device")

terminal_name = ctx.ufname().getText()
pin_number = int(ctx.INT.getText())
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ docs = ["sphinx"]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
minversion = "6.0"
testpaths = [
"./tests/"
]

0 comments on commit dc4959b

Please sign in to comment.