source: node_modules/highlight.js/lib/languages/llvm.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

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