fix primitive bug | add gen primitive bin to copy sh
This commit is contained in:
parent
935a852ba0
commit
103baacb8f
Binary file not shown.
@ -23,15 +23,15 @@ pub struct PrimitiveXml {
|
||||
pub name_to_template: HashMap<String, Template>
|
||||
}
|
||||
|
||||
pub fn init_parse_primitive_files() -> Result<PrimitiveXml, Error> {
|
||||
const XML_DIR: &str = "../../primitive_files";
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn init_parse_primitive_files(dir: &str) -> Result<PrimitiveXml, Error> {
|
||||
let mut primitive_xml = PrimitiveXml::default();
|
||||
for entry in fs::read_dir(XML_DIR)? {
|
||||
for entry in fs::read_dir(dir)? {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
if let Some(ext) = path.extension() {
|
||||
if ext == "xml" {
|
||||
println!("parse xml file {}", path.to_str().unwrap());
|
||||
if let Ok(primitive) = xml_parser(path.to_str().unwrap()) {
|
||||
primitive_xml.name_to_template.extend(
|
||||
primitive.name_to_template
|
||||
@ -40,7 +40,6 @@ pub fn init_parse_primitive_files() -> Result<PrimitiveXml, Error> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(primitive_xml)
|
||||
}
|
||||
|
||||
@ -56,8 +55,9 @@ fn xml_parser(path: &str) -> Result<PrimitiveXml, Error> {
|
||||
match parser.next() {
|
||||
Ok(XmlEvent::StartElement { name, .. }) => {
|
||||
if name.local_name == "Template" {
|
||||
let (inst_name , template) = xml_parse_template(&mut parser);
|
||||
primitive_xml.name_to_template.insert(inst_name, template);
|
||||
if let Some((inst_name , template)) = xml_parse_template(&mut parser) {
|
||||
primitive_xml.name_to_template.insert(inst_name, template);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(XmlEvent::EndElement { name }) => {
|
||||
@ -70,17 +70,19 @@ fn xml_parser(path: &str) -> Result<PrimitiveXml, Error> {
|
||||
Ok((primitive_xml))
|
||||
}
|
||||
|
||||
fn xml_parse_template(parser: &mut EventReader<BufReader<File>>) -> (String, Template) {
|
||||
fn xml_parse_template(parser: &mut EventReader<BufReader<File>>) -> Option<(String, Template)> {
|
||||
loop {
|
||||
match parser.next() {
|
||||
Ok(XmlEvent::Characters(text)) => {
|
||||
if text.contains("Cut code below this line") {
|
||||
if let Some((name, text, fast)) = xml_parse_text(&text) {
|
||||
return (name, Template { text, fast });
|
||||
return Some((name, Template { text, fast }));
|
||||
} else {
|
||||
return None
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
_ => return None
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -201,15 +203,35 @@ fn xml_parse_text(text: &str) -> Option<(String, String, FastHdlparam)> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs, path::Path};
|
||||
use super::xml_parser;
|
||||
use std::{fs::{self, File}, io::Write, path::Path};
|
||||
use super::{init_parse_primitive_files, xml_parser};
|
||||
|
||||
const TESTFILE: &str = "D:\\work\\playground\\digital-lsp-server\\primitive_files\\verilog1.xml";
|
||||
const TESTFILE: &str = "D:\\work\\playground\\digital-lsp-server\\primitive_files\\verilog2.xml";
|
||||
const TESTDIR: &str = "/home/dide/project/Digital-Test/Digital-IDE-test/user/factory/xilinx";
|
||||
|
||||
#[test]
|
||||
fn gen_primitive_bin() {
|
||||
if let Ok(primitive_info) = init_parse_primitive_files("primitive_files") {
|
||||
let serialized_data = bincode::serialize(&primitive_info).unwrap();
|
||||
let path = "target/primitive.bin";
|
||||
let mut file = File::create(path).unwrap();
|
||||
let _ = file.write_all(&serialized_data);
|
||||
} else {
|
||||
println!("parse primitive error");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_xml() {
|
||||
let _ = xml_parser(TESTFILE);
|
||||
let res = xml_parser(TESTFILE);
|
||||
match res {
|
||||
Ok(r) => {
|
||||
println!("res len {:#?}", r.name_to_template.len())
|
||||
}
|
||||
Err(e) => {
|
||||
println!("error {:#?}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user