summaryrefslogtreecommitdiff
path: root/src/wasm-parse.h
blob: 64ddcefb45cff87acbd35ea92d8ee3f5b2241fee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef WASM_PARSE_H
#define WASM_PARSE_H

#include "wasm.h"

typedef union WasmNumber {
  uint32_t i32;
  uint64_t i64;
  float f32;
  double f64;
} WasmNumber;

typedef uintptr_t WasmParserCookie;

typedef struct WasmParserCallbacks {
  void* user_data;
  void (*error)(WasmSourceLocation loc, const char* msg, void* user_data);
  void (*before_module)(struct WasmModule* m, void* user_data);
  void (*after_module)(struct WasmModule* m, void* user_data);
  void (*before_function)(struct WasmModule* m,
                          struct WasmFunction* f,
                          void* user_data);
  void (*after_function)(struct WasmModule* m,
                         struct WasmFunction* f,
                         int num_exprs,
                         void* user_data);
  void (*before_export)(struct WasmModule* m, void* user_data);
  void (*after_export)(struct WasmModule* m,
                       struct WasmFunction* f,
                       void* user_data);

  void (*before_binary)(enum WasmOpcode opcode, void* user_data);
  WasmParserCookie (*before_block)(void* user_data);
  void (*after_block)(WasmType type,
                      int num_exprs,
                      WasmParserCookie cookie,
                      void* user_data);
  WasmParserCookie (*before_break)(int with_expr,
                                   int label_depth,
                                   void* user_data);
  void (*after_break)(WasmParserCookie cookie, void* user_data);
  void (*before_call)(int function_index, void* user_data);
  void (*before_call_import)(int import_index, void* user_data);
  void (*before_compare)(enum WasmOpcode opcode, void* user_data);
  void (*after_const)(enum WasmOpcode opcode,
                      WasmType type,
                      WasmNumber value,
                      void* user_data);
  void (*before_convert)(enum WasmOpcode opcode, void* user_data);
  WasmParserCookie (*before_label)(void* user_data);
  void (*after_label)(WasmType type,
                      int num_exprs,
                      WasmParserCookie cookie,
                      void* user_data);
  void (*after_get_local)(int remapped_index, void* user_data);
  WasmParserCookie (*before_loop)(void* user_data);
  void (*after_loop)(int num_exprs, WasmParserCookie cookie, void* user_data);
  WasmParserCookie (*before_if)(void* user_data);
  void (*after_if)(WasmType type,
                   int with_else,
                   WasmParserCookie cookie,
                   void* user_data);
  void (*before_load)(enum WasmOpcode opcode, uint8_t access, void* user_data);
  void (*after_load_global)(int index, void* user_data);
  void (*after_memory_size)(void* user_data);
  void (*after_nop)(void* user_data);
  void (*after_page_size)(void* user_data);
  void (*before_resize_memory)(void* user_data);
  void (*before_return)(void* user_data);
  void (*after_return)(WasmType type, void* user_data);
  void (*before_set_local)(int index, void* user_data);
  void (*before_store)(enum WasmOpcode opcode, uint8_t access, void* user_data);
  void (*before_store_global)(int index, void* user_data);
  WasmParserCookie (*before_switch)(void* user_data);
  void (*after_switch)(WasmParserCookie cookie, void* user_data);
  WasmParserCookie (*before_switch_case)(WasmNumber number, void* user_data);
  void (*after_switch_case)(int num_exprs,
                            int with_fallthrough,
                            WasmParserCookie cookie,
                            void* user_data);
  WasmParserCookie (*before_switch_default)(void* user_data);
  void (*after_switch_default)(WasmParserCookie cookie, void* user_data);
  void (*before_unary)(enum WasmOpcode opcode, void* user_data);

  /* used in spec repo tests */
  WasmParserCookie (*before_assert_eq)(void* user_data);
  void (*after_assert_eq)(WasmType type,
                          WasmParserCookie cookie,
                          void* user_data);
  void (*before_assert_trap)(void* user_data);
  void (*after_assert_trap)(void* user_data);
  WasmParserCookie (*before_invoke)(const char* invoke_name,
                                    int invoke_function_index,
                                    void* user_data);
  void (*after_invoke)(WasmParserCookie cookie, void* user_data);

  /* called with the error from the module parsed inside of assert_invalid */
  void (*assert_invalid_error)(WasmSourceLocation loc,
                               const char* msg,
                               void* user_data);
} WasmParserCallbacks;

EXTERN_C int wasm_parse_module(WasmSource* source, WasmParserCallbacks* parser);
EXTERN_C int wasm_parse_file(WasmSource* source, WasmParserCallbacks* parser);
EXTERN_C void wasm_copy_segment_data(WasmSegmentData data,
                                     char* dest,
                                     size_t size);

#endif /* WASM_PARSE_H */