Skip to content

Commit

Permalink
Support functions with pure-asm bodies (#11)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cdisselkoen authored Apr 22, 2021
1 parent a52aca5 commit 4b25892
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frontc/clexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ let keywords =
("for", fun _ -> FOR (curfile(), curline()));
("if", fun _ -> IF (curfile(), curline()));
("else", fun _ -> ELSE (curfile(), curline()));
("asm", id ASM);
("asm", id ASM); ("__asm__", id ASM);
]

(*** Specific GNU ***)
Expand Down
19 changes: 19 additions & 0 deletions frontc/cparser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ global_type global_defs SEMICOLON
| _ ->
parse_error ()
}
| global_type global_proto basic_asm SEMICOLON
{
let (_, base, _, _) = $2 in
match base with
PROTO _ ->
FUNDEF (set_single $1 $2, ([], $3))
| OLD_PROTO _ ->
OLDFUNDEF (set_single $1 $2, [], ([], $3))
| _ ->
parse_error ()
}
| global_type old_proto old_pardefs body
{ OLDFUNDEF (set_single $1 $2, List.rev $3, (snd $4)) }
| global_type SEMICOLON
Expand Down Expand Up @@ -1057,6 +1068,14 @@ SEMICOLON opt_expression RPAREN statement
{ Clexer.test_gcc(); GNU_ASM ($3, List.rev $4, List.rev $5, List.rev $6) }
;

/* "Basic asm" https://gcc.gnu.org/onlinedocs/gcc/Basic-Asm.html#Basic-Asm */
basic_asm:
ASM opt_gcc_attributes LPAREN string_list RPAREN
{ ASM $4 }
| ASM VOLATILE opt_gcc_attributes LPAREN string_list RPAREN
{ ASM $5 }
| ASM opt_gcc_attributes VOLATILE LPAREN string_list RPAREN
{ ASM $5 }

/*** GNU asm ***/
gnu_asm_io:
Expand Down

0 comments on commit 4b25892

Please sign in to comment.