Skip to content

Commit

Permalink
Merge pull request #35 from iwillspeak/treebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
iwillspeak authored Aug 28, 2022
2 parents a2d595c + 829ef8d commit c0330d9
Show file tree
Hide file tree
Showing 27 changed files with 843 additions and 539 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

root = true

[*.rs]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
indent_style = space
indent_size = 4
163 changes: 65 additions & 98 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ categories = [ "parsing" ]
edition = "2018"

[features]
default = [ "llvm-9" ]
default = [ "llvm-13" ]

[dependencies]
llvm-9 = { package = "llvm-sys", version = "90", optional = true }
llvm-10 = { package = "llvm-sys", version = "100", optional = true }
llvm-13 = { package = "llvm-sys", version = "130", optional = true }
docopt = "1.1"
serde = { version = "1.0", features = ["derive"] }
tempfile = "3.1"
failure = "0.1"
libc = "0.2"
indexmap = "1.5"
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
features := "llvm-10"
features := "llvm-13"

build:
cargo build --release --no-default-features --features={{features}}
Expand Down
13 changes: 13 additions & 0 deletions spec/malformed/invalid_calls.ulg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn foo(n: Number, b: Bool): Number
n if b else 2
end

# !> 6:4:error: unexpected token: expected expression but found ','
foo(,)

# it's OK to have a trailing `,`
foo(100, false,)

# don't go nuts though...
# !> 13:15:error: unexpected token: expected expression but found ','
foo(969, true, ,)
20 changes: 11 additions & 9 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ use crate::diag::Diagnostic;
use crate::low_loader::prelude::*;
use crate::sem;
use crate::syntax;
use linker::Linker;
use std::path::Path;
use std::process::Command;
use tempfile::Builder;

pub use self::error::{CompError, CompResult};
pub use self::options::{CompilationOptions, LinkKind, OptimisationLevel};
pub use self::options::{CompilationOptions, OptimisationLevel};

pub mod error;
pub mod linker;
pub mod options;

mod lower;
Expand Down Expand Up @@ -105,13 +107,13 @@ impl Compilation {
fun.verify_or_panic();
module.verify_or_panic();

let linker = self.options.linker.unwrap_or_else(Linker::default);

// Create a tempdir to write the LLVM IR or bitcode to
let (suffix, kind) = match self.options.link_kind {
LinkKind::IL => (".il", OutputFileKind::LLVMIl),
LinkKind::Bitcode => (".bc", OutputFileKind::Bitcode),
LinkKind::Object => (".o", OutputFileKind::NativeObject),
};
let temp_file = Builder::new().prefix("ullage").suffix(suffix).tempfile()?;
let temp_file = Builder::new()
.prefix("ullage")
.suffix(linker.asset_ty.extension())
.tempfile()?;

// check if we have optimiation enabled and run the
// corresponding optimisations if we do.
Expand All @@ -123,10 +125,10 @@ impl Compilation {
if self.options.dump_ir {
module.dump();
}
module.write_to_file(&target, temp_file.path(), kind)?;
module.write_to_file(&target, temp_file.path(), linker.asset_ty.file_kind())?;

// Shell out to Clang to link the final assembly
let output = Command::new("clang")
let output = Command::new(linker.cmd.executable())
.arg(temp_file.path())
.arg(format!("--target={}", target.triple()))
.arg("-o")
Expand Down
Loading

0 comments on commit c0330d9

Please sign in to comment.