mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
Merge branch 'main' of github.com:betrusted-io/xous-core into main
This commit is contained in:
commit
65ecba75fa
1 changed files with 17 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ use convert_case::{Case, Casing};
|
||||||
use quick_xml::events::Event;
|
use quick_xml::events::Event;
|
||||||
use quick_xml::Reader;
|
use quick_xml::Reader;
|
||||||
use std::io::{BufRead, BufReader, Read, Write};
|
use std::io::{BufRead, BufReader, Read, Write};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ParseError {
|
pub enum ParseError {
|
||||||
UnexpectedTag,
|
UnexpectedTag,
|
||||||
|
|
@ -9,6 +10,7 @@ pub enum ParseError {
|
||||||
ParseIntError,
|
ParseIntError,
|
||||||
NonUTF8,
|
NonUTF8,
|
||||||
WriteError,
|
WriteError,
|
||||||
|
UnexpectedValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
|
|
@ -66,6 +68,7 @@ impl core::fmt::Display for ParseError {
|
||||||
use ParseError::*;
|
use ParseError::*;
|
||||||
match *self {
|
match *self {
|
||||||
UnexpectedTag => write!(f, "unexpected XML tag encountered"),
|
UnexpectedTag => write!(f, "unexpected XML tag encountered"),
|
||||||
|
UnexpectedValue => write!(f, "unexpected XML tag value encountered"),
|
||||||
MissingValue => write!(f, "XML tag should have contained a value"),
|
MissingValue => write!(f, "XML tag should have contained a value"),
|
||||||
ParseIntError => write!(f, "unable to parse number"),
|
ParseIntError => write!(f, "unable to parse number"),
|
||||||
NonUTF8 => write!(f, "file is not UTF-8"),
|
NonUTF8 => write!(f, "file is not UTF-8"),
|
||||||
|
|
@ -123,9 +126,21 @@ fn generate_field<T: BufRead>(reader: &mut Reader<T>) -> Result<Field, ParseErro
|
||||||
.unescape_and_decode(reader)
|
.unescape_and_decode(reader)
|
||||||
.map_err(|_| ParseError::NonUTF8)?;
|
.map_err(|_| ParseError::NonUTF8)?;
|
||||||
match tag_name.as_str() {
|
match tag_name.as_str() {
|
||||||
"name" => name = Some(extract_contents(reader)?),
|
"name" if name.is_none() => name = Some(extract_contents(reader)?),
|
||||||
"lsb" => lsb = Some(parse_usize(extract_contents(reader)?.as_bytes())?),
|
"lsb" => lsb = Some(parse_usize(extract_contents(reader)?.as_bytes())?),
|
||||||
"msb" => msb = Some(parse_usize(extract_contents(reader)?.as_bytes())?),
|
"msb" => msb = Some(parse_usize(extract_contents(reader)?.as_bytes())?),
|
||||||
|
"bitRange" => {
|
||||||
|
let range = extract_contents(reader)?;
|
||||||
|
if !range.starts_with("[") || !range.ends_with("]") {
|
||||||
|
return Err(ParseError::UnexpectedValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut parts = range[1..range.len() - 1].split(':');
|
||||||
|
msb = Some(parts.next().ok_or_else(|| ParseError::UnexpectedValue)?
|
||||||
|
.parse::<usize>().or_else(|_| Err(ParseError::ParseIntError))?);
|
||||||
|
lsb = Some(parts.next().ok_or_else(|| ParseError::UnexpectedValue)?
|
||||||
|
.parse::<usize>().or_else(|_| Err(ParseError::ParseIntError))?);
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -822,7 +837,7 @@ pub mod utra {
|
||||||
out,
|
out,
|
||||||
" {} = {},",
|
" {} = {},",
|
||||||
register.name.to_case(Case::UpperCamel),
|
register.name.to_case(Case::UpperCamel),
|
||||||
register.offset / 4
|
register.offset
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
writeln!(out, " }}")?;
|
writeln!(out, " }}")?;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue