Implemented concat

This commit is contained in:
Connor Wood
2017-08-29 11:32:48 +01:00
parent 60edb9da68
commit 71c5301448
2 changed files with 71 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ use collections::string::ToString;
use collections::vec::Vec;
use core::fmt::{Debug, Formatter, Error};
use core::str::FromStr;
use super::termlist::parse_term_list;
use super::namedobj::{ RegionSpace, FieldFlags };
@@ -124,6 +125,29 @@ impl Debug for AmlValue {
}
impl AmlValue {
pub fn get_type_string(&self) -> String {
match *self {
AmlValue::Uninitialized => String::from_str("[Uninitialized Object]").unwrap(),
AmlValue::Integer(_) => String::from_str("[Integer]").unwrap(),
AmlValue::String(_) => String::from_str("[String]").unwrap(),
AmlValue::Buffer(_) => String::from_str("[Buffer]").unwrap(),
AmlValue::Package(_) => String::from_str("[Package]").unwrap(),
AmlValue::FieldUnit(_) => String::from_str("[Field]").unwrap(),
AmlValue::Device(_) => String::from_str("[Device]").unwrap(),
AmlValue::Event(_) => String::from_str("[Event]").unwrap(),
AmlValue::Method(_) => String::from_str("[Control Method]").unwrap(),
AmlValue::Mutex(_) => String::from_str("[Mutex]").unwrap(),
AmlValue::OperationRegion(_) => String::from_str("[Operation Region]").unwrap(),
AmlValue::PowerResource(_) => String::from_str("[Power Resource]").unwrap(),
AmlValue::Processor(_) => String::from_str("[Processor]").unwrap(),
AmlValue::ThermalZone(_) => String::from_str("[Thermal Zone]").unwrap(),
AmlValue::BufferField(_) => String::from_str("[Buffer Field]").unwrap(),
AmlValue::DDBHandle(_) => String::from_str("[DDB Handle]").unwrap(),
AmlValue::DebugObject => String::from_str("[Debug Object]").unwrap(),
_ => String::new()
}
}
pub fn get_as_type(&self, t: AmlValue) -> Result<AmlValue, AmlError> {
match t {
AmlValue::None => Ok(AmlValue::None),

View File

@@ -1106,16 +1106,60 @@ fn parse_def_concat(data: &[u8],
})
}
// TODO: Compute the result
// TODO: Store the result
parser_opcode!(data, 0x73);
let lhs = parse_term_arg(&data[1..], ctx)?;
let rhs = parse_term_arg(&data[1 + lhs.len..], ctx)?;
let target = parse_target(&data[1 + lhs.len + rhs.len..], ctx)?;
let result = match lhs.val {
AmlValue::Integer(i) => {
let j = AmlValue::Integer(rhs.val.get_as_integer()?);
let mut first = lhs.val.get_as_buffer()?.clone();
let mut second = j.get_as_buffer()?.clone();
first.append(&mut second);
AmlValue::Buffer(first)
},
AmlValue::String(s) => {
let t = if let Ok(t) = rhs.val.get_as_string() {
t
} else {
rhs.val.get_type_string()
};
AmlValue::String(format!("{}{}", s, t))
},
AmlValue::Buffer(b) => {
let mut b = b.clone();
let mut c = if let Ok(c) = rhs.val.get_as_buffer() {
c.clone()
} else {
AmlValue::String(rhs.val.get_type_string()).get_as_buffer()?.clone()
};
b.append(&mut c);
AmlValue::Buffer(b)
},
_ => {
let first = lhs.val.get_type_string();
let second = if let Ok(second) = rhs.val.get_as_string() {
second
} else {
rhs.val.get_type_string()
};
AmlValue::String(format!("{}{}", first, second))
}
};
ctx.modify(target.val, result.clone())?;
Ok(AmlParseType {
val: AmlValue::Uninitialized,
val: result,
len: 1 + lhs.len + rhs.len + target.len
})
}