Skip to content

Commit 4b25892

Browse files
authored
Support functions with pure-asm bodies (#11)
* accept __asm__ as a keyword in the lexer, synonym for asm * parse functions with basic-asm bodies * update to use the new error helper from #7
1 parent a52aca5 commit 4b25892

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

frontc/clexer.mll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ let keywords =
164164
("for", fun _ -> FOR (curfile(), curline()));
165165
("if", fun _ -> IF (curfile(), curline()));
166166
("else", fun _ -> ELSE (curfile(), curline()));
167-
("asm", id ASM);
167+
("asm", id ASM); ("__asm__", id ASM);
168168
]
169169

170170
(*** Specific GNU ***)

frontc/cparser.mly

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,17 @@ global_type global_defs SEMICOLON
290290
| _ ->
291291
parse_error ()
292292
}
293+
| global_type global_proto basic_asm SEMICOLON
294+
{
295+
let (_, base, _, _) = $2 in
296+
match base with
297+
PROTO _ ->
298+
FUNDEF (set_single $1 $2, ([], $3))
299+
| OLD_PROTO _ ->
300+
OLDFUNDEF (set_single $1 $2, [], ([], $3))
301+
| _ ->
302+
parse_error ()
303+
}
293304
| global_type old_proto old_pardefs body
294305
{ OLDFUNDEF (set_single $1 $2, List.rev $3, (snd $4)) }
295306
| global_type SEMICOLON
@@ -1057,6 +1068,14 @@ SEMICOLON opt_expression RPAREN statement
10571068
{ Clexer.test_gcc(); GNU_ASM ($3, List.rev $4, List.rev $5, List.rev $6) }
10581069
;
10591070

1071+
/* "Basic asm" https://gcc.gnu.org/onlinedocs/gcc/Basic-Asm.html#Basic-Asm */
1072+
basic_asm:
1073+
ASM opt_gcc_attributes LPAREN string_list RPAREN
1074+
{ ASM $4 }
1075+
| ASM VOLATILE opt_gcc_attributes LPAREN string_list RPAREN
1076+
{ ASM $5 }
1077+
| ASM opt_gcc_attributes VOLATILE LPAREN string_list RPAREN
1078+
{ ASM $5 }
10601079

10611080
/*** GNU asm ***/
10621081
gnu_asm_io:

0 commit comments

Comments
 (0)