avm2: Reduce the size of Op on 64bit
This commit is contained in:
parent
0a6a95e6f1
commit
dd53b4e06b
|
@ -1102,12 +1102,9 @@ impl<'a, 'gc> Activation<'a, 'gc> {
|
||||||
Op::TypeOf => self.op_type_of(),
|
Op::TypeOf => self.op_type_of(),
|
||||||
Op::EscXAttr => self.op_esc_xattr(),
|
Op::EscXAttr => self.op_esc_xattr(),
|
||||||
Op::EscXElem => self.op_esc_elem(),
|
Op::EscXElem => self.op_esc_elem(),
|
||||||
Op::LookupSwitch {
|
Op::LookupSwitch(ref lookup_switch) => self.op_lookup_switch(
|
||||||
default_offset,
|
lookup_switch.default_offset,
|
||||||
case_offsets,
|
&lookup_switch.case_offsets,
|
||||||
} => self.op_lookup_switch(
|
|
||||||
default_offset,
|
|
||||||
&case_offsets,
|
|
||||||
instruction_start,
|
instruction_start,
|
||||||
reader,
|
reader,
|
||||||
full_data,
|
full_data,
|
||||||
|
|
|
@ -754,7 +754,7 @@ impl<'a> Reader<'a> {
|
||||||
OpCode::Li16 => Op::Li16,
|
OpCode::Li16 => Op::Li16,
|
||||||
OpCode::Li32 => Op::Li32,
|
OpCode::Li32 => Op::Li32,
|
||||||
OpCode::Li8 => Op::Li8,
|
OpCode::Li8 => Op::Li8,
|
||||||
OpCode::LookupSwitch => Op::LookupSwitch {
|
OpCode::LookupSwitch => Op::LookupSwitch(Box::new(LookupSwitch {
|
||||||
default_offset: self.read_i24()?,
|
default_offset: self.read_i24()?,
|
||||||
case_offsets: {
|
case_offsets: {
|
||||||
let num_cases = self.read_u30()? + 1;
|
let num_cases = self.read_u30()? + 1;
|
||||||
|
@ -764,7 +764,7 @@ impl<'a> Reader<'a> {
|
||||||
}
|
}
|
||||||
case_offsets.into()
|
case_offsets.into()
|
||||||
},
|
},
|
||||||
},
|
})),
|
||||||
OpCode::LShift => Op::LShift,
|
OpCode::LShift => Op::LShift,
|
||||||
OpCode::Modulo => Op::Modulo,
|
OpCode::Modulo => Op::Modulo,
|
||||||
OpCode::Multiply => Op::Multiply,
|
OpCode::Multiply => Op::Multiply,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
#[cfg(target_pointer_width = "64")]
|
||||||
|
use std::mem::size_of;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct AbcFile {
|
pub struct AbcFile {
|
||||||
|
@ -246,6 +248,12 @@ pub struct Script {
|
||||||
pub traits: Vec<Trait>,
|
pub traits: Vec<Trait>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct LookupSwitch {
|
||||||
|
pub default_offset: i32,
|
||||||
|
pub case_offsets: Box<[i32]>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Op {
|
pub enum Op {
|
||||||
Add,
|
Add,
|
||||||
|
@ -471,10 +479,7 @@ pub enum Op {
|
||||||
Li16,
|
Li16,
|
||||||
Li32,
|
Li32,
|
||||||
Li8,
|
Li8,
|
||||||
LookupSwitch {
|
LookupSwitch(Box<LookupSwitch>),
|
||||||
default_offset: i32,
|
|
||||||
case_offsets: Box<[i32]>,
|
|
||||||
},
|
|
||||||
LShift,
|
LShift,
|
||||||
Modulo,
|
Modulo,
|
||||||
Multiply,
|
Multiply,
|
||||||
|
@ -569,3 +574,6 @@ pub enum Op {
|
||||||
Timestamp,
|
Timestamp,
|
||||||
URShift,
|
URShift,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_pointer_width = "64")]
|
||||||
|
const _: () = assert!(size_of::<Op>() == 16);
|
||||||
|
|
|
@ -907,14 +907,11 @@ impl<W: Write> Writer<W> {
|
||||||
Op::Li16 => self.write_opcode(OpCode::Li16)?,
|
Op::Li16 => self.write_opcode(OpCode::Li16)?,
|
||||||
Op::Li32 => self.write_opcode(OpCode::Li32)?,
|
Op::Li32 => self.write_opcode(OpCode::Li32)?,
|
||||||
Op::Li8 => self.write_opcode(OpCode::Li8)?,
|
Op::Li8 => self.write_opcode(OpCode::Li8)?,
|
||||||
Op::LookupSwitch {
|
Op::LookupSwitch(ref lookup_switch) => {
|
||||||
default_offset,
|
|
||||||
ref case_offsets,
|
|
||||||
} => {
|
|
||||||
self.write_opcode(OpCode::LookupSwitch)?;
|
self.write_opcode(OpCode::LookupSwitch)?;
|
||||||
self.write_i24(default_offset)?;
|
self.write_i24(lookup_switch.default_offset)?;
|
||||||
self.write_u30(case_offsets.len() as u32 - 1)?;
|
self.write_u30(lookup_switch.case_offsets.len() as u32 - 1)?;
|
||||||
for offset in case_offsets.iter() {
|
for offset in lookup_switch.case_offsets.iter() {
|
||||||
self.write_i24(*offset)?;
|
self.write_i24(*offset)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1439,10 +1436,10 @@ pub mod tests {
|
||||||
assert_eq!(write(Op::Li8), b"\x35");
|
assert_eq!(write(Op::Li8), b"\x35");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
write(Op::LookupSwitch {
|
write(Op::LookupSwitch(Box::new(LookupSwitch {
|
||||||
default_offset: 1,
|
default_offset: 1,
|
||||||
case_offsets: Box::new([3, 4, 5])
|
case_offsets: Box::new([3, 4, 5])
|
||||||
}),
|
}))),
|
||||||
b"\x1B\x01\x00\x00\x02\x03\x00\x00\x04\x00\x00\x05\x00\x00"
|
b"\x1B\x01\x00\x00\x02\x03\x00\x00\x04\x00\x00\x05\x00\x00"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue