[gtksourceview] Adding syntax highlighting for LLVM IR



commit b10d067620880e010d7111f35c6568422642c2ad
Author: Stefan Sundin <recover89 gmail com>
Date:   Wed Mar 21 20:47:31 2012 +0100

    Adding syntax highlighting for LLVM IR
    
    https://bugzilla.gnome.org/show_bug.cgi?id=672309

 data/language-specs/Makefile.am |    1 +
 data/language-specs/llvm.lang   |  315 +++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in                  |    1 +
 tests/testfiles.sh              |   21 +++
 4 files changed, 338 insertions(+), 0 deletions(-)
---
diff --git a/data/language-specs/Makefile.am b/data/language-specs/Makefile.am
index e654ab2..2bb090c 100644
--- a/data/language-specs/Makefile.am
+++ b/data/language-specs/Makefile.am
@@ -58,6 +58,7 @@ LANGUAGES =                   \
        latex.lang              \
        lex.lang                \
        libtool.lang            \
+       llvm.lang               \
        lua.lang                \
        m4.lang                 \
        makefile.lang           \
diff --git a/data/language-specs/llvm.lang b/data/language-specs/llvm.lang
new file mode 100644
index 0000000..21caadb
--- /dev/null
+++ b/data/language-specs/llvm.lang
@@ -0,0 +1,315 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ This file is part of GtkSourceView
+
+ Copyright (C) 2012  Stefan Sundin (recover89 gmail com)
+
+ GtkSourceView is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ GtkSourceView is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+-->
+<language id="llvm" _name="LLVM IR" version="2.0" _section="Source">
+  <metadata>
+    <property name="globs">*.ll</property>
+    <property name="line-comment-start">;</property>
+  </metadata>
+
+  <styles>
+    <style id="comment"     _name="Comment"       map-to="def:comment"/>
+    <style id="string"      _name="String"        map-to="def:string"/>
+    <style id="keyword"     _name="Keyword"       map-to="def:keyword"/>
+    <style id="function"    _name="Function"      map-to="def:function"/>
+    <style id="constant"    _name="Constants"     map-to="def:constant"/>
+    <style id="variable"    _name="Variable"      map-to="def:variable"/>
+    <style id="identifier"  _name="Identifier"    map-to="def:identifier"/>
+    <style id="type"        _name="Data Type"     map-to="def:type"/>
+    <style id="boolean"     _name="Boolean value" map-to="def:boolean"/>
+    <style id="number"      _name="Number"        map-to="def:decimal"/>
+  </styles>
+
+  <definitions>
+    <context id="keywords" style-ref="keyword">
+      <!-- Linkage Types -->
+      <keyword>private</keyword>
+      <keyword>linker_private</keyword>
+      <keyword>linker_private_weak</keyword>
+      <keyword>linker_private_weak_def_auto</keyword>
+      <keyword>internal</keyword>
+      <keyword>available_externally</keyword>
+      <keyword>linkonce</keyword>
+      <keyword>common</keyword>
+      <keyword>weak</keyword>
+      <keyword>appending</keyword>
+      <keyword>extern_weak</keyword>
+      <keyword>linkonce_odr</keyword>
+      <keyword>weak_odr</keyword>
+      <keyword>external</keyword>
+      <keyword>dllimport</keyword>
+      <keyword>dllexport</keyword>
+      <!-- Calling Conventions -->
+      <keyword>ccc</keyword>
+      <keyword>fastcc</keyword>
+      <keyword>coldcc</keyword>
+      <!-- Visibility Styles -->
+      <keyword>default</keyword>
+      <keyword>hidden</keyword>
+      <keyword>protected</keyword>
+      <!-- Named Types -->
+      <keyword>type</keyword>
+      <!-- Global Variables -->
+      <keyword>thread_local</keyword>
+      <keyword>constant</keyword>
+      <keyword>unnamed_addr</keyword>
+      <keyword>addrspace</keyword>
+      <!-- Functions -->
+      <keyword>define</keyword>
+      <!-- Aliases -->
+      <keyword>alias</keyword>
+      <!-- Parameter Attributes -->
+      <keyword>declare</keyword>
+      <keyword>zeroext</keyword>
+      <keyword>signext</keyword>
+      <keyword>inreg</keyword>
+      <keyword>byval</keyword>
+      <keyword>sret</keyword>
+      <keyword>noalias</keyword>
+      <keyword>nocapture</keyword>
+      <keyword>nest</keyword>
+      <!-- Garbage Collector Names -->
+      <keyword>gc</keyword>
+      <!-- Function Attributes -->
+      <keyword>address_safety</keyword>
+      <keyword>alignstack</keyword>
+      <keyword>alwaysinline</keyword>
+      <keyword>nonlazybind</keyword>
+      <keyword>inlinehint</keyword>
+      <keyword>naked</keyword>
+      <keyword>noimplicitfloat</keyword>
+      <keyword>noinline</keyword>
+      <keyword>noredzone</keyword>
+      <keyword>noreturn</keyword>
+      <keyword>nounwind</keyword>
+      <keyword>optsize</keyword>
+      <keyword>readnone</keyword>
+      <keyword>readonly</keyword>
+      <keyword>returns_twice</keyword>
+      <keyword>ssp</keyword>
+      <keyword>sspreq</keyword>
+      <keyword>uwtable</keyword>
+      <keyword>align</keyword>
+      <!-- Module-Level Inline Assembly -->
+      <keyword>module</keyword>
+      <keyword>asm</keyword>
+      <!-- Data Layout -->
+      <keyword>target</keyword>
+      <keyword>datalayout</keyword>
+      <keyword>triple</keyword>
+      <!-- Atomic Memory Ordering Constraints -->
+      <keyword>unordered</keyword>
+      <keyword>monotonic</keyword>
+      <keyword>acquire</keyword>
+      <keyword>release</keyword>
+      <keyword>acq_rel</keyword>
+      <keyword>seq_cst</keyword>
+      <keyword>singlethread</keyword>
+      <!-- add / sub / mul / shl -->
+      <keyword>nuw</keyword>
+      <keyword>nsw</keyword>
+      <!-- udiv / sdiv / lshr / ashr -->
+      <keyword>exact</keyword>
+      <!-- load / store / cmpxchg / atomicrmw -->
+      <keyword>volatile</keyword>
+      <keyword>atomic</keyword>
+      <!-- trunc / zext / sext / fptrunc / fpext / fptoui / fptosi / uitofp / sitofp / ptrtoint / inttoptr / 
bitcast -->
+      <keyword>to</keyword>
+      <!-- landingpad -->
+      <keyword>personality</keyword>
+      <keyword>cleanup</keyword>
+      <keyword>catch</keyword>
+      <keyword>filter</keyword>
+      <!-- icmp -->
+      <keyword>eq</keyword>
+      <keyword>ne</keyword>
+      <keyword>ugt</keyword>
+      <keyword>uge</keyword>
+      <keyword>ult</keyword>
+      <keyword>ule</keyword>
+      <keyword>sgt</keyword>
+      <keyword>slt</keyword>
+      <keyword>sle</keyword>
+      <!-- fcmp -->
+      <keyword>oeq</keyword>
+      <keyword>ogt</keyword>
+      <keyword>oge</keyword>
+      <keyword>olt</keyword>
+      <keyword>ole</keyword>
+      <keyword>one</keyword>
+      <keyword>ord</keyword>
+      <keyword>ueq</keyword>
+      <keyword>ugt</keyword>
+      <keyword>uge</keyword>
+      <keyword>ult</keyword>
+      <keyword>ule</keyword>
+      <keyword>une</keyword>
+      <keyword>uno</keyword>
+      <!-- getelementptr -->
+      <keyword>inbounds</keyword>
+    </context>
+
+    <context id="functions" style-ref="function">
+      <!-- Terminator Instructions -->
+      <keyword>ret</keyword>
+      <keyword>br</keyword>
+      <keyword>switch</keyword>
+      <keyword>indirectbr</keyword>
+      <keyword>invoke</keyword>
+      <keyword>resume</keyword>
+      <keyword>unreachable</keyword>
+      <!-- Binary Operations -->
+      <keyword>add</keyword>
+      <keyword>fadd</keyword>
+      <keyword>sub</keyword>
+      <keyword>fsub</keyword>
+      <keyword>mul</keyword>
+      <keyword>fmul</keyword>
+      <keyword>udiv</keyword>
+      <keyword>sdiv</keyword>
+      <keyword>fdiv</keyword>
+      <keyword>urem</keyword>
+      <keyword>srem</keyword>
+      <keyword>frem</keyword>
+      <!-- Bitwise Binary Operations -->
+      <keyword>shl</keyword>
+      <keyword>lshr</keyword>
+      <keyword>ashr</keyword>
+      <keyword>and</keyword>
+      <keyword>or</keyword>
+      <keyword>xor</keyword>
+      <!-- Vector Operations -->
+      <keyword>extractelement</keyword>
+      <keyword>insertelement</keyword>
+      <keyword>shufflevector</keyword>
+      <!-- Aggregate Operations -->
+      <keyword>extractvalue</keyword>
+      <keyword>insertvalue</keyword>
+      <!-- Memory Access and Addressing Operations -->
+      <keyword>alloca</keyword>
+      <keyword>load</keyword>
+      <keyword>store</keyword>
+      <keyword>fence</keyword>
+      <keyword>cmpxchg</keyword>
+      <keyword>atomicrmw</keyword>
+      <keyword>getelementptr</keyword>
+      <!-- Conversion Operations -->
+      <keyword>trunc</keyword>
+      <keyword>zext</keyword>
+      <keyword>sext</keyword>
+      <keyword>fptrunc</keyword>
+      <keyword>fpext</keyword>
+      <keyword>fptoui</keyword>
+      <keyword>fptosi</keyword>
+      <keyword>uitofp</keyword>
+      <keyword>sitofp</keyword>
+      <keyword>ptrtoint</keyword>
+      <keyword>inttoptr</keyword>
+      <keyword>bitcast</keyword>
+      <!-- Other Operations -->
+      <keyword>icmp</keyword>
+      <keyword>fcmp</keyword>
+      <keyword>phi</keyword>
+      <keyword>select</keyword>
+      <keyword>call</keyword>
+      <keyword>va_arg</keyword>
+      <keyword>landingpad</keyword>
+    </context>
+
+    <context id="constant" style-ref="constant">
+      <keyword>null</keyword>
+      <keyword>zeroinitializer</keyword>
+      <keyword>undef</keyword>
+    </context>
+
+    <context id="boolean" style-ref="boolean">
+      <keyword>true</keyword>
+      <keyword>false</keyword>
+    </context>
+
+    <context id="types" style-ref="type">
+      <!-- Floating Point Types -->
+      <keyword>half</keyword>
+      <keyword>float</keyword>
+      <keyword>double</keyword>
+      <keyword>x86_fp80</keyword>
+      <keyword>fp128</keyword>
+      <keyword>ppc_fp128</keyword>
+      <!-- X86mmx Type -->
+      <keyword>x86mmx</keyword>
+      <!-- Void Type -->
+      <keyword>void</keyword>
+      <!-- Label Type -->
+      <keyword>label</keyword>
+      <!-- Metadata Type -->
+      <keyword>metadata</keyword>
+      <!-- Opaque Structure Types -->
+      <keyword>opaque</keyword>
+    </context>
+
+    <context id="integertype" style-ref="type">
+     <match>i[0-9]+</match>
+    </context>
+
+    <context id="variable" style-ref="variable">
+      <match>[%!][a-zA-Z$\._0-9]*</match>
+    </context>
+
+    <context id="identifier" style-ref="identifier">
+      <match>@[a-zA-Z$\._][a-zA-Z$\._0-9]*</match>
+    </context>
+
+    <context id="numeric" style-ref="number">
+      <match extended="true">
+        (\b([0-9]+|0x[0-9a-fA-F]+)\b|
+        \b([0-9]*\.[0-9]+[Ee][+-]?[0-9]+|
+        [0-9]+))
+      </match>
+    </context>
+
+    <context id="string" style-ref="string" end-at-line-end="true">
+      <start>"</start>
+      <end>"</end>
+    </context>
+
+    <context id="line-comment" style-ref="comment" end-at-line-end="true">
+      <start>;</start>
+    </context>
+
+    <context id="llvm">
+      <include>
+        <context ref="keywords"/>
+        <context ref="functions"/>
+        <context ref="constant"/>
+        <context ref="boolean"/>
+        <context ref="types"/>
+        <context ref="integertype"/>
+        <context ref="variable"/>
+        <context ref="identifier"/>
+        <context ref="numeric"/>
+        <context ref="string"/>
+        <context ref="line-comment"/>
+      </include>
+    </context>
+
+  </definitions>
+</language>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index fe584e0..741a970 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -56,6 +56,7 @@ data/language-specs/julia.lang
 data/language-specs/latex.lang
 data/language-specs/lex.lang
 data/language-specs/libtool.lang
