Skip to content

Commit

Permalink
Merge branch 'feature/codegenv2' of github.com:hotg-ai/rune into feat…
Browse files Browse the repository at this point in the history
…ure/update_rune_execution
  • Loading branch information
kthakore committed Feb 11, 2021
2 parents 2b914f8 + 0b4559a commit 207a7b2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
16 changes: 5 additions & 11 deletions runefile-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ pub fn generate(contents: String) -> PathBuf {
let mut cargo_toml = String::from("");

// We need to use toml editor here
// Code which is appended below is displayed in reverse order in Cargo.toml

cargo_toml = [
format!("\n[lib]\ncrate-type = [\"cdylib\"]\n"),
format!("\n[profile.release]\nopt-level = \"s\"\ncodegen-units = 1\nlto = true\n"),
String::from(cargo_toml),
]
.concat();
Expand All @@ -152,13 +153,11 @@ pub fn generate(contents: String) -> PathBuf {
]
.concat();


cargo_toml = [
format!("\n[profile.release]\nopt-level = \"s\"\ncodegen-units = 1\nlto = true\n"),
format!("\n[lib]\ncrate-type = [\"cdylib\"]\n"),
String::from(cargo_toml),
]
.concat();


for key in dependencies.keys() {
cargo_toml = [
Expand Down Expand Up @@ -205,27 +204,22 @@ pub fn generate(contents: String) -> PathBuf {

//generates lib.rs. Calls enums (Attributes, Header, etc...) from runegen.rs where code is setup using codegen:
let lib_code: String = [
// Attrributes enum is blank, but `#[cfg(test)]...` is generated from cargo new:
// Attrributes enum is blank, but `#[cfg(test)]...` is generated from cargo new. This has been overwritten by the following in lib.rs.
runegen::generate_code(runegen::CodeChunk::Attributes, None),
// Imports dependencies:
runegen::generate_code(runegen::CodeChunk::Header, None),
runegen::generate_code(runegen::CodeChunk::PanicHandler, None),
runegen::generate_code(runegen::CodeChunk::AllocErrorHandler, None),
//how about this ugly temp fix
// String::from("mod wrapper;\nuse wrapper::Wrapper;\n\n"),
runegen::generate_code(runegen::CodeChunk::ProviderResponsePtr, None),
runegen::generate_code(runegen::CodeChunk::TfmModelInvoke, None),
runegen::generate_code(runegen::CodeChunk::Debug, None),
runegen::generate_code(runegen::CodeChunk::Enum, None),
// runegen::generate_code(runegen::CodeChunk::Malloc, None),
// runegen::generate_code(runegen::CodeChunk::RuneBufferPtr, None),
runegen::generate_code(runegen::CodeChunk::ManifestFn, None),
// runegen::generate_manifest_function(capability_manifest, models_manifest, outtype_manifest),
runegen::generate_code(runegen::CodeChunk::Call, Some(proc_options)),
]
.concat();

// Appends generated code from runegen.rs (which is called to lib_code) to lib.rs in rune
// Overwrites generated code from runegen.rs (which is called to lib_code) to lib.rs in rune
overwrite_to_file(
format!(
"{}/src/lib.rs",
Expand Down
15 changes: 12 additions & 3 deletions runefile-parser/src/parser/instructions/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,19 @@ impl ModelInstruction {
let code_string = format!("ml::Model {{ name: String::from(\"{}\"), input_dims: vec!{}, output_dims: vec!{}, framework: ml::FRAMEWORK::TFLITE }}",model_name_param,input_dims,output_dims);
//add CARGO dependencies
dependencies_map.insert(
"runic-pb-mod".to_string(),
"{ git = \"ssh://git@github.com/hotg-ai/runic-pb-mod\" }".to_string(),
"no-std-compat".to_string(),
"\"0.4.1\"".to_string()
);
dependencies_map.insert(
"wee_alloc".to_string(),
"\"0.4.5\"".to_string()
);
dependencies_map.insert(
"runic-types".to_string(),
// "{ path = \"../../runic-types\" }".to_string()
"{ git = \"ssh://git@github.com/hotg-ai/runic-types\" }".to_string()
// "{ git = \"ssh://git@github.com/hotg-ai/runic-types\" , branch = \"feature/generics_integration_lang\" }".to_string()
);
dependencies_map.insert("runic-types".to_string(),"{ git = \"ssh://git@github.com/hotg-ai/runic-types\" , branch = \"feature/generics_integration_lang\" }".to_string());
//generate some code

Self {
Expand Down
4 changes: 2 additions & 2 deletions runefile-parser/src/parser/runegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ pub fn generate_code(code: CodeChunk, params: Option<HashMap<String, String>>) -
// }
CodeChunk::ProviderResponsePtr => {
scope
.raw("mod wrapper;\nuse wrapper::Wrapper;\n")
// .raw("mod wrapper;\nuse wrapper::Wrapper;\n")
.raw("const PROVIDER_RESPONSE_BUFFER_SIZE: usize = 512;")
.raw("static mut PROVIDER_RESPONSE_BUFFER: [u8; PROVIDER_RESPONSE_BUFFER_SIZE] = [0; PROVIDER_RESPONSE_BUFFER_SIZE];")
.raw("static mut PRINT_BUF: [u8;512] = [0 as u8; 512];")
.raw("mod model;")
.raw("mod sine_model;")
.raw("");
}
CodeChunk::ManifestFn => {
Expand Down

0 comments on commit 207a7b2

Please sign in to comment.