|
|
@ -33,10 +33,10 @@ pub struct Module {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Cell<'a> {
|
|
|
|
pub struct Cell {
|
|
|
|
pub cell_type: String,
|
|
|
|
pub cell_type: String,
|
|
|
|
pub parameters: HashMap<&'a str, usize>,
|
|
|
|
pub parameters: HashMap<String, usize>,
|
|
|
|
pub connections: HashMap<&'a str, Vec<usize>>,
|
|
|
|
pub connections: HashMap<String, Vec<usize>>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl From<io::Error> for Error {
|
|
|
|
impl From<io::Error> for Error {
|
|
|
@ -55,7 +55,7 @@ pub fn get_modules(files: &[&str]) -> Result<Vec<String>, Error> {
|
|
|
|
return Ok(module_names);
|
|
|
|
return Ok(module_names);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn compile_module(module_name: &str, files: &[&str]) -> Result<(), Error> {
|
|
|
|
pub fn compile_module(module_name: &str, files: &[&str]) -> Result<Vec<Cell>, Error> {
|
|
|
|
let json = run_yosys("proc; flatten; wreduce; opt; fsm; opt; memory -nomap -nordff; opt; muxpack; peepopt; async2sync; wreduce; opt -mux_bool", Some(module_name), files)?;
|
|
|
|
let json = run_yosys("proc; flatten; wreduce; opt; fsm; opt; memory -nomap -nordff; opt; muxpack; peepopt; async2sync; wreduce; opt -mux_bool", Some(module_name), files)?;
|
|
|
|
let compiled_module = &json["modules"][module_name];
|
|
|
|
let compiled_module = &json["modules"][module_name];
|
|
|
|
let ports_json = &compiled_module["ports"];
|
|
|
|
let ports_json = &compiled_module["ports"];
|
|
|
@ -85,28 +85,23 @@ pub fn compile_module(module_name: &str, files: &[&str]) -> Result<(), Error> {
|
|
|
|
|
|
|
|
|
|
|
|
let cells = &compiled_module["cells"];
|
|
|
|
let cells = &compiled_module["cells"];
|
|
|
|
|
|
|
|
|
|
|
|
for (_, cell) in cells.entries() {
|
|
|
|
return cells.entries().map(|(_, cell)| resolve_cell(cell)).collect::<Result<_, _>>();
|
|
|
|
let cell = resolve_cell(cell)?;
|
|
|
|
|
|
|
|
println!("{:?}", cell);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn resolve_cell(cell: &JsonValue) -> Result<Cell, Error> {
|
|
|
|
pub fn resolve_cell(cell: &JsonValue) -> Result<Cell, Error> {
|
|
|
|
let json_parameters = &cell["parameters"];
|
|
|
|
let json_parameters = &cell["parameters"];
|
|
|
|
let mut parameters: HashMap<&str, usize> = HashMap::new();
|
|
|
|
let mut parameters: HashMap<String, usize> = HashMap::new();
|
|
|
|
|
|
|
|
|
|
|
|
for (key, value) in json_parameters.entries() {
|
|
|
|
for (key, value) in json_parameters.entries() {
|
|
|
|
parameters.insert(
|
|
|
|
parameters.insert(
|
|
|
|
key,
|
|
|
|
key.to_owned(),
|
|
|
|
usize::from_str_radix(value.as_str().ok_or(Error::BadJson)?, 2)
|
|
|
|
usize::from_str_radix(value.as_str().ok_or(Error::BadJson)?, 2)
|
|
|
|
.map_err(|_| Error::BadJson)?,
|
|
|
|
.map_err(|_| Error::BadJson)?,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let json_connections = &cell["connections"];
|
|
|
|
let json_connections = &cell["connections"];
|
|
|
|
let mut connections: HashMap<&str, Vec<usize>> = HashMap::new();
|
|
|
|
let mut connections: HashMap<String, Vec<usize>> = HashMap::new();
|
|
|
|
|
|
|
|
|
|
|
|
for (key, bits) in json_connections.entries() {
|
|
|
|
for (key, bits) in json_connections.entries() {
|
|
|
|
let JsonValue::Array(arr) = bits else {
|
|
|
|
let JsonValue::Array(arr) = bits else {
|
|
|
@ -116,7 +111,7 @@ pub fn resolve_cell(cell: &JsonValue) -> Result<Cell, Error> {
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.map(|x| x.as_usize().ok_or(Error::BadJson))
|
|
|
|
.map(|x| x.as_usize().ok_or(Error::BadJson))
|
|
|
|
.collect::<Result<_, _>>()?;
|
|
|
|
.collect::<Result<_, _>>()?;
|
|
|
|
connections.insert(key, connection_bits);
|
|
|
|
connections.insert(key.to_owned(), connection_bits);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let cell_type = cell["type"].as_str().ok_or(Error::BadJson)?.to_owned();
|
|
|
|
let cell_type = cell["type"].as_str().ok_or(Error::BadJson)?.to_owned();
|
|
|
|