Hash :
43efde2e
Author :
Date :
2020-03-23T17:44:09
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
; 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()*
; 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}
----------------------------------------------------
[
["comment", "; Declare the string constant as a global constant."],
["variable", "@.str"],
["punctuation", "="],
["keyword", "private"],
["keyword", "unnamed_addr"],
["keyword", "constant"],
["punctuation", "["],
["number", "13"],
["keyword", "x"],
["type", "i8"],
["punctuation", "]"],
["keyword", "c"],
["string", "\"hello world\\0A\\00\""],
["comment", "; External declaration of the puts function"],
["keyword", "declare"],
["type", "i32"],
["variable", "@puts"],
["punctuation", "("],
["type", "i8"],
["punctuation", "*"],
["keyword", "nocapture"],
["punctuation", ")"],
["keyword", "nounwind"],
["comment", "; Definition of main function"],
["keyword", "define"],
["type", "i32"],
["variable", "@main"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],
["comment", "; i32()*"],
["comment", "; Convert [13 x i8]* to i8*..."],
["variable", "%cast210"],
["punctuation", "="],
["keyword", "getelementptr"],
["punctuation", "["],
["number", "13"],
["keyword", "x"],
["type", "i8"],
["punctuation", "]"],
["punctuation", ","],
["punctuation", "["],
["number", "13"],
["keyword", "x"],
["type", "i8"],
["punctuation", "]"],
["punctuation", "*"],
["variable", "@.str"],
["punctuation", ","],
["type", "i64"],
["number", "0"],
["punctuation", ","],
["type", "i64"],
["number", "0"],
["comment", "; Call puts function to write out the string to stdout."],
["keyword", "call"],
["type", "i32"],
["variable", "@puts"],
["punctuation", "("],
["type", "i8"],
["punctuation", "*"],
["variable", "%cast210"],
["punctuation", ")"],
["keyword", "ret"],
["type", "i32"],
["number", "0"],
["punctuation", "}"],
["comment", "; Named metadata"],
["variable", "!0"],
["punctuation", "="],
["punctuation", "!"],
["punctuation", "{"],
["type", "i32"],
["number", "42"],
["punctuation", ","],
["keyword", "null"],
["punctuation", ","],
["punctuation", "!"],
["string", "\"string\""],
["punctuation", "}"],
["variable", "!foo"],
["punctuation", "="],
["punctuation", "!"],
["punctuation", "{"],
["variable", "!0"],
["punctuation", "}"]
]
----------------------------------------------------
Tests the example included on the LangRef, at:
https://llvm.org/docs/LangRef.html#module-structure