feat: initial work on edb, the edlang project manager

This commit is contained in:
Edgar 2024-03-11 09:36:49 +01:00
parent b1eea5a0bd
commit 22498719e1
No known key found for this signature in database
GPG Key ID: 70ADAE8F35904387
11 changed files with 468 additions and 133 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/target
/target_ed
playground/

359
Cargo.lock generated
View File

@ -2,21 +2,6 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "1.1.2"
@ -106,21 +91,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "backtrace"
version = "0.3.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "beef"
version = "0.5.2"
@ -159,6 +129,10 @@ name = "cc"
version = "1.0.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5"
dependencies = [
"jobserver",
"libc",
]
[[package]]
name = "cfg-if"
@ -206,33 +180,6 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
[[package]]
name = "color-eyre"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2"
dependencies = [
"once_cell",
"owo-colors",
"tracing-core",
"tracing-error",
]
[[package]]
name = "colorchoice"
version = "1.0.0"
@ -287,10 +234,15 @@ dependencies = [
]
[[package]]
name = "edlang"
name = "edb"
version = "0.0.1-alpha.12"
dependencies = [
"anyhow",
"clap",
"edlang_driver",
"git2",
"serde",
"toml",
]
[[package]]
@ -328,9 +280,9 @@ dependencies = [
name = "edlang_driver"
version = "0.0.1-alpha.12"
dependencies = [
"anyhow",
"ariadne",
"clap",
"color-eyre",
"edlang_ast",
"edlang_check",
"edlang_codegen_llvm",
@ -387,6 +339,13 @@ dependencies = [
name = "edlang_span"
version = "0.0.1-alpha.12"
[[package]]
name = "edlangc"
version = "0.0.1-alpha.12"
dependencies = [
"edlang_driver",
]
[[package]]
name = "educe"
version = "0.5.11"
@ -450,16 +409,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "eyre"
version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec"
dependencies = [
"indenter",
"once_cell",
]
[[package]]
name = "fastrand"
version = "2.0.1"
@ -478,6 +427,15 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "form_urlencoded"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
dependencies = [
"percent-encoding",
]
[[package]]
name = "getrandom"
version = "0.2.12"
@ -490,10 +448,19 @@ dependencies = [
]
[[package]]
name = "gimli"
version = "0.28.1"
name = "git2"
version = "0.18.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
checksum = "1b3ba52851e73b46a4c3df1d89343741112003f0f6f13beb0dfac9e457c3fdcd"
dependencies = [
"bitflags 2.4.2",
"libc",
"libgit2-sys",
"log",
"openssl-probe",
"openssl-sys",
"url",
]
[[package]]
name = "hashbrown"
@ -514,10 +481,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
[[package]]
name = "indenter"
version = "0.3.3"
name = "idna"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
dependencies = [
"unicode-bidi",
"unicode-normalization",
]
[[package]]
name = "indexmap"
@ -581,6 +552,15 @@ dependencies = [
"either",
]
[[package]]
name = "jobserver"
version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6"
dependencies = [
"libc",
]
[[package]]
name = "lalrpop"
version = "0.20.2"
@ -624,6 +604,20 @@ version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "libgit2-sys"
version = "0.16.2+1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee4126d8b4ee5c9d9ea891dd875cfdc1e9d0950437179104b183d7d8a74d24e8"
dependencies = [
"cc",
"libc",
"libssh2-sys",
"libz-sys",
"openssl-sys",
"pkg-config",
]
[[package]]
name = "libredox"
version = "0.0.1"
@ -635,6 +629,32 @@ dependencies = [
"redox_syscall",
]
[[package]]
name = "libssh2-sys"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dc8a030b787e2119a731f1951d6a773e2280c660f8ec4b0f5e1505a386e71ee"
dependencies = [
"cc",
"libc",
"libz-sys",
"openssl-sys",
"pkg-config",
"vcpkg",
]
[[package]]
name = "libz-sys"
version = "1.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "037731f5d3aaa87a5675e895b63ddff1a87624bc29f77004ea829809654e48f6"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "linux-raw-sys"
version = "0.4.13"
@ -719,15 +739,6 @@ version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[package]]
name = "miniz_oxide"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7"
dependencies = [
"adler",
]
[[package]]
name = "new_debug_unreachable"
version = "1.0.4"
@ -744,33 +755,36 @@ dependencies = [
"winapi",
]
[[package]]
name = "object"
version = "0.32.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "openssl-probe"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-sys"
version = "0.9.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dda2b0f344e78efc2facf7d195d098df0dd72151b26ab98da807afc26c198dff"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "owo-colors"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]]
name = "parking_lot"
version = "0.12.1"
@ -794,6 +808,12 @@ dependencies = [
"windows-targets 0.48.5",
]
[[package]]
name = "percent-encoding"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "petgraph"
version = "0.6.4"
@ -825,6 +845,12 @@ version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
[[package]]
name = "pkg-config"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
[[package]]
name = "precomputed-hash"
version = "0.1.1"
@ -919,12 +945,6 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "rustc-demangle"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]]
name = "rustix"
version = "0.38.31"
@ -965,6 +985,35 @@ version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca"
[[package]]
name = "serde"
version = "1.0.197"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.197"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_spanned"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1"
dependencies = [
"serde",
]
[[package]]
name = "sharded-slab"
version = "0.1.7"
@ -1111,6 +1160,55 @@ dependencies = [
"crunchy",
]
[[package]]
name = "tinyvec"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
dependencies = [
"tinyvec_macros",
]
[[package]]
name = "tinyvec_macros"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "toml"
version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a9aad4a3066010876e8dcf5a8a06e70a558751117a145c6ce2b82c2e2054290"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c1b5fd4128cc8d3e0cb74d4ed9a9cc7c7284becd4df68f5f940e1ad123606f6"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
]
[[package]]
name = "tracing"
version = "0.1.40"
@ -1143,16 +1241,6 @@ dependencies = [
"valuable",
]
[[package]]
name = "tracing-error"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e"
dependencies = [
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-log"
version = "0.2.0"
@ -1182,12 +1270,27 @@ dependencies = [
"tracing-log",
]
[[package]]
name = "unicode-bidi"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75"
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-normalization"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5"
dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-width"
version = "0.1.11"
@ -1200,6 +1303,17 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "url"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
]
[[package]]
name = "utf8parse"
version = "0.2.1"
@ -1212,6 +1326,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "walkdir"
version = "2.5.0"
@ -1448,6 +1568,15 @@ version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8"
[[package]]
name = "winnow"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8"
dependencies = [
"memchr",
]
[[package]]
name = "yansi"
version = "0.5.1"

