Skip to content
Draft
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
20 changes: 20 additions & 0 deletions gazprea-clean/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
31 changes: 31 additions & 0 deletions gazprea-clean/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Editing the Spec

This project uses [Sphinx](https://www.sphinx-doc.org/) to generate
documentation from [reStructuredText](https://docutils.sourceforge.io/rst.html)
(RST).

For a quick introduction to Sphinx, refer to the
[Sphinx Quickstart](https://www.sphinx-doc.org/en/master/usage/quickstart.html)
documentation.

For a quick introduction to RST, refer to the
[reStructuredText Primer](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html).

# Building

## Required Software
- `texlive-full` (for PDF output only)
- `python`

## Required Python (PyPI) Packages
- `sphinx`
- `sphinx_rtd_theme`

## Usage

- `make html` to build html files
- `make latexpdf` to build PDF/LaTeX files
- `make clean` to delete build files

The HTML build is output to the `_build/html` folder.
The PDF/LaTeX build is output to the `_build/latex` folder.
18 changes: 18 additions & 0 deletions gazprea-clean/_static/css/googleFonts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* This file is meant to reduce our upload size. Instead of uploading static
* font files, we outsource them instead to other static hosting sites.
*
* If you delete this file you must leave the generated
* _build/html/_static/css/fonts directory alone. This includes the line that
* deletes this folder in the root Makefile.
*/

@import url('https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;1,400&family=Roboto+Slab:wght@400;700&display=swap');

@font-face {
font-family: 'FontAwesome';
src: url('https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/fonts/fontawesome-webfont.eot?v=4.7.0');
src: url('https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/fonts/fontawesome-webfont.eot?#iefix&v=4.7.0') format('embedded-opentype'), url('https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0') format('woff2'), url('https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/fonts/fontawesome-webfont.woff?v=4.7.0') format('woff'), url('https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/fonts/fontawesome-webfont.ttf?v=4.7.0') format('truetype'), url('https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/fonts/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular') format('svg');
font-weight: normal;
font-style: normal;
}
Empty file.
Binary file added gazprea-clean/assets/images/GazpreaLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gazprea-clean/assets/images/logo-reverse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions gazprea-clean/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = 'gazprea'
copyright = '2025, cmput415'
author = 'cmput415'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx_rtd_theme',
'sphinx.ext.todo'
]

# Toggles the display of "Todo" message boxes in the output
todo_include_todos = True

# Toggle warnings in build log when todos are present
todo_emit_warnings = True

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

html_theme_options = {
'logo_only': False,
'style_nav_header_background': '#007C41',
# Toc options
'collapse_navigation': False,
'sticky_navigation': False,
}

html_logo = 'assets/images/logo-reverse.png'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# These paths are either relative to html_static_path
# or fully qualified paths (eg. https://...)
html_css_files = [
'css/googleFonts.css',
]

# Disable syntax highlighting in code blocks
highlight_language ='none'
1 change: 1 addition & 0 deletions gazprea-clean/htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DirectoryIndex index.html
116 changes: 116 additions & 0 deletions gazprea-clean/impl/backend.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
.. _sec:backend:

Backend
=======

You don’t need to implement an interpreter for Gazprea. You only need to
implement a *MLIR* code generator that outputs *LLVM IR*.

.. _ssec:backend_memory:

Memory Management
-----------------

It is important that you are able to automatically free and allocate memory for
arrays when they enter and exit scope. You could allocate them on the stack,
but this could be problematic if the arrays are very large.
It is likely safer to use ``malloc`` and ``free`` for these purposes.
This may be done in either your runtime or directly within MLIR.

Below is an example of how to use ``malloc`` and ``free`` within MLIR using the LLVM dialect:

::

module {
llvm.func @malloc(i32) -> !llvm.ptr<i8>
llvm.func @free(!llvm.ptr<i8>)
llvm.func @main() -> i32 {
%0 = llvm.mlir.constant(128 : i32) : i32
%1 = llvm.call @malloc(%0) : (i32) -> !llvm.ptr<i8>
llvm.call @free(%1) : (!llvm.ptr<i8>) -> ()
%c0_i32 = llvm.mlir.constant(0 : i32) : i32
llvm.return %c0_i32 : i32
}
}

It is important that the code generated by your compiler has no memory leaks,
and that all memory is freed as it leaves scope.

.. _ssec:backend_runtime:

Runtime Libraries
-----------------

If you make a runtime library, the runtime library must be implemented
in a runtime directory (``runtime``). Beware that in C++ there is additional
name mangling that occurs to allow class functions. Thus, we recommend
that all runtime functions should be written in C and not in C++. There
is a Makefile in the ``runtime`` folder designed to turn all ``*.c`` and
``*.h`` pairs into part of the unified runtime library ``libruntime.a``.
An example of how to make a runtime function is provided bellow.

``functions.c``

::

#include "functions.h"

uint64_t factorial(uint64_t n) {
uint64_t fact = 1;

while (n > 0) {
fact *= n;
n--;
}

return fact;
}

``functions.h``

::

#pragma once

#include <stdint.h>

uint64_t factorial(uint64_t n);

If your compiler was compiling the following input

::

3! + (2 + 7)!

Here is how to call the function in the LLVM dialect of MLIR:

``MLIR src``

::

module {
// This makes the function available for calling
llvm.func @factorial(i64) -> i64

llvm.func @main() -> i32 {
// Calls factorial with the constant 3 as an argument
%0 = llvm.mlir.constant(3 : i64) : i64
%1 = llvm.call @factorial(%0) : (i64) -> (i64)

// Adds 2 and 7 together
%2 = llvm.mlir.constant(2 : i64) : i64
%3 = llvm.mlir.constant(7 : i64) : i64
%4 = llvm.add %2, %3 : i64

// Calls factorial with the result of 2+7
%5 = llvm.call @factorial(%4) : (i64) -> (i64)

// Adds the result of 3! with (2+7)!
%6 = llvm.add %1, %5 : i64

// Done, return 0
%c0_i32 = llvm.mlir.constant(0 : i32) : i32
llvm.return %c0_i32 : i32
}
}

Loading
Loading