Add support for user-extending cpuif for PeakRDL command-line

This commit is contained in:
Alex Mykyta
2022-11-08 22:10:35 -08:00
parent 232faba417
commit 17afaf13ff
3 changed files with 67 additions and 2 deletions

View File

@@ -1,15 +1,15 @@
from typing import TYPE_CHECKING
from .exporter import RegblockExporter
from .cpuif import apb3, apb4, axi4lite, passthrough
from .cpuif import apb3, apb4, axi4lite, passthrough, CpuifBase
from .udps import ALL_UDPS
from . import entry_points
if TYPE_CHECKING:
import argparse
from systemrdl.node import AddrmapNode
# TODO: make this user-extensible
CPUIF_DICT = {
"apb3": apb3.APB3_Cpuif,
"apb3-flat": apb3.APB3_Cpuif_flattened,
@@ -20,6 +20,16 @@ CPUIF_DICT = {
"passthrough": passthrough.PassthroughCpuif
}
# Load any user-plugins
for ep in entry_points.get_entry_points("peakrdl_regblock.cpuif"): # type: ignore
name = ep.name
cpuif = ep.load()
if name in CPUIF_DICT:
raise RuntimeError(f"A plugin for 'peakrdl-regblock' tried to load cpuif '{name}' but it already exists")
if not issubclass(cpuif, CpuifBase):
raise RuntimeError(f"A plugin for 'peakrdl-regblock' tried to load cpuif '{name}' but it not a CpuifBase class")
CPUIF_DICT[name] = cpuif
class Exporter:
short_desc = "Generate a SystemVerilog control/status register (CSR) block"

View File

@@ -0,0 +1,19 @@
# type: ignore
import sys
if sys.version_info >= (3,10,0):
from importlib import metadata
def get_entry_points(group_name):
return metadata.entry_points().select(group=group_name)
elif sys.version_info >= (3,8,0):
from importlib import metadata
def get_entry_points(group_name):
return metadata.entry_points().get(group_name, tuple())
else:
import pkg_resources
def get_entry_points(group_name):
return pkg_resources.iter_entry_points(group_name)