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

Cover #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
53 changes: 53 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import mill._
import mill.scalalib.TestModule.Utest
import mill.scalalib._
import mill.scalalib.scalafmt._
import $ivy.`com.lihaoyi::mill-contrib-jmh:`
import contrib.jmh.JmhModule
import $file.rvdecoderdb.common
import os.Path

object v {
Expand All @@ -14,6 +17,7 @@ object v {
val utest = ivy"com.lihaoyi::utest:0.8.4"
val sourcecode = ivy"com.lihaoyi::sourcecode:0.4.2"
val pprint = ivy"com.lihaoyi::pprint:0.9.0"
val jmh = "1.35"
}

object zaozi extends ScalaModule with ScalafmtModule { m =>
Expand Down Expand Up @@ -41,6 +45,11 @@ object zaozi extends ScalaModule with ScalafmtModule { m =>
}
}

object benchmark extends ScalaModule with JmhModule {
def scalaVersion = T(v.scala)
def jmhCoreVersion = T(v.jmh)
}

object tests extends ScalaTests with ScalafmtModule with Utest {
def ivyDeps = Agg(v.utest)

Expand Down Expand Up @@ -295,3 +304,47 @@ trait PanamaModule extends JavaModule {

def jextractBinary: Target[Path]
}

object rvdecoderdb extends RVDecoderDB

trait RVDecoderDB extends common.RVDecoderDBJVMModule with ScalaModule with ScalafmtModule {
def scalaVersion = T(v.scala)
def osLibIvy = v.oslib
def upickleIvy = v.upickle

override def millSourcePath = os.pwd / "rvdecoderdb" / "rvdecoderdb"
}

object cover extends ScalaModule with ScalafmtModule { m =>
def scalaVersion = T(v.scala)
def ivyDeps = T(Seq(v.mainargs, v.oslib, v.upickle, v.sourcecode))
def moduleDeps = Seq(circtlib, rvdecoderdb)

override def scalacOptions: Target[Seq[String]] = T(super.scalacOptions() ++ Some("-Xprint-suspension"))

object lit extends ScalaModule with ScalafmtModule {
def scalaVersion = T(v.scala)
def moduleDeps = Seq(m)
override def forkArgs: T[Seq[String]] = T(
super.forkArgs() ++ circtlib.forkArgs()
)
object tests extends LitModule {
def scalaVersion: T[String] = T(m.scalaVersion())
def runClasspath: T[Seq[os.Path]] = T(lit.runClasspath().map(_.path))
def javaLibraryPath: T[Seq[os.Path]] = T(
(circtlib.libraryPaths()).map(_.path)
)
def javaHome: T[os.Path] = T(os.Path(sys.props("java.home")))
def litDir: T[os.Path] = T(millSourcePath)
def litConfigIn: T[PathRef] = T.source(millSourcePath / "lit.site.cfg.py.in")
}
}

object tests extends ScalaTests with ScalafmtModule with Utest {
def ivyDeps = Agg(v.utest)

override def forkArgs: T[Seq[String]] = T(
super.forkArgs() ++ circtlib.forkArgs()
)
}
}
23 changes: 23 additions & 0 deletions cover/src/Api.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2025 Jiuyang Liu <[email protected]>

package cover

trait Instruction {
def name: String
def attributes: Map[String, Any]
}

trait Constraint {
def apply(attributes: Map[String, Any]): Boolean
}

trait InstructionGenerator {
def instruction(name: String, count: Int): Unit

def constraint(constraint: Constraint): Unit

def build(): Seq[Instruction]

def clear(): Unit
}
15 changes: 15 additions & 0 deletions cover/tests/src/CoverTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2025 Jiuyang Liu <[email protected]>

package cover.tests

import org.chipsalliance.rvdecoderdb
import utest.*
import os.*

object RVDecoderDBTest extends TestSuite:
val tests = Tests:
test("rvdecoderdb works"):
val instTable: Iterable[rvdecoderdb.Instruction] = rvdecoderdb.instructions(os.pwd / "rvdecoderdb" / "riscv-opcodes")
assert(instTable.nonEmpty)

94 changes: 94 additions & 0 deletions nix/zaozi/cover.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2024 Jiuyang Liu <[email protected]>

{ lib
, stdenv
, fetchMillDeps
, makeWrapper
, jdk21
, mill
, circt-install
, mlir-install
, jextract-21
, lit
, scala-cli
, add-determinism
, projectDependencies
}:

let
self = stdenv.mkDerivation rec {
name = "cover";

src = with lib.fileset;
toSource {
root = ./../..;
fileset = unions [
./../../build.sc
./../../circtlib
./../../mlirlib
./../../cover
./../../rvdecoder
];
};

passthru.millDeps = fetchMillDeps {
inherit name;
src = with lib.fileset;
toSource {
root = ./../..;
fileset = unions [ ./../../build.sc ];
};
millDepsHash =
if stdenv.isDarwin then
"sha256-5wHqKYd4Gn/FKhKLHrqeGmfa8OSQO+l/cuE4BMHiKpM="
else
"sha256-MQs1o/+3Grr8aOzE1sUIEk8BAwU6JsftQaRmal0EgG4=";
nativeBuildInputs = [ projectDependencies.setupHook ];
};

passthru.editable = self.overrideAttrs (_: {
shellHook = ''
setupSubmodulesEditable
mill mill.bsp.BSP/install 0
'';
});

shellHook = ''
setupSubmodules
'';

nativeBuildInputs = [
mill
circt-install
mlir-install
jextract-21
lit
scala-cli
add-determinism
makeWrapper
passthru.millDeps.setupHook
projectDependencies.setupHook
];

env.CIRCT_INSTALL_PATH = circt-install;
env.MLIR_INSTALL_PATH = mlir-install;
env.JEXTRACT_INSTALL_PATH = jextract-21;
env.LIT_INSTALL_PATH = lit;

outputs = [ "out" ];

buildPhase = ''
mill -i '__.assembly'
'';

installPhase = ''
mkdir -p $out/share/java

add-determinism -j $NIX_BUILD_CORES out/elaborator/assembly.dest/out.jar

mv out/elaborator/assembly.dest/out.jar $out/share/java/elaborator.jar
'';
};
in
self
1 change: 1 addition & 0 deletions nix/zaozi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
{ lib, newScope, }:
lib.makeScope newScope (scope: {
zaozi-assembly = scope.callPackage ./zaozi.nix { };
cover = scope.callPackage ./cover.nix { };
})

55 changes: 55 additions & 0 deletions rvdecoderdb/common.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 Jiuyang Liu <[email protected]>

import mill._
import mill.scalalib._
import mill.scalajslib._

trait RVDecoderDBJVMModule extends ScalaModule {
override def sources: T[Seq[PathRef]] = T.sources { super.sources() ++ Some(PathRef(millSourcePath / "jvm" / "src")) }
def osLibIvy: Dep
def upickleIvy: Dep
override def ivyDeps = super.ivyDeps() ++ Some(osLibIvy) ++ Some(upickleIvy)
}

trait HasRVDecoderDBResource extends ScalaModule {
def riscvOpcodesPath: T[Option[PathRef]] = T(None)
def riscvOpcodesTar: T[Option[PathRef]] = T {
riscvOpcodesPath().map { riscvOpcodesPath =>
val tmpDir = os.temp.dir()
os.makeDir(tmpDir / "unratified")
os.walk(riscvOpcodesPath.path)
.filter(f =>
f.baseName.startsWith("rv128_") ||
f.baseName.startsWith("rv64_") ||
f.baseName.startsWith("rv32_") ||
f.baseName.startsWith("rv_") ||
f.ext == "csv"
).groupBy(_.segments.contains("unratified")).map {
case (true, fs) => fs.map(os.copy.into(_, tmpDir / "unratified"))
case (false, fs) => fs.map(os.copy.into(_, tmpDir))
}
os.proc("tar", "cf", T.dest / "riscv-opcodes.tar", ".").call(tmpDir)
PathRef(T.dest)
}
}
override def resources: T[Seq[PathRef]] = super.resources() ++ riscvOpcodesTar()
}

trait RVDecoderDBJVMTestModule extends HasRVDecoderDBResource with ScalaModule {
override def sources: T[Seq[PathRef]] = T.sources { super.sources() ++ Some(PathRef(millSourcePath / "jvm" / "src")) }
def dut: RVDecoderDBJVMModule
override def moduleDeps = super.moduleDeps ++ Some(dut)
}

trait RVDecoderDBJSModule extends ScalaJSModule {
override def sources: T[Seq[PathRef]] = T.sources { super.sources() ++ Some(PathRef(millSourcePath / "js" / "src")) }
def upickleIvy: Dep
override def ivyDeps = super.ivyDeps() ++ Some(upickleIvy)
}

trait RVDecoderDBTestJSModule extends ScalaJSModule {
override def sources: T[Seq[PathRef]] = T.sources { super.sources() ++ Some(PathRef(millSourcePath / "js" / "src")) }
def dut: RVDecoderDBJSModule
override def moduleDeps = super.moduleDeps ++ Some(dut)
}
30 changes: 30 additions & 0 deletions rvdecoderdb/riscv-opcodes/.github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Opcodes generation

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install PyYAML
run: |
pip3 install -r requirements.txt
pip3 install coverage
- name: Generate
run: coverage run ./parse.py -c -chisel -sverilog -rust -latex -spinalhdl -go "rv*" "unratified/rv*"
- name: Check C output
run: cat encoding.out.h | cpp
- name: Generate coverage
run: coverage xml
- name: Upload coverage
uses: codecov/codecov-action@v2

28 changes: 28 additions & 0 deletions rvdecoderdb/riscv-opcodes/.github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Unit tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install PyYAML
run: |
pip3 install -r requirements.txt
pip3 install coverage
- name: Test error outputs
run: coverage run -m unittest -b
- name: Generate coverage
run: coverage xml
- name: Upload coverage
uses: codecov/codecov-action@v2

13 changes: 13 additions & 0 deletions rvdecoderdb/riscv-opcodes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.*.swp
encoding.out.h
inst.chisel
inst.spinalhdl
inst.go
instr-table.tex
priv-instr-table.tex
inst.rs
inst.spinalhdl
inst.sverilog
instr_dict.yaml

__pycache__/
23 changes: 23 additions & 0 deletions rvdecoderdb/riscv-opcodes/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2022 RISC-V International

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading