Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract prog gen to Origen Metal #204

Merged
merged 11 commits into from
Aug 2, 2024
6 changes: 3 additions & 3 deletions python/origen/origen/helpers/regressions/cli/origen.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class Names:
# new = _CommonNames.new
pl = _CommonNames.pl
pls = _CommonNames.pls
# save_ref = "save_ref"
save_ref = "save_ref"
target = "target"
# web = "web"
names = Names()
Expand Down Expand Up @@ -384,7 +384,7 @@ def targets_arg(cls, help):
# new = Cmd(names.new)
pl = _CommonNames.pl_cmd()
pls = _CommonNames.pls_cmd()
# save_ref = Cmd(names.save_ref)
save_ref = Cmd(names.save_ref)
target = Cmd(
names.target,
help="Set/view the default target",
Expand Down Expand Up @@ -436,7 +436,7 @@ def targets_arg(cls, help):

commands = [
# app, aux_cmds, build, compile, creds, env, eval, exec, fmt, generate, i, mailer, mode, new, pl, pls, save_ref, target, web
app, aux_cmds, creds, env, eval, exec, generate, i, pl, pls, target
app, aux_cmds, creds, env, eval, exec, generate, i, pl, pls, save_ref, target
]
cmds = commands

Expand Down
5 changes: 3 additions & 2 deletions python/origen/origen/interface.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import origen
import _origen
from origen_metal import _origen_metal


# Base class for all test program flow interfaces
class BaseInterface(_origen.interface.PyInterface):
class BaseInterface(_origen_metal.interface.PyInterface):
def __init__(self):
self._options = []
self.bypass_sub_flows = False
Expand All @@ -12,7 +13,7 @@ def __init__(self):

def include(self, path, **kwargs):
origen.log.trace(f"Resolving include reference '{path}'")
file = self.resolve_file_reference(path)
file = _origen.prog_gen.resolve_file_reference(path)
origen.log.trace(f"Found include file '{file}'")
origen.producer.current_job.add_file(file)
context = origen.producer.api()
Expand Down
7 changes: 4 additions & 3 deletions python/origen/origen/producer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _origen
from origen_metal import _origen_metal
from contextlib import contextmanager, ContextDecorator
import origen.producer
import origen.helpers
Expand Down Expand Up @@ -139,7 +140,7 @@ def Flow(self, **kwargs):
top_level = False
origen.logger.debug(
f"Producing sub-flow '{flow.name}' in job '{job.id}'")
flow_refs = _origen.prog_gen.start_new_flow(flow.name,
flow_refs = _origen_metal.prog_gen.start_new_flow(flow.name,
sub_flow=True)
else:
origen.logger.debug(
Expand All @@ -155,7 +156,7 @@ def Flow(self, **kwargs):
options["add_flow_enable"] = kwargs["add_flow_enable"]
else:
options["add_flow_enable"] = origen.interface.add_flow_enable
flow_refs = _origen.prog_gen.start_new_flow(flow.name, **options)
flow_refs = _origen_metal.prog_gen.start_new_flow(flow.name, **options)
origen.interface.top_level_options = kwargs

#origen.tester.reset()
Expand All @@ -170,7 +171,7 @@ def Flow(self, **kwargs):
if top_level:
top_level_flow_open = False

_origen.prog_gen.end_flow(flow_refs)
_origen_metal.prog_gen.end_flow(flow_refs)

#origen.tester.end_pattern()
#origen.tester.render()
Expand Down
5 changes: 3 additions & 2 deletions python/origen/origen/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import _origen
import pickle
from contextlib import contextmanager, ContextDecorator
from origen_metal import _origen_metal


class Tester(_origen.tester.PyTester):
Expand Down Expand Up @@ -95,9 +96,9 @@ def generate(self, ast):
print(f"Python Generator: Node: {i}: {n}")


class V93K(_origen.tester_apis.V93K):
class V93K(_origen_metal.tester_apis.V93K):
pass


class IGXL(_origen.tester_apis.IGXL):
class IGXL(_origen_metal.tester_apis.IGXL):
pass
5 changes: 5 additions & 0 deletions rust/origen/Cargo.lock

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

34 changes: 0 additions & 34 deletions rust/origen/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
extern crate built;
use std::fs;
use std::path::PathBuf;
use walkdir::WalkDir;

fn main() {
let rust_origen_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
Expand Down Expand Up @@ -62,37 +61,4 @@ fn main() {
fs::remove_file(rust_origen_dir.clone().join("Cargo.lock"))
.expect("Unable to remove Cargo.lock from verification directory");
}

// This creates a file which defines a map of all files in the test program test_templates dir.
// This file is then included by the test program module to give it access to the template files.
let test_templates_dir = rust_origen_dir
.join("src")
.join("prog_gen")
.join("test_templates");

let mut data = "".to_string();

data += "pub static TEST_TEMPLATES: phf::Map<&'static str, &'static str> = phf_map! {\n";

for entry in WalkDir::new(&test_templates_dir)
.into_iter()
.filter_map(|e| e.ok())
{
let path = entry.path();
if path.is_file() {
let file = path
.strip_prefix(&test_templates_dir)
.unwrap()
.display()
.to_string()
.replace(".tera", "")
.replace("\\", "/");
let contents = std::fs::read_to_string(path).unwrap();
data += &format!("r#\"{}\"# => r#\"{}\"#,\n", &file, &contents);
}
}

data += "};\n\n";

fs::write(&out_dir.join("test_templates.rs"), data).expect("Unable to write to test templates");
}
44 changes: 6 additions & 38 deletions rust/origen/cli/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ fn main() -> Result<()> {
commands::env::add_helps(&mut helps);
commands::generate::add_helps(&mut helps);
commands::target::add_helps(&mut helps);
commands::save_ref::add_helps(&mut helps);
} else {
commands::new::add_helps(&mut helps);
}
Expand Down Expand Up @@ -474,6 +475,7 @@ fn main() -> Result<()> {
app = commands::app::add_commands(app, &helps, app_cmds.as_ref().unwrap(), &extensions)?;
app = commands::env::add_commands(app, &helps, &extensions)?;
app = commands::generate::add_commands(app, &helps, &extensions)?;
app = commands::save_ref::add_commands(app, &helps, &extensions)?;

// /************************************************************************************/
// let new_help = "Generate a new block, flow, pattern, etc. for your application";
Expand Down Expand Up @@ -765,40 +767,6 @@ fn main() -> Result<()> {
// .action(SetArg)
// .value_name("MODE"),
// ),
// );

// /************************************************************************************/
// let save_ref_help = "Save a reference version of the given file, this will be automatically checked for differences the next time it is generated";
// origen_commands.push(CommandHelp {
// name: "save_ref".to_string(),
// help: save_ref_help.to_string(),
// shortcut: None,
// });
// app = app.subcommand(
// Command::new("save_ref")
// .about(save_ref_help)
// .arg(
// Arg::new("files")
// .help("The name of the file(s) to be saved")
// .action(SetArg)
// .value_name("FILES")
// .multiple(true)
// .required_unless_one(&["new", "changed"]),
// )
// .arg(
// Arg::new("new")
// .long("new")
// .required(false)
// .action(SetArgTrue)
// .help("Update all NEW file references from the last generate run"),
// )
// .arg(
// Arg::new("changed")
// .long("changed")
// .required(false)
// .action(SetArgTrue)
// .help("Update all CHANGED file references from the last generate run"),
// ),
// );
} else {
app = commands::new::add_commands(app, &helps, &extensions)?;
Expand Down Expand Up @@ -1181,10 +1149,10 @@ fn main() -> Result<()> {
// let matches = matches.subcommand_matches("mode").unwrap();
// commands::mode::run(matches.get_one::<&str>("mode").map(|s| *s));
// }
// Some("save_ref") => {
// let matches = matches.subcommand_matches("save_ref").unwrap();
// commands::save_ref::run(matches);
// }
Some(commands::save_ref::BASE_CMD) => {
let matches = matches.subcommand_matches(commands::save_ref::BASE_CMD).unwrap();
commands::save_ref::run(matches)?;
}
Some(commands::plugin::BASE_CMD) => run_cmd_match_case!(plugin),
Some(commands::plugins::BASE_CMD) => commands::plugins::run(matches.subcommand_matches(commands::plugins::BASE_CMD).unwrap(), plugins.as_ref())?,
Some(invalid_cmd) => {
Expand Down
2 changes: 1 addition & 1 deletion rust/origen/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod interactive;
// pub mod mode;
pub mod new;
// pub mod proj;
// pub mod save_ref;
pub mod save_ref;
pub mod target;
// pub mod mailer;
pub mod credentials;
Expand Down
50 changes: 40 additions & 10 deletions rust/origen/cli/src/commands/save_ref.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,67 @@
use origen_metal::framework::reference_files;
use std::path::Path;

pub fn run(matches: &clap::ArgMatches) {
let mut exit_code = 0;
use origen_metal::framework::reference_files;
use crate::commands::_prelude::*;

pub const BASE_CMD: &'static str = "save_ref";

gen_core_cmd_funcs!(
BASE_CMD,
"Save a reference version of the given file, this will be automatically checked for differences the next time it is generated",
{ |cmd: App<'a>| {
cmd
.arg(
Arg::new("files")
.help("The name of the file(s) to be saved")
.action(SetArg)
.value_name("FILES")
.multiple(true)
.required_unless_one(&["new", "changed"]),
)
.arg(
Arg::new("new")
.long("new")
.required(false)
.action(SetArgTrue)
.help("Update all NEW file references from the last generate run"),
)
.arg(
Arg::new("changed")
.long("changed")
.required(false)
.action(SetArgTrue)
.help("Update all CHANGED file references from the last generate run"),
)
}}
);


pub fn run(matches: &clap::ArgMatches) -> Result<()> {
let new = matches.contains_id("new");
let changed = matches.contains_id("changed");
let files = matches.get_many::<String>("files");

if new {
if let Err(e) = reference_files::apply_all_new_refs() {
log_error!("Something went wrong saving the NEW references - {}", e);
exit_code = 1;
bail!("Something went wrong saving the NEW references - {}", e);
}
}

if changed {
if let Err(e) = reference_files::apply_all_changed_refs() {
log_error!(
bail!(
"Something went wrong updating the CHANGED references - {}",
e
);
exit_code = 1;
}
}

if let Some(files) = files {
for key in files {
if let Err(e) = reference_files::apply_ref(Path::new(key)) {
log_error!("Could not save '{}' - {}", key, e);
exit_code = 1;
bail!("Could not save '{}' - {}", key, e);
}
}
}
std::process::exit(exit_code);
Ok(())
}
6 changes: 3 additions & 3 deletions rust/origen/cli/src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use std::collections::HashMap;
use origen_metal::indexmap::IndexMap;

pub use extensions::{Extensions, ExtensionTOML, Extension};
pub use plugins::{Plugins, Plugin};
pub use plugins::Plugins;
pub use aux_cmds::AuxCmds;
pub use app_cmds::AppCmds;
pub use helps::{CmdHelps, CmdHelp, CmdSrc};
use std::{env};
use std::env;

use clap::{App};
use clap::App;
use clap::Command as ClapCommand;
use clap::Arg as ClapArg;
use origen::{Result, in_app_invocation};
Expand Down
Loading
Loading