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

Add start_FABulator command to be able to run FABulator from the FABulous shell #227

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
61 changes: 55 additions & 6 deletions FABulous/FABulous.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
MAX_BITBYTES = 16384


def setup_logger(detailed: bool):
def setup_logger(verbosity: int):
# Remove the default logger to avoid duplicate logs
logger.remove()

# Define logger format
if detailed:
if verbosity >= 1:
log_format = (
"<level>{level:}</level> | "
"<cyan>[{time:DD-MM-YYYY HH:mm:ss]}</cyan> | "
Expand Down Expand Up @@ -310,6 +310,7 @@ def __init__(self, fab: FABulous, projectDir: str, script: str = ""):
self.superTiles = []
self.csvFile = ""
self.script = script
self.verbose = False
if isinstance(self.fabricGen.writer, VHDLWriter):
self.extension = "vhdl"
else:
Expand Down Expand Up @@ -823,7 +824,7 @@ def do_gen_fabric(self, *ignored):
logger.info("Fabric generation complete")

def do_gen_geometry(self, *vargs):
"""Generates geometry of fabric for the FABulous editor by checking if fabric
"""Generates geometry of fabric for FABulator by checking if fabric
is loaded, and calling 'genGeometry' and passing on padding value. Default
padding is '8'.

Expand Down Expand Up @@ -869,10 +870,55 @@ def do_gen_geometry(self, *vargs):
if 4 <= padding <= 32:
self.fabricGen.genGeometry(padding)
logger.info("Geometry generation complete")
logger.info(f"{geomFile} can now be imported into the FABulous Editor")
logger.info(f"{geomFile} can now be imported into FABulator")
else:
logger.error("padding has to be between 4 and 32 inclusively!")

def do_start_FABulator(self, *ignored):
"""Starts FABulator if an installation can be found.
If no installation can be found, a warning is produced.

Usage:
start_FABulator

Parameters
----------
*ignored : tuple
Ignores additional arguments.

"""
logger.info("Checking for FABulator installation")
fabulatorRoot = os.getenv("FABULATOR_ROOT")

if fabulatorRoot is None:
logger.warning("FABULATOR_ROOT environment variable not set.")
logger.warning(
"Install FABulator (https://github.com/FPGA-Research-Manchester/FABulator) "
"and set the FABULATOR_ROOT environment variable to the root directory to use this feature."
)
return

if not os.path.exists(fabulatorRoot):
logger.error(
f"FABULATOR_ROOT environment variable set to {fabulatorRoot} but the directory does not exist."
)
JakobTernes marked this conversation as resolved.
Show resolved Hide resolved
return

logger.info(f"Found FABulator installation at {fabulatorRoot}")
logger.info(f"Trying to start FABulator...")

startupCmd = ["mvn", "-f", f"{fabulatorRoot}/pom.xml", "javafx:run"]
try:
if self.verbose:
# log FABulator output to the FABulous shell
sp.Popen(startupCmd)
else:
# discard FABulator output
sp.Popen(startupCmd, stdout=sp.DEVNULL, stderr=sp.DEVNULL)

except sp.SubprocessError:
logger.error("Startup of FABulator failed.")

def do_gen_bitStream_spec(self, *ignored):
"""Generates bitstream specification of the fabric by calling
'genBitStreamspec' and saving the specification to a binary and CSV file.
Expand Down Expand Up @@ -1536,8 +1582,9 @@ def main():
"-v",
"--verbose",
default=False,
action="store_true",
help="Show detailed log information including function and line number",
action="count",
help="Show detailed log information including function and line number. For -vv additionally output from "
"FABulator is logged to the shell for the start_FABulator command",
)

args = parser.parse_args()
Expand Down Expand Up @@ -1565,6 +1612,8 @@ def main():
fabShell = FABulousShell(
FABulous(writer, fabricCSV=args.csv), args.project_dir, args.script
)
if args.verbose == 2:
fabShell.verbose = True

if args.metaDataDir:
metaDataDir = args.metaDataDir
Expand Down
2 changes: 1 addition & 1 deletion FABulous/geometry_generator/geometry_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ def generateGeometry(self, padding: int = 8) -> None:

def saveToCSV(self, fileName: str) -> None:
"""Saves the generated geometry into a file specified by the given file name.
This file can then be imported into the FABulous Editor.
This file can then be imported into FABulator.
"""
self.fabricGeometry.saveToCSV(fileName)
Loading