Skip to content

Commit

Permalink
[wast mode] Support atomics from the Wasm Threads proposal
Browse files Browse the repository at this point in the history
This also adds more test coverage for not only the atomic memory
instructions, but also the regular memory instructions. It also
shortens the regex's for keyword and atom a bit.
  • Loading branch information
bmeurer authored and marijnh committed Jun 14, 2020
1 parent 1191965 commit a45f699
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 3 deletions.
96 changes: 95 additions & 1 deletion mode/wast/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'[string "foo #\\"# bar"]');

MT('atom-test',
'[atom anyfunc]',
'[atom i32]',
'[atom i64]',
'[atom f32]',
Expand All @@ -31,5 +32,98 @@
'[keyword if]',
'[keyword loop]',
'[keyword i32.add]',
'[keyword local.get]')
'[keyword local.get]');

MT('memory-instructions',
'[keyword i32.load] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i32.load8_s] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i32.load8_u] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i32.load16_s] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i32.load16_u] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i32.store] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i32.store8] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i32.store16] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i64.store] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i64.load] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i64.load8_s] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i64.load8_u] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i64.load16_s] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i64.load16_u] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i64.load32_s] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i64.load32_u] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i64.store8] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i64.store16] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword i64.store32] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword f32.load] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword f32.store] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword f64.load] [keyword offset]=[number 4] [keyword align]=[number 4]',
'[keyword f64.store] [keyword offset]=[number 4] [keyword align]=[number 4]');

MT('atomic-memory-instructions',
'[keyword atomic.notify] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.wait] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.wait] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.load] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.load8_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.load16_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.store] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.store8] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.store16] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.load] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.load8_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.load16_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.load32_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.store] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.store8] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.store16] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.store32] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw.add] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw8.add_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw16.add_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw.add] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw8.add_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw16.add_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw32.add_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw.sub] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw8.sub_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw16.sub_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw.sub] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw8.sub_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw16.sub_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw32.sub_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw.and] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw8.and_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw16.and_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw.and] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw8.and_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw16.and_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw32.and_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw.or] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw8.or_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw16.or_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw.or] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw8.or_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw16.or_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw32.or_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw.xor] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw8.xor_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw16.xor_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw.xor] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw8.xor_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw16.xor_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw32.xor_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw.xchg] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw8.xchg_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw16.xchg_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw.xchg] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw8.xchg_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw16.xchg_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw32.xchg_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw.cmpxchg] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw8.cmpxchg_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i32.atomic.rmw16.cmpxchg_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw.cmpxchg] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw8.cmpxchg_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw16.cmpxchg_u] [keyword offset]=[number 32] [keyword align]=[number 4]',
'[keyword i64.atomic.rmw32.cmpxchg_u] [keyword offset]=[number 32] [keyword align]=[number 4]');
})();
4 changes: 2 additions & 2 deletions mode/wast/wast.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
CodeMirror.defineSimpleMode('wast', {
start: [
{regex: /[+\-]?(?:nan(?::0x[0-9a-fA-F]+)?|infinity|inf|0x[0-9a-fA-F]+\.?[0-9a-fA-F]*p[+\/-]?\d+|\d+(?:\.\d*)?[eE][+\-]?\d*|\d+\.\d*|0x[0-9a-fA-F]+|\d+)/, token: "number"},
{regex: /mut|nop|block|if|then|else|loop|br_if|br_table|br|call_indirect|call|drop|end|return|local\.(get|set|tee)|global\.(get|set)|i(32|64)\.(store(8|16)|(load(8|16)_(s|u)))|i64\.(load32_(s|u)|store16)|(i32|i64|f32|f64)\.(load|store)|(i32|i64|f32|f64)\.const|f(32|64)\.(abs|add|ceil|copysign|div|eq|floor|(g|l)(t|e)|max|min|mul|nearest|neg?|sqrt|sub|trunc)|i(32|64)\.(add|and|clz|ctz|(div|rem)_(s|u)|eqz?|(g|l)(e|t)_(s|u)|mul|ne|popcnt|or|rot(l|r)|sh(l|r_(s|u))|sub|xor)|i64\.extend_(s|u)_i32|i32\.wrap_i64|i(32|64)\.trunc_f(32|64)_(s|u)|f(32|64)\.convert_i(32|64)_(s|u)|f64\.promote_f32|f32\.demote_f64|f32\.reinterpret_i32|i32\.reinterpret_f32|f64\.reinterpret_i64|i64\.reinterpret_f64|select|unreachable|current_memory|memory\.(size|grow)|type|func|param|result|local|global|module|table|memory|start|elem|data|align|offset|import|export/, token: "keyword"},
{regex: /\b(anyfunc|i32|i64|f32|f64)\b/, token: "atom"},
{regex: /mut|nop|block|if|then|else|loop|br_if|br_table|br|call_indirect|call|drop|end|return|local\.(get|set|tee)|global\.(get|set)|i(32|64)\.(store(8|16)|(load(8|16)_[su]))|i64\.(load32_[su]|store32)|[fi](32|64)\.(const|load|store)|f(32|64)\.(abs|add|ceil|copysign|div|eq|floor|[gl][et]|max|min|mul|nearest|neg?|sqrt|sub|trunc)|i(32|64)\.(a[dn]d|c[lt]z|(div|rem)_[su]|eqz?|[gl][te]_[su]|mul|ne|popcnt|rot[lr]|sh(l|r_[su])|sub|x?or)|i64\.extend_[su]_i32|i32\.wrap_i64|i(32|64)\.trunc_f(32|64)_[su]|f(32|64)\.convert_i(32|64)_[su]|f64\.promote_f32|f32\.demote_f64|f32\.reinterpret_i32|i32\.reinterpret_f32|f64\.reinterpret_i64|i64\.reinterpret_f64|select|unreachable|current_memory|memory\.(size|grow)|type|func|param|result|local|global|module|table|memory|start|elem|data|align|offset|import|export|atomic\.notify|i64\.atomic\.(load32_u|store32|rmw32\.(a[dn]d|sub|x?or|(cmp)?xchg)_u)|i(32|64)\.atomic\.(wait|load((8|16)_u)?|store(8|16)?|rmw(\.(a[dn]d|sub|x?or|(cmp)?xchg)|(8|16)\.(a[dn]d|sub|x?or|(cmp)?xchg)_u))/, token: "keyword"},
{regex: /\b(anyfunc|[fi](32|64))\b/, token: "atom"},
{regex: /\$([a-zA-Z0-9_`\+\-\*\/\\\^~=<>!\?@#$%&|:\.]+)/, token: "variable-2"},
{regex: /"(?:[^"\\\x00-\x1f\x7f]|\\[nt\\'"]|\\[0-9a-fA-F][0-9a-fA-F])*"/, token: "string"},
{regex: /\(;.*?/, token: "comment", next: "comment"},
Expand Down

0 comments on commit a45f699

Please sign in to comment.