View File

@ -1,7 +1,7 @@
[workspace]
resolver = "2"
members = [ "bin/edlang", "lib/edlang_ast", "lib/edlang_check", "lib/edlang_codegen_llvm", "lib/edlang_driver", "lib/edlang_ir", "lib/edlang_lowering","lib/edlang_parser", "lib/edlang_session", "lib/edlang_span"]
members = [ "bin/edlangc", "edb", "lib/edlang_ast", "lib/edlang_check", "lib/edlang_codegen_llvm", "lib/edlang_driver", "lib/edlang_ir", "lib/edlang_lowering","lib/edlang_parser", "lib/edlang_session", "lib/edlang_span"]
[profile.release]
lto = true

View File

@ -1,5 +1,5 @@
[package]
name = "edlang"
name = "edlangc"
version = "0.0.1-alpha.12"
authors = ["Edgar Luque <edgar@edgarluque.com>"]
description = "A experimental language using LLVM."

View File

@ -1,5 +1,5 @@
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
edlang_driver::main()
Ok(edlang_driver::main()?)
}

22
edb/Cargo.toml Normal file
View File

@ -0,0 +1,22 @@
[package]
name = "edb"
version = "0.0.1-alpha.12"
authors = ["Edgar Luque <edgar@edgarluque.com>"]
description = "The edlang language builder."
edition = "2021"
readme = "README.md"
keywords = ["llvm", "compiler"]
license = "AGPL-3.0-only"
categories = ["compilers"]
documentation = "https://docs.rs/edlang"
repository = "https://github.com/edg-l/edlang"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
edlang_driver = { version = "0.0.1-alpha.12", path = "../lib/edlang_driver" }
anyhow = "1"
clap = { version = "4.4.16", features = ["derive"] }
toml = "0.8.10"
serde = { version = "1.0.197", features = ["derive"] }
git2 = "0.18.2"

23
edb/src/config.rs Normal file
View File

