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

@ -11,6 +11,9 @@
%} %}
(* keywords *) (* keywords *)
%token TARGET
%token DATALAYOUT
%token TRIPLE
%token DEFINE %token DEFINE
(* delimiters *) (* delimiters *)
@ -42,6 +45,7 @@
%token LABEL %token LABEL
%token METADATA %token METADATA
%token <string> CONSTANT_STRING
(* CONSTANTS *) (* CONSTANTS *)
%token <int> CONSTANT_INT %token <int> CONSTANT_INT
%token NULL %token NULL
@ -148,7 +152,20 @@
%% %%
prog: 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_def:
| metadata_var EQUALS METADATA? METADATA_NODE { () } | metadata_var EQUALS METADATA? METADATA_NODE { () }

Loading…
Cancel
Save