1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | function llvm(hljs) {
|
12 | const regex = hljs.regex;
|
13 | const IDENT_RE = /([-a-zA-Z$._][\w$.-]*)/;
|
14 | const TYPE = {
|
15 | className: 'type',
|
16 | begin: /\bi\d+(?=\s|\b)/
|
17 | };
|
18 | const OPERATOR = {
|
19 | className: 'operator',
|
20 | relevance: 0,
|
21 | begin: /=/
|
22 | };
|
23 | const PUNCTUATION = {
|
24 | className: 'punctuation',
|
25 | relevance: 0,
|
26 | begin: /,/
|
27 | };
|
28 | const NUMBER = {
|
29 | className: 'number',
|
30 | variants: [
|
31 | { begin: /0[xX][a-fA-F0-9]+/ },
|
32 | { begin: /-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?/ }
|
33 | ],
|
34 | relevance: 0
|
35 | };
|
36 | const LABEL = {
|
37 | className: 'symbol',
|
38 | variants: [
|
39 | { begin: /^\s*[a-z]+:/ },
|
40 | ],
|
41 | relevance: 0
|
42 | };
|
43 | const VARIABLE = {
|
44 | className: 'variable',
|
45 | variants: [
|
46 | { begin: regex.concat(/%/, IDENT_RE) },
|
47 | { begin: /%\d+/ },
|
48 | { begin: /#\d+/ },
|
49 | ]
|
50 | };
|
51 | const FUNCTION = {
|
52 | className: 'title',
|
53 | variants: [
|
54 | { begin: regex.concat(/@/, IDENT_RE) },
|
55 | { begin: /@\d+/ },
|
56 | { begin: regex.concat(/!/, IDENT_RE) },
|
57 | { begin: regex.concat(/!\d+/, IDENT_RE) },
|
58 |
|
59 |
|
60 | { begin: /!\d+/ }
|
61 | ]
|
62 | };
|
63 |
|
64 | return {
|
65 | name: 'LLVM IR',
|
66 |
|
67 | keywords:
|
68 | 'begin end true false declare define global ' +
|
69 | 'constant private linker_private internal ' +
|
70 | 'available_externally linkonce linkonce_odr weak ' +
|
71 | 'weak_odr appending dllimport dllexport common ' +
|
72 | 'default hidden protected extern_weak external ' +
|
73 | 'thread_local zeroinitializer undef null to tail ' +
|
74 | 'target triple datalayout volatile nuw nsw nnan ' +
|
75 | 'ninf nsz arcp fast exact inbounds align ' +
|
76 | 'addrspace section alias module asm sideeffect ' +
|
77 | 'gc dbg linker_private_weak attributes blockaddress ' +
|
78 | 'initialexec localdynamic localexec prefix unnamed_addr ' +
|
79 | 'ccc fastcc coldcc x86_stdcallcc x86_fastcallcc ' +
|
80 | 'arm_apcscc arm_aapcscc arm_aapcs_vfpcc ptx_device ' +
|
81 | 'ptx_kernel intel_ocl_bicc msp430_intrcc spir_func ' +
|
82 | 'spir_kernel x86_64_sysvcc x86_64_win64cc x86_thiscallcc ' +
|
83 | 'cc c signext zeroext inreg sret nounwind ' +
|
84 | 'noreturn noalias nocapture byval nest readnone ' +
|
85 | 'readonly inlinehint noinline alwaysinline optsize ssp ' +
|
86 | 'sspreq noredzone noimplicitfloat naked builtin cold ' +
|
87 | 'nobuiltin noduplicate nonlazybind optnone returns_twice ' +
|
88 | 'sanitize_address sanitize_memory sanitize_thread sspstrong ' +
|
89 | 'uwtable returned type opaque eq ne slt sgt ' +
|
90 | 'sle sge ult ugt ule uge oeq one olt ogt ' +
|
91 | 'ole oge ord uno ueq une x acq_rel acquire ' +
|
92 | 'alignstack atomic catch cleanup filter inteldialect ' +
|
93 | 'max min monotonic nand personality release seq_cst ' +
|
94 | 'singlethread umax umin unordered xchg add fadd ' +
|
95 | 'sub fsub mul fmul udiv sdiv fdiv urem srem ' +
|
96 | 'frem shl lshr ashr and or xor icmp fcmp ' +
|
97 | 'phi call trunc zext sext fptrunc fpext uitofp ' +
|
98 | 'sitofp fptoui fptosi inttoptr ptrtoint bitcast ' +
|
99 | 'addrspacecast select va_arg ret br switch invoke ' +
|
100 | 'unwind unreachable indirectbr landingpad resume ' +
|
101 | 'malloc alloca free load store getelementptr ' +
|
102 | 'extractelement insertelement shufflevector getresult ' +
|
103 | 'extractvalue insertvalue atomicrmw cmpxchg fence ' +
|
104 | 'argmemonly double',
|
105 | contains: [
|
106 | TYPE,
|
107 |
|
108 |
|
109 |
|
110 | hljs.COMMENT(/;\s*$/, null, { relevance: 0 }),
|
111 | hljs.COMMENT(/;/, /$/),
|
112 | hljs.QUOTE_STRING_MODE,
|
113 | {
|
114 | className: 'string',
|
115 | variants: [
|
116 |
|
117 | { begin: /"/, end: /[^\\]"/ },
|
118 | ]
|
119 | },
|
120 | FUNCTION,
|
121 | PUNCTUATION,
|
122 | OPERATOR,
|
123 | VARIABLE,
|
124 | LABEL,
|
125 | NUMBER
|
126 | ]
|
127 | };
|
128 | }
|
129 |
|
130 | export { llvm as default };
|