Skip to content

Commit

Permalink
feat/fe cli interface (#732)
Browse files Browse the repository at this point in the history
  • Loading branch information
vuvoth authored Jun 15, 2022
1 parent a761022 commit d7df92b
Show file tree
Hide file tree
Showing 12 changed files with 541 additions and 304 deletions.
87 changes: 71 additions & 16 deletions Cargo.lock

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

29 changes: 28 additions & 1 deletion crates/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ pub struct CompiledContract {
#[derive(Debug)]
pub struct CompileError(pub Vec<Diagnostic>);

pub fn check_single_file(db: &mut Db, path: &str, src: &str) -> Vec<Diagnostic> {
let module = ModuleId::new_standalone(db, path, src);
module.diagnostics(db)
}

pub fn compile_single_file(
db: &mut Db,
path: &str,
Expand All @@ -43,15 +48,37 @@ pub fn compile_single_file(
optimize: bool,
) -> Result<CompiledModule, CompileError> {
let module = ModuleId::new_standalone(db, path, src);

let diags = module.diagnostics(db);

if diags.is_empty() {
compile_module_id(db, module, with_bytecode, optimize)
} else {
Err(CompileError(diags))
}
}

// Run analysis with ingot
// Return vector error,waring...
pub fn check_ingot(
db: &mut Db,
name: &str,
files: &[(impl AsRef<str>, impl AsRef<str>)],
) -> Vec<Diagnostic> {
let std = IngotId::std_lib(db);
let ingot = IngotId::from_files(
db,
name,
IngotMode::Main,
FileKind::Local,
files,
indexmap! { "std".into() => std },
);

let mut diags = ingot.diagnostics(db);
ingot.sink_external_ingot_diagnostics(db, &mut diags);
diags
}

/// Compiles the main module of a project.
///
/// If `with_bytecode` is set to false, the compiler will skip the final Yul ->
Expand Down
4 changes: 3 additions & 1 deletion crates/fe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ version = "0.18.0-alpha"
solc-backend = ["fe-driver/solc-backend"]

[dependencies]
clap = "2.33.3"
clap = {version="3.1.18", features = ["derive"]}
fs_extra = "1.2.0"
walkdir = "2"
indexmap = "1.6.2"
include_dir = "0.7.2"

fe-common = {path = "../common", version = "^0.18.0-alpha"}
fe-driver = {path = "../driver", version = "^0.18.0-alpha"}
Expand Down
Loading

0 comments on commit d7df92b

Please sign in to comment.