Skip to content

Commit

Permalink
refactor(kclvm-runner): merge main and refacor kclvm-runner.
Browse files Browse the repository at this point in the history
      1. Encapsulated method "emit_code" into "lock_ll_file_and_gen_dylib" to
         reduce repetitive code in kclvm-runner/KclvmAssembler.gen_dylibs().
      2. In order to support reuse and simplify the structure of Method "gen_dylibs()",
         encapsulates some operations of cleaning file paths.
      3. Due to issue #79, some test cases are temporarily commented out

      fix #67

      refactor(kclvm-runner): decouping assembler and llvm.

      1. Decoupling the assembler and llvm.
      2. The assembling LLVM IR into a dynamic link library is encapsulated into "LlvmLibAssembler" separately.
      3. Add trait "LibAssembler" to describe the interface "KclvmLibAssembler" should have.
         If other intermediate code is added in the future, the corresponding assembler must implement this trait.
      4. Struct "LlvmLibAssembler" is provided in "KclvmLibAssembler".
         "KclvmLibAssembler" is an enum that implements trait "LibAssembler".
         "KclvmLibAssembler" is responsible for the compilation of a single kcl file in one thread.
    , 5. "KclvmAssembler" is responsible for the concurrent compilation of multiple kcl files.
      6. "KclvmAssembler" will call the method in "KclvmLibAssembler" to generate a dynamic link library
         for a single kcl file in each thread of concurrent compilation.

      fix #67
  • Loading branch information
Peefy committed Jun 13, 2022
1 parent 625db47 commit 77c3872
Show file tree
Hide file tree
Showing 14 changed files with 660 additions and 366 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ jobs:
components: clippy, rustfmt
- name: Rust unit test
working-directory: ./kclvm
run: make test
run: export PATH=$PATH:../_build/dist/ubuntu/kclvm/bin && make test
shell: bash
1 change: 1 addition & 0 deletions kclvm/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 kclvm/config/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl Default for SettingsFile {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct KeyValuePair {
key: String,
value: String,
pub key: String,
pub value: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down
12 changes: 12 additions & 0 deletions kclvm/runner/Cargo.lock

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

1 change: 1 addition & 0 deletions kclvm/runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ kclvm-runtime = {path = "../runtime", version = "0.1.0"}
kclvm-sema = {path = "../sema", version = "0.1.0"}
kclvm-version = {path = "../version", version = "0.1.0"}
kclvm-error = {path = "../error", version="0.1.0"}
kclvm-tools = {path = "../tools", version = "0.1.0"}

[dev-dependencies]
kclvm-parser = {path = "../parser", version = "0.1.0"}
Expand Down
26 changes: 20 additions & 6 deletions kclvm/runner/benches/bench_runner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use criterion::{criterion_group, criterion_main, Criterion};
use kclvm_parser::load_program;
use kclvm_runner::{execute, runner::ExecProgramArgs};
use kclvm_tools::query::apply_overrides;

const TEST_CASE_PATH: &str = "/src/test_datas/init_check_order_0/main.k";

Expand All @@ -10,17 +11,30 @@ pub fn criterion_benchmark(c: &mut Criterion) {
std::env::current_dir().unwrap().to_str().unwrap(),
TEST_CASE_PATH
);
let plugin_agent = 0;

c.bench_function("load_program -> execute", |b| {
c.bench_function("refactor kclvm-runner", |b| {
b.iter(|| {
let args = ExecProgramArgs::default();
let opts = args.get_load_program_options();
let program = load_program(&[kcl_path], Some(opts)).unwrap();
execute(program, plugin_agent, &args).unwrap()
after_refactor(kcl_path.to_string());
})
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

fn after_refactor(k_path: String) {
let mut args = ExecProgramArgs::default();
args.k_filename_list.push(k_path);

let plugin_agent = 0;

let files = args.get_files();
let opts = args.get_load_program_options();

// load ast
let mut program = load_program(&files, Some(opts)).unwrap();
apply_overrides(&mut program, &args.overrides, &[]);

// resolve ast, generate libs, link libs and execute.
execute(program, plugin_agent, &args);
}
Loading

0 comments on commit 77c3872

Please sign in to comment.