From: kramm <kramm>
Date: Tue, 30 Dec 2008 22:54:54 +0000 (+0000)
Subject: added function cut_last_push()
X-Git-Tag: release-0-9-0~563
X-Git-Url: http://git.asbjorn.biz/?a=commitdiff_plain;h=500a78184feefc89eb0eeda46ff088fb8057352c;p=swftools.git

added function cut_last_push()
---

diff --git a/lib/as3/code.c b/lib/as3/code.c
index 49f794e..bb59ede 100644
--- a/lib/as3/code.c
+++ b/lib/as3/code.c
@@ -1105,3 +1105,41 @@ code_t*code_cutlast(code_t*c)
     return prev;
 }
 
+code_t* cut_last_push(code_t*c)
+{
+    while(c) {
+        if(!c) break;
+        opcode_t*op = opcode_get(c->opcode);
+        /* cut conversion type operations */
+        if(op->stack_minus == -1 && op->stack_plus == 1 && !(op->flags)) {
+            c = code_cutlast(c);
+            continue;
+        }
+        /* cut any type of push */
+        else if(op->stack_minus == 0 && op->stack_plus == 1 && !(op->flags)) {
+            return code_cutlast(c);
+        }
+        /* cut register lookups */
+        else if(c->opcode == OPCODE_GETLOCAL ||
+           c->opcode == OPCODE_GETLOCAL_0 ||
+           c->opcode == OPCODE_GETLOCAL_1 ||
+           c->opcode == OPCODE_GETLOCAL_2 ||
+           c->opcode == OPCODE_GETLOCAL_3) {
+            return code_cutlast(c);
+        }
+        /* discard function call values */
+        else if(c->opcode == OPCODE_CALLPROPERTY) {
+            c->opcode = OPCODE_CALLPROPVOID;
+            return c;
+        } else if(c->opcode == OPCODE_CALLSUPER) {
+            c->opcode = OPCODE_CALLSUPERVOID;
+            return c;
+        }
+        else
+            break;
+    }
+    c = abc_pop(c);
+    return c;
+}
+
+
diff --git a/lib/as3/code.h b/lib/as3/code.h
index 6e326a3..885bfbe 100644
--- a/lib/as3/code.h
+++ b/lib/as3/code.h
@@ -97,6 +97,8 @@ void codestats_free(codestats_t*s);
 
 code_t* code_append(code_t*code, code_t*toappend);
 
+code_t* cut_last_push(code_t*_c);
+
 #define code_new() (0)
 
 #endif