Guest User

wasm-grammar

a guest
Feb 18th, 2024
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.68 KB | None | 0 0
  1. sign ::= '+' | '-'
  2.  
  3. num ::= digit
  4. | num [ '_' ] digit
  5.  
  6. hexnum ::= hexdigit
  7. | hexnum [ '_' ] hexdigit
  8.  
  9. nat ::= num
  10. | '0x' hexnum
  11.  
  12. int ::= [ sign ] nat
  13.  
  14. float ::= num '.' [ num ] [ ( 'e' | 'E' ) num ]
  15. | '0x' hexnum '.' [ hexnum ] [ ( 'p' | 'P' ) num ]
  16.  
  17. id ::= '$' idchar { idchar }
  18.  
  19. idchar ::= letter | digit
  20. | '!' | '#' | '$' | '%' | '&' | '′' | '∗' | '+' | '−' | '.' | '/' | ':'
  21. | '<' | '=' | '>' | '?' | '@' | '∖' | '^' | '_' | '`' | '|' | '~'
  22.  
  23. string ::= '"' { char | '\n' | '\t' | '\\' | "\'" | '\"' | '\' hexnum hexnum | '\u{' hexnum { hexnum } '}' } '"'
  24.  
  25. name ::= string
  26.  
  27. value ::= int
  28. | float
  29.  
  30. var ::= nat
  31. | name
  32.  
  33. unop ::= 'ctz' | 'clz' | 'popcnt'
  34.  
  35. binop ::= 'add' | 'sub' | 'mul' | 'div' | 'rem' | 'and' | 'or' | 'xor' | 'shl' | 'shr' | 'rotl' | 'rotr'
  36.  
  37. relop ::= 'eq' | 'ne' | 'lt' | 'gt' | 'le' | 'ge'
  38.  
  39. funop ::= 'abs' | 'neg' | 'sqrt' | 'ceil' | 'floor' | 'trunc' | 'nearest'
  40.  
  41. fbiunop ::= 'add' | 'sub' | 'mul' | 'div' | 'min' | 'max' | 'copysign'
  42.  
  43. itestop ::= 'eqz'
  44.  
  45. sign ::= 's' | 'u'
  46.  
  47. offset ::= "offset=" nat
  48.  
  49. align ::= "align=" ( 1 | 2 | 4 | 8 | ... )
  50.  
  51. cvtop ::= 'wrap' | 'extend' | 'trunc' | 'convert' | 'demote' | 'promote' | 'reinterpret'
  52.  
  53. val_type ::= 'i32' | 'i64' | 'f32' | 'f64'
  54. elem_type ::= funcref
  55. block_type ::= ( 'result' val_type* )*
  56. func_type ::= ( type <var> )? param* result*
  57. global_type ::= <val_type> | ( 'mut' val_type )
  58. table_type ::= nat [ nat ] elem_type
  59. memory_type ::= nat [ nat ]
  60.  
  61. module ::= '(' 'module' [ id ] { field } ')'
  62.  
  63. field ::= type
  64. | import
  65. | func
  66. | table
  67. | mem
  68. | global
  69. | export
  70. | start
  71. | elem
  72. | data
  73.  
  74. type ::= '(' 'type' [ id ] functype ')'
  75.  
  76. typeuse ::= '(' 'type' typeidx ')'
  77. | '(' 'type' typeidx ')' (param)∗ (result)∗
  78.  
  79. import ::= '(' 'import' name name importdesc ')'
  80.  
  81. importdesc ::= '(' 'func' [ id ] typeuse ')'
  82. | '(' 'table' [ id ] tabletype ')'
  83. | '(' 'memory' [ id ] memtype ')'
  84. | '(' 'global' [ id ] globaltype ')'
  85.  
  86. func ::= '(' 'func' [ id ] typeuse (local)∗ (instr)∗ ')'
  87.  
  88. local ::= '(' 'local' [ id ] valtype ')'
  89.  
  90. table ::= '(' 'table' [ id ] tabletype ')'
  91.  
  92. mem ::= '(' 'memory' [ id ] memtype ')'
  93.  
  94. global ::= '(' 'global' [ id ] globaltype expr ')'
  95.  
  96. export ::= '(' 'export' name exportdesc ')'
  97.  
  98. start ::= '(' 'start' funcidx ')'
  99.  
  100. elem ::= '(' 'elem' tableidx '(' offset expr ')' funcidx* ')'
  101.  
  102. data ::= '(' 'data' memidx '(' offset expr ')' datastring ')'
  103.  
  104. expr ::= '(' op ')'
  105. | '(' op expr+ ')'
  106. | '(' 'block' [ name ] block_type instr* ')'
  107. | '(' 'loop' [ name ] block_type instr* ')'
  108. | '(' 'if' [ name ] block_type '(' 'then' instr* ) '(' 'else' instr* ')'? ')'
  109. | '(' 'if' [ name ] block_type expr+ '(' 'then' instr* ')' '(' 'else' instr* ')'? ')'
  110.  
  111. instr ::= expr
  112. | op
  113. | "block" [ name ] block_type instr* "end" [ name ]
  114. | "loop" [ name ] block_type instr* "end" [ name ]
  115. | "if" [ name ] block_type instr* "else" [ name ] instr* "end" [ name ]
  116. | "if" [ name ] block_type instr* "end" [ name ]
  117.  
  118.  
  119. op ::= "unreachable"
  120. | "nop"
  121. | "br" var
  122. | "br_if" var
  123. | "br_table" var+
  124. | "return"
  125. | "call" var
  126. | "call_indirect" func_type
  127. | "drop"
  128. | "select"
  129. | "local.get" var
  130. | "local.set" var
  131. | "local.tee" var
  132. | "global.get" var
  133. | "global.set" var
  134. | <val_type> '.' load((8|16|32)_<sign>)? <offset>? <align>?
  135. | <val_type> '.' store(8|16|32)? <offset>? <align>?
  136. | "memory.size"
  137. | "memory.grow"
  138. | <val_type> '.' "const" <value>
  139. | <val_type> '.' <unop>
  140. | <val_type> '.' <binop>
  141. | <val_type> '.' <testop>
  142. | <val_type> '.' <relop>
  143. | <val_type> '.' <cvtop> '_' <val_type> (_<sign>)?
  144.  
  145. func ::= ( func [ name ] <func_type> <local>* <instr>* )
  146. | ( func [ name ] ( export <string> ) <instr>* )
  147. | ( func [ name ] ( import <string> <string> ) <func_type>)
  148.  
  149. param ::= ( param <val_type>* )
  150. | ( param <name> <val_type> )
  151.  
  152. result ::= ( result <val_type>* )
  153.  
  154. local ::= ( local <val_type>* )
  155. | ( local <name> <val_type> )
  156.  
  157. global ::= ( global [ name ] <global_type> <instr>* )
  158. | ( global [ name ] ( export <string> ) <...> )
  159. | ( global [ name ] ( import <string> <string> ) <global_type> )
  160.  
  161. table ::= ( table [ name ] <table_type> )
  162. | ( table [ name ] ( export <string> ) <...> )
  163. | ( table [ name ] ( import <string> <string> ) <table_type> )
  164. | ( table [ name ] ( export <string> )* <elem_type> ( elem <var>* ) )
  165.  
  166. elem ::= ( elem <var>? (offset <instr>* ) <var>* )
  167. | ( elem <var>? <expr> <var>* )
  168.  
  169. memory ::= ( memory [ name ] <memory_type> )
  170. | ( memory [ name ] ( export <string> ) <...> )
  171. | ( memory [ name ] ( import <string> <string> ) <memory_type> )
  172. | ( memory [ name ] ( export <string> )* ( data <string>* ) )
  173.  
  174. data ::= ( data <var>? ( offset <instr>* ) <string>* )
  175. | ( data <var>? <expr> <string>* )
  176.  
  177. start ::= ( start <var> )
  178.  
  179. typedef ::= ( type [ name ] ( func <param>* <result>* ) )
  180.  
  181. import ::= '(' 'import' string string imkind ')'
  182.  
  183. imkind ::= '(' 'func' [ name ] func_type ')'
  184. | '(' 'global' [ name ] global_type ')'
  185. | '(' 'table' [ name ] table_type ')'
  186. | '(' 'memory' [ name ] memory_type ')'
  187.  
  188. export ::= '(' 'export' string exkind ')'
  189.  
  190. exkind ::= '(' 'func' var ')'
  191. | '(' 'global' var ')'
  192. | '(' 'table' var ')'
  193. | '(' 'memory' var ')'
  194.  
  195. module ::= '(' 'module' [name] {typedef} {func} {import} {export} [table] [memory] {global} {elem} {data} [start] ')'
  196. | {typedef} {func} {import} {export} [table] [memory] {global} {elem} {data} [start]
  197.  
  198. start ::= module
Advertisement
Add Comment
Please, Sign In to add comment