Home

Awesome

Φ 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:

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

Building

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