Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.12)
project(GazpreaBase)

# Ensure tool dependencies.
include(ExternalProject) # Required to download and build external projects (i.e. ANTLR).
find_package(Git REQUIRED) # Need git to download ANTLR through ExternalProject.
find_package(Java COMPONENTS Runtime REQUIRED) # Need java to run ANTLR, but only the runtime.

# Ensure we have LLVM.
include("${CMAKE_SOURCE_DIR}/cmake/get_llvm.cmake")
# Ensure we have MLIR.
include("${CMAKE_SOURCE_DIR}/cmake/get_mlir.cmake")

# Link against the pthreads library to make std::call_once
# in generated ANTLR code to run without producing system errors
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CMPUT 415 Student Submission License (Version 1.0)

Copyright 2022 `student name`
Copyright 2023 `student name`

Unauthorized redistribution is forbidden in all circumstances. Use of this
software without explicit authorization from the author **or** CMPUT 415
Expand Down
67 changes: 8 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,18 @@ The base cmake setup for Gazprea assignment.
Author: Braedy Kuzma (braedy@ualberta.ca)
Updated by: Deric Cheung (dacheung@ualberta.ca)

# Usage
## Installing LLVM
You will be working with LLVM in this project. Due to the complex nature (and
size) of the project we did not want to include LLVM as a subproject.
Therefore, there is some additional setup required to get your build up and
running.
# Building
CMake will use the environment variables ANTLR_INS, ANTLR_JAR, and MLIR_DIR
to find locally installed builds of ANTLR and MLIR.
See the [setup document](https://webdocs.cs.ualberta.ca/~c415/setup/)
to find out how to install these packages on your machine.

### On a personal machine
The first thing you should do is have a look into the `configureLLVM.sh` script
in the scripts folder and understand as much as possible. We'll touch some
things briefly here that are better explained there. The steps here will expect
you have some knowledge of what's going on inside the script.

1. Checkout LLVM to a to your home directory from
[OUR FORK](https://github.com/cmput415/llvm-project), checkout the 10.0.0
release, and change the directory in your script.
1. `cd $HOME`
1. `git clone git@github.com:cmput415/llvm-project.git`
1. `cd llvm`
1. `git checkout llvmorg-10.0.0`
1. Add these configuration lines to your `~/.bashrc` on linux or
`~/.bash_profile` on MacOS to setup the next steps. You should restart your
terminal after editing these files.
```bash
export LLVM_INS="$HOME/llvm-ins/" # Change me if you really want.
export LLVM_DIR="$LLVM_INS/lib/cmake/llvm/" # Don't change me.
export PATH="$LLVM_INS/bin:$PATH" # Don't change me
```
1. If you want a debug build you may change this by looking at Step 2 in the
`scripts/configureLLVM.sh` script.
1. Run `configureLLVM.sh`.
1. `cd $HOME/llvm-project/build`
1. `make -j x` where x is the number of compilation threads. `4` is safe if
you have >= 8gb RAM. Haven't experimented much here. The script is set up
to try to use a better linker, but if you end up with your system linker
the memory usage can balloon quickly and paging can become a problem. If
you're having problems with hanging or system lag while compiling you
might want to kill this (you won't lose your progress if `ctrl+c` works)
and run with less threads.
1. Run `make install`.
1. CMake should automatically pick up your built llvm now. You should return
to the assignment specification to complete setup.

### On university machines
You won't be building LLVM on the university machines: AICT wouldn't be very
happy with you. Instead, we are providing a **RELEASE** build available for
everyone.
1. Follow the instructions on the [setup
page](https://webdocs.cs.ualberta.ca/~c415/setup/) for the CS computers and
LLVM will be available to you.

## Building
### Linux
1. Install git, java (only the runtime is necessary), and cmake (>= v3.0).
- Until now, cmake has found the dependencies without issues. If you
encounter an issue, let a TA know and we can fix it.
1. Make a directory that you intend to build the project in and change into
that directory.
1. Run `cmake <path-to-Gazprea-Base>`.
1. Run `make`.
1. Done.
2. Run `cmake <path-to-GazpreaBase>`.
3. Run `make`.

## Pulling in upstream changes
# Pulling in upstream changes
If there are updates to your assignment you can retrieve them using the
instructions here.
1. Add the upstream as a remote using `git remote add upstream <clone-link>`.
Expand Down
37 changes: 14 additions & 23 deletions cmake/get_antlr.cmake
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
# A module to obtain the ANTLR C++ runtime. It attempts to find a locally installed copy of the
# runtime pointed to by an environment variable called ANTLR_INS. Can swap in get_antlr_manual
# if you'd rather have it auto-install a copy just for this project (more space).

# CMake module that finds a previously installed copy of the ANTLR C++ runtime required when linking
# a generated lexer/parser. Creates the variable ANTLR_INCLUDE_DIRS to add to your target's
# include directories, adds the antlr library path to the project, allows your target to link
# against antlr4-runtime, creates ANTLR_JAR for generating grammars, and creates an antlr target
# that you can add via add_dependencies to make sure everything has happened already.
# A module to obtain the ANTLR C++ runtime. It attempts to find a locally installed
# copy of the runtime pointed to by an environment variable called ANTLR_INS.
# The module also looks for the environment variable ANTLR_JAR, which is used
# to generate the lexer and parser.
# Creates the variable ANTLR_INCLUDE_DIRS to add to your target's include
# directories, adds the antlr library path to the project, allows your target
# to link against antlr4-runtime, and creates an antlr target that you can add
# via add_dependencies to make sure everything has happened already.

# Get the environment variable that tells us where the manual install was.
if (NOT DEFINED ENV{ANTLR_INS})
message(FATAL_ERROR "Did you forget to install ANTLR? The ANTLR_INS environment variable was "
"not set.")
message(FATAL_ERROR "Did you forget to install ANTLR?"
"The ANTLR_INS environment variable was not set.")
endif()
file(TO_CMAKE_PATH "$ENV{ANTLR_INS}" _ANTLR_DIR)

# Set the directory for binaries.
file(TO_CMAKE_PATH "${_ANTLR_DIR}/bin" BIN_DIR) # Join dir.
set(BIN_DIR ${BIN_DIR} CACHE PATH "ANTLR jar directory.") # Set for internal use.

# Download ANTLR executable, saves us from ensuring people have java build tools (e.g. Maven)...
file(TO_CMAKE_PATH "${BIN_DIR}/antlr-4.10.1-complete.jar" ANTLR_JAR)
if (NOT EXISTS "${ANTLR_JAR}")
message(STATUS "Downloading ANTLR generator...")
file(
DOWNLOAD
http://www.antlr.org/download/antlr-4.10.1-complete.jar
"${ANTLR_JAR}"
SHOW_PROGRESS
)
file(TO_NATIVE_PATH "${BIN_DIR}" BIN_DIR_NATIVE) # Transform for display.
message(STATUS "Downloaded ANTLR jar destination: ${BIN_DIR_NATIVE}")
# Find the ANTLR binary
if (NOT DEFINED ENV{ANTLR_JAR})
message(FATAL_ERROR "The ANTLR_JAR environment variable is not set")
endif()
set(ANTLR_JAR "$ENV{ANTLR_JAR}")

# Check that the base include path exists.
if (NOT EXISTS "${_ANTLR_DIR}/include/antlr4-runtime/")
Expand Down
79 changes: 0 additions & 79 deletions cmake/get_antlr_manual.cmake

This file was deleted.

19 changes: 0 additions & 19 deletions cmake/get_llvm.cmake

This file was deleted.

12 changes: 12 additions & 0 deletions cmake/get_mlir.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Need MLIR so we can link against it. Either we automatically find this in the "default" place or
# it's found because we set up $MLIR_DIR. There should be no additions necessary here.
find_package(MLIR REQUIRED CONFIG)

# Status messages about LLVM found.
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using Config.cmake in: ${MLIR_DIR}")

# Add mlir specific pieces to our build.
include_directories("${MLIR_INCLUDE_DIRS}")
include_directories("${LLVM_INCLUDE_DIRS}")
add_definitions("${MLIR_DEFINITIONS}")
107 changes: 0 additions & 107 deletions scripts/configureLLVM.sh

This file was deleted.

11 changes: 9 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ add_dependencies(gazc antlr)

# Find the libraries that correspond to the LLVM components
# that we wish to use
set(LLVM_LINK_COMPONENTS Core Support)
llvm_map_components_to_libnames(llvm_libs core)
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)

# Add the antlr runtime and parser as libraries to link.
target_link_libraries(gazc parser antlr4-runtime ${llvm_libs})
# Add the MLIR, LLVM, antlr runtime and parser as libraries to link.
target_link_libraries(gazc PRIVATE
parser
antlr4-runtime
${llvm_libs}
${dialect_libs}
)

# Symbolic link our executable to the base directory so we don't have to go searching for it.
symlink_to_bin("gazc")