5acc8d1b254add359a7d55c07b9ae64081fcd285
[swftools.git] / lib / as3 / code.h
1 #ifndef __abc_code_h__
2 #define __abc_code_h__
3
4 #include "../q.h"
5
6 DECLARE(code);
7 DECLARE_LIST(code);
8 DECLARE(codestats);
9 DECLARE(codelookup);
10 DECLARE(lookupswitch);
11
12 #include "abc.h"
13
14 typedef struct _opcode
15 {
16     unsigned char opcode;
17     char*name;
18     char*params;
19
20     int stack_minus;
21     int stack_plus;
22     int scope_stack_plus;
23     int flags;
24 } opcode_t;
25
26 struct _code {
27     void*data[2];
28     code_t*next;
29     code_t*prev;
30
31     code_t*branch;
32     int pos; //used during code path evaluation
33     
34     U8 opcode;
35     char badbranch;
36 };
37
38 struct _lookupswitch {
39     code_t*def;
40     code_list_t*targets;
41 };
42
43 #define FLAGS_ACTIVATION 0x02
44 #define FLAGS_SET_DXNS 0x40
45 struct _codestats {
46     int max_stack;
47     int local_count;
48     int max_scope_depth;
49     int flags;
50 };
51
52 struct _codelookup {
53     code_t**bytepos;
54     int len;
55 };
56
57 code_t*add_opcode(code_t*atag, U8 op);
58
59 code_t*code_parse(TAG*tag, int len, abc_file_t*file, pool_t*pool, codelookup_t**codelookup);
60 int        code_dump(code_t*c, exception_list_t*exceptions, abc_file_t*file, char*prefix, FILE*fo);
61 void       code_write(TAG*tag, code_t*code, pool_t*pool, abc_file_t*file);
62 void       code_free(code_t*c);
63 code_t* code_atposition(codelookup_t*l, int pos);
64 void codelookup_free(codelookup_t*codelookup);
65
66 codestats_t* code_get_statistics(code_t*code, exception_list_t*exceptions);
67
68 void codestats_print(codestats_t*s);
69 void codestats_free(codestats_t*s);
70
71 code_t* code_append(code_t*code, code_t*toappend);
72
73 #define code_new() (0)
74
75 #endif