acpi_tables: aml: Add support for binary operators

Signed-off-by: Qiu Wenbo <qiuwenbo@phytium.com.cn>
This commit is contained in:
Qiu Wenbo 2019-11-29 12:34:32 +08:00 committed by Rob Bradford
parent f787139805
commit 861d902c21

View File

@ -1064,28 +1064,49 @@ impl<'a> Aml for While<'a> {
} }
} }
pub struct Add<'a> { macro_rules! binary_op {
a: &'a dyn Aml, ($name:ident, $opcode:expr) => {
b: &'a dyn Aml, pub struct $name<'a> {
target: &'a dyn Aml, a: &'a dyn Aml,
b: &'a dyn Aml,
target: &'a dyn Aml,
}
impl<'a> $name<'a> {
pub fn new(target: &'a dyn Aml, a: &'a dyn Aml, b: &'a dyn Aml) -> Self {
$name { target, a, b }
}
}
impl<'a> Aml for $name<'a> {
fn to_aml_bytes(&self) -> Vec<u8> {
let mut bytes = Vec::new();
bytes.push($opcode); /* Op for the binary operator */
bytes.extend_from_slice(&self.a.to_aml_bytes());
bytes.extend_from_slice(&self.b.to_aml_bytes());
bytes.extend_from_slice(&self.target.to_aml_bytes());
bytes
}
}
};
} }
impl<'a> Add<'a> { /* binary operators: TermArg TermArg Target */
pub fn new(target: &'a dyn Aml, a: &'a dyn Aml, b: &'a dyn Aml) -> Self { binary_op!(Add, 0x72);
Add { target, a, b } binary_op!(Concat, 0x73);
} binary_op!(Subtract, 0x74);
} binary_op!(Multiply, 0x77);
binary_op!(ShiftLeft, 0x79);
impl<'a> Aml for Add<'a> { binary_op!(ShiftRight, 0x7A);
fn to_aml_bytes(&self) -> Vec<u8> { binary_op!(And, 0x7B);
let mut bytes = Vec::new(); binary_op!(Nand, 0x7C);
bytes.push(0x72); /* AddOp */ binary_op!(Or, 0x7D);
bytes.extend_from_slice(&self.a.to_aml_bytes()); binary_op!(Nor, 0x7E);
bytes.extend_from_slice(&self.b.to_aml_bytes()); binary_op!(Xor, 0x7F);
bytes.extend_from_slice(&self.target.to_aml_bytes()); binary_op!(ConateRes, 0x84);
bytes binary_op!(Mod, 0x85);
} binary_op!(Index, 0x88);
} binary_op!(ToString, 0x9C);
pub struct MethodCall<'a> { pub struct MethodCall<'a> {
name: Path, name: Path,