]> luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/llvm.js
Initial commit.
[flow-web.git] / static / highlight / languages / llvm.js
1 /*! `llvm` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 /*
7 Language: LLVM IR
8 Author: Michael Rodler <contact@f0rki.at>
9 Description: language used as intermediate representation in the LLVM compiler framework
10 Website: https://llvm.org/docs/LangRef.html
11 Category: assembler
12 Audit: 2020
13 */
14
15 /** @type LanguageFn */
16 function llvm(hljs) {
17 const regex = hljs.regex;
18 const IDENT_RE = /([-a-zA-Z$._][\w$.-]*)/;
19 const TYPE = {
20 className: 'type',
21 begin: /\bi\d+(?=\s|\b)/
22 };
23 const OPERATOR = {
24 className: 'operator',
25 relevance: 0,
26 begin: /=/
27 };
28 const PUNCTUATION = {
29 className: 'punctuation',
30 relevance: 0,
31 begin: /,/
32 };
33 const NUMBER = {
34 className: 'number',
35 variants: [
36 { begin: /[su]?0[xX][KMLHR]?[a-fA-F0-9]+/ },
37 { begin: /[-+]?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?/ }
38 ],
39 relevance: 0
40 };
41 const LABEL = {
42 className: 'symbol',
43 variants: [ { begin: /^\s*[a-z]+:/ }, // labels
44 ],
45 relevance: 0
46 };
47 const VARIABLE = {
48 className: 'variable',
49 variants: [
50 { begin: regex.concat(/%/, IDENT_RE) },
51 { begin: /%\d+/ },
52 { begin: /#\d+/ },
53 ]
54 };
55 const FUNCTION = {
56 className: 'title',
57 variants: [
58 { begin: regex.concat(/@/, IDENT_RE) },
59 { begin: /@\d+/ },
60 { begin: regex.concat(/!/, IDENT_RE) },
61 { begin: regex.concat(/!\d+/, IDENT_RE) },
62 // https://llvm.org/docs/LangRef.html#namedmetadatastructure
63 // obviously a single digit can also be used in this fashion
64 { begin: /!\d+/ }
65 ]
66 };
67
68 return {
69 name: 'LLVM IR',
70 // TODO: split into different categories of keywords
71 keywords: {
72 keyword: 'begin end true false declare define global '
73 + 'constant private linker_private internal '
74 + 'available_externally linkonce linkonce_odr weak '
75 + 'weak_odr appending dllimport dllexport common '
76 + 'default hidden protected extern_weak external '
77 + 'thread_local zeroinitializer undef null to tail '
78 + 'target triple datalayout volatile nuw nsw nnan '
79 + 'ninf nsz arcp fast exact inbounds align '
80 + 'addrspace section alias module asm sideeffect '
81 + 'gc dbg linker_private_weak attributes blockaddress '
82 + 'initialexec localdynamic localexec prefix unnamed_addr '
83 + 'ccc fastcc coldcc x86_stdcallcc x86_fastcallcc '
84 + 'arm_apcscc arm_aapcscc arm_aapcs_vfpcc ptx_device '
85 + 'ptx_kernel intel_ocl_bicc msp430_intrcc spir_func '
86 + 'spir_kernel x86_64_sysvcc x86_64_win64cc x86_thiscallcc '
87 + 'cc c signext zeroext inreg sret nounwind '
88 + 'noreturn noalias nocapture byval nest readnone '
89 + 'readonly inlinehint noinline alwaysinline optsize ssp '
90 + 'sspreq noredzone noimplicitfloat naked builtin cold '
91 + 'nobuiltin noduplicate nonlazybind optnone returns_twice '
92 + 'sanitize_address sanitize_memory sanitize_thread sspstrong '
93 + 'uwtable returned type opaque eq ne slt sgt '
94 + 'sle sge ult ugt ule uge oeq one olt ogt '
95 + 'ole oge ord uno ueq une x acq_rel acquire '
96 + 'alignstack atomic catch cleanup filter inteldialect '
97 + 'max min monotonic nand personality release seq_cst '
98 + 'singlethread umax umin unordered xchg add fadd '
99 + 'sub fsub mul fmul udiv sdiv fdiv urem srem '
100 + 'frem shl lshr ashr and or xor icmp fcmp '
101 + 'phi call trunc zext sext fptrunc fpext uitofp '
102 + 'sitofp fptoui fptosi inttoptr ptrtoint bitcast '
103 + 'addrspacecast select va_arg ret br switch invoke '
104 + 'unwind unreachable indirectbr landingpad resume '
105 + 'malloc alloca free load store getelementptr '
106 + 'extractelement insertelement shufflevector getresult '
107 + 'extractvalue insertvalue atomicrmw cmpxchg fence '
108 + 'argmemonly',
109 type: 'void half bfloat float double fp128 x86_fp80 ppc_fp128 '
110 + 'x86_amx x86_mmx ptr label token metadata opaque'
111 },
112 contains: [
113 TYPE,
114 // this matches "empty comments"...
115 // ...because it's far more likely this is a statement terminator in
116 // another language than an actual comment
117 hljs.COMMENT(/;\s*$/, null, { relevance: 0 }),
118 hljs.COMMENT(/;/, /$/),
119 {
120 className: 'string',
121 begin: /"/,
122 end: /"/,
123 contains: [
124 {
125 className: 'char.escape',
126 match: /\\\d\d/
127 }
128 ]
129 },
130 FUNCTION,
131 PUNCTUATION,
132 OPERATOR,
133 VARIABLE,
134 LABEL,
135 NUMBER
136 ]
137 };
138 }
139
140 return llvm;
141
142 })();
143
144 hljs.registerLanguage('llvm', hljsGrammar);
145 })();