bugfixes, added exception handling
[swftools.git] / lib / as3 / code.h
1 #ifndef __code_h__
2 #define __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 struct _codestats {
44     int max_stack;
45     int local_count;
46     int init_scope_depth;
47     int max_scope_depth;
48 };
49
50 struct _codelookup {
51     code_t**bytepos;
52     int len;
53 };
54
55 code_t*add_opcode(code_t*atag, U8 op);
56
57 code_t*code_parse(TAG*tag, int len, abc_file_t*file, pool_t*pool, codelookup_t**codelookup);
58 int        code_dump(code_t*c, exception_list_t*exceptions, abc_file_t*file, char*prefix, FILE*fo);
59 void       code_write(TAG*tag, code_t*code, pool_t*pool, abc_file_t*file);
60 void       code_free(code_t*c);
61 code_t* code_atposition(codelookup_t*l, int pos);
62 void codelookup_free(codelookup_t*codelookup);
63
64 codestats_t* code_get_statistics(code_t*code, exception_list_t*exceptions);
65
66 void codestats_print(codestats_t*s);
67 void codestats_free(codestats_t*s);
68
69
70 #endif