From 026ca7176e4d707b22fe7c98b4ff7d3aca401f39 Mon Sep 17 00:00:00 2001 From: Rohan Jacob-Rao Date: Fri, 7 Aug 2015 15:27:17 -0700 Subject: [PATCH] Parse data layout and target triple. --- infer/src/llvm/lLexer.mll | 6 +++++- infer/src/llvm/lParser.mly | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/infer/src/llvm/lLexer.mll b/infer/src/llvm/lLexer.mll index 8e675d03c..96b6d7286 100644 --- a/infer/src/llvm/lLexer.mll +++ b/infer/src/llvm/lLexer.mll @@ -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 } diff --git a/infer/src/llvm/lParser.mly b/infer/src/llvm/lParser.mly index a048f0669..c36f58073 100644 --- a/infer/src/llvm/lParser.mly +++ b/infer/src/llvm/lParser.mly @@ -11,6 +11,9 @@ %} (* keywords *) +%token TARGET +%token DATALAYOUT +%token TRIPLE %token DEFINE (* delimiters *) @@ -42,6 +45,7 @@ %token LABEL %token METADATA +%token CONSTANT_STRING (* CONSTANTS *) %token 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 { () }