Matt Godbolt | 895bfd5 | 2019-05-30 16:33:07 -0500 | [diff] [blame] | 1 | // Copyright (c) 2018, Compiler Explorer Authors |
Andre Meyering | 848e84f | 2018-10-14 17:01:29 +0200 | [diff] [blame] | 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are met: |
| 6 | // |
| 7 | // * Redistributions of source code must retain the above copyright notice, |
| 8 | // this list of conditions and the following disclaimer. |
| 9 | // * Redistributions in binary form must reproduce the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer in the |
| 11 | // documentation and/or other materials provided with the distribution. |
| 12 | // |
| 13 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 14 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 16 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 17 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 23 | // POSSIBILITY OF SUCH DAMAGE. |
| 24 | |
| 25 | "use strict"; |
RabsRincon | 8015e5f | 2019-07-22 15:15:58 +0200 | [diff] [blame] | 26 | var monaco = require('monaco-editor'); |
Andre Meyering | 848e84f | 2018-10-14 17:01:29 +0200 | [diff] [blame] | 27 | |
| 28 | // This definition is based on the official LLVM vim syntax: |
| 29 | // http://llvm.org/svn/llvm-project/llvm/trunk/utils/vim/syntax/llvm.vim |
| 30 | // For VIM regex syntax, see: http://vimdoc.sourceforge.net/htmldoc/pattern.html |
| 31 | function definition() { |
| 32 | return { |
| 33 | // llvmType |
| 34 | types: [ |
| 35 | 'void', 'half', 'float', 'double', 'x86_fp80', 'fp128', 'ppc_fp128', |
| 36 | 'label', 'metadata', 'x86_mmx', |
| 37 | 'type', 'label', 'opaque', 'token' |
| 38 | ], |
| 39 | // llvmStatement |
| 40 | statements: [ |
| 41 | 'add', 'addrspacecast', 'alloca', 'and', 'arcp', 'ashr', 'atomicrmw', |
| 42 | 'bitcast', 'br', 'catchpad', 'catchswitch', 'catchret', 'call', |
| 43 | 'cleanuppad', 'cleanupret', 'cmpxchg', 'eq', 'exact', 'extractelement', |
| 44 | 'extractvalue', 'fadd', 'fast', 'fcmp', 'fdiv', 'fence', 'fmul', 'fpext', |
| 45 | 'fptosi', 'fptoui', 'fptrunc', 'free', 'frem', 'fsub', 'getelementptr', |
| 46 | 'icmp', 'inbounds', 'indirectbr', 'insertelement', 'insertvalue', |
| 47 | 'inttoptr', 'invoke', 'landingpad', 'load', 'lshr', 'malloc', 'max', 'min', |
| 48 | 'mul', 'nand', 'ne', 'ninf', 'nnan', 'nsw', 'nsz', 'nuw', 'oeq', 'oge', 'ogt', 'ole', |
| 49 | 'olt', 'one', 'or', 'ord', 'phi', 'ptrtoint', 'resume', 'ret', 'sdiv', 'select', |
| 50 | 'sext', 'sge', 'sgt', 'shl', 'shufflevector', 'sitofp', 'sle', 'slt', 'srem', |
| 51 | 'store', 'sub', 'switch', 'trunc', 'udiv', 'ueq', 'uge', 'ugt', 'uitofp', 'ule', 'ult', |
| 52 | 'umax', 'umin', 'une', 'uno', 'unreachable', 'unwind', 'urem', 'va_arg', |
| 53 | 'xchg', 'xor', 'zext' |
| 54 | ], |
| 55 | // llvmKeyword |
| 56 | keywords: [ |
| 57 | 'acq_rel', 'acquire', 'addrspace', 'alias', 'align', 'alignstack', 'alwaysinline', |
| 58 | 'appending', 'argmemonly', 'arm_aapcscc', 'arm_aapcs_vfpcc', 'arm_apcscc', 'asm', |
| 59 | 'atomic', 'available_externally', 'blockaddress', 'builtin', 'byval', 'c', 'catch', |
| 60 | 'caller', 'cc', 'ccc', 'cleanup', 'coldcc', 'comdat', 'common', 'constant', |
| 61 | 'datalayout', 'declare', 'default', 'define', 'deplibs', 'dereferenceable', |
| 62 | 'distinct', 'dllexport', 'dllimport', 'dso_local', 'dso_preemptable', 'except', |
| 63 | 'external', 'externally_initialized', 'extern_weak', 'fastcc', 'filter', 'from', |
| 64 | 'gc', 'global', 'hhvmcc', 'hhvm_ccc', 'hidden', 'initialexec', 'inlinehint', |
| 65 | 'inreg', 'inteldialect', 'intel_ocl_bicc', 'internal', 'linkonce', 'linkonce_odr', |
| 66 | 'localdynamic', 'localexec', 'local_unnamed_addr', 'minsize', 'module', |
| 67 | 'monotonic', 'msp430_intrcc', 'musttail', 'naked', 'nest', 'noalias', 'nobuiltin', |
| 68 | 'nocapture', 'noimplicitfloat', 'noinline', 'nonlazybind', 'nonnull', 'norecurse', |
| 69 | 'noredzone', 'noreturn', 'nounwind', 'optnone', 'optsize', 'personality', |
| 70 | 'private', 'protected', 'ptx_device', 'ptx_kernel', 'readnone', 'readonly', |
| 71 | 'release', 'returned', 'returns_twice', 'sanitize_address', 'sanitize_memory', |
| 72 | 'sanitize_thread', 'section', 'seq_cst', 'sideeffect', 'signext', 'syncscope', |
| 73 | 'source_filename', 'speculatable', 'spir_func', 'spir_kernel', 'sret', 'ssp', |
| 74 | 'sspreq', 'sspstrong', 'strictfp', 'swiftcc', 'tail', 'target', 'thread_local', |
| 75 | 'to', 'triple', 'unnamed_addr', 'unordered', 'uselistorder', 'uselistorder_bb', |
| 76 | 'uwtable', 'volatile', 'weak', 'weak_odr', 'within', 'writeonly', 'x86_64_sysvcc', |
| 77 | 'win64cc', 'x86_fastcallcc', 'x86_stdcallcc', 'x86_thiscallcc', 'zeroext' |
| 78 | ], |
| 79 | |
| 80 | escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/, |
| 81 | |
| 82 | tokenizer: { |
| 83 | root: [ |
Patrick Quist | 71058de | 2018-11-01 03:43:05 +0100 | [diff] [blame] | 84 | [/[,(){}<>[\]]/, 'delimiters'], |
Andre Meyering | 848e84f | 2018-10-14 17:01:29 +0200 | [diff] [blame] | 85 | [/i\d+\**/, 'type'], // llvmType |
| 86 | |
| 87 | // Misc syntax. |
| 88 | [/[%@!]\d+/, 'variable.name'], // llvmNoName |
| 89 | [/-?\d+\.\d*(e[+-]\d+)?/, 'number.float'], // llvmFloat |
| 90 | [/0[xX][0-9A-Fa-f]+/, 'number.hex'], // llvmFloat |
| 91 | [/-?\d+/, 'number'], // llvmNumber |
| 92 | [/\b(true|false)\b/, 'keyword'], // llvmBoolean |
| 93 | [/\b(zeroinitializer|undef|null|none)\b/, 'constant'], // llvmConstant |
Matt Godbolt | 2e7fc5f | 2019-03-21 21:28:43 -0500 | [diff] [blame] | 94 | [/"([^"\\]|\\.)*$/, 'string.invalid'], // non-terminated string |
| 95 | [/"/, 'string', '@string'], // push to string state |
Andre Meyering | 848e84f | 2018-10-14 17:01:29 +0200 | [diff] [blame] | 96 | [/[-a-zA-Z$._][-a-zA-Z$._0-9]*:/, 'tag'], // llvmLabel |
| 97 | [/[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*/, 'variable.name'], // llvmIdentifier |
| 98 | |
| 99 | // Named metadata and specialized metadata keywords. |
| 100 | [/![-a-zA-Z$._][-a-zA-Z$._0-9]*(?=\s*)$/, 'identifier'], // llvmIdentifier |
| 101 | [/![-a-zA-Z$._][-a-zA-Z$._0-9]*(?=\s*[=!])/, 'identifier'], // llvmIdentifier |
| 102 | [/![A-Za-z]+(?=\s*\()/, 'type'], // llvmType |
| 103 | [/\bDW_TAG_[a-z_]+\b/, 'constant'], // llvmConstant |
| 104 | [/\bDW_ATE_[a-zA-Z_]+\b/, 'constant'], // llvmConstant |
| 105 | [/\bDW_OP_[a-zA-Z0-9_]+\b/, 'constant'], // llvmConstant |
| 106 | [/\bDW_LANG_[a-zA-Z0-9_]+\b/, 'constant'], // llvmConstant |
| 107 | [/\bDW_VIRTUALITY_[a-z_]+\b/, 'constant'], // llvmConstant |
| 108 | [/\bDIFlag[A-Za-z]+\b/, 'constant'], // llvmConstant |
| 109 | |
| 110 | // Syntax-highlight lit test commands and bug numbers. |
| 111 | [/;\s*PR\d*\s*$/, 'comment.doc'], // llvmSpecialComment |
| 112 | [/;\s*REQUIRES:.*$/, 'comment.doc'], // llvmSpecialComment |
| 113 | [/;\s*RUN:.*$/, 'comment.doc'], // llvmSpecialComment |
| 114 | [/;\s*CHECK:.*$/, 'comment.doc'], // llvmSpecialComment |
| 115 | [/;\s*CHECK-(?:NEXT|NOT|DAG|SAME|LABEL):.*$/, 'comment.doc'], // llvmSpecialComment |
| 116 | [/;\s*XFAIL:.*$/, 'comment.doc'], // llvmSpecialComment |
| 117 | [/;.*$/, 'comment'], |
| 118 | [/[*#=!]/, 'operators'], |
| 119 | [/[a-z_$][\w$]*/, { |
| 120 | cases: { |
| 121 | '@statements': 'operators', |
| 122 | '@keywords': 'keyword', |
| 123 | '@types': 'type', |
| 124 | '@default': 'identifier' |
| 125 | } |
| 126 | }], |
| 127 | [/[ \t\r\n]+/, 'white'] |
| 128 | |
| 129 | ], |
| 130 | string: [ |
Matt Godbolt | 2e7fc5f | 2019-03-21 21:28:43 -0500 | [diff] [blame] | 131 | [/[^\\"]+/, 'string'], |
Andre Meyering | 848e84f | 2018-10-14 17:01:29 +0200 | [diff] [blame] | 132 | [/@escapes/, 'string.escape'], |
Matt Godbolt | 2e7fc5f | 2019-03-21 21:28:43 -0500 | [diff] [blame] | 133 | [/\\./, 'string.escape.invalid'], |
| 134 | [/"/, 'string', '@pop'] |
Andre Meyering | 848e84f | 2018-10-14 17:01:29 +0200 | [diff] [blame] | 135 | ] |
| 136 | } |
| 137 | }; |
| 138 | } |
| 139 | |
| 140 | monaco.languages.register({id: 'llvm-ir'}); |
| 141 | monaco.languages.setMonarchTokensProvider('llvm-ir', definition()); |