+data/language-specs/llvm.lang
 data/language-specs/lua.lang
 data/language-specs/m4.lang
 data/language-specs/makefile.lang
diff --git a/tests/testfiles.sh b/tests/testfiles.sh
index eb323a9..1f7c30a 100755
--- a/tests/testfiles.sh
+++ b/tests/testfiles.sh
@@ -877,6 +877,27 @@ libdir='/usr/local/gtk/lib/python2.4/site-packages'
 relink_command="(cd /home/muntyan/projects/gtk/build/moo/moo; /bin/sh ../libtool  --tag=CC --mode=relink gcc 
-g -L/usr/local/gtk/lib -o moo.la -rpath /usr/local/gtk/lib/python2.4/site-packages -no-undefined -module 
-avoid-version -export-symbols-regex initmoo moopython/libmoomod.la libmoo.la -lutil -L/usr/local/gtk/lib 
-lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 
-lgmodule-2.0 -ldl -lglib-2.0 -pthread -L/usr/local/gtk/lib -lgthread-2.0 -lglib-2.0 -lpcre -lfam -lxml2 
-L/usr/lib/python2.4 -lpython2.4 @inst_prefix_dir@)"
 EOFEOF
 
+cat > $dir/file.ll <<EOFEOF
+; LLVM intermediate representation
+; Run with: llc file.ll && gcc file.s && ./a.out
+
+ str = internal constant [4 x i8] c"%d\0A\00"
+
+declare i32 @printf(i8*, ...)
+
+define i32 @main() {
+  ; Print a secret number on the screen
+  %1 = select i1 true, float 0x402ABD70A0000000, float 0xC0FFEE0000000000
+  %2 = fpext float %1 to double
+  %3 = fmul double %2, 1.000000e+02
+  %4 = fptoui double %3 to i32
+  %5 = add i32 %4, 1
+  ; Call printf
+  call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x i8]* @str, i32 0, i32 0), i32 %5)
+  ret i32 0
+}
+EOFEOF
+
 cat > $dir/file.pc <<EOFEOF
 # A comment
 prefix=/usr


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]