@ -0,0 +1,23 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
pub package: Package,
pub profile: HashMap<String, Profile>,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Package {
pub name: String,
pub version: String,
pub license: String,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Profile {
pub release: bool,
pub opt_level: u8,
pub debug_info: bool,
}

153
edb/src/main.rs Normal file
View File

@ -0,0 +1,153 @@
use std::{collections::HashMap, path::PathBuf};
use anyhow::{Context, Result};
use clap::{Parser, Subcommand};
use config::{Config, Package, Profile};
use git2::{IndexAddOption, Repository, RepositoryInitOptions};
mod config;
#[derive(Parser, Debug)]
#[command(author, version, about = "edlang builder", long_about = None, bin_name = "edlang")]
pub struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand, Debug)]
enum Commands {
/// Initialize a project
New {
path: PathBuf,
/// The name of the project, defaults to the directory name
#[arg(long)]
name: Option<String>,
/// Use a binary (application) template [default]
#[arg(long, group = "binary", default_value_t = true)]
bin: bool,
#[arg(long, group = "binary")]
lib: bool,
},
/// Build a project
Build {
/// Build for release with all optimizations.
#[arg(short, long, default_value_t = false)]
release: bool,
},
}
fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::New {
path,
name,
bin,
lib,
} => {
let name = name.unwrap_or_else(|| {
path.file_name()
.context("Failed to get project name")
.unwrap()
.to_string_lossy()
.to_string()
});
if !path.exists() {
std::fs::create_dir_all(&path).context("failed to create the project directory")?;
std::fs::create_dir_all(path.join("src")).context("failed to create src/")?;
}
let config_path = path.join("Ed.toml");
let mut profiles = HashMap::new();
profiles.insert(
"release".to_string(),
Profile {
release: true,
opt_level: 3,
debug_info: false,
},
);
profiles.insert(
"dev".to_string(),
Profile {
release: false,
opt_level: 0,
debug_info: true,
},
);
let config = Config {
package: Package {
name: name.clone(),
version: "0.1.0".to_string(),
license: "AGPL-3.0-only".to_string(),
},
profile: profiles,
};
std::fs::write(config_path, toml::to_string_pretty(&config)?)
.context("failed to write Ed.toml")?;
std::fs::write(path.join(".gitignore"), "/target-ed\n")
.context("failed to write .gitignore")?;
std::fs::write(path.join(".gitattributes"), "*.ed linguist-language=Rust\n")
.context("failed to write .gitattributes")?;
if bin {
std::fs::write(
path.join("src").join("main.ed"),
format!(
r#"
mod {} {{
pub fn main() -> i32 {{
return 0;
}}
}}"#,
name
),
)?;
}
if lib {
std::fs::write(
path.join("src").join("lib.ed"),
format!(
r#"
mod {} {{
pub fn hello_world() -> i32 {{
return 0;
}}
}}"#,
name
),
)?;
}
{
let mut repo = Repository::init(&path).context("failed to create repository")?;
let sig = repo.signature()?;
let tree_id = {
let mut index = repo.index()?;
index.add_all(["*"], IndexAddOption::DEFAULT, None)?;
index.write_tree()?
};
let tree = repo.find_tree(tree_id).context("failed to find git tree")?;
repo.commit(Some("HEAD"), &sig, &sig, "Initial commit", &tree, &[])
.context("failed to create initial commit")?;
}
}
Commands::Build { release } => todo!(),
}
Ok(())
}

View File

@ -3,10 +3,7 @@ use std::path::Path;
use tracing::instrument;
#[instrument(level = "debug")]
pub fn link_shared_lib(
input_path: &Path,
output_filename: &Path,
) -> Result<(), Box<dyn std::error::Error>> {
pub fn link_shared_lib(input_path: &Path, output_filename: &Path) -> std::io::Result<()> {
let args: &[&str] = {
#[cfg(target_os = "macos")]
{
@ -51,10 +48,7 @@ pub fn link_shared_lib(
}
#[instrument(level = "debug")]
pub fn link_binary(
input_path: &Path,
output_filename: &Path,
) -> Result<(), Box<dyn std::error::Error>> {
pub fn link_binary(input_path: &Path, output_filename: &Path) -> std::io::Result<()> {
let args: &[&str] = {
#[cfg(target_os = "macos")]
{

View File

@ -15,7 +15,7 @@ repository = "https://github.com/edg-l/edlang"
[dependencies]
ariadne = { version = "0.4.0", features = ["auto-color"] }
clap = { version = "4.4.16", features = ["derive"] }
color-eyre = "0.6.2"
anyhow = "1"
edlang_ast = { version = "0.0.1-alpha.12", path = "../edlang_ast" }
edlang_check = { version = "0.0.1-alpha.12", path = "../edlang_check" }
edlang_codegen_llvm = { version = "0.0.1-alpha.12", path = "../edlang_codegen_llvm" }

View File

@ -1,5 +1,6 @@
use std::{error::Error, path::PathBuf, time::Instant};
use std::{path::PathBuf, time::Instant};
use anyhow::{bail, Result};
use ariadne::Source;
use clap::Parser;
use edlang_codegen_llvm::linker::{link_binary, link_shared_lib};
@ -7,7 +8,7 @@ use edlang_lowering::lower_modules;
use edlang_session::{DebugInfo, OptLevel, Session};
#[derive(Parser, Debug)]
#[command(author, version, about = "edlang compiler driver", long_about = None, bin_name = "edlang")]
#[command(author, version, about = "edlang compiler driver", long_about = None, bin_name = "edlangc")]
pub struct CompilerArgs {
/// The input file.
input: PathBuf,
@ -45,13 +46,25 @@ pub struct CompilerArgs {
asm: bool,
}
pub fn main() -> Result<(), Box<dyn Error>> {
let start_time = Instant::now();
pub fn main() -> Result<()> {
tracing_subscriber::fmt::init();
let args = CompilerArgs::parse();
compile_single_file(args)?;
Ok(())
}
pub fn compile_single_file(args: CompilerArgs) -> Result<()> {
if !args.input.is_file() {
bail!("Input is not a file");
}
let start_time = Instant::now();
tracing_subscriber::fmt::init();
let path = args.input.display().to_string();
let source = std::fs::read_to_string(&args.input)?;
@ -140,7 +153,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
return Ok(());
}
let object_path = edlang_codegen_llvm::compile(&session, &program_ir)?;
let object_path = edlang_codegen_llvm::compile(&session, &program_ir).unwrap();
if session.library {
link_shared_lib(&object_path, &session.output_file)?;