Giter VIP home page Giter VIP logo

cynth's Introduction

Cynth

Cynth is a simple C-to-Verilog compiler. It is under development.

Building

Cynth is written in Scala. Build it with sbt by running:

$ sbt stage

Cynth will be built in target/universal/stage. To invoke Cynth:

$ cynth design.c > design.v

Input

Cynth input has the following restrictions:

  • All variables must be scalar integer types.

  • No multiply, divide or modulo.

  • No float, double, array, struct, union or pointers. No address of or function pointers.

  • No global variables.

  • No preprocessor. Use your favorite.

  • for, break, continue and switch still under development.

I plan to support memories (array, struct, union and pointers).

Interface

Cynth generates a Verilog module for each defined function. The interface of the module is determined by the signature of the the function. Here is an example:

int f(int x);

generates the interface:

module f(
  input __clk,
  input __resetn,
  input [31:0] __p_x,
  output reg [31:0] __retval,
  input __start,
  output __idle,
  output __valid);

In addition to the arguments and the return value, there are five control signals: the clock, reset, start, idle and valid. When the function is idle, it can be invoked by asserting start. valid is asserted when the function is complete. The return value is omitted if the return type is void.

Extensions

Cynth supports arbitrary-width integer types with __intN, e.g., __int4 or __int1024.

When compiling a function f which calls another function g, Cynth normally instantiates g in the implementation of f. If g is declared with __nonstd, Cynth instead will instead add the control signals for g to the interface for f and the module instantiating f will also be responsible for instantiating g. This is useful if g is implemented in Verilog and has a non-standard interface. See the write_leds example below.

Example

Here is a simple example that creates a roving eye pattern on the Arty Artix-7 board. The C design is:

__nonstd void write_leds(unsigned __int4 c);
void sleep(int ms);

void roving() {
  unsigned __int4 c = 1;
  unsigned __int1 dir = 1;
  
  while (1)
    {
      if (dir && c == 8)
        dir = 0;
      else if (!dir && c == 1)
        dir = 1;
      
      if (dir)
        c <<= 1;
      else
        c >>= 1;
      
      write_leds(c);
      
      sleep(1000);  // 1s
    }
}

write_leds and sleep are both implemented in Verilog. write_leds is non-standard since it has signals to drive the LEDs.

To build the example, just run make in the example directory. To flash it to the board, run make program. This has been tested on Linux with Vivado 2016.4.

cynth's People

Contributors

cseed 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.