-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds support for LLVM's assembly language. https://llvm.org/docs/LangRef.html
- Loading branch information
1 parent
e635260
commit 43efde2
Showing
13 changed files
with
479 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(function(Prism) { | ||
Prism.languages.llvm = { | ||
'comment': /;.*/, | ||
'string': { | ||
pattern: /"[^"]*"/, | ||
greedy: true, | ||
}, | ||
'boolean': /\b(?:true|false)\b/, | ||
'variable': /[%@!#](?:(?!\d)(?:[-$.\w]|\\[a-f\d]{2})+|\d+)/i, | ||
'label': /(?!\d)(?:[-$.\w]|\\[a-f\d]{2})+:/i, | ||
'type': { | ||
pattern: /\b(?:double|float|fp128|half|i[1-9]\d*|label|metadata|ppc_fp128|token|void|x86_fp80|x86_mmx)\b/, | ||
alias: 'class-name', | ||
}, | ||
'keyword': /\b[a-z_][a-z_0-9]*\b/, | ||
'number': /[+-]?\b\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\b|\b0x[\dA-Fa-f]+\b|\b0xK[\dA-Fa-f]{20}\b|\b0x[ML][\dA-Fa-f]{32}\b|\b0xH[\dA-Fa-f]{4}\b/, | ||
'punctuation': /[{}[\];(),.!*=<>]/, | ||
}; | ||
}(Prism)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<h2>Full Example</h2> | ||
<pre><code> | ||
; Declare the string constant as a global constant. | ||
@.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00" | ||
|
||
; External declaration of the puts function | ||
declare i32 @puts(i8* nocapture) nounwind | ||
|
||
; Definition of main function | ||
define i32 @main() { ; i32()* | ||
entry: | ||
; Convert [13 x i8]* to i8*... | ||
%cast210 = getelementptr [13 x i8], [13 x i8]* @.str, i64 0, i64 0 | ||
|
||
; Call puts function to write out the string to stdout. | ||
call i32 @puts(i8* %cast210) | ||
ret i32 0 | ||
} | ||
|
||
; Named metadata | ||
!0 = !{i32 42, null, !"string"} | ||
!foo = !{!0} | ||
</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
; 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 { ... } | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "; Target-independent attributes:"], | ||
["keyword", "attributes"], | ||
["variable", "#0"], | ||
["punctuation", "="], | ||
["punctuation", "{"], | ||
["keyword", "alwaysinline"], | ||
["keyword", "alignstack"], | ||
["punctuation", "="], | ||
["number", "4"], | ||
["punctuation", "}"], | ||
["comment", "; Target-dependent attributes:"], | ||
["keyword", "attributes"], | ||
["variable", "#1"], | ||
["punctuation", "="], | ||
["punctuation", "{"], | ||
["string", "\"no-sse\""], | ||
["punctuation", "}"], | ||
["comment", "; Function @f has attributes: alwaysinline, alignstack=4, and \"no-sse\"."], | ||
["keyword", "define"], | ||
["type", "void"], | ||
["variable", "@f"], | ||
["punctuation", "("], | ||
["punctuation", ")"], | ||
["variable", "#0"], | ||
["variable", "#1"], | ||
["punctuation", "{"], | ||
["punctuation", "."], | ||
["punctuation", "."], | ||
["punctuation", "."], | ||
["punctuation", "}"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Tests the attribute "#id" syntax. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
define i32 @add(i32 %a, i32 %b) { | ||
entry: | ||
br label %tailrecurse | ||
|
||
tailrecurse: | ||
%a.tr = phi i32 [ %a, %entry ], [ %tmp2, %recurse ] | ||
%b.tr = phi i32 [ %b, %entry ], [ %tmp3, %recurse ] | ||
%tmp1 = icmp eq i32 %a.tr, 0 | ||
br i1 %tmp1, label %done, label %recurse | ||
|
||
recurse: | ||
%tmp2 = sub i32 %a.tr, 1 | ||
%tmp3 = add i32 %b.tr, 1 | ||
br label %tailrecurse | ||
|
||
done: | ||
ret i32 %b.tr | ||
} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "define"], | ||
["type", "i32"], | ||
["variable", "@add"], | ||
["punctuation", "("], | ||
["type", "i32"], | ||
["variable", "%a"], | ||
["punctuation", ","], | ||
["type", "i32"], | ||
["variable", "%b"], | ||
["punctuation", ")"], | ||
["punctuation", "{"], | ||
["label", "entry:"], | ||
["keyword", "br"], | ||
["type", "label"], | ||
["variable", "%tailrecurse"], | ||
["label", "tailrecurse:"], | ||
["variable", "%a.tr"], | ||
["punctuation", "="], | ||
["keyword", "phi"], | ||
["type", "i32"], | ||
["punctuation", "["], | ||
["variable", "%a"], | ||
["punctuation", ","], | ||
["variable", "%entry"], | ||
["punctuation", "]"], | ||
["punctuation", ","], | ||
["punctuation", "["], | ||
["variable", "%tmp2"], | ||
["punctuation", ","], | ||
["variable", "%recurse"], | ||
["punctuation", "]"], | ||
["variable", "%b.tr"], | ||
["punctuation", "="], | ||
["keyword", "phi"], | ||
["type", "i32"], | ||
["punctuation", "["], | ||
["variable", "%b"], | ||
["punctuation", ","], | ||
["variable", "%entry"], | ||
["punctuation", "]"], | ||
["punctuation", ","], | ||
["punctuation", "["], | ||
["variable", "%tmp3"], | ||
["punctuation", ","], | ||
["variable", "%recurse"], | ||
["punctuation", "]"], | ||
["variable", "%tmp1"], | ||
["punctuation", "="], | ||
["keyword", "icmp"], | ||
["keyword", "eq"], | ||
["type", "i32"], | ||
["variable", "%a.tr"], | ||
["punctuation", ","], | ||
["number", "0"], | ||
["keyword", "br"], | ||
["type", "i1"], | ||
["variable", "%tmp1"], | ||
["punctuation", ","], | ||
["type", "label"], | ||
["variable", "%done"], | ||
["punctuation", ","], | ||
["type", "label"], | ||
["variable", "%recurse"], | ||
["label", "recurse:"], | ||
["variable", "%tmp2"], | ||
["punctuation", "="], | ||
["keyword", "sub"], | ||
["type", "i32"], | ||
["variable", "%a.tr"], | ||
["punctuation", ","], | ||
["number", "1"], | ||
["variable", "%tmp3"], | ||
["punctuation", "="], | ||
["keyword", "add"], | ||
["type", "i32"], | ||
["variable", "%b.tr"], | ||
["punctuation", ","], | ||
["number", "1"], | ||
["keyword", "br"], | ||
["type", "label"], | ||
["variable", "%tailrecurse"], | ||
["label", "done:"], | ||
["keyword", "ret"], | ||
["type", "i32"], | ||
["variable", "%b.tr"], | ||
["punctuation", "}"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
An iterative example program. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
define i32 @add(i32 %a, i32 %b) { | ||
entry: | ||
%tmp1 = icmp eq i32 %a, 0 | ||
br i1 %tmp1, label %done, label %recurse | ||
|
||
recurse: | ||
%tmp2 = sub i32 %a, 1 | ||
%tmp3 = add i32 %b, 1 | ||
%tmp4 = call i32 @add(i32 %tmp2, i32 %tmp3) | ||
ret i32 %tmp4 | ||
|
||
done: | ||
ret i32 %b | ||
} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "define"], | ||
["type", "i32"], | ||
["variable", "@add"], | ||
["punctuation", "("], | ||
["type", "i32"], | ||
["variable", "%a"], | ||
["punctuation", ","], | ||
["type", "i32"], | ||
["variable", "%b"], | ||
["punctuation", ")"], | ||
["punctuation", "{"], | ||
["label", "entry:"], | ||
["variable", "%tmp1"], | ||
["punctuation", "="], | ||
["keyword", "icmp"], | ||
["keyword", "eq"], | ||
["type", "i32"], | ||
["variable", "%a"], | ||
["punctuation", ","], | ||
["number", "0"], | ||
["keyword", "br"], | ||
["type", "i1"], | ||
["variable", "%tmp1"], | ||
["punctuation", ","], | ||
["type", "label"], | ||
["variable", "%done"], | ||
["punctuation", ","], | ||
["type", "label"], | ||
["variable", "%recurse"], | ||
["label", "recurse:"], | ||
["variable", "%tmp2"], | ||
["punctuation", "="], | ||
["keyword", "sub"], | ||
["type", "i32"], | ||
["variable", "%a"], | ||
["punctuation", ","], | ||
["number", "1"], | ||
["variable", "%tmp3"], | ||
["punctuation", "="], | ||
["keyword", "add"], | ||
["type", "i32"], | ||
["variable", "%b"], | ||
["punctuation", ","], | ||
["number", "1"], | ||
["variable", "%tmp4"], | ||
["punctuation", "="], | ||
["keyword", "call"], | ||
["type", "i32"], | ||
["variable", "@add"], | ||
["punctuation", "("], | ||
["type", "i32"], | ||
["variable", "%tmp2"], | ||
["punctuation", ","], | ||
["type", "i32"], | ||
["variable", "%tmp3"], | ||
["punctuation", ")"], | ||
["keyword", "ret"], | ||
["type", "i32"], | ||
["variable", "%tmp4"], | ||
["label", "done:"], | ||
["keyword", "ret"], | ||
["type", "i32"], | ||
["variable", "%b"], | ||
["punctuation", "}"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
A recursive example program. |
Oops, something went wrong.