Skip to content

Instantly share code, notes, and snippets.

@adrian17
Created May 7, 2024 16:52
Show Gist options
  • Save adrian17/3d1484343115be518a53299899a81008 to your computer and use it in GitHub Desktop.
Save adrian17/3d1484343115be518a53299899a81008 to your computer and use it in GitHub Desktop.
diff --git a/core/src/avm2/activation.rs b/core/src/avm2/activation.rs
index ae72dceb9..89b3464f4 100644
--- a/core/src/avm2/activation.rs
+++ b/core/src/avm2/activation.rs
@@ -35,6 +35,8 @@ use swf::avm2::types::{
use super::error::make_mismatch_error;
+static mut STATS: [u32; 256] = [0; 256];
+
/// Represents a particular register set.
///
/// This type exists primarily because SmallVec isn't garbage-collectable.
@@ -875,6 +877,12 @@ impl<'a, 'gc> Activation<'a, 'gc> {
self.ip += 1;
avm_debug!(self.avm2(), "Opcode: {op:?}");
+ unsafe {
+ // safety: safe thanks to repr u8, see std::mem::discriminant docs example
+ let discriminant = *<*const _>::from(op).cast::<u8>();
+ STATS[discriminant as usize] += 1;
+ }
+
{
let result = match op {
Op::PushByte { value } => self.op_push_byte(*value),
@@ -3123,6 +3131,15 @@ impl<'a, 'gc> Activation<'a, 'gc> {
fn op_bkpt(&mut self) -> Result<FrameControl<'gc>, Error<'gc>> {
// while a debugger is not attached, this is a no-op
+
+ unsafe {
+ let mut i = 0;
+ for row in &STATS {
+ println!("{} {}", i, row);
+ i += 1;
+ }
+ }
+
Ok(FrameControl::Continue)
}
diff --git a/core/src/avm2/op.rs b/core/src/avm2/op.rs
index 5ad40b861..f36482bf2 100644
--- a/core/src/avm2/op.rs
+++ b/core/src/avm2/op.rs
@@ -7,6 +7,7 @@ use swf::avm2::types::{Class as AbcClass, Exception, Index, LookupSwitch, Method
#[derive(Clone, Collect, Debug)]
#[collect(no_drop)]
+#[repr(u8)]
pub enum Op<'gc> {
Add,
AddI,
@@ -335,5 +336,5 @@ pub enum Op<'gc> {
URShift,
}
-#[cfg(target_pointer_width = "64")]
-const _: () = assert!(std::mem::size_of::<Op>() == 16);
+//#[cfg(target_pointer_width = "64")]
+//const _: () = assert!(std::mem::size_of::<Op>() == 16);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment