File tree Expand file tree Collapse file tree 8 files changed +80
-2
lines changed Expand file tree Collapse file tree 8 files changed +80
-2
lines changed Original file line number Diff line number Diff line change @@ -122,13 +122,14 @@ And the hard way:
122
122
.. code-block:: llvm
123
123
124
124
%0 = add i32 %X, %X ; yields i32:%0
125
- %1 = add i32 %0, %0 ; yields i32:%1
125
+ %1 = add i32 %0, %0 /* yields i32:%1 */
126
126
%result = add i32 %1, %1
127
127
128
128
This last way of multiplying ``%X`` by 8 illustrates several important
129
129
lexical features of LLVM:
130
130
131
131
#. Comments are delimited with a '``;``' and go until the end of line.
132
+ Alternatively, comments can start with ``/*`` and terminate with ``*/``.
132
133
#. Unnamed temporaries are created when the result of a computation is
133
134
not assigned to a named value.
134
135
#. By default, unnamed temporaries are numbered sequentially (using a
Original file line number Diff line number Diff line change @@ -95,6 +95,7 @@ namespace llvm {
95
95
96
96
int getNextChar ();
97
97
void SkipLineComment ();
98
+ bool SkipCComment ();
98
99
lltok::Kind ReadString (lltok::Kind kind);
99
100
bool ReadVarName ();
100
101
Original file line number Diff line number Diff line change @@ -200,7 +200,6 @@ lltok::Kind LLLexer::LexToken() {
200
200
// Handle letters: [a-zA-Z_]
201
201
if (isalpha (static_cast <unsigned char >(CurChar)) || CurChar == ' _' )
202
202
return LexIdentifier ();
203
-
204
203
return lltok::Error;
205
204
case EOF: return lltok::Eof;
206
205
case 0 :
@@ -251,6 +250,12 @@ lltok::Kind LLLexer::LexToken() {
251
250
case ' ,' : return lltok::comma;
252
251
case ' *' : return lltok::star;
253
252
case ' |' : return lltok::bar;
253
+ case ' /' :
254
+ if (getNextChar () != ' *' )
255
+ return lltok::Error;
256
+ if (SkipCComment ())
257
+ return lltok::Error;
258
+ continue ;
254
259
}
255
260
}
256
261
}
@@ -262,6 +267,28 @@ void LLLexer::SkipLineComment() {
262
267
}
263
268
}
264
269
270
+ // / This skips C-style /**/ comments. Returns true if there
271
+ // / was an error.
272
+ bool LLLexer::SkipCComment () {
273
+ while (true ) {
274
+ int CurChar = getNextChar ();
275
+ switch (CurChar) {
276
+ case EOF:
277
+ LexError (" unterminated comment" );
278
+ return true ;
279
+ case ' *' :
280
+ // End of the comment?
281
+ CurChar = getNextChar ();
282
+ if (CurChar == ' /' )
283
+ return false ;
284
+ if (CurChar == EOF) {
285
+ LexError (" unterminated comment" );
286
+ return true ;
287
+ }
288
+ }
289
+ }
290
+ }
291
+
265
292
// / Lex all tokens that start with an @ character.
266
293
// / GlobalVar @\"[^\"]*\"
267
294
// / GlobalVar @[-a-zA-Z$._][-a-zA-Z$._0-9]*
Original file line number Diff line number Diff line change
1
+ ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
2
+
3
+ /* Simple C style comment */
4
+
5
+ ; CHECK: @B = external global i32
6
+ @B = external global i32
7
+
8
+ /* multiline C ctyle comment at "top-level"
9
+ * This is the second line
10
+ * and this is third
11
+ */
12
+
13
+
14
+ ; CHECK: @foo
15
+ define <4 x i1 > @foo (<4 x float > %a , <4 x float > %b ) nounwind {
16
+ entry: /* inline comment */
17
+ %cmp = fcmp olt <4 x float > %a , /* to be ignored */ %b
18
+ ret <4 x i1 > %cmp /* ignore */
19
+ }
20
+
21
+ /* End of the assembly file */
22
+
Original file line number Diff line number Diff line change
1
+ ; RUN: not llvm-as --disable-output %s 2>&1 | FileCheck %s -DFILE=%s
2
+
3
+ @B = external global i32
4
+
5
+ ; CHECK: [[FILE]]:[[@LINE+1]]:1: error: unterminated comment
6
+ /* End of the assembly file
Original file line number Diff line number Diff line change
1
+ ; RUN: not llvm-as --disable-output %s 2>&1 | FileCheck %s -DFILE=%s
2
+
3
+ @B = external global i32
4
+
5
+ /* /* Nested comments not supported */
6
+
7
+ ; CHECK: [[FILE]]:[[@LINE+1]]:1: error: redefinition of global '@B'
8
+ @B = external global i32
Original file line number Diff line number Diff line change
1
+ ; RUN: not llvm-as --disable-output %s 2>&1 | FileCheck %s -DFILE=%s
2
+
3
+ @B = external global i32
4
+
5
+ ; CHECK: [[FILE]]:[[@LINE+1]]:2: error: expected top-level entity
6
+ */
7
+
Original file line number Diff line number Diff line change
1
+ ; RUN: not llvm-as --disable-output %s 2>&1 | FileCheck %s -DFILE=%s
2
+
3
+ @B = external global i32
4
+
5
+ ; CHECK: [[FILE]]:[[@LINE+1]]:1: error: unterminated comment
6
+ /* End of the assembly file *
You can’t perform that action at this time.
0 commit comments