From e9759448372045761c4dfa8beef2f28d6e8ea6b1 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Tue, 9 Feb 2021 00:04:04 +0100 Subject: [PATCH 01/15] feat: basic llvm code generation --- Cargo.lock | 198 ++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 5 +- examples/playground.sb | 9 +- src/generator/llvm.rs | 33 +++++++ src/generator/mod.rs | 3 + 5 files changed, 238 insertions(+), 10 deletions(-) create mode 100644 src/generator/llvm.rs diff --git a/Cargo.lock b/Cargo.lock index da272ca..e46d3b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,14 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "aho-corasick" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +dependencies = [ + "memchr", +] + [[package]] name = "ansi_term" version = "0.11.0" @@ -26,12 +35,24 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "cc" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" + [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "clap" version = "2.33.3" @@ -47,13 +68,19 @@ dependencies = [ "vec_map", ] +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + [[package]] name = "getrandom" version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "wasi", ] @@ -76,6 +103,41 @@ dependencies = [ "libc", ] +[[package]] +name = "inkwell" +version = "0.1.0-beta.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5fe0be1e47c0c0f3da4397693e08f5d78329ae095c25d529e12ade78420fb41" +dependencies = [ + "either", + "inkwell_internals", + "libc", + "llvm-sys", + "once_cell", + "parking_lot", + "regex", +] + +[[package]] +name = "inkwell_internals" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2e1f71330ccec54ee62533ae88574c4169b67fb4b95cbb1196a1322582abd11" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "instant" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -88,6 +150,74 @@ version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" +[[package]] +name = "llvm-sys" +version = "110.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0062a0c6635fb5d57c6ebba072dcae50e41651030363cf06d220b0d016840f2" +dependencies = [ + "cc", + "lazy_static", + "libc", + "regex", + "semver", +] + +[[package]] +name = "lock_api" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" + +[[package]] +name = "once_cell" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" + +[[package]] +name = "parking_lot" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ccb628cad4f84851442432c60ad8e1f607e29752d0bf072cbd0baf28aa34272" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + [[package]] name = "ppv-lite86" version = "0.2.10" @@ -183,6 +313,24 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +[[package]] +name = "regex" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-syntax" +version = "0.6.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" + [[package]] name = "remove_dir_all" version = "0.5.3" @@ -228,6 +376,7 @@ dependencies = [ name = "sabre-lang" version = "0.2.1" dependencies = [ + "inkwell", "rust-embed", "structopt", "tempfile", @@ -242,6 +391,36 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + +[[package]] +name = "smallvec" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" + [[package]] name = "strsim" version = "0.8.0" @@ -289,7 +468,7 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "rand", "redox_syscall", @@ -306,6 +485,21 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "thread_local" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" +dependencies = [ + "once_cell", +] + +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + [[package]] name = "unicode-segmentation" version = "1.7.1" diff --git a/Cargo.toml b/Cargo.toml index c4d2e1e..394ad70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,10 +17,13 @@ path = "src/main.rs" [features] backend_c = [] backend_node = [] +backend_llvm = ["inkwell"] -default = ["backend_node"] +default = ["backend_llvm"] [dependencies] structopt = "0.3.21" rust-embed = "5.7.0" tempfile = "3.1.0" +inkwell = { version = "0.1.0-beta.2", features = ["llvm11-0"], optional = true } + diff --git a/examples/playground.sb b/examples/playground.sb index 6b9a030..bfae892 100644 --- a/examples/playground.sb +++ b/examples/playground.sb @@ -1,8 +1,3 @@ -fn main() { +fn main() {} - let arr = [1, 2, 3] - - for x in arr { - _printf(x) - } -} \ No newline at end of file +fn add_one() {} \ No newline at end of file diff --git a/src/generator/llvm.rs b/src/generator/llvm.rs new file mode 100644 index 0000000..afd5b57 --- /dev/null +++ b/src/generator/llvm.rs @@ -0,0 +1,33 @@ +use crate::generator::Generator; +use crate::parser::node_type::*; +use inkwell::builder::Builder; +use inkwell::context::Context; +use inkwell::module::Module; +use inkwell::targets::{InitializationConfig, Target}; + +pub struct LLVMGenerator<'ctx> { + ctx: &'ctx Context, + module: Module<'ctx>, +} + +impl<'ctx> Generator for LLVMGenerator<'ctx> { + fn generate(prog: Program) -> String { + let ctx = Context::create(); + let module = ctx.create_module("main"); + let mut generator = LLVMGenerator { + ctx: &ctx, + module: module, + }; + for func in prog.func { + generator.generate_function(func); + } + generator.module.print_to_string().to_string() + } +} + +impl<'ctx> LLVMGenerator<'ctx> { + fn generate_function(&mut self, func: Function) { + self.module + .add_function(&func.name, self.ctx.void_type().fn_type(&[], false), None); + } +} diff --git a/src/generator/mod.rs b/src/generator/mod.rs index 8f2f045..b18c468 100644 --- a/src/generator/mod.rs +++ b/src/generator/mod.rs @@ -17,6 +17,7 @@ use crate::parser::node_type::*; pub mod c; pub mod js; +pub mod llvm; #[cfg(test)] mod tests; pub mod x86; @@ -30,6 +31,8 @@ pub fn generate(prog: Program) -> String { c::CGenerator::generate(prog) } else if cfg!(feature = "backend_node") { js::JsGenerator::generate(prog) + } else if cfg!(feature = "backend_llvm") { + llvm::LLVMGenerator::generate(prog) } else { panic!("No backend specified") } From ee702e166f0df4b1a22acadf6942e3a91604402c Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Tue, 9 Feb 2021 15:52:16 +0100 Subject: [PATCH 02/15] ci: only build master branch --- .builds/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.builds/ci.yml b/.builds/ci.yml index 9332efc..6f8c9fc 100644 --- a/.builds/ci.yml +++ b/.builds/ci.yml @@ -3,7 +3,7 @@ packages: - rust - node sources: - - https://git.sr.ht/~garritfra/sabre + - https://git.sr.ht/~garritfra/sabre#master tasks: - build: | cd sabre From 087bdb19a0bacdf2a7270358c8781e538bf0a287 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Tue, 9 Feb 2021 16:41:08 +0100 Subject: [PATCH 03/15] ci: add github actions --- .builds/ci.yml | 1 - .github/workflows/ci.yml | 64 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.builds/ci.yml b/.builds/ci.yml index 6f8c9fc..7d3bf99 100644 --- a/.builds/ci.yml +++ b/.builds/ci.yml @@ -6,6 +6,5 @@ sources: - https://git.sr.ht/~garritfra/sabre#master tasks: - build: | - cd sabre cargo build cargo test diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bd39dac --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,64 @@ +on: [push, pull_request] + +name: Continuous integration + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: check + + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: test + + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add clippy + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- # -D warnings <-- Uncomment to fail when there is a clippy warning From cfdb0ead49c54933ff76eabbd8ab87d1583d9ec6 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Tue, 9 Feb 2021 17:42:04 +0100 Subject: [PATCH 04/15] feat: array as function call parameter --- TODO | 1 - examples/playground.sb | 2 +- src/generator/js.rs | 2 +- src/parser/rules.rs | 6 ++++++ src/parser/tests.rs | 1 - 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index a9b4bec..6e9d5cb 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,5 @@ # Bugs - Nested expressions can have invalid parens. E.g.: 6 % 3 == 0 should be true; is false (See test_complex_nested_expressions) -- Arrays as function arguments don't work (See test_array_as_argument) # Cleanups - Improve error reporting (See ./util/string_util::highlight_position_in_file) diff --git a/examples/playground.sb b/examples/playground.sb index bfae892..1e6b0d6 100644 --- a/examples/playground.sb +++ b/examples/playground.sb @@ -1,3 +1,3 @@ fn main() {} -fn add_one() {} \ No newline at end of file +fn add_one() {} diff --git a/src/generator/js.rs b/src/generator/js.rs index bb649bd..8649982 100644 --- a/src/generator/js.rs +++ b/src/generator/js.rs @@ -212,7 +212,7 @@ fn generate_function_call(func: String, args: Vec) -> String { Expression::ArrayAccess(name, expr) => generate_array_access(name, *expr), Expression::FunctionCall(n, a) => generate_function_call(n, a), Expression::Str(s) | Expression::Variable(s) => s, - Expression::Array(_) => todo!(), + Expression::Array(elements) => generate_array(elements), Expression::BinOp(left, op, right) => generate_bin_op(*left, op, *right), }) .collect::>() diff --git a/src/parser/rules.rs b/src/parser/rules.rs index dcf1596..218c951 100644 --- a/src/parser/rules.rs +++ b/src/parser/rules.rs @@ -188,6 +188,12 @@ impl Parser { args.push(self.parse_expression()?) } TokenKind::Keyword(Keyword::Boolean) => args.push(self.parse_expression()?), + TokenKind::SquareBraceOpen => { + // TODO: Expression parsing currently uses `next` instead of `peek`. + // We have to eat that token here until that is resolved + self.match_token(TokenKind::SquareBraceOpen)?; + args.push(self.parse_array()?); + } _ => { return Err(self.make_error(TokenKind::BraceClose, next)); } diff --git a/src/parser/tests.rs b/src/parser/tests.rs index 0f2d54d..210b96b 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -766,7 +766,6 @@ fn test_complex_nested_expressions() { } #[test] -#[ignore] fn test_array_as_argument() { let raw = " fn main() { From 5f5b246c68d9a22d0da64f9a19d42c177a9bbc03 Mon Sep 17 00:00:00 2001 From: Garrit Franke <32395585+garritfra@users.noreply.github.com> Date: Tue, 9 Feb 2021 17:34:47 +0100 Subject: [PATCH 05/15] GitHub actions (#3) * ci: fix clippy * ci: fix clippy warning * ci: add status badge to readme Co-authored-by: Garrit Franke --- README.md | 2 +- src/command/build.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1f7f0d2..72aec95 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # The Sabre Programming language [![](https://img.shields.io/crates/v/sabre-lang.svg)](https://crates.io/crates/sabre-lang) -[![builds.sr.ht status](https://builds.sr.ht/~garritfra/sabre/commits/ci.yml.svg)](https://builds.sr.ht/~garritfra/sabre/commits/ci.yml?) +![Continuous integration](https://github.com/garritfra/sabre/workflows/Continuous%20integration/badge.svg?branch=master) [![docs](https://img.shields.io/badge/docs-mdBook-blue.svg)](https://garritfra.github.io/sabre/latest) [![Chat on Matrix](https://img.shields.io/badge/chat-on%20Matrix-green)](https://matrix.to/#/#sabre:matrix.slashdev.space?via=matrix.slashdev.space) diff --git a/src/command/build.rs b/src/command/build.rs index d562d75..287ecdb 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -39,7 +39,7 @@ pub fn build(in_file: &PathBuf, out_file: &PathBuf) -> Result<(), String> { let output = generator::generate(program); let mut file = std::fs::File::create(out_file).expect("create failed"); - file.write(output.as_bytes()).expect("write failed"); + file.write_all(output.as_bytes()).expect("write failed"); file.flush().expect("Could not flush file"); Ok(()) From 9cd07811c94fe0319fbd0d4b8f4f7eac8dba4766 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Wed, 10 Feb 2021 15:10:47 +0100 Subject: [PATCH 06/15] chore: remove playground --- examples/playground.sb | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 examples/playground.sb diff --git a/examples/playground.sb b/examples/playground.sb deleted file mode 100644 index 1e6b0d6..0000000 --- a/examples/playground.sb +++ /dev/null @@ -1,3 +0,0 @@ -fn main() {} - -fn add_one() {} From 0705c80e9f4ce98dbfa3a648f3e1b10951705cd0 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Wed, 10 Feb 2021 15:11:28 +0100 Subject: [PATCH 07/15] chore: ignore playground --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 09dbe4c..4a9063a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ target/ .vscode/ examples_out/ tests_out/ -book/ \ No newline at end of file +book/ +examples/playground.sb \ No newline at end of file From 635f139305403cf89d49b039edfa4b28e1d0525f Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Wed, 10 Feb 2021 15:21:37 +0100 Subject: [PATCH 08/15] ci: add llvm --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd39dac..a8255e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Install LLVM and Clang + uses: KyleMayes/install-llvm-action@v1 + with: + version: "10.0" + directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: profile: minimal @@ -22,6 +27,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Install LLVM and Clang + uses: KyleMayes/install-llvm-action@v1 + with: + version: "10.0" + directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: profile: minimal @@ -36,6 +46,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Install LLVM and Clang + uses: KyleMayes/install-llvm-action@v1 + with: + version: "10.0" + directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: profile: minimal @@ -52,6 +67,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Install LLVM and Clang + uses: KyleMayes/install-llvm-action@v1 + with: + version: "10.0" + directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: profile: minimal From da1174c0c101edaf1409804bcfd49e4b72f36438 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Wed, 10 Feb 2021 15:25:29 +0100 Subject: [PATCH 09/15] ci: use llvm version 11 --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8255e1..8303cf8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 with: - version: "10.0" + version: "11.0" directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: @@ -30,7 +30,7 @@ jobs: - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 with: - version: "10.0" + version: "11.0" directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: @@ -49,7 +49,7 @@ jobs: - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 with: - version: "10.0" + version: "11.0" directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: @@ -70,7 +70,7 @@ jobs: - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 with: - version: "10.0" + version: "11.0" directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: From ca2b4825aeb7e3c95d85d35e9b457a0d44827107 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Wed, 10 Feb 2021 15:30:32 +0100 Subject: [PATCH 10/15] ci: use llvm version 11 --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8303cf8..9cae85a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 with: - version: "11.0" + version: "11" directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: @@ -30,7 +30,7 @@ jobs: - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 with: - version: "11.0" + version: "11" directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: @@ -49,7 +49,7 @@ jobs: - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 with: - version: "11.0" + version: "11" directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: @@ -70,7 +70,7 @@ jobs: - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 with: - version: "11.0" + version: "11" directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: From 4759fb277422c8053edd986b5decef16f60ff537 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Wed, 10 Feb 2021 15:35:45 +0100 Subject: [PATCH 11/15] ci: use llvm 10 --- .github/workflows/ci.yml | 8 ++++---- Cargo.lock | 30 ++++++------------------------ Cargo.toml | 2 +- 3 files changed, 11 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cae85a..0b36744 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 with: - version: "11" + version: "10" directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: @@ -30,7 +30,7 @@ jobs: - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 with: - version: "11" + version: "10" directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: @@ -49,7 +49,7 @@ jobs: - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 with: - version: "11" + version: "10" directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: @@ -70,7 +70,7 @@ jobs: - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v1 with: - version: "11" + version: "10" directory: ${{ runner.temp }}/llvm - uses: actions-rs/toolchain@v1 with: diff --git a/Cargo.lock b/Cargo.lock index e46d3b3..b38bcf4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -152,9 +152,9 @@ checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" [[package]] name = "llvm-sys" -version = "110.0.0" +version = "100.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0062a0c6635fb5d57c6ebba072dcae50e41651030363cf06d220b0d016840f2" +checksum = "9109e19fbfac3458f2970189719fa19f1007c6fd4e08c44fdebf4be0ddbe261d" dependencies = [ "cc", "lazy_static", @@ -209,15 +209,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "pest" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" -dependencies = [ - "ucd-trie", -] - [[package]] name = "ppv-lite86" version = "0.2.10" @@ -399,21 +390,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "semver" -version = "0.11.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ "semver-parser", ] [[package]] name = "semver-parser" -version = "0.10.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "smallvec" @@ -494,12 +482,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "ucd-trie" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" - [[package]] name = "unicode-segmentation" version = "1.7.1" diff --git a/Cargo.toml b/Cargo.toml index 394ad70..f559cde 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,5 +25,5 @@ default = ["backend_llvm"] structopt = "0.3.21" rust-embed = "5.7.0" tempfile = "3.1.0" -inkwell = { version = "0.1.0-beta.2", features = ["llvm11-0"], optional = true } +inkwell = { version = "0.1.0-beta.2", features = ["llvm10-0"], optional = true } From 460dd4b708b2cbeb936513ff994ca70fec319a49 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Wed, 10 Feb 2021 15:41:03 +0100 Subject: [PATCH 12/15] chore: use node target as default --- Cargo.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f559cde..abf3f0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,9 @@ backend_c = [] backend_node = [] backend_llvm = ["inkwell"] -default = ["backend_llvm"] +# To change, use the --featues flag: +# cargo run --features backend_llvm +default = ["backend_node"] [dependencies] structopt = "0.3.21" From e440cdcbd1d71b026f3ba0456bd4745a7cc2f070 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Wed, 10 Feb 2021 15:43:52 +0100 Subject: [PATCH 13/15] docs: document llvm target --- docs/developers/backends.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/developers/backends.md b/docs/developers/backends.md index 4a16fb3..1ac62c2 100644 --- a/docs/developers/backends.md +++ b/docs/developers/backends.md @@ -10,9 +10,16 @@ The backend can be specified in the `Cargo.toml` file in the root of the project default = ["backend_c"] ``` +If you're working on an unstable backend, you can override the backend using the `--features` flag of the cargo CLI: + +``` +cargo run --features backend_llvm ... +``` + ## Available Backends | Target Language | Identifier | Stability notice | | :-------------- | :------------- | :--------------- | | Node.js | `backend_node` | mostly stable | +| LLVM | `backend_llvm` | unstable | | C | `backend_c` | unstable | From 6c2f1ffaa3bf05450d2af367e9ef38cbdcef2ead Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Wed, 10 Feb 2021 15:54:51 +0100 Subject: [PATCH 14/15] chore: refactor backend plugin infrastructure --- src/generator/mod.rs | 22 +++++++++++++--------- src/generator/tests/mod.rs | 1 + 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/generator/mod.rs b/src/generator/mod.rs index b18c468..482009f 100644 --- a/src/generator/mod.rs +++ b/src/generator/mod.rs @@ -15,8 +15,11 @@ */ use crate::parser::node_type::*; +#[cfg(feature = "backend_c")] pub mod c; +#[cfg(feature = "backend_node")] pub mod js; +#[cfg(feature = "backend_llvm")] pub mod llvm; #[cfg(test)] mod tests; @@ -27,13 +30,14 @@ pub trait Generator { } pub fn generate(prog: Program) -> String { - if cfg!(feature = "backend_c") { - c::CGenerator::generate(prog) - } else if cfg!(feature = "backend_node") { - js::JsGenerator::generate(prog) - } else if cfg!(feature = "backend_llvm") { - llvm::LLVMGenerator::generate(prog) - } else { - panic!("No backend specified") - } + #[cfg(feature = "backend_llvm")] + return llvm::LLVMGenerator::generate(prog); + + #[cfg(feature = "backend_c")] + return c::CGenerator::generate(prog); + + #[cfg(feature = "backend_node")] + return js::JsGenerator::generate(prog); + + panic!("No backend specified"); } diff --git a/src/generator/tests/mod.rs b/src/generator/tests/mod.rs index 8999cd3..4e807ca 100644 --- a/src/generator/tests/mod.rs +++ b/src/generator/tests/mod.rs @@ -1 +1,2 @@ +#[cfg(feature = "backend_c")] mod c_tests; From 0848c4166b094b14c3b58c0b3f15470d1bd38f0e Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Wed, 10 Feb 2021 16:00:33 +0100 Subject: [PATCH 15/15] ci: fix builds.sr.ht --- .builds/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.builds/ci.yml b/.builds/ci.yml index 7d3bf99..aba3a23 100644 --- a/.builds/ci.yml +++ b/.builds/ci.yml @@ -3,7 +3,7 @@ packages: - rust - node sources: - - https://git.sr.ht/~garritfra/sabre#master + - https://git.sr.ht/~garritfra/sabre tasks: - build: | cargo build