Parse data layout and target triple.

master
Rohan Jacob-Rao 9 years ago
parent 06f6e349c7
commit 026ca7176e

@ -31,12 +31,16 @@ let id = id_char (id_char | digit)*
(* definition of attribute group - not used for now *)
let attribute_junk = "attributes" [^ '\n']*
let string_content = [^ '"']*
rule token = parse
| space | comment { token lexbuf }
| newline { token lexbuf }
(* keywords *)
| "target" { TARGET }
| "datalayout" { DATALAYOUT }
| "triple" { TRIPLE }
| "define" { DEFINE }
(* delimiters *)
@ -68,7 +72,7 @@ rule token = parse
| "label" { LABEL }
| "metadata" { METADATA }
| pos_int as size { CONSTANT_INT (int_of_string size) }
| '"' (string_content as str) '"' { CONSTANT_STRING str }
(* CONSTANTS *)
| "true" { CONSTANT_INT 1 }
| "false" { CONSTANT_INT 0 }

@ -11,6 +11,9 @@
%}
(* keywords *)
%token TARGET
%token DATALAYOUT
%token TRIPLE
%token DEFINE
(* delimiters *)
@ -42,6 +45,7 @@
%token LABEL
%token METADATA
%token <string> CONSTANT_STRING
(* CONSTANTS *)
%token <int> CONSTANT_INT
%token NULL
@ -148,7 +152,20 @@
%%
prog:
| defs = list(func_def) metadata_def* EOF { Prog defs }
| targets defs = list(func_def) metadata_def* EOF { Prog defs }
targets:
| { (None, None) }
| dl = datalayout { (Some dl, None) }
| tt = target_triple { (None, Some tt) }
| dl = datalayout tt = target_triple { (Some dl, Some tt) }
| tt = target_triple dl = datalayout { (Some dl, Some tt) }
datalayout:
| TARGET DATALAYOUT EQUALS str = CONSTANT_STRING { str }
target_triple:
| TARGET TRIPLE EQUALS str = CONSTANT_STRING { str }
metadata_def:
| metadata_var EQUALS METADATA? METADATA_NODE { () }

Loading…
Cancel
Save