Giter Club home page Giter Club logo

knitkit's Introduction

Made with Spacemacs

knitkit

Syntax is close to chisel3, without FIRRTL optimizing and generating readable Verilog code faster.

Quick Install

$ pip3 install knitkit
$ knitkit create hello_knitkit
$ cd hello_knitkit
$ make verilog

Source code in hw/knitkit/src/Mux2.scala and generated in builds/Mux2.v.

Install in offline environment

Download knitkit-py and then:

$ pip3 install --user knitkit-0.3-py3-none-any.whl

The same as quick install.

Install

Build by SBT or Mill locally. If just have a look, use Scastie online.

SBT

  1. Create hello_knitkit project directory.
$ mkdir -p hello_knitkit/src/main/scala
$ cd hello_knitkit
$ touch build.sbt
  1. Create SBT configuration as below:
lazy val hello = (project in file("."))
  .settings(
    name := "HelloKnitkit",
    scalaVersion := "2.13.6",
    libraryDependencies += "io.github.colin4124" %% "knitkit" % "0.3.0",
  )
  1. Write Knitkit source code:
$ touch src/main/scala/Mux2.scala
import knitkit._

class Mux2 extends RawModule {
  val sel = IO(Input(UInt(1.W)))
  val in0 = IO(Input(UInt(1.W)))
  val in1 = IO(Input(UInt(1.W)))
  val out = IO(Output(UInt(1.W)))

  out := (sel & in1) | (~sel & in0)
}

object Main extends App {
  Driver.execute(() => new Mux2, args(0))
}
  1. Run SBT, the first argument is generated directory, here is builds.
$ sbt "run builds"
  1. Check generated verilog file builds/Mux2.v:
module Mux2 (
  input  sel,
  input  in0,
  input  in1,
  output out
);
  assign out = (sel & in1) | ((~ sel) & in0);
endmodule

Mill

  1. Create hello_knitkit project directory.
$ mkdir -p hello_knitkit/src
$ cd hello_knitkit
$ touch build.sc
  1. Create Mill configuration as below:
import mill._, scalalib._
  
object hello extends ScalaModule {
  def scalaVersion = "2.13.6"
  def millSourcePath = super.millSourcePath / ammonite.ops.up

  def ivyDeps = Agg(
    ivy"io.github.colin4124::knitkit:0.3.0",
  )
}
  1. Put source code Mux2.scala to hello_knitkit/src/ directory.

  2. Run Mill, hello is the object name in build.sc defined, builds is the first argument where verilog generated.

$ mill hello.run builds
  1. Check generated verilog file builds/Mux2.v.

Online Scastie

  1. Open Scastie website.

  2. Click Build Settings in left sidebar.

  3. Choose scala 2 in Target, 2.13.6 in Scala Version, search knitkit in Libraries.

  4. Click Editor in left sidebar, wirte down:

import knitkit._
  
class Mux2 extends RawModule {
  override def desiredName = "Mux2"
  val sel = IO(Input(UInt(1.W)))
  val in0 = IO(Input(UInt(1.W)))
  val in1 = IO(Input(UInt(1.W)))
  val out = IO(Output(UInt(1.W)))

  out := (sel & in1) | (~sel & in0)
}
Driver.genVerilog(() => new Mux2)
  1. Here is the exmple

knitkit's People

Contributors

colin4124 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.