Giter Site home page Giter Site logo

donn / phi Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 3.0 903 KB

Hardware description language that tries not to suck

License: Apache License 2.0

Makefile 2.61% C 2.27% C++ 62.84% Lex 3.28% Yacc 8.95% Shell 0.23% Ruby 1.78% TeX 16.08% SystemVerilog 1.17% Verilog 0.80%
hdl eda fpga verilog systemverilog phi compilers

phi's Introduction

Φ Phi (Alpha)

macOS CI Linux CI

Phi is a pure-ish RTL hardware description language based on Verilog that aims to be safer and more explicit. It was my undergrad thesis project.

Phi aims to have:

  • No behavioral ambiguity
  • A clear definition and meta-definition divide

Syntactically, it takes a lot from C/C++/Swift. Semantically, it takes the best parts of Verilog.

Phi supports Linux, macOS, and Windows with MSYS2.

Examples

Counter

module Counter(
    clock: Input,
    reset: Input,
    enable: Input,
    output: Output[31..0]
) {
    Register[31..0] counter = 32b0
    counter.clock = clock
    counter.reset = reset
    counter.data = counter &+ 32b1
    counter.enable = enable

    output = counter
}

Dependencies

Running

  • A reasonably recent libstdc++.

Building

  • A POSIX environment
  • A C++17 compiler that supports standard C++17
    • No GCC or Clang specific extensions are used. Any used by accident are a bug we are interested in fixing.
    • We still recommend Clang + LLDB for debugging.
  • Git (for submodules)
  • GNU Make 3.8.1+
  • GNU Bison 3.0.4+
  • LLVM 14.0+
  • Ruby 2.3+
  • zlib

macOS

Install Xcode 9.0 or higher from the App Store.

For the other dependencies, we recommend Homebrew. Install it using the command in the link provided, then invoke:

    brew install ruby bison llvm

This will take some time, llvm is big.

You will need to add bison to PATH, as brew won't. Do this however you want: a suggestion is to add this to your shell's profile:

export BISON="/usr/local/opt/bison/bin/bison"

You will also need to expose LLVM Config to the compiler, as brew also won't. Again, it is suggested to add this to your shell's profile:

export LLVM_CONFIG="/usr/local/opt/llvm/bin/llvm-config"

(For the default shells, that's ~/.bash_profile on Mojave and below, and ~/.zprofile on Catalina and above.)

GNU/Linux

Install git, gcc, make and bison using your package manager.

If you have Clang and you want to use it, you can export and set the CC and CXX environment variables to clang and clang++ respectively.

Debian-based OSes (incl. Ubuntu, elementary...)

Phi has been tested and is working on Ubuntu 18.04, 19.04 and their derivatives.

Using apt...

    sudo apt-get install -y build-essential git make llvm-11-dev zlib1g-dev bison ruby

If you're into clang...

    sudo apt-get install clang lldb

Do note you'll need to expose LLVM Config to the compiler- it is suggested to add this to your shell's profile.

export LLVM_CONFIG="llvm-config-11"

Windows with MSYS2

First, get MSYS2-x86_64 if you haven't already.

pacman -S git make mingw-w64-x86_64-gcc bison mingw-w64-x86_64-llvm ruby

You can still also use Clang and lldb if you're into that:

pacman -S mingw-w64-x86_64-clang lldb

We are interested in supporting Visual Studio in the future.

Build Instructions

Run git submodule update --init --recursive --depth 1.

We use open source libraries for various functions, and they're all imported using git submodules.

You can then invoke either make or make release. The former produces a debug binary, which is slower but packs more features. It is more suitable for doing dev work on the actual compiler. If you intend on using the Phi compiler itself, we recommend make release.

Usage Instructions

./phic can be used to invoke Phi. It's a plain binary. You can write ./phi --help for more information, but the short story is, to invoke it write ./phi <phi source file>. Currently just the one is supported. If there are no errors returned, it creates a file with the same name as the filename given with ".sv" appended.

⚖️ Copyright & Licensing

©2019-2021 The Phi Authors. Phi is available under the Apache 2.0 license, available at the root of this project as 'License'.

Phi was partially developed as part of senior project coursework at the American University in Cairo.

Special Thanks

  • Prof. Shalan for consistent input and encouragement.
  • Genivia/RE-flex, our primary dependency, for not breaking the API and the CLI every three seconds like some libraries do.

phi's People

Contributors

ayaelnaggar avatar donn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

phi's Issues

Clean parser up

Parser uses new with reckless abandon, unsafe casts, uses unions for type punning instead of polymorphism, and it's all because of bison. I think we'll need a new parser generator by the end of this.

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.