2 Ming, an SWF output library
3 Copyright (C) 2002 Opaque Industries - http://www.opaque.net/
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "assembler.h"
38 struct label labels[256];
42 findLabel(char *label)
46 for ( i=0; i<nLabels; ++i )
48 if ( strcmp(label, labels[i].name) == 0 )
59 int i = findLabel(label);
63 labels[nLabels].name = strdup(label);
64 labels[nLabels].offset = len;
68 labels[i].offset = len;
73 bufferBranchTarget(Buffer output, char *label)
75 int i = findLabel(label);
83 return bufferWriteS16(output, i);
88 bufferPatchTargets(Buffer buffer)
91 unsigned char *output = buffer->buffer;
95 if ( output[i] & 0x80 ) /* then it's a multibyte instruction */
97 if ( output[i] == SWFACTION_BRANCHALWAYS ||
98 output[i] == SWFACTION_BRANCHIFTRUE )
102 i += 3; /* plus instruction plus two-byte length */
105 offset = labels[target].offset - (i+2);
106 output[i] = offset & 0xff;
107 output[++i] = (offset>>8) & 0xff;