Skip to content

Commit

Permalink
Merge pull request #303 from baszalmstra/feature/inkwell_beta1
Browse files Browse the repository at this point in the history
bump: Inkwell beta.2 and LLVM11
  • Loading branch information
baszalmstra authored Feb 28, 2021
2 parents 1feebf0 + 72ea35b commit df03295
Show file tree
Hide file tree
Showing 135 changed files with 644 additions and 597 deletions.
8 changes: 0 additions & 8 deletions .github/actions-rs/grcov.yml

This file was deleted.

11 changes: 6 additions & 5 deletions .github/actions/install-llvm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,14 +1182,15 @@ async function execute(cmd) {
(async () => {
try {
if(isLinux) {
await exec.exec("sudo apt install llvm-8 llvm-8-* liblld-8*");
const installScript = path.join(__dirname, "../../../../scripts/install-llvm.sh");
await exec.exec(`sudo ${installScript}`);
} else if(isMacOS) {
await exec.exec("brew install llvm@8")
let llvmPath = await execute("brew --prefix llvm@8");
await exec.exec("brew install llvm@11")
let llvmPath = await execute("brew --prefix llvm@11");
core.addPath(`${llvmPath}/bin`)
} else if(isWindows) {
const downloadUrl = "https://github.com/mun-lang/llvm-package-windows/releases/download/v8.0.1/llvm-8.0.1-windows-x64-msvc16.7z"
core.info(`Downloading LLVM from '${downloadUrl}'`)
const downloadUrl = "https://github.com/mun-lang/llvm-package-windows/releases/download/v11.0.1/llvm-11.0.1-windows-x64-msvc16.7z"
core.info(`downloading LLVM from '${downloadUrl}'`)
const downloadLocation = await tc.downloadTool(downloadUrl);

core.info("Succesfully downloaded LLVM release, extracting...")
Expand Down
11 changes: 6 additions & 5 deletions .github/actions/install-llvm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ export async function execute(cmd) {
(async () => {
try {
if(isLinux) {
await exec.exec("sudo apt install llvm-8 llvm-8-* liblld-8*");
const installScript = path.join(__dirname, "../../../../scripts/install-llvm.sh");
await exec.exec(`sudo ${installScript}`);
} else if(isMacOS) {
await exec.exec("brew install llvm@8")
let llvmPath = await execute("brew --prefix llvm@8");
await exec.exec("brew install llvm@11")
let llvmPath = await execute("brew --prefix llvm@11");
core.addPath(`${llvmPath}/bin`)
} else if(isWindows) {
const downloadUrl = "https://github.com/mun-lang/llvm-package-windows/releases/download/v8.0.1/llvm-8.0.1-windows-x64-msvc16.7z"
core.info(`Downloading LLVM from '${downloadUrl}'`)
const downloadUrl = "https://github.com/mun-lang/llvm-package-windows/releases/download/v11.0.1/llvm-11.0.1-windows-x64-msvc16.7z"
core.info(`downloading LLVM from '${downloadUrl}'`)
const downloadLocation = await tc.downloadTool(downloadUrl);

core.info("Succesfully downloaded LLVM release, extracting...")
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
artifacts: "mun libmun_runtime.so"
}
- {
os: "windows-2016",
os: "windows-latest",
dir: win64,
artifacts: "mun.exe mun_runtime.dll mun_runtime.dll.lib"
}
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
- **Cross compilation** - The Mun compiler is able to compile to all supported
target platforms from any supported compiler platform.

- **Powerful IDE integration** *not implemented yet* - The Mun language and
compiler framework are designed to support source code queries, allowing for
powerful IDE integrations such as code completion and refactoring tools.
- **Powerful IDE integration** - The Mun language and compiler framework are
designed to support source code queries, allowing for powerful IDE
integrations such as code completion and refactoring tools.

## Example

Expand Down Expand Up @@ -145,7 +145,7 @@ Windows (64-bit only).
Make sure you have the following dependencies installed on you machine:

* [Rust](https://www.rust-lang.org/tools/install)
* [LLVM 8](https://docs.mun-lang.org/ch04-02-building-llvm.html)
* [LLVM 11](https://docs.mun-lang.org/ch04-02-building-llvm.html)

Clone the source code, including all submodules:

Expand Down
22 changes: 11 additions & 11 deletions book/src/ch04-02-building-llvm.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The Mun compiler makes heavy use of LLVM for all code-generation capabilities.
Installing it, however, can be tricky.
This document is a short guide on how to install LLVM on your machine so you can build Mun yourself.

Currently, Mun targets LLVM 8 so everything in this document refers to that version.
Currently, Mun targets LLVM 11 so everything in this document refers to that version.
However, these instructions should also hold for newer versions.

## Prebuild binaries
Expand All @@ -21,7 +21,7 @@ For Windows, [we maintain a repository](https://github.com/mun-lang/llvm-package
These releases are also used on our CI runners.

To use a release, download and extract it to your machine.
To make sure the build pipeline can find the binaries, add an environment variable called `LLVM_SYS_80_PREFIX` that points to the folder where you extracted the release.
To make sure the build pipeline can find the binaries, add an environment variable called `LLVM_SYS_110_PREFIX` that points to the folder where you extracted the release.
It is also possible to add the `bin` folder of the release to your path but using the environment variables allows you to have multiple LLVM releases on your machine.

> For LLVM 8 you should add the `LLVM_SYS_80_PREFIX` environment variable, for LLVM 11 add `LLVM_SYS_110_PREFIX`.
Expand All @@ -38,7 +38,7 @@ wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -

# Add the repository
# ${REPO_NAME} should be something like:
# deb http://apt.llvm.org/focal/ llvm-toolchain-focal-8 main
# deb http://apt.llvm.org/focal/ llvm-toolchain-focal-11 main
#
# The `add-apt-repository` command is installed by the `software-properties-common` package:
# sudo apt install software-properties-common
Expand All @@ -48,24 +48,24 @@ add-apt-repository "${REPO_NAME}"
Once you have the proper APT repository configured you can install the required LLVM binaries with:

```bash
apt install llvm-8 llvm-8-* liblld-8*
apt install llvm-11 llvm-11-* liblld-11*
```

### MacOS

[Brew](https://brew.sh/) contains a cask for LLVM that can be used to build Mun:

```bash
brew install llvm@8
brew install llvm@11
```

After installing LLVM, you can either add the `bin` folder of the release to your path; or you can add a release-specific environment variable called `LLVM_SYS_80_PREFIX` that points to the release:
After installing LLVM, you can either add the `bin` folder of the release to your path; or you can add a release-specific environment variable called `LLVM_SYS_110_PREFIX` that points to the release:

```bash
export LLVM_SYS_80_PREFIX=$(brew --prefix llvm@8)
export LLVM_SYS_110_PREFIX=$(brew --prefix llvm@11)
```

Adding the `LLVM_SYS_80_PREFIX` variable is usually easier because the LLVM binaries will not conflict with any preinstalled version of LLVM and it allows you to easily install another version of LLVM side-by-side.
Adding the `LLVM_SYS_110_PREFIX` variable is usually easier because the LLVM binaries will not conflict with any preinstalled version of LLVM and it allows you to easily install another version of LLVM side-by-side.

> For LLVM 8 you should add the `LLVM_SYS_80_PREFIX` environment variable, for LLVM 11 add `LLVM_SYS_110_PREFIX`.
Expand All @@ -83,18 +83,18 @@ Download a dump of the LLVM repository from the [LLVM github repository](https:/

```bash
wget -qO- \
https://github.com/llvm/llvm-project/archive/llvmorg-8.0.1.tar.gz | \
https://github.com/llvm/llvm-project/archive/llvmorg-11.0.1.tar.gz | \
tar xzf -
```

Then build the required components and install them to `~/local`.

```bash
cd llvm-project-llvmorg-8.0.1/llvm
cd llvm-project-llvmorg-11.0.1/llvm
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="lld;clang" -DCMAKE_INSTALL_PREFIX=$HOME/local -DCMAKE_INSTALL_PREFIX=$HOME/local -DLLVM_ENABLE_LIBXML2=OFF
make install -j
```

After LLVM is build, make sure to add the `$HOME/local/bin` to you path or add an environment variable `LLVM_SYS_80_PREFIX` (or `LLVM_SYS_110_PREFIX` depending on the LLVM version you installed) that points to `$HOME/local`.
After LLVM is build, make sure to add the `$HOME/local/bin` to you path or add an environment variable `LLVM_SYS_110_PREFIX` (or `LLVM_SYS_110_PREFIX` depending on the LLVM version you installed) that points to `$HOME/local`.
4 changes: 2 additions & 2 deletions crates/mun_codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ hir = { version = "=0.2.0", path = "../mun_hir", package = "mun_hir" }
itertools = "0.9.0"
mun_codegen_macros = { path = "../mun_codegen_macros", package = "mun_codegen_macros" }
mun_target = { version = "=0.2.0", path = "../mun_target" }
mun_lld = { version = "=80.0.0", path = "../mun_lld" }
mun_lld = { path = "../mun_lld" }
anyhow = "1.0.31"
thiserror = "1.0.19"
salsa = "0.15.0"
Expand All @@ -28,7 +28,7 @@ array-init="0.1.0"
tempfile = "3"
paste = "0.1.6"
parking_lot = "0.10"
inkwell = { version = "=0.1.0-llvm8sample", features = ["llvm8-0"]}
inkwell = { version = "=0.1.0-beta.2", features = ["llvm11-0", "no-libffi-linking"]}
by_address = "1.0.4"

[dev-dependencies]
Expand Down
17 changes: 12 additions & 5 deletions crates/mun_codegen/src/code_gen/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,18 @@ fn gen_get_info_fn<'ink>(
};

// Get access to the structs internals
let symbols_addr = unsafe { builder.build_struct_gep(result_ptr, 1, "symbols") };
let dispatch_table_addr = unsafe { builder.build_struct_gep(result_ptr, 3, "dispatch_table") };
let dependencies_addr = unsafe { builder.build_struct_gep(result_ptr, 5, "dependencies") };
let num_dependencies_addr =
unsafe { builder.build_struct_gep(result_ptr, 7, "num_dependencies") };
let symbols_addr = builder
.build_struct_gep(result_ptr, 1, "symbols")
.expect("could not retrieve `symbols` from result struct");
let dispatch_table_addr = builder
.build_struct_gep(result_ptr, 3, "dispatch_table")
.expect("could not retrieve `dispatch_table` from result struct");
let dependencies_addr = builder
.build_struct_gep(result_ptr, 5, "dependencies")
.expect("could not retrieve `dependencies` from result struct");
let num_dependencies_addr = builder
.build_struct_gep(result_ptr, 7, "num_dependencies")
.expect("could not retrieve `num_dependencies` from result struct");

// Assign the struct values one by one.
builder.build_store(symbols_addr, module_info.as_value(context).value);
Expand Down
23 changes: 17 additions & 6 deletions crates/mun_codegen/src/ir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,13 +1340,19 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
let receiver_ptr = self
.opt_deref_value(receiver_expr, receiver_ptr.into())
.into_pointer_value();
let field_ptr = unsafe {
self.builder.build_struct_gep(
let field_ptr = self
.builder
.build_struct_gep(
receiver_ptr,
field_idx,
&format!("{}.{}_ptr", hir_struct_name, name),
)
};
.unwrap_or_else(|_| {
panic!(
"could not get pointer to field `{}::{}` at index {}",
hir_struct_name, name, field_idx
)
});
Some(self.builder.build_load(field_ptr, &field_ir_name))
} else {
let receiver_value = self.gen_expr(receiver_expr)?;
Expand Down Expand Up @@ -1389,13 +1395,18 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
let receiver_ptr = self
.opt_deref_value(receiver_expr, receiver_ptr.into())
.into_pointer_value();
unsafe {
self.builder.build_struct_gep(
self.builder
.build_struct_gep(
receiver_ptr,
field_idx,
&format!("{}.{}_ptr", hir_struct_name, name),
)
}
.unwrap_or_else(|_| {
panic!(
"could not get pointer to field `{}::{}` at index {}",
hir_struct_name, name, field_idx
)
})
}
}

Expand Down
11 changes: 8 additions & 3 deletions crates/mun_codegen/src/ir/dispatch_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,18 @@ impl<'ink> DispatchTable<'ink> {
let table_ref = table_ref.expect("no dispatch table defined");

// Create an expression that finds the associated field in the table and returns this as a pointer access
let ptr_to_function_ptr = unsafe {
builder.build_struct_gep(
let ptr_to_function_ptr = builder
.build_struct_gep(
table_ref.as_pointer_value(),
index as u32,
&format!("{0}_ptr_ptr", function_name),
)
};
.unwrap_or_else(|_| {
panic!(
"could not get {} (index: {}) from dispatch table",
function_name, index
)
});

builder
.build_load(ptr_to_function_ptr, &format!("{0}_ptr", function_name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ source_filename = "main.mun"

@global_type_table = external global [1 x %"mun_codegen::ir::types::TypeInfo"*]

define float @add(float, float) {
define float @add(float %0, float %1) {
body:
%add = fadd float %0, %1
ret float %add
}

define float @subtract(float, float) {
define float @subtract(float %0, float %1) {
body:
%sub = fsub float %0, %1
ret float %sub
}

define float @multiply(float, float) {
define float @multiply(float %0, float %1) {
body:
%mul = fmul float %0, %1
ret float %mul
}

define float @divide(float, float) {
define float @divide(float %0, float %1) {
body:
%div = fdiv float %0, %1
ret float %div
}

define float @remainder(float, float) {
define float @remainder(float %0, float %1) {
body:
%rem = frem float %0, %1
ret float %rem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ source_filename = "main.mun"

@global_type_table = external global [1 x %"mun_codegen::ir::types::TypeInfo"*]

define double @add(double, double) {
define double @add(double %0, double %1) {
body:
%add = fadd double %0, %1
ret double %add
}

define double @subtract(double, double) {
define double @subtract(double %0, double %1) {
body:
%sub = fsub double %0, %1
ret double %sub
}

define double @multiply(double, double) {
define double @multiply(double %0, double %1) {
body:
%mul = fmul double %0, %1
ret double %mul
}

define double @divide(double, double) {
define double @divide(double %0, double %1) {
body:
%div = fdiv double %0, %1
ret double %div
}

define double @remainder(double, double) {
define double @remainder(double %0, double %1) {
body:
%rem = frem double %0, %1
ret double %rem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ source_filename = "main.mun"

@global_type_table = external global [1 x %"mun_codegen::ir::types::TypeInfo"*]

define i128 @add(i128, i128) {
define i128 @add(i128 %0, i128 %1) {
body:
%add = add i128 %0, %1
ret i128 %add
}

define i128 @subtract(i128, i128) {
define i128 @subtract(i128 %0, i128 %1) {
body:
%sub = sub i128 %0, %1
ret i128 %sub
}

define i128 @multiply(i128, i128) {
define i128 @multiply(i128 %0, i128 %1) {
body:
%mul = mul i128 %0, %1
ret i128 %mul
}

define i128 @divide(i128, i128) {
define i128 @divide(i128 %0, i128 %1) {
body:
%div = sdiv i128 %0, %1
ret i128 %div
}

define i128 @remainder(i128, i128) {
define i128 @remainder(i128 %0, i128 %1) {
body:
%rem = srem i128 %0, %1
ret i128 %rem
Expand Down
Loading

0 comments on commit df03295

Please sign in to comment.