From 275e5ff9fc90f6fada3c27ea538fbd112497abc1 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Mon, 10 Sep 2018 18:06:19 +0200 Subject: [PATCH 1/3] Add a failing visual example for LLVM --- spec/visual/samples/llvm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/visual/samples/llvm b/spec/visual/samples/llvm index 004e97212b..d6467cae24 100644 --- a/spec/visual/samples/llvm +++ b/spec/visual/samples/llvm @@ -71,3 +71,14 @@ second_end: ; control-equivalent to %end, so this is ; well-defined (ignoring earlier undefined ; behavior in this example). + +; copied from https://llvm.org/docs/LangRef.html#attribute-groups + +; Target-independent attributes: +attributes #0 = { alwaysinline alignstack=4 } + +; Target-dependent attributes: +attributes #1 = { "no-sse" } + +; Function @f has attributes: alwaysinline, alignstack=4, and "no-sse". +define void @f() #0 #1 { ... } From a6f0221f67526ec9826bd584f7ec80b4cd67278f Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Mon, 10 Sep 2018 18:07:29 +0200 Subject: [PATCH 2/3] Add missing function attributes as keywords Specifically move the `alignstack` keyword, before the `align` one because otherwise, the former get partially highlighted as `align` and `c`. Also add the `attributes` keyword that defines attribute groups. --- lib/rouge/lexers/llvm.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/rouge/lexers/llvm.rb b/lib/rouge/lexers/llvm.rb index 521933f6d2..d5bd46d3cf 100644 --- a/lib/rouge/lexers/llvm.rb +++ b/lib/rouge/lexers/llvm.rb @@ -41,7 +41,7 @@ class LLVM < RegexLexer end builtin_keywords = %w( - begin end true false declare define global constant personality private + begin end true false declare define global constant alignstack private landingpad linker_private internal available_externally linkonce_odr linkonce weak weak_odr appending dllimport dllexport common default hidden protected extern_weak external thread_local zeroinitializer @@ -53,7 +53,13 @@ class LLVM < RegexLexer nest readnone readonly inlinehint noinline alwaysinline optsize ssp sspreq noredzone noimplicitfloat naked type opaque eq ne slt sgt sle sge ult ugt ule uge oeq one olt ogt ole oge ord uno unnamed_addr ueq - une uwtable x + une uwtable x personality allocsize builtin cold convergent + inaccessiblememonly inaccessiblemem_or_argmemonly jumptable minsize + no-jump-tables nobuiltin noduplicate nonlazybind noredzone norecurse + optforfuzzing optnone writeonly argmemonly returns_twice safestack + sanitize_address sanitize_memory sanitize_thread sanitize_hwaddress + speculative_load_hardening speculatable sspstrong strictfp nocf_check + shadowcallstack attributes ) builtin_instructions = %w( From 8572b40e1dd10a55065469561d74cefd7d65684b Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Mon, 10 Sep 2018 18:14:54 +0200 Subject: [PATCH 3/3] Properly highlight attribute groups' ID Highlight attribute groups' ID as global variables as Pygments does. --- lib/rouge/lexers/llvm.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/rouge/lexers/llvm.rb b/lib/rouge/lexers/llvm.rb index d5bd46d3cf..b598b740f9 100644 --- a/lib/rouge/lexers/llvm.rb +++ b/lib/rouge/lexers/llvm.rb @@ -20,6 +20,7 @@ class LLVM < RegexLexer rule /#{identifier}\s*:/, Name::Label rule /@(#{identifier}|\d+)/, Name::Variable::Global + rule /#\d+/, Name::Variable::Global rule /(%|!)#{identifier}/, Name::Variable rule /(%|!)\d+/, Name::Variable