Skip to content

Commit

Permalink
chore: Update Scala version to 3.8.3 and maxColumn to 100 in .scalafm…
Browse files Browse the repository at this point in the history
…t.conf
  • Loading branch information
doofin committed Sep 20, 2024
1 parent 01a4c5f commit 742ab4d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 39 deletions.
6 changes: 4 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version = "3.7.17"
version = "3.8.3"
runner.dialect = scala3
maxColumn = 90 # For my wide 30" display.
maxColumn = 100 # For my wide 30" display.
runner.dialectOverride.allowSignificantIndentation = false
runner.dialectOverride.allowQuietSyntax = true
84 changes: 62 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
# dependentChisel
This is the Master thesis : Dependent Chisel: Statically-checked hardware designs based on Chisel and Scala 3, by Yuchen du
This is the impl for Master thesis : Dependent Chisel: Statically-checked hardware designs based on Chisel and Scala 3, by Yuchen du
https://github.com/doofin/dependentChisel/blob/master/Msc_Thesis_yuchen.pdf

It uses partial dependent types in Scala 3 to provide early error message for Chisel.
It uses partial dependent types in Scala 3 to provide early error message for Chisel, a hardware description language embedded in Scala.
This allows you to identify bitwidth mismatch at compile time where IDE can show errors instantly in the editor.

## theories and related work
related work : https://github.com/doofin/dependentChisel/blob/master/resources.md

## interop with chisel

Although scala 3 can invoke scala 2.13 libraries,chisel uses scala 2 macros different from scala 3 ,making it partially incompatible.

here are some proposed ways :

rewrite all macros and make everything compat
rewrite some macros and extend some base class
write a new frontend and emit firrtl

# compile and run
This is a sbt project for Scala 3

run : `sbt run`
compile : `sbt compile`
## examples
examples like adder, etc. can be found in src/test/scala/dependentChisel/

an simple adder example:
some inline examples:

```scala
class Adder1(using GlobalInfo) extends UserModule {
Expand All @@ -34,8 +19,59 @@ an simple adder example:
y := a + b
}
```
A parameterized adder with static guarante:

```scala
class AdderParm[I <: Int: ValueOf](using GlobalInfo) extends UserModule {
val a = newInput[I]("a")
val b = newInput[I]("b")
val y = newOutput[I]("y")

y := a + b
}
```

Instantiate those modules :
```scala
class AdderComb4(using parent: GlobalInfo) extends UserModule {

val a = newInput[2]("a")
val b = newInput[2]("b")
val c = newInput[2]("c")
val d = newInput[2]("d")
val y = newOutput[2]("y")

val m1 = newMod(new AdderParm[2])
val m2 = newMod(new AdderParm[2])

m1.a := a
m1.b := b
m2.a := c
m2.b := d

y := m1.y + m2.y
}
```


## Interop with chisel
The current implementation is based on Chisel 3.5.1, which is used internally. There's no direct interop with the original Chisel, but you can probably use the generated FIRRTL for that.


Although scala 3 can invoke scala 2.13 libraries,chisel uses scala 2 macros different from scala 3 ,making it partially incompatible.

To fix the mismatch, there are several possible ways:

- Rewrite all macros and make everything compatible.
- Rewrite some macros and extend some base class.
- Write a new frontend and emit FIRRTL.

# compile and run
This is a sbt project for Scala 3

run : `sbt run`
compile : `sbt compile`

# test

many tests under src/test can be run by
sbt test
Expand All @@ -46,6 +82,10 @@ many tests under src/test can be run by

[IntelliJ](https://blog.jetbrains.com/scala/)

## theories and related work
related work : https://github.com/doofin/dependentChisel/blob/master/resources.md


## misc

with
Expand Down
19 changes: 4 additions & 15 deletions src/test/scala/dependentChisel/examples/adder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import dependentChisel.typesAndSyntax.chiselModules.*
import dependentChisel.typesAndSyntax.varDecls.newIO
import dependentChisel.codegen.compiler.*

// import dependentChisel.api.*

import dependentChisel.typesAndSyntax.varDecls.newIODym

Expand All @@ -28,10 +27,8 @@ object adder extends mainRunnable {
chiselMod2verilog(mod)
}

/* static adder
*/
/** static adder with 2 inputs and 1 output
*/
class Adder1(using GlobalInfo) extends UserModule {
val a = newIO[2](VarType.Input)
val b = newIO[2](VarType.Input)
Expand All @@ -40,16 +37,8 @@ object adder extends mainRunnable {
y := a + b
}

/*
parametric static adder
*/
/** static adder, parameterized
*/
class AdderParm[I <: Int: ValueOf](using GlobalInfo) extends UserModule {
val a = newInput[I]("a")
val b = newInput[I]("b")
Expand Down

0 comments on commit 742ab4d

Please sign in to comment.