[Swfdec-commits] 3 commits - swfdec/swfdec_bots.c vivified/code

Benjamin Otte company at kemper.freedesktop.org
Tue Apr 22 05:02:43 PDT 2008


 swfdec/swfdec_bots.c               |   55 +++++---------
 vivified/code/Makefile.am          |    2 
 vivified/code/rewrite.c            |    2 
 vivified/code/vivi_code_asm_with.c |  145 +++++++++++++++++++++++++++++++++++++
 vivified/code/vivi_code_asm_with.h |   59 +++++++++++++++
 vivified/code/vivi_disassembler.c  |   11 ++
 6 files changed, 239 insertions(+), 35 deletions(-)

New commits:
commit 863729844a84fdcf8c8d9a136786184ce2221290
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Apr 22 13:56:22 2008 +0200

    file sizes contain the initial 8 bytes

diff --git a/vivified/code/rewrite.c b/vivified/code/rewrite.c
index 89375cb..1ae5c66 100644
--- a/vivified/code/rewrite.c
+++ b/vivified/code/rewrite.c
@@ -142,7 +142,7 @@ process_buffer (SwfdecBuffer *original)
   swfdec_bots_put_u8 (full, 'W');
   swfdec_bots_put_u8 (full, 'S');
   swfdec_bots_put_u8 (full, version);
-  swfdec_bots_put_u32 (full, swfdec_bots_get_bytes (bots));
+  swfdec_bots_put_u32 (full, swfdec_bots_get_bytes (bots) + 8);
   swfdec_bots_put_bots (full, bots);
   swfdec_bots_free (bots);
   return swfdec_bots_close (full);
commit 8b4a5d4b98e1da458a1a5d06928826db12ad2483
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Apr 22 13:52:41 2008 +0200

    implement With bytecode

diff --git a/vivified/code/Makefile.am b/vivified/code/Makefile.am
index acd4dbf..8de3b83 100644
--- a/vivified/code/Makefile.am
+++ b/vivified/code/Makefile.am
@@ -27,6 +27,7 @@ libvivified_compiler_la_SOURCES = \
 	vivi_code_asm_pool.c \
 	vivi_code_asm_push.c \
 	vivi_code_asm_store.c \
+	vivi_code_asm_with.c \
 	vivi_code_assembler.c \
 	vivi_code_assignment.c \
 	vivi_code_binary.c \
@@ -98,6 +99,7 @@ noinst_HEADERS = \
 	vivi_code_asm_pool.h \
 	vivi_code_asm_push.h \
 	vivi_code_asm_store.h \
+	vivi_code_asm_with.h \
 	vivi_code_assembler.h \
 	vivi_code_assignment.h \
 	vivi_code_binary.h \
diff --git a/vivified/code/vivi_code_asm_with.c b/vivified/code/vivi_code_asm_with.c
new file mode 100644
index 0000000..4c2dd2f
--- /dev/null
+++ b/vivified/code/vivi_code_asm_with.c
@@ -0,0 +1,145 @@
+/* Vivified
+ * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <swfdec/swfdec_as_interpret.h>
+#include <swfdec/swfdec_bits.h>
+
+#include "vivi_code_asm_with.h"
+#include "vivi_code_asm.h"
+#include "vivi_code_emitter.h"
+#include "vivi_code_error.h"
+#include "vivi_code_printer.h"
+
+static gboolean
+vivi_code_asm_with_resolve (ViviCodeEmitter *emitter, SwfdecBuffer *buffer,
+    gsize offset, gpointer data, GError **error)
+{
+  ViviCodeAsmWith *with = VIVI_CODE_ASM_WITH (data);
+  gssize label_offset;
+  gsize diff;
+
+  label_offset = vivi_code_emitter_get_label_offset (emitter, with->label);
+  if (label_offset < 0) {
+    g_set_error (error, VIVI_CODE_ERROR, VIVI_CODE_ERROR_MISSING_LABEL,
+	"no label \"%s\"", vivi_code_label_get_name (with->label));
+    return FALSE;
+  }
+  if ((gsize) label_offset < offset) {
+    g_set_error (error, VIVI_CODE_ERROR, VIVI_CODE_ERROR_INVALID_LABEL,
+	"cannot jump backwards");
+    return FALSE;
+  }
+  diff = label_offset - offset;
+  if (diff > G_MAXUINT16) {
+    g_set_error (error, VIVI_CODE_ERROR, VIVI_CODE_ERROR_SIZE,
+	"with body too big");
+    return FALSE;
+  }
+  buffer->data[offset - 1] = diff >> 8;
+  buffer->data[offset - 2] = diff;
+  return TRUE;
+}
+
+
+static gboolean
+vivi_code_asm_with_emit (ViviCodeAsm *code, ViviCodeEmitter *emitter, GError **error)
+{
+  SwfdecBots *emit = vivi_code_emitter_get_bots (emitter);
+
+  swfdec_bots_put_u8 (emit, SWFDEC_AS_ACTION_WITH);
+  swfdec_bots_put_u16 (emit, 2);
+  swfdec_bots_put_u16 (emit, 0); /* with to be resolved later */
+  vivi_code_emitter_add_later (emitter, vivi_code_asm_with_resolve, code);
+
+  return TRUE;
+}
+
+static void
+vivi_code_asm_with_asm_init (ViviCodeAsmInterface *iface)
+{
+  iface->emit = vivi_code_asm_with_emit;
+}
+
+G_DEFINE_TYPE_WITH_CODE (ViviCodeAsmWith, vivi_code_asm_with, VIVI_TYPE_CODE_ASM_CODE,
+    G_IMPLEMENT_INTERFACE (VIVI_TYPE_CODE_ASM, vivi_code_asm_with_asm_init))
+
+static void
+vivi_code_asm_with_print (ViviCodeToken *token, ViviCodePrinter*printer)
+{
+  ViviCodeAsmWith *with = VIVI_CODE_ASM_WITH (token);
+
+  vivi_code_printer_print (printer, "with ");
+  vivi_code_printer_print (printer, vivi_code_label_get_name (with->label));
+  vivi_code_printer_new_line (printer, FALSE);
+}
+
+static void
+vivi_code_asm_with_dispose (GObject *object)
+{
+  ViviCodeAsmWith *with = VIVI_CODE_ASM_WITH (object);
+
+  g_object_unref (with->label);
+
+  G_OBJECT_CLASS (vivi_code_asm_with_parent_class)->dispose (object);
+}
+
+static void
+vivi_code_asm_with_class_init (ViviCodeAsmWithClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  ViviCodeTokenClass *token_class = VIVI_CODE_TOKEN_CLASS (klass);
+  ViviCodeAsmCodeClass *code_class = VIVI_CODE_ASM_CODE_CLASS (klass);
+
+  object_class->dispose = vivi_code_asm_with_dispose;
+
+  token_class->print = vivi_code_asm_with_print;
+
+  code_class->bytecode = SWFDEC_AS_ACTION_WITH;
+}
+
+static void
+vivi_code_asm_with_init (ViviCodeAsmWith *with)
+{
+}
+
+ViviCodeAsm *
+vivi_code_asm_with_new (ViviCodeLabel *label)
+{
+  ViviCodeAsmWith *with;
+
+  g_return_val_if_fail (VIVI_IS_CODE_LABEL (label), NULL);
+
+  with = g_object_new (VIVI_TYPE_CODE_ASM_WITH, NULL);
+  with->label = g_object_ref (label);
+
+  return VIVI_CODE_ASM (with);
+}
+
+ViviCodeLabel *
+vivi_code_asm_with_get_label (ViviCodeAsmWith *with)
+{
+  g_return_val_if_fail (VIVI_IS_CODE_ASM_WITH (with), NULL);
+
+  return with->label;
+}
+
diff --git a/vivified/code/vivi_code_asm_with.h b/vivified/code/vivi_code_asm_with.h
new file mode 100644
index 0000000..295ea50
--- /dev/null
+++ b/vivified/code/vivi_code_asm_with.h
@@ -0,0 +1,59 @@
+/* Vivified
+ * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifndef _VIVI_CODE_ASM_WITH_H_
+#define _VIVI_CODE_ASM_WITH_H_
+
+#include <vivified/code/vivi_code_asm.h>
+#include <vivified/code/vivi_code_asm_code.h>
+#include <vivified/code/vivi_code_label.h>
+
+G_BEGIN_DECLS
+
+typedef struct _ViviCodeAsmWith ViviCodeAsmWith;
+typedef struct _ViviCodeAsmWithClass ViviCodeAsmWithClass;
+
+#define VIVI_TYPE_CODE_ASM_WITH                    (vivi_code_asm_with_get_type())
+#define VIVI_IS_CODE_ASM_WITH(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIVI_TYPE_CODE_ASM_WITH))
+#define VIVI_IS_CODE_ASM_WITH_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE ((klass), VIVI_TYPE_CODE_ASM_WITH))
+#define VIVI_CODE_ASM_WITH(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIVI_TYPE_CODE_ASM_WITH, ViviCodeAsmWith))
+#define VIVI_CODE_ASM_WITH_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), VIVI_TYPE_CODE_ASM_WITH, ViviCodeAsmWithClass))
+#define VIVI_CODE_ASM_WITH_GET_CLASS(obj)          (G_TYPE_INSTANCE_GET_CLASS ((obj), VIVI_TYPE_CODE_ASM_WITH, ViviCodeAsmWithClass))
+
+struct _ViviCodeAsmWith
+{
+  ViviCodeAsmCode	code;
+
+  ViviCodeLabel *	label;
+};
+
+struct _ViviCodeAsmWithClass
+{
+  ViviCodeAsmCodeClass	code_class;
+};
+
+GType			vivi_code_asm_with_get_type	  	(void);
+
+ViviCodeAsm *		vivi_code_asm_with_new			(ViviCodeLabel *	label);
+
+ViviCodeLabel *	  	vivi_code_asm_with_get_label		(ViviCodeAsmWith *	with);
+
+
+G_END_DECLS
+#endif
diff --git a/vivified/code/vivi_disassembler.c b/vivified/code/vivi_disassembler.c
index afeebe0..d967003 100644
--- a/vivified/code/vivi_disassembler.c
+++ b/vivified/code/vivi_disassembler.c
@@ -34,6 +34,7 @@
 #include "vivi_code_asm_pool.h"
 #include "vivi_code_asm_push.h"
 #include "vivi_code_asm_store.h"
+#include "vivi_code_asm_with.h"
 #include "vivi_code_assembler.h"
 #include "vivi_code_comment.h"
 #include "vivi_code_label.h"
@@ -296,6 +297,15 @@ vivi_disassemble_script (SwfdecScript *script)
 	    g_object_unref (asm_code);
 	  }
 	  break;
+        case SWFDEC_AS_ACTION_WITH:
+	  {
+	    ViviCodeLabel *label = vivi_disassemble_labels_get_label (labels, 
+		pc + swfdec_bits_get_u16 (&bits));
+	    ViviCodeAsm *asm_code = vivi_code_asm_with_new (label);
+	    vivi_code_assembler_add_code (assembler, asm_code);
+	    g_object_unref (asm_code);
+	  }
+	  break;
         case SWFDEC_AS_ACTION_DEFINE_FUNCTION:
 	  {
 	    char *name;
@@ -360,7 +370,6 @@ vivi_disassemble_script (SwfdecScript *script)
         case SWFDEC_AS_ACTION_GOTO_LABEL:
         case SWFDEC_AS_ACTION_WAIT_FOR_FRAME2:
         case SWFDEC_AS_ACTION_TRY:
-        case SWFDEC_AS_ACTION_WITH:
         case SWFDEC_AS_ACTION_GET_URL2:
         case SWFDEC_AS_ACTION_CALL:
         case SWFDEC_AS_ACTION_GOTO_FRAME2:
commit 09d1aa7b9f385fd7cffe03a74f844cc3733c7580
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Apr 22 13:52:09 2008 +0200

    s/swfdec_bots_bits_required/g_bit_storage/
    
    It makes sense to use existing functions ;)

diff --git a/swfdec/swfdec_bots.c b/swfdec/swfdec_bots.c
index 0bdf16e..b18aa78 100644
--- a/swfdec/swfdec_bots.c
+++ b/swfdec/swfdec_bots.c
@@ -242,6 +242,7 @@ void
 swfdec_bots_put_sbits (SwfdecBots *bots, int bits, guint n_bits)
 {
   g_return_if_fail (bots != NULL);
+
   swfdec_bots_put_bits (bots, bits, n_bits);
 }
 
@@ -298,23 +299,11 @@ swfdec_bots_put_double (SwfdecBots *bots, double value)
 }
 
 static guint
-swfdec_bots_bits_required (guint x)
-{
-  guint ret = 0;
-
-  while (x > 0) {
-    x >>= 1;
-    ret++;
-  }
-  return ret;
-}
-
-static guint
-swfdec_bots_sbits_required (int x)
+swfdec_bit_sstorage (long x)
 {
   if (x < 0)
-    x = !x;
-  return swfdec_bots_bits_required (x) + 1;
+    x = ~x;
+  return g_bit_storage (x) + 1;
 }
 
 void
@@ -330,12 +319,12 @@ swfdec_bots_put_rect (SwfdecBots *bots, const SwfdecRect *rect)
   y0 = rect->y0;
   x1 = rect->x1;
   y1 = rect->y1;
-  req = swfdec_bots_sbits_required (x0);
-  tmp = swfdec_bots_sbits_required (y0);
+  req = swfdec_bit_sstorage (x0);
+  tmp = swfdec_bit_sstorage (y0);
   req = MAX (req, tmp);
-  tmp = swfdec_bots_sbits_required (x1);
+  tmp = swfdec_bit_sstorage (x1);
   req = MAX (req, tmp);
-  tmp = swfdec_bots_sbits_required (y1);
+  tmp = swfdec_bit_sstorage (y1);
   req = MAX (req, tmp);
   swfdec_bots_syncbits (bots);
   swfdec_bots_put_bits (bots, req, 5);
@@ -356,8 +345,8 @@ swfdec_bots_put_matrix (SwfdecBots *bots, const cairo_matrix_t *matrix)
     swfdec_bots_put_bit (bots, 1);
     x = SWFDEC_DOUBLE_TO_FIXED (matrix->xx);
     y = SWFDEC_DOUBLE_TO_FIXED (matrix->yy);
-    xbits = swfdec_bots_sbits_required (x);
-    ybits = swfdec_bots_sbits_required (y);
+    xbits = swfdec_bit_sstorage (x);
+    ybits = swfdec_bit_sstorage (y);
     xbits = MAX (xbits, ybits);
     swfdec_bots_put_bits (bots, xbits, 5);
     swfdec_bots_put_sbits (bots, x, xbits);
@@ -369,8 +358,8 @@ swfdec_bots_put_matrix (SwfdecBots *bots, const cairo_matrix_t *matrix)
     swfdec_bots_put_bit (bots, 1);
     x = SWFDEC_DOUBLE_TO_FIXED (matrix->yx);
     y = SWFDEC_DOUBLE_TO_FIXED (matrix->xy);
-    xbits = swfdec_bots_sbits_required (x);
-    ybits = swfdec_bots_sbits_required (y);
+    xbits = swfdec_bit_sstorage (x);
+    ybits = swfdec_bit_sstorage (y);
     xbits = MAX (xbits, ybits);
     swfdec_bots_put_bits (bots, xbits, 5);
     swfdec_bots_put_sbits (bots, x, xbits);
@@ -380,8 +369,8 @@ swfdec_bots_put_matrix (SwfdecBots *bots, const cairo_matrix_t *matrix)
   }
   x = matrix->x0;
   y = matrix->y0;
-  xbits = swfdec_bots_sbits_required (x);
-  ybits = swfdec_bots_sbits_required (y);
+  xbits = swfdec_bit_sstorage (x);
+  ybits = swfdec_bit_sstorage (y);
   xbits = MAX (xbits, ybits);
   swfdec_bots_put_bits (bots, xbits, 5);
   swfdec_bots_put_sbits (bots, x, xbits);
@@ -398,24 +387,24 @@ swfdec_bots_put_color_transform (SwfdecBots *bots, const SwfdecColorTransform *t
   has_mult = trans->ra != 256 || trans->ga != 256 || trans->ba != 256 || trans->aa != 256;
   has_add = trans->rb != 0 || trans->gb != 0 || trans->bb != 0 || trans->ab != 0;
   if (has_mult) {
-    n_bits = swfdec_bots_sbits_required (trans->ra);
-    tmp = swfdec_bots_sbits_required (trans->ga);
+    n_bits = swfdec_bit_sstorage (trans->ra);
+    tmp = swfdec_bit_sstorage (trans->ga);
     n_bits = MAX (tmp, n_bits);
-    tmp = swfdec_bots_sbits_required (trans->ba);
+    tmp = swfdec_bit_sstorage (trans->ba);
     n_bits = MAX (tmp, n_bits);
-    tmp = swfdec_bots_sbits_required (trans->aa);
+    tmp = swfdec_bit_sstorage (trans->aa);
     n_bits = MAX (tmp, n_bits);
   } else {
     n_bits = 0;
   }
   if (has_add) {
-    tmp = swfdec_bots_sbits_required (trans->rb);
+    tmp = swfdec_bit_sstorage (trans->rb);
     n_bits = MAX (tmp, n_bits);
-    tmp = swfdec_bots_sbits_required (trans->gb);
+    tmp = swfdec_bit_sstorage (trans->gb);
     n_bits = MAX (tmp, n_bits);
-    tmp = swfdec_bots_sbits_required (trans->bb);
+    tmp = swfdec_bit_sstorage (trans->bb);
     n_bits = MAX (tmp, n_bits);
-    tmp = swfdec_bots_sbits_required (trans->ab);
+    tmp = swfdec_bit_sstorage (trans->ab);
     n_bits = MAX (tmp, n_bits);
   }
   if (n_bits >= (1 << 4))


More information about the Swfdec-commits mailing list