Skip to content

Commit

Permalink
Add new print feature (#225)
Browse files Browse the repository at this point in the history
* print support and minor cleaning

* fix auto complete for Bel print

* Fix super tile print

* lint

* More lint

* Remove used import

---------

Co-authored-by: King Lok Chung <[email protected]>
  • Loading branch information
KelvinChung2000 and King Lok Chung authored Aug 9, 2024
1 parent 39d7b81 commit ea1013c
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 165 deletions.
218 changes: 57 additions & 161 deletions FABulous/FABulous.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import os
import pickle
import platform
import pprint
import readline
import shutil
import subprocess as sp
Expand Down Expand Up @@ -567,23 +568,68 @@ def do_load_fabric(self, args=""):
logger.info("Complete")

def complete_load_fabric(self, text, *ignored):
"""Autocompletes file path to load fabric command.
return self._complete_path(text)

def do_print_bel(self, args):
"""Prints a Bel object to the console.
Usage:
print_bel <bel_name>
Parameters
----------
text : str
Current text input to autocomplete.
*ignored : tuple
Ignored additional arguments.
args : str
Name of the Bel object to print.
"""
args = self.parse(args)
if len(args) != 1:
logger.error("Please provide a Bel name")
return

Returns
-------
List[str]
List of possible file path completions.
if not self.fabricLoaded:
logger.error("Need to load fabric first")
return

bels = self.fabricGen.getBels()
for i in bels:
if i.name == args[0]:
logger.info(f"\n{pprint.pformat(i, width=200)}")
return
logger.error("Bel not found")

def complete_print_bel(self, text, *ignored):
return [i.name for i in self.fabricGen.getBels() if i.name.startswith(text)]

def do_print_tile(self, args):
"""Prints a tile object to the console.
Usage:
print_tile <tile_name>
Parameters
----------
args : str
Name of the tile object to print.
"""
return self._complete_path(text)
args = self.parse(args)
if len(args) != 1:
logger.error("Please provide a tile name")
return

if not self.fabricLoaded:
logger.error("Need to load fabric first")
return

if tile := self.fabricGen.getTile(args[0]):
logger.info(f"\n{pprint.pformat(tile, width=200)}")
elif tile := self.fabricGen.getSuperTile(args[0]):
logger.info(f"\n{pprint.pformat(tile, width=200)}")
else:
logger.error("Tile not found")

def complete_print_tile(self, text, *ignored):
return self._complete_tileName(text)

# TODO REMOVE once have transition the model gen to object based
def do_set_fabric_csv(self, args):
"""Sets the CSV file to be used for fabric generation.
Expand All @@ -599,20 +645,6 @@ def do_set_fabric_csv(self, args):
self.csvFile = args[0]

def complete_set_fabric_csv(self, text, *ignored):
"""Autocomplete file path for the set fabric CSV command.
Parameters
----------
text : str
The current text input to autocomplete.
*ignored : tuple
Ignores additional arguments.
Returns
-------
List[str]
List of possible file path completions.
"""
return self._complete_path(text)

def do_gen_config_mem(self, args):
Expand Down Expand Up @@ -642,20 +674,6 @@ def do_gen_config_mem(self, args):
logger.info("Generating configMem complete")

def complete_gen_config_mem(self, text, *ignored):
"""Autocompletes tile names for generate configuration memory.
Parameters
----------
text : str
Current text input to autocomplete.
*ignored : tuple
Ignores additional arguments.
Returns
-------
List[str]
List of possible tile name completions.
"""
return self._complete_tileName(text)

def do_gen_switch_matrix(self, args):
Expand Down Expand Up @@ -683,20 +701,6 @@ def do_gen_switch_matrix(self, args):
logger.info("Switch matrix generation complete")

def complete_gen_switch_matrix(self, text, *ignored):
"""Autocompletes tile names for generate switch matrix.
Parameters
----------
text : str
Current text input to autocomplete.
*ignored : tuple
Ignores additional arguments.
Returns
-------
List[str]
List of possible tile name completions.
"""
return self._complete_tileName(text)

def do_gen_tile(self, args):
Expand Down Expand Up @@ -780,20 +784,6 @@ def do_gen_tile(self, args):
logger.info("Tile generation complete")

def complete_gen_tile(self, text: str, *ignored):
"""Autocompletes tile names for generate tiles.
Parameters
----------
text : str
Current text input to be autocompleted.
*ignored : tuple
Ignores additional arguments.
Returns
-------
List[str]
List of possible tile name completions.
"""
return self._complete_tileName(text)

def do_gen_all_tile(self, *ignored):
Expand Down Expand Up @@ -1094,20 +1084,6 @@ def do_synthesis(self, args):
raise SynthesisError

def complete_synthesis(self, text, *ignored):
"""Autocompletes path for synthesis.
Parameters
----------
text : str
Current text input to be autocompleted.
*ignored : tuple
Ignores additional arguments.
Returns
-------
List[str]
List of possible path name completions.
"""
return self._complete_path(text)

def do_place_and_route(self, args):
Expand Down Expand Up @@ -1210,20 +1186,6 @@ def do_place_and_route(self, args):
raise FileNotFoundError

def complete_place_and_route(self, text, *ignored):
"""Autocompletes path for Nextpnr place and route.
Parameters
----------
text : str
Current text input to be autocompleted.
*ignored : tuple
Ignores additional arguments.
Returns
-------
List[str]
List of possible path name completions.
"""
return self._complete_path(text)

def do_gen_bitStream_binary(self, args):
Expand Down Expand Up @@ -1292,20 +1254,6 @@ def do_gen_bitStream_binary(self, args):
logger.info("Bitstream generated")

def complete_gen_bitStream_binary(self, text, *ignored):
"""Autocompletes path for bitstream generation.
Parameters
----------
text : str
Current text input to be autocompleted.
*ignored : tuple
Ignores additional arguments.
Returns
-------
List[str]
List of possible path name completions.
"""
return self._complete_path(text)

def do_run_simulation(self, args):
Expand Down Expand Up @@ -1430,20 +1378,6 @@ def do_run_simulation(self, args):
logger.info("Simulation finished")

def complete_run_simulation(self, text, *ignored):
"""Autocompletes path for simulation.
Parameters
----------
text : str
Current text input to be autocompleted.
*ignored : tuple
Ignores additional arguments.
Returns
-------
List[str]
List of possible path name completions.
"""
return self._complete_path(text)

def do_run_FABulous_bitstream(self, *args):
Expand All @@ -1458,10 +1392,6 @@ def do_run_FABulous_bitstream(self, *args):
Usage:
run_FABulous_bitstream <top_module_file>
Returns
-------
Int
returns 0 if process is completed successfully.
"""
if len(args) != 1:
logger.error("Usage: run_FABulous_bitstream <top_module_file>")
Expand All @@ -1486,25 +1416,7 @@ def do_run_FABulous_bitstream(self, *args):
self.do_place_and_route(str(json_file_path))
self.do_gen_bitStream_binary(str(fasm_file_path))

return 0

def complete_run_FABulous_bitstream(self, text, line, *ignored):
"""Autocompletes path for run_FABulous_bitstream.
Parameters
----------
text :str
Current text input being autocomplete.
line : str
Entire command line input.
*ignored : tuple
Ignores additional arguments.
Returns
-------
List[str]
List of possible path name completions.
"""
return self._complete_path(text)

def do_tcl(self, args):
Expand Down Expand Up @@ -1543,22 +1455,6 @@ def do_tcl(self, args):
logger.info("TCL script executed")

def complete_tcl(self, text, *ignored):
"""Autocompletes path for tcl script execution.
Parameters
----------
text :str
Current text input being autocompleted.
line : str
Entire command line input.
*ignored : tuple
Ignores additional arguments.
Returns
-------
List[str]
List of possible path name completions.
"""
return self._complete_path(text)


Expand Down
62 changes: 62 additions & 0 deletions FABulous/FABulous_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import FABulous.fabric_cad.model_generation_npnr as model_gen_npnr

# Importing Modules from FABulous Framework.
from FABulous.fabric_definition.Bel import Bel
from FABulous.fabric_definition.SuperTile import SuperTile
from FABulous.fabric_definition.Tile import Tile
import FABulous.fabric_generator.code_generator as codeGen
import FABulous.fabric_generator.file_parser as fileParser
from FABulous.fabric_definition.Fabric import Fabric
Expand Down Expand Up @@ -211,3 +214,62 @@ def genRoutingModel(self):
Model generated by 'model_gen_npnr.genNextpnrModel'.
"""
return model_gen_npnr.genNextpnrModel(self.fabric)

def getBels(self) -> list[Bel]:
"""Returns all unique Bels within a fabric.
Returns
-------
Bel
Bel object based on bel name.
"""
return self.fabric.getAllUniqueBels()

def getTile(self, tileName: str) -> Tile | None:
"""Returns Tile object based on tile name.
Parameters
----------
tileName : str
Name of the Tile.
Returns
-------
Tile
Tile object based on tile name.
"""

return self.fabric.getTileByName(tileName)

def getTiles(self):
"""Returns all Tiles within a fabric.
Returns
-------
Tile
Tile object based on tile name.
"""
return self.fabric.tileDic.values()

def getSuperTile(self, tileName: str) -> SuperTile | None:
"""Returns SuperTile object based on tile name.
Parameters
----------
tileName : str
Name of the SuperTile.
Returns
-------
SuperTile
SuperTile object based on tile name.
"""

return self.fabric.getSuperTileByName(tileName)

def getSuperTiles(self):
"""Returns all SuperTiles within a fabric.
Returns
-------
SuperTile
SuperTile object based on tile name.
"""
return self.fabric.superTileDic.values()
Loading

0 comments on commit ea1013c

Please sign in to comment.