Bug 591908: Remove Math.floor from microbenchmark iterations/sec calculation (r=fklockii)
[tamarin-stm.git] / utils / swfmake.as
bloba90c8b2028b9d034af8edf89d89606d1fe86316a
1 /* -*- mode: java -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is [Open Source Virtual Machine.].
17 * The Initial Developer of the Original Code is
18 * Adobe System Incorporated.
19 * Portions created by the Initial Developer are Copyright (C) 2009
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Adobe AS3 Team
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 /* Utility to stitch ABC files together into a single swf.
41 * Usage:
43 * swfmake [-c] [-o filename] abcfile ...
45 * -o filename defines the name of the output file
47 * -c creates a compressed swf
49 * By default the name of the output file is the name of the first abc
50 * file with ".abc" replaced by ".swf", and the swf file is uncompressed.
53 package swfmake
55 import avmplus.*;
56 import flash.utils.*;
58 var input_names = [];
59 var output_name = null;
60 var compress = undefined;
62 var i=0, j;
63 var argc=System.argv.length;
64 var argv=System.argv;
65 var s;
66 while (i < argc) {
67 s = argv[i];
68 if (s == "-o") {
69 if (output_name != null || i+1 == argc)
70 usage();
71 output_name = argv[i+1];
72 i += 2;
74 else if (s == "-c") {
75 if (compress is Boolean)
76 usage();
77 compress = true;
78 i++;
80 else if (s.charAt(0) == "-") {
81 usage();
83 else {
84 input_names.push(s);
85 i++;
89 if (!(compress is Boolean))
90 compress = false;
92 if (input_names.length == 0)
93 usage();
95 if (output_name == null) {
96 s = input_names[0];
97 if (s.match(/\.abc$/))
98 output_name = s.replace(/\.abc$/, ".swf");
99 else
100 output_name = s + ".swf";
103 var body = new ByteArray();
104 body.endian = "littleEndian";
105 body.writeByte(2 << 3); // RECT: 2 bits per dim
106 body.writeByte(0); // and they're all zero
107 body.writeShort(0); // framerate
108 body.writeShort(0); // framecount
110 for ( i=0 ; i < input_names.length ; i++ ) {
111 s = input_names[i];
112 var bytes = ByteArray.readFile(s);
113 body.writeShort((82 << 6) | 63); // DoABC, extended length
114 body.writeUnsignedInt(bytes.length + 4 + s.length + 1);
115 body.writeUnsignedInt(0); // flags
116 for ( j=0 ; j < s.length ; j++ )
117 body.writeByte(s.charCodeAt(j) & 255);
118 body.writeByte(0);
119 body.writeBytes(bytes);
121 body.writeShort(0); // End
123 var numbytes = body.length + 8;
125 if (compress)
126 body.compress();
128 var result = new ByteArray();
129 result.endian = "littleEndian";
130 result.writeByte((compress ? 'C' : 'F').charCodeAt(0));
131 result.writeByte('W'.charCodeAt(0));
132 result.writeByte('S'.charCodeAt(0));
133 result.writeByte(9);
134 result.writeUnsignedInt(numbytes);
135 result.writeBytes(body);
136 File.writeByteArray(output_name, result);
137 System.exit(0);
139 function usage() {
140 print("Usage: avmshell swfmake.abc -- [-c] [-o filename] abcfile ...");
141 System.exit(1);