Skip to content

Commit

Permalink
enh(llvm) match additional types (#3875)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangtz0607 authored Mar 21, 2024
1 parent e75b7e4 commit acb6eb6
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 50 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Core Grammars:
- fix(swift) `warn_unqualified_access` is an attribute [Bradley Mackey][]
- enh(swift) macro attributes are highlighted as keywords [Bradley Mackey][]
- enh(stan) updated for version 2.33 (#3859) [Brian Ward][]
- enh(llvm) match additional types [wtz][]
- fix(css) added '_' css variable detection [Md Saad Akhtar][]
- enh(groovy) add `record` and `var` as keywords [Guillaume Laforge][]

Expand All @@ -156,6 +157,7 @@ Developer Tool:
[Nicholas Thompson]: https://github.com/NAThompson
[Yasith Deelaka]: https://github.com/YasithD
[Brian Ward]: https://github.com/WardBrian
[wtz]: https://github.com/wangtz0607
[Md Saad Akhtar]: https://github.com/akhtarmdsaad
[Guillaume Laforge]: https://github.com/glaforge

Expand Down
79 changes: 41 additions & 38 deletions src/languages/llvm.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,44 +63,47 @@ export default function(hljs) {
return {
name: 'LLVM IR',
// TODO: split into different categories of keywords
keywords:
'begin end true false declare define global '
+ 'constant private linker_private internal '
+ 'available_externally linkonce linkonce_odr weak '
+ 'weak_odr appending dllimport dllexport common '
+ 'default hidden protected extern_weak external '
+ 'thread_local zeroinitializer undef null to tail '
+ 'target triple datalayout volatile nuw nsw nnan '
+ 'ninf nsz arcp fast exact inbounds align '
+ 'addrspace section alias module asm sideeffect '
+ 'gc dbg linker_private_weak attributes blockaddress '
+ 'initialexec localdynamic localexec prefix unnamed_addr '
+ 'ccc fastcc coldcc x86_stdcallcc x86_fastcallcc '
+ 'arm_apcscc arm_aapcscc arm_aapcs_vfpcc ptx_device '
+ 'ptx_kernel intel_ocl_bicc msp430_intrcc spir_func '
+ 'spir_kernel x86_64_sysvcc x86_64_win64cc x86_thiscallcc '
+ 'cc c signext zeroext inreg sret nounwind '
+ 'noreturn noalias nocapture byval nest readnone '
+ 'readonly inlinehint noinline alwaysinline optsize ssp '
+ 'sspreq noredzone noimplicitfloat naked builtin cold '
+ 'nobuiltin noduplicate nonlazybind optnone returns_twice '
+ 'sanitize_address sanitize_memory sanitize_thread sspstrong '
+ 'uwtable returned type opaque eq ne slt sgt '
+ 'sle sge ult ugt ule uge oeq one olt ogt '
+ 'ole oge ord uno ueq une x acq_rel acquire '
+ 'alignstack atomic catch cleanup filter inteldialect '
+ 'max min monotonic nand personality release seq_cst '
+ 'singlethread umax umin unordered xchg add fadd '
+ 'sub fsub mul fmul udiv sdiv fdiv urem srem '
+ 'frem shl lshr ashr and or xor icmp fcmp '
+ 'phi call trunc zext sext fptrunc fpext uitofp '
+ 'sitofp fptoui fptosi inttoptr ptrtoint bitcast '
+ 'addrspacecast select va_arg ret br switch invoke '
+ 'unwind unreachable indirectbr landingpad resume '
+ 'malloc alloca free load store getelementptr '
+ 'extractelement insertelement shufflevector getresult '
+ 'extractvalue insertvalue atomicrmw cmpxchg fence '
+ 'argmemonly double',
keywords: {
keyword: 'begin end true false declare define global '
+ 'constant private linker_private internal '
+ 'available_externally linkonce linkonce_odr weak '
+ 'weak_odr appending dllimport dllexport common '
+ 'default hidden protected extern_weak external '
+ 'thread_local zeroinitializer undef null to tail '
+ 'target triple datalayout volatile nuw nsw nnan '
+ 'ninf nsz arcp fast exact inbounds align '
+ 'addrspace section alias module asm sideeffect '
+ 'gc dbg linker_private_weak attributes blockaddress '
+ 'initialexec localdynamic localexec prefix unnamed_addr '
+ 'ccc fastcc coldcc x86_stdcallcc x86_fastcallcc '
+ 'arm_apcscc arm_aapcscc arm_aapcs_vfpcc ptx_device '
+ 'ptx_kernel intel_ocl_bicc msp430_intrcc spir_func '
+ 'spir_kernel x86_64_sysvcc x86_64_win64cc x86_thiscallcc '
+ 'cc c signext zeroext inreg sret nounwind '
+ 'noreturn noalias nocapture byval nest readnone '
+ 'readonly inlinehint noinline alwaysinline optsize ssp '
+ 'sspreq noredzone noimplicitfloat naked builtin cold '
+ 'nobuiltin noduplicate nonlazybind optnone returns_twice '
+ 'sanitize_address sanitize_memory sanitize_thread sspstrong '
+ 'uwtable returned type opaque eq ne slt sgt '
+ 'sle sge ult ugt ule uge oeq one olt ogt '
+ 'ole oge ord uno ueq une x acq_rel acquire '
+ 'alignstack atomic catch cleanup filter inteldialect '
+ 'max min monotonic nand personality release seq_cst '
+ 'singlethread umax umin unordered xchg add fadd '
+ 'sub fsub mul fmul udiv sdiv fdiv urem srem '
+ 'frem shl lshr ashr and or xor icmp fcmp '
+ 'phi call trunc zext sext fptrunc fpext uitofp '
+ 'sitofp fptoui fptosi inttoptr ptrtoint bitcast '
+ 'addrspacecast select va_arg ret br switch invoke '
+ 'unwind unreachable indirectbr landingpad resume '
+ 'malloc alloca free load store getelementptr '
+ 'extractelement insertelement shufflevector getresult '
+ 'extractvalue insertvalue atomicrmw cmpxchg fence '
+ 'argmemonly',
type: 'void half bfloat float double fp128 x86_fp80 ppc_fp128 '
+ 'x86_amx x86_mmx ptr label token metadata opaque'
},
contains: [
TYPE,
// this matches "empty comments"...
Expand Down
8 changes: 4 additions & 4 deletions test/markup/llvm/default.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<span class="hljs-title">@.str</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">private</span> <span class="hljs-keyword">unnamed_addr</span> <span class="hljs-keyword">constant</span> [<span class="hljs-number">6</span> <span class="hljs-keyword">x</span> <span class="hljs-type">i8</span>] <span class="hljs-keyword">c</span><span class="hljs-string">&quot;foo()<span class="hljs-char escape_">\00</span>&quot;</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">1</span>
<span class="hljs-title">@e_long</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">common</span> <span class="hljs-keyword">global</span> <span class="hljs-type">i64</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">8</span>
<span class="hljs-title">@g_double</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">common</span> <span class="hljs-keyword">global</span> <span class="hljs-keyword">double</span> <span class="hljs-number">0.000000e+00</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">8</span>
<span class="hljs-title">@g_double</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">common</span> <span class="hljs-keyword">global</span> <span class="hljs-type">double</span> <span class="hljs-number">0.000000e+00</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">8</span>
<span class="hljs-title">@.str.1</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">private</span> <span class="hljs-keyword">unnamed_addr</span> <span class="hljs-keyword">constant</span> [<span class="hljs-number">7</span> <span class="hljs-keyword">x</span> <span class="hljs-type">i8</span>] <span class="hljs-keyword">c</span><span class="hljs-string">&quot;oooooh<span class="hljs-char escape_">\00</span>&quot;</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">1</span>
<span class="hljs-title">@func_ptr</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">common</span> <span class="hljs-keyword">global</span> <span class="hljs-type">i32</span> (...)* <span class="hljs-keyword">null</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">8</span>
<span class="hljs-title">@stderr</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">external</span> <span class="hljs-keyword">global</span> <span class="hljs-variable">%struct._IO_FILE</span>*<span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">8</span>
Expand All @@ -32,18 +32,18 @@
<span class="hljs-keyword">store</span> <span class="hljs-type">i8</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span> <span class="hljs-type">i8</span>* <span class="hljs-variable">%8</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">2</span>
<span class="hljs-keyword">store</span> <span class="hljs-type">i8</span> <span class="hljs-number">49</span><span class="hljs-punctuation">,</span> <span class="hljs-type">i8</span>* <span class="hljs-variable">%b_char</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">1</span>
<span class="hljs-variable">%9</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">getelementptr</span> <span class="hljs-keyword">inbounds</span> <span class="hljs-variable">%struct.what</span><span class="hljs-punctuation">,</span> <span class="hljs-variable">%struct.what</span>* <span class="hljs-variable">%X</span><span class="hljs-punctuation">,</span> <span class="hljs-type">i32</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span> <span class="hljs-type">i32</span> <span class="hljs-number">1</span>
<span class="hljs-keyword">store</span> <span class="hljs-keyword">double</span> <span class="hljs-number">1.000000e+01</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">double</span>* <span class="hljs-title">@g_double</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">8</span>
<span class="hljs-keyword">store</span> <span class="hljs-type">double</span> <span class="hljs-number">1.000000e+01</span><span class="hljs-punctuation">,</span> <span class="hljs-type">double</span>* <span class="hljs-title">@g_double</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">8</span>
<span class="hljs-keyword">store</span> <span class="hljs-type">i8</span>* <span class="hljs-keyword">getelementptr</span> <span class="hljs-keyword">inbounds</span> ([<span class="hljs-number">7</span> <span class="hljs-keyword">x</span> <span class="hljs-type">i8</span>]<span class="hljs-punctuation">,</span> [<span class="hljs-number">7</span> <span class="hljs-keyword">x</span> <span class="hljs-type">i8</span>]* <span class="hljs-title">@.str.1</span><span class="hljs-punctuation">,</span> <span class="hljs-type">i32</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span> <span class="hljs-type">i32</span> <span class="hljs-number">0</span>)<span class="hljs-punctuation">,</span> <span class="hljs-type">i8</span>** <span class="hljs-variable">%cp_char_ptr</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">8</span>
<span class="hljs-keyword">store</span> <span class="hljs-type">i32</span> (...)* <span class="hljs-keyword">bitcast</span> (<span class="hljs-type">i32</span> ()* <span class="hljs-title">@foo</span> <span class="hljs-keyword">to</span> <span class="hljs-type">i32</span> (...)*)<span class="hljs-punctuation">,</span> <span class="hljs-type">i32</span> (...)** <span class="hljs-title">@func_ptr</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">8</span>
<span class="hljs-variable">%10</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">call</span> <span class="hljs-type">i32</span> <span class="hljs-title">@puts</span>(<span class="hljs-type">i8</span>* <span class="hljs-keyword">getelementptr</span> <span class="hljs-keyword">inbounds</span> ([<span class="hljs-number">8</span> <span class="hljs-keyword">x</span> <span class="hljs-type">i8</span>]<span class="hljs-punctuation">,</span> [<span class="hljs-number">8</span> <span class="hljs-keyword">x</span> <span class="hljs-type">i8</span>]* <span class="hljs-title">@.str.2</span><span class="hljs-punctuation">,</span> <span class="hljs-type">i32</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span> <span class="hljs-type">i32</span> <span class="hljs-number">0</span>))
<span class="hljs-keyword">store</span> <span class="hljs-type">i32</span> <span class="hljs-number">10</span><span class="hljs-punctuation">,</span> <span class="hljs-type">i32</span>* <span class="hljs-variable">%1</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">4</span>
<span class="hljs-keyword">br</span> label <span class="hljs-variable">%66</span>
<span class="hljs-keyword">br</span> <span class="hljs-type">label</span> <span class="hljs-variable">%66</span>

<span class="hljs-comment">; &lt;label&gt;:63 ; preds = %11</span>
<span class="hljs-variable">%64</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">load</span> <span class="hljs-variable">%struct._IO_FILE</span>*<span class="hljs-punctuation">,</span> <span class="hljs-variable">%struct._IO_FILE</span>** <span class="hljs-title">@stderr</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">8</span>
<span class="hljs-variable">%65</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">call</span> <span class="hljs-type">i32</span> <span class="hljs-title">@fputs</span>(<span class="hljs-type">i8</span>* <span class="hljs-keyword">getelementptr</span> <span class="hljs-keyword">inbounds</span> ([<span class="hljs-number">11</span> <span class="hljs-keyword">x</span> <span class="hljs-type">i8</span>]<span class="hljs-punctuation">,</span> [<span class="hljs-number">11</span> <span class="hljs-keyword">x</span> <span class="hljs-type">i8</span>]* <span class="hljs-title">@.str.9</span><span class="hljs-punctuation">,</span> <span class="hljs-type">i32</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span> <span class="hljs-type">i32</span> <span class="hljs-number">0</span>)<span class="hljs-punctuation">,</span> <span class="hljs-variable">%struct._IO_FILE</span>* <span class="hljs-variable">%64</span>)
<span class="hljs-keyword">store</span> <span class="hljs-type">i32</span> <span class="hljs-number">-1</span><span class="hljs-punctuation">,</span> <span class="hljs-type">i32</span>* <span class="hljs-variable">%1</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">4</span>
<span class="hljs-keyword">br</span> label <span class="hljs-variable">%66</span>
<span class="hljs-keyword">br</span> <span class="hljs-type">label</span> <span class="hljs-variable">%66</span>

<span class="hljs-comment">; &lt;label&gt;:66 ; preds = %63, %46, %7</span>
<span class="hljs-variable">%67</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">load</span> <span class="hljs-type">i32</span><span class="hljs-punctuation">,</span> <span class="hljs-type">i32</span>* <span class="hljs-variable">%1</span><span class="hljs-punctuation">,</span> <span class="hljs-keyword">align</span> <span class="hljs-number">4</span>
Expand Down
8 changes: 4 additions & 4 deletions test/markup/llvm/numbers.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<span class="hljs-keyword">ret</span> <span class="hljs-type">i32</span> <span class="hljs-number">s0x12a</span>
}

<span class="hljs-keyword">define</span> float <span class="hljs-title">@signed_float</span>() {
<span class="hljs-keyword">ret</span> float <span class="hljs-number">+1.0</span>
<span class="hljs-keyword">define</span> <span class="hljs-type">float</span> <span class="hljs-title">@signed_float</span>() {
<span class="hljs-keyword">ret</span> <span class="hljs-type">float</span> <span class="hljs-number">+1.0</span>
}

<span class="hljs-keyword">define</span> float <span class="hljs-title">@float_format</span>() {
<span class="hljs-keyword">ret</span> float <span class="hljs-number">0xK12a</span>
<span class="hljs-keyword">define</span> <span class="hljs-type">float</span> <span class="hljs-title">@float_format</span>() {
<span class="hljs-keyword">ret</span> <span class="hljs-type">float</span> <span class="hljs-number">0xK12a</span>
}
8 changes: 4 additions & 4 deletions test/markup/llvm/string.expect.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<span class="hljs-comment">; Backslashes do not escape quotes, this is a legal string</span>
<span class="hljs-keyword">define</span> void @<span class="hljs-string">&quot;C:\&quot;</span>() {
<span class="hljs-keyword">ret</span> void
<span class="hljs-keyword">define</span> <span class="hljs-type">void</span> @<span class="hljs-string">&quot;C:\&quot;</span>() {
<span class="hljs-keyword">ret</span> <span class="hljs-type">void</span>
}

<span class="hljs-keyword">define</span> void @<span class="hljs-string">&quot;escape_code_<span class="hljs-char escape_">\01</span>23<span class="hljs-char escape_">\04</span>end&quot;</span>() {
<span class="hljs-keyword">ret</span> void
<span class="hljs-keyword">define</span> <span class="hljs-type">void</span> @<span class="hljs-string">&quot;escape_code_<span class="hljs-char escape_">\01</span>23<span class="hljs-char escape_">\04</span>end&quot;</span>() {
<span class="hljs-keyword">ret</span> <span class="hljs-type">void</span>
}

0 comments on commit acb6eb6

Please sign in to comment.