Skip to content

Commit

Permalink
Merge branch 'draft' into wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sylefeb committed Jan 25, 2024
2 parents 279d122 + f439292 commit 515ea4c
Show file tree
Hide file tree
Showing 160 changed files with 4,208 additions and 1,072 deletions.
53 changes: 41 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.5)
project(silice)

INCLUDE_DIRECTORIES(
Expand All @@ -16,6 +16,10 @@ INCLUDE_DIRECTORIES(

if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:4194304")
else()
if (MINGW)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --static")
endif()
endif()

set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -124,22 +128,47 @@ add_library(libsilice STATIC ${SILICE_CORE})
add_executable(silice src/silice.cpp)
# set_target_properties(silice PROPERTIES OUTPUT_NAME "silice")
target_link_libraries(silice libsilice antlr4_static lua luabind)

if(WIN32)
target_link_libraries(silice shlwapi)
endif(WIN32)
target_link_libraries(silice shlwapi)
endif()

install(TARGETS silice RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
install(TARGETS libsilice ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/lib)
install(TARGETS lua ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/lib)
install(TARGETS lua ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/lib)
install(TARGETS luabind ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/lib)
install(TARGETS antlr4_static ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/lib)
# install and paths

if(WIN32)
IF(MINGW)
set(INSTALL_IN_REPO OFF CACHE BOOL "Install in repository")
else()
set(INSTALL_IN_REPO ON CACHE BOOL "Install in repository")
endif()
else()
set(INSTALL_IN_REPO OFF CACHE BOOL "Install in repository")
endif()

if (INSTALL_IN_REPO)

install(TARGETS silice RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
install(TARGETS libsilice ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/lib)
add_definitions(-DFRAMEWORKS_DEFAULT_PATH=\"${CMAKE_SOURCE_DIR}/frameworks\")

else()

install(TARGETS silice RUNTIME DESTINATION bin/)
install(TARGETS libsilice ARCHIVE DESTINATION bin/)
install(FILES bin/silice-make.py PERMISSIONS WORLD_EXECUTE OWNER_WRITE WORLD_READ DESTINATION bin/)
install(FILES bin/report-cycles.py PERMISSIONS WORLD_EXECUTE OWNER_WRITE WORLD_READ DESTINATION bin/)
install(FILES projects/ice-v/CPUs/ice-v.si DESTINATION share/silice/projects/ice-v/CPUs/)
install(FILES projects/ice-v/CPUs/ice-v-dual.si DESTINATION share/silice/projects/ice-v/CPUs/)
install(DIRECTORY frameworks DESTINATION share/silice/ USE_SOURCE_PERMISSIONS)
install(DIRECTORY src/libs/LibSL-small DESTINATION share/silice/src/libs/)
add_definitions(-DFRAMEWORKS_DEFAULT_PATH=\"${CMAKE_INSTALL_PREFIX}/share/silice/frameworks\")

endif()

# compiler checks

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8)
message(FATAL_ERROR "Silice requires g++ 8 at least")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8)
message(FATAL_ERROR "Silice requires g++ 8 at least")
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
Expand Down
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [\[CL0002\] Tracker declarations](#cl0002-tracker-declarations)
- [\[CL0003\] Pipeline syntax](#cl0003-pipeline-syntax)
- [\[CL0004\] While loops cycle rules](#cl0004-while-loops-cycle-rules)
- [\[CL0005\] If-else cycle rules](#cl0005-if-else-cycle-rules)

## [CL0001] Instantiation time pre-processor

Expand Down
51 changes: 10 additions & 41 deletions GetStarted_Linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,18 @@

## Compiling Silice

First, some dependencies are required. To install all of them you may run the script `install_dependencies_linux.sh` that uses `apt`, or inspect the script content and manually add the missing packages. Note that the Java jre/jdk are only required for compilation.
Hopefully this will be as simple as running `./get_started_linux.sh`
Beware that this script is installing dependencies and will request sudo access.
If that is not ok, please open the script and see what it wants to install.
The script also installs Silice on the system, using standard paths (`/usr/local/bin` and `/usr/local/shared/silice`).
Finally, the script appends paths to `.bashrc`.

Compiling Silice should then be as simple as:
```shell
git clone --recurse-submodules https://github.com/sylefeb/Silice.git
cd Silice
./compile_silice_linux.sh
```
## Notes on dependencies

Done! This compiled and installed the Silice executable in `Silice/bin/`.
The `get_started_linux.sh` script calls the scripts `install_dependencies_*.sh` to install dependencies. It attempts to detect your distrib to call the corresponding dependencies installation script, but if that fails you may have to manually install the dependencies. In such a case, please refer to the script's contents to see what is needed. Note that the Java jre/jdk are only required for compilation.

**Note:** It is highly recommended for all tools to be available from the PATH (Silice/bin, yosys, nextpnr, dfu-utils, fujprog, etc.). This is required by the default build system.
The script also downloads and sets up pre-compiled binaries for the FPGA toolchain (from [oss-cad-suite](https://github.com/YosysHQ/oss-cad-suite-build)). These are placed in `/usr/local/shared/silice`, and environment variables are set by adding a line to the user's `.bashrc`.

## Getting the toolchain
## Testing after installation

Using Silice with your FPGA requires many other tools: yosys, icestorm, trellis, nextpnr, verilator, icarus verilog (*iverilog*), gtkwave, fujprog, dfu-utils.

**Note:** It is highly recommended for all tools to be available from the PATH. This is required by the default build system.

The most critical are yosys, icestorm, trellis, nextpnr. For these ones, please do not use any package that
may come with your system. These are likely outdated and won't understand the latest features. Verilator also often needs to be updated.

There are two options:

### Compile from source (recommended)

Yosys, icestorm, trellis, nextpnr, verilator are not difficult to compile and install, and have detailed instructions on their git pages:
- [Yosys](https://github.com/YosysHQ/yosys)
- [Project trellis](https://github.com/YosysHQ/prjtrellis)
- [Project icestorm](https://github.com/YosysHQ/icestorm)
- [NextPNR](https://github.com/YosysHQ/nextpnr)
- [Verilator](https://github.com/verilator/verilator)

Note that trellis and icestorm have to be compiled and installed before nextpnr (please refer to the NextPNR setup instructions).

These tools take a bit of time to compile, but it is worth doing as they constantly improve.

> **Note** You might want to apply my [ice40 DSP patch](https://github.com/sylefeb/fpga-binutils/blob/master/patches/yosys_patch_ice40_dsp.diff) on Yosys before compiling.
### Use compiled binaries

Checkout the [fpga-toolchain project](https://github.com/open-tool-forge/fpga-toolchain) as they provide nightly builds of many tools for multiple platforms.

## Testing

Time to [run a few tests](GetStarted.md#testing).
Time to [run a few tests](GetStarted.md#testing) and [start having fun!](projects/README.md)
6 changes: 4 additions & 2 deletions GetStarted_Windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ The prompt should look like this (note the MinGW64 label in purple):

Then, from the prompt, enter the Silice directory and type: `./get_started_mingw64.sh`.

> **Note:** The script adds Silice and the FPGA toolchain to PATH in` ~/.bashrc`. Open a new MinGW64 prompt to start using Silice.
> **Note:** The script downloads necessary MinGW packages, compiles and installs Silice using standard paths (`/usr/local/bin` and `/usr/local/shared/silice`) as well as downloads and sets up the [oss-cad-suite](https://github.com/YosysHQ/oss-cad-suite-build) FPGA toolchain in `/usr/local/shared/silice`, adding a line in ` ~/.bashrc` to set environment variables.
> **Note:** This automatically downloads pre-compiled FPGA tools from https://github.com/sylefeb/fpga-binutils/ (~16MB) as well as installs required MinGW64 packages. For details please refer to the [script source code](get_started_mingw64.sh).
Open a new MinGW64 prompt to start using Silice.

For details please refer to the [script source code](get_started_mingw64.sh).

## Drivers

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Silice
*A language for hardcoding algorithms into FPGA hardware*
*A language for hardcoding algorithms with pipelines and parallelism into FPGA hardware*

---
**Quick links:**
Expand Down
11 changes: 7 additions & 4 deletions antlr/antlr4-cpp-runtime-4.7.2-source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- mode:cmake -*-
cmake_minimum_required (VERSION 2.8)
cmake_minimum_required (VERSION 3.5)
# 2.8 needed because of ExternalProject

# Detect build type, fallback to release and throw a warning if use didn't specify any
Expand Down Expand Up @@ -41,7 +41,7 @@ endif()

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
find_package(PkgConfig REQUIRED)
pkg_check_modules(UUID REQUIRED uuid)
# pkg_check_modules(UUID REQUIRED uuid)
endif()
if(APPLE)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
Expand Down Expand Up @@ -106,7 +106,7 @@ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHE
if(NOT (GCC_VERSION VERSION_GREATER 5.0 OR GCC_VERSION VERSION_EQUAL 5.0))
message(FATAL_ERROR "${PROJECT_NAME} requires g++ 5.0 or greater.")
endif ()
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND ANDROID)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND ANDROID)
# Need -Os cflag and cxxflags here to work with exception handling on armeabi.
# see https://github.com/android-ndk/ndk/issues/573
# and without -stdlib=libc++ cxxflags
Expand All @@ -123,7 +123,10 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND ( CMAKE_SYSTEM_NAME MATCH
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
elseif(MSVC_VERSION GREATER 1800 OR MSVC_VERSION EQUAL 1800)
# Visual Studio 2012+ supports c++11 features
# Visual Studio 2012+ supports c++11 features
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# default fallback (e.g. EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
else ()
message(FATAL_ERROR "Your C++ compiler does not support C++11.")
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ add_dependencies(antlr4_static make_lib_output_dir)

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
# target_link_libraries(antlr4_shared ${UUID_LIBRARIES})
target_link_libraries(antlr4_static ${UUID_LIBRARIES})
# target_link_libraries(antlr4_static ${UUID_LIBRARIES})
elseif(APPLE)
# target_link_libraries(antlr4_shared ${COREFOUNDATION_LIBRARY})
target_link_libraries(antlr4_static ${COREFOUNDATION_LIBRARY})
Expand Down
2 changes: 1 addition & 1 deletion antlr/silice.g4
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ sformdepth : '#depth' '=' NUMBER ;
sformtimeout : '#timeout' '=' NUMBER ;
sformmode : '#mode' '=' IDENTIFIER ('&' IDENTIFIER)* ;
sspecialize : IDENTIFIER ':' TYPE ;
sparam : IDENTIFIER '=' NUMBER ;
sparam : IDENTIFIER '=' (NUMBER|CONSTANT) ;

bpModifier : sclock | sreset | sautorun | sonehot | sstacksz | sformdepth | sformtimeout | sformmode | sreginput | sspecialize | sparam;
bpModifiers : '<' bpModifier (',' bpModifier)* '>' ;
Expand Down
12 changes: 10 additions & 2 deletions antlr/vmodule.g4
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ OUTP : 'output';

INOUTP : 'inout';

PARAMETER : 'parameter';

NUMBER : DIGIT+ ;

IDENTIFIER : LETTER+ (DIGIT|LETTER)* ;

ALPHANUM : (LETTER|DIGIT|'\'')+ ;

WHITESPACE : (' ' | '\t') -> skip ;

NEWLINE : ('\r'? '\n' | '\r')+ -> skip ;
Expand All @@ -69,8 +73,12 @@ inout : INOUTP mod IDENTIFIER ;

inOrOut : input | output | inout ;

inOutList : (inOrOut ',') * inOrOut | ;
inOutList : (inOrOut ',') * inOrOut | ;

paramDecl : PARAMETER name=IDENTIFIER '=' value=(NUMBER|IDENTIFIER|ALPHANUM) | ;

paramList : '#' '(' paramDecl ( ',' paramDecl )* ')' ;

vmodule : 'module' IDENTIFIER '(' inOutList ')' ';' ;
vmodule : 'module' IDENTIFIER paramList? '(' inOutList ')' ';' ;

root : vmodule EOF ;
Empty file modified bin/report-cycles.py
100644 → 100755
Empty file.
31 changes: 22 additions & 9 deletions bin/silice-make.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import argparse
import platform
import sysconfig
import subprocess
# from termcolor import colored

def colored(str,clr,attrs=0):
Expand All @@ -43,8 +44,7 @@ def colored(str,clr,attrs=0):
parser.add_argument('-r','--root', help="Root directory, use to override default frameworks.")
parser.add_argument('-D','--defines', help="List of comma-separated defines to pass to Silice, e.g. -D A=0,B=1")
parser.add_argument('--no_build', help="Only generate verilog output file.", action="store_true")
parser.add_argument('--no_program', help="Only generate verilog output file and build bitstream.",
action="store_true")
parser.add_argument('--no_program', help="Only generate verilog output file and build bitstream.", action="store_true")
parser.add_argument('--reprogram', help="Only program device.", action="store_true")

args = parser.parse_args()
Expand Down Expand Up @@ -75,15 +75,28 @@ def colored(str,clr,attrs=0):
os.environ["BUILD_DIR"] = out_dir

# - frameworks directory
frameworks_dir = os.path.realpath(os.path.join(make_dir,"../frameworks/"))
frameworks_dirs=list()
frameworks_dirs.append(os.path.realpath(os.path.join(make_dir,"../frameworks/")))
frameworks_dirs.append('/usr/local/share/silice/frameworks/')
if platform.system() == "Windows":
if sysconfig.get_platform().startswith("mingw"):
frameworks_dirs.append(subprocess.check_output('cygpath -m /usr/local/share/silice/frameworks/').decode('utf-8').strip())
if args.root:
frameworks_dir = os.path.realpath(os.path.abspath(args.root))
print("* Silice frameworks directory: ",frameworks_dir,"\t\t\t",end='')
if (os.path.exists(frameworks_dir)):
print(colored("[ok]", 'green'))
frameworks_dirs.append(os.path.realpath(os.path.abspath(args.root)))
# search in expected paths
frameworks_dir = None
for fdir in frameworks_dirs:
if (os.path.exists(fdir)):
frameworks_dir = fdir
break
if frameworks_dir == None:
print("* Silice frameworks directory: \t\t\t",end='')
print(colored("[not found]", 'red'))
sys.exit(-1)
else:
print(colored("[not found]", 'red'))
sys.exit(-1)
print("* Silice frameworks directory: ",frameworks_dir,"\t\t\t",end='')
print(colored("[ok]", 'green'))
frameworks_dir = fdir
os.environ["FRAMEWORKS_DIR"] = frameworks_dir

# enter build directory
Expand Down
11 changes: 6 additions & 5 deletions compile_silice_linux.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash

if ! type "javac" > /dev/null; then
echo "Silice compilation requires packages default-jre and default-jdk"
echo "Silice compilation requires javac (typically in package default-jdk or jdk-openjdk)"
exit
fi

git submodule init
git submodule update
rm -f bin/silice || true

mkdir BUILD
cd BUILD
Expand All @@ -18,15 +19,15 @@ mkdir build-silice
cd build-silice

cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ../..
make -j$(nproc) install
make -j$(nproc)
sudo make -j$(nproc) install

cd ..

cd ..

echo -e "\nInstalling python packages for building designs\n"
pip install termcolor
pip install edalize
pip install --upgrade termcolor
pip install --upgrade edalize

echo " "
echo " "
Expand Down
3 changes: 1 addition & 2 deletions compile_silice_mingw64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ export PATH=$PATH:$DIR/jdk-14.0.1/bin/
mkdir build-silice
cd build-silice

/mingw64/bin/cmake -DCMAKE_BUILD_TYPE=Release -G "MinGW Makefiles" ../..
/mingw64/bin/cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -G "MinGW Makefiles" ../..
mingw32-make -j16 install

cd ..

cd ..
12 changes: 9 additions & 3 deletions frameworks/boards/brot/board.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
"name" : "configurable",
"framework" : "brot.v",
"pins" : [
{"set" : "basic"},
{"set" : "basic", "define" : "BASIC=1"},
{"set" : "buttons", "define" : "BUTTONS=1"},
{"set" : "pmod", "define" : "PMOD=1"},
{"set" : "uart", "define" : "UART=1"},
{"set" : "uart2", "define" : "UART2=1"},
{"set" : "spiflash", "define" : "SPIFLASH=1"},
{"set" : "pmod_qqspi", "define" : "PMOD_QQSPI=1"},
{"set" : "spiflash_dspi", "define" : "SPIFLASH_DSPI=1"},
{"set" : "pmod_dspi", "define" : "PMOD_DSPI=1"},
{"set" : "pmod_com_out", "define" : "PMOD_COM_OUT=1"},
{"set" : "pmod_com_in", "define" : "PMOD_COM_IN=1"},
{"set" : "parallel_screen", "define" : "PARALLEL_SCREEN=1"}
{"set" : "parallel_screen", "define" : "PARALLEL_SCREEN=1"},
{"set" : "qpsram", "define" : "QPSRAM=1"},
{"set" : "sync_in", "define" : "SYNC_IN=1"},
{"set" : "sync_out", "define" : "SYNC_OUT=1"}
],
"builders": [
{
Expand Down
Loading

0 comments on commit 515ea4c

Please sign in to comment.