Skip to content

Commit

Permalink
Merge branch 'master' into lekcyjna/add-pytest-2
Browse files Browse the repository at this point in the history
  • Loading branch information
lekcyjna123 authored Mar 6, 2024
2 parents f7c5fdf + 903ab2e commit 1b97828
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 200 deletions.
8 changes: 0 additions & 8 deletions coreblocks/frontend/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ def __init__(self, gen_params: GenParams, icache: CacheInterface, cont: Method)
# ExceptionCauseRegister uses separate Transaction for it, so performace is not affected.
self.stall_exception.add_conflict(self.resume, Priority.LEFT)

# PC of the last fetched instruction. For now only used in tests.
self.pc = Signal(self.gen_params.isa.xlen)

def elaborate(self, platform):
m = TModule()

Expand Down Expand Up @@ -91,7 +88,6 @@ def stall(exception=False):
with m.If(unsafe_instr):
stall()

m.d.sync += self.pc.eq(target.addr)
m.d.comb += instr.eq(res.instr)

self.cont(m, instr=instr, pc=target.addr, access_fault=fetch_error, rvc=0)
Expand Down Expand Up @@ -138,9 +134,6 @@ def __init__(self, gen_params: GenParams, icache: CacheInterface, cont: Method)

self.perf_rvc = HwCounter("frontend.ifu.rvc", "Number of decompressed RVC instructions")

# PC of the last fetched instruction. For now only used in tests.
self.pc = Signal(self.gen_params.isa.xlen)

def elaborate(self, platform) -> TModule:
m = TModule()

Expand Down Expand Up @@ -231,7 +224,6 @@ def elaborate(self, platform) -> TModule:
m.d.sync += stalled_unsafe.eq(1)
m.d.sync += flushing.eq(1)

m.d.sync += self.pc.eq(current_pc)
with m.If(~cache_resp.error):
m.d.sync += current_pc.eq(current_pc + Mux(is_rvc, C(2, 3), C(4, 3)))

Expand Down
144 changes: 144 additions & 0 deletions stubs/amaranth/_toolchain/yosys.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
"""
This type stub file was generated by pyright.
"""

__all__ = ["YosysError", "YosysBinary", "find_yosys"]
from typing import Optional
from pathlib import Path


class YosysError(Exception):
...


class YosysWarning(Warning):
...


class YosysBinary:
@classmethod
def available(cls) -> bool:
"""Check for Yosys availability.
Returns
-------
available : bool
``True`` if Yosys is installed, ``False`` otherwise. Installed binary may still not
be runnable, or might be too old to be useful.
"""
...

@classmethod
def version(cls) -> Optional[tuple[int, int, int]]:
"""Get Yosys version.
Returns
-------
``None`` if version number could not be determined, or a 3-tuple ``(major, minor, distance)`` if it could.
major : int
Major version.
minor : int
Minor version.
distance : int
Distance to last tag per ``git describe``. May not be exact for system Yosys.
"""
...

@classmethod
def data_dir(cls) -> pathlib.Path:
"""Get Yosys data directory.
Returns
-------
data_dir : pathlib.Path
Yosys data directory (also known as "datdir").
"""
...

@classmethod
def run(cls, args: list[str], stdin: str=...) -> str:
"""Run Yosys process.
Parameters
----------
args : list of str
Arguments, not including the program name.
stdin : str
Standard input.
Returns
-------
stdout : str
Standard output.
Exceptions
----------
YosysError
Raised if Yosys returns a non-zero code. The exception message is the standard error
output.
"""
...



class _BuiltinYosys(YosysBinary):
YOSYS_PACKAGE = ...
@classmethod
def available(cls): # -> bool:
...

@classmethod
def version(cls): # -> tuple[int, int, int]:
...

@classmethod
def data_dir(cls): # -> Traversable:
...

@classmethod
def run(cls, args, stdin=..., *, ignore_warnings=..., src_loc_at=...):
...



class _SystemYosys(YosysBinary):
YOSYS_BINARY = ...
@classmethod
def available(cls): # -> bool:
...

@classmethod
def version(cls): # -> tuple[int, int, int] | None:
...

@classmethod
def data_dir(cls): # -> Path:
...

@classmethod
def run(cls, args, stdin=..., *, ignore_warnings=..., src_loc_at=...):
...



def find_yosys(requirement):
"""Find an available Yosys executable of required version.
Parameters
----------
requirement : function
Version check. Should return ``True`` if the version is acceptable, ``False`` otherwise.
Returns
-------
yosys_binary : subclass of YosysBinary
Proxy for running the requested version of Yosys.
Exceptions
----------
YosysError
Raised if required Yosys version is not found.
"""
...

4 changes: 4 additions & 0 deletions stubs/amaranth/back/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
This type stub file was generated by pyright.
"""

14 changes: 14 additions & 0 deletions stubs/amaranth/back/verilog.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
This type stub file was generated by pyright.
"""

from .._toolchain.yosys import *
from ..hdl.ast import SignalDict

__all__ = ["YosysError", "convert", "convert_fragment"]
def convert_fragment(*args, strip_internal_attrs=..., **kwargs) -> tuple[str, SignalDict]:
...

def convert(elaboratable, name=..., platform=..., *, ports=..., emit_src=..., strip_internal_attrs=..., **kwargs) -> str:
...

13 changes: 13 additions & 0 deletions test/regression/cocotb.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ def get_cocotb_handle(self, path_components: list[str]) -> ModifiableObject:

return obj

async def assert_handler(self, clock):
clock_edge_event = FallingEdge(clock)

while True:
for assert_info in self.gen_info.asserts:
assert_val = self.get_cocotb_handle(assert_info.location)
n, i = assert_info.src_loc
assert assert_val.value, f"Assertion at {n}:{i}"

await clock_edge_event # type: ignore

async def run(self, mem_model: CoreMemoryModel, timeout_cycles: int = 5000) -> SimulationExecutionResult:
clk = Clock(self.dut.clk, 1, "ns")
cocotb.start_soon(clk.start())
Expand All @@ -171,6 +182,8 @@ async def run(self, mem_model: CoreMemoryModel, timeout_cycles: int = 5000) -> S
data_wb = WishboneSlave(self.dut, "wb_data", self.dut.clk, mem_model, is_instr_bus=False)
cocotb.start_soon(data_wb.start())

cocotb.start_soon(self.assert_handler(self.dut.clk))

success = True
try:
await with_timeout(self.finish_event.wait(), timeout_cycles, "ns")
Expand Down
Loading

0 comments on commit 1b97828

Please sign in to comment.