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
                    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 20, 2022
1 parent 625db47 commit 0fe6ac2
Show file tree
Hide file tree
Showing 13 changed files with 687 additions and 371 deletions.
2 changes: 2 additions & 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
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.

2 changes: 2 additions & 0 deletions kclvm/runner/Cargo.toml
Expand Up @@ -17,6 +17,7 @@ fslock = "0.2.1"
libloading = "0.7.3"
threadpool = "1.0"
chrono = "0.4.19"
tempfile = "3.3.0"

kclvm-ast = {path = "../ast", version = "0.1.0"}
kclvm-parser = {path = "../parser", version = "0.1.0"}
Expand All @@ -26,6 +27,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
@@ -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);
}

0 comments on commit 0fe6ac2

Please sign in to comment.