Fixed bug in parsing of variables.

master
Rohan Jacob-Rao 9 years ago
parent 5169419216
commit 51ebf2493e

@ -29,98 +29,98 @@ let id_char = lower | upper | id_special_char
let id = id_char (id_char | digit)* let id = id_char (id_char | digit)*
rule token = parse rule token = parse
| space | comment { token lexbuf } | space | comment { token lexbuf }
| newline { token lexbuf } | newline { token lexbuf }
(* keywords *) (* keywords *)
| "define" { DEFINE } | "define" { DEFINE }
(* delimiters *) (* delimiters *)
| ',' { COMMA } | ',' { COMMA }
| '(' { LPAREN } | '(' { LPAREN }
| ')' { RPAREN } | ')' { RPAREN }
| '{' { LBRACE } | '{' { LBRACE }
| '}' { RBRACE } | '}' { RBRACE }
| '<' { LANGLE } | '<' { LANGLE }
| '>' { RANGLE } | '>' { RANGLE }
| '[' { LSQBRACK } | '[' { LSQBRACK }
| ']' { RSQBRACK } | ']' { RSQBRACK }
(* symbols *) (* symbols *)
| '=' { EQUALS } | '=' { EQUALS }
| '*' { STAR } | '*' { STAR }
| ['x' 'X'] { X } | ['x' 'X'] { X }
(* TYPES *) (* TYPES *)
| "void" { VOID } | "void" { VOID }
| "i1" { BIT (* INT 1 *) } | "i1" { BIT (* INT 1 *) }
| 'i' (pos_int as width) { INT (int_of_string width) } | 'i' (pos_int as width) { INT (int_of_string width) }
| "half" { HALF } | "half" { HALF }
| "float" { FLOAT } | "float" { FLOAT }
| "double" { DOUBLE } | "double" { DOUBLE }
| "fp128" { FP128 } | "fp128" { FP128 }
| "x86_fp80" { X86_FP80 } | "x86_fp80" { X86_FP80 }
| "ppc_fp128" { PPC_FP128 } | "ppc_fp128" { PPC_FP128 }
(*| "x86_mmx" { X86_MMX }*) (*| "x86_mmx" { X86_MMX }*)
| "label" { LABEL } | "label" { LABEL }
| "metadata" { METADATA } | "metadata" { METADATA }
| pos_int as size { SIZE (int_of_string size) } | pos_int as size { SIZE (int_of_string size) }
(* CONSTANTS *) (* CONSTANTS *)
| "true" { CONSTINT 1 } | "true" { CONSTINT 1 }
| "false" { CONSTINT 0 } | "false" { CONSTINT 0 }
| intlit as i { CONSTINT (int_of_string i) } | intlit as i { CONSTINT (int_of_string i) }
(* floating point constants *) (* floating point constants *)
| "null" { NULL } | "null" { NULL }
(* INSTRUCTIONS *) (* INSTRUCTIONS *)
(* terminator instructions *) (* terminator instructions *)
| "ret" { RET } | "ret" { RET }
| "br" { BR } | "br" { BR }
(*| "switch" { SWITCH } (*| "switch" { SWITCH }
| "indirectbr" { INDIRECTBR } | "indirectbr" { INDIRECTBR }
| "invoke" { INVOKE } | "invoke" { INVOKE }
| "resume" { RESUME } | "resume" { RESUME }
| "unreachable" { UNREACHABLE }*) | "unreachable" { UNREACHABLE }*)
(* binary operations *) (* binary operations *)
| "add" { ADD } | "add" { ADD }
| "fadd" { FADD } | "fadd" { FADD }
| "sub" { SUB } | "sub" { SUB }
| "fsub" { FSUB } | "fsub" { FSUB }
| "mul" { MUL } | "mul" { MUL }
| "fmul" { FMUL } | "fmul" { FMUL }
| "udiv" { UDIV } | "udiv" { UDIV }
| "sdiv" { SDIV } | "sdiv" { SDIV }
| "fdiv" { FDIV } | "fdiv" { FDIV }
| "urem" { UREM } | "urem" { UREM }
| "srem" { SREM } | "srem" { SREM }
| "frem" { FREM } | "frem" { FREM }
(* arithmetic options *) (* arithmetic options *)
| "nuw" { NUW } | "nuw" { NUW }
| "nsw" { NSW } | "nsw" { NSW }
| "exact" { EXACT } | "exact" { EXACT }
(* floating point options *) (* floating point options *)
| "nnan" { NNAN } | "nnan" { NNAN }
| "ninf" { NINF } | "ninf" { NINF }
| "nsz" { NSZ } | "nsz" { NSZ }
| "arcp" { ARCP } | "arcp" { ARCP }
| "fast" { FAST } | "fast" { FAST }
(* bitwise binary operations *) (* bitwise binary operations *)
| "shl" { SHL } | "shl" { SHL }
| "lshr" { LSHR } | "lshr" { LSHR }
| "ashr" { ASHR } | "ashr" { ASHR }
| "and" { AND } | "and" { AND }
| "or" { OR } | "or" { OR }
| "xor" { XOR } | "xor" { XOR }
(* vector operations *) (* vector operations *)
| "extractelement" { EXTRACTELEMENT } | "extractelement" { EXTRACTELEMENT }
| "insertelement" { INSERTELEMENT } | "insertelement" { INSERTELEMENT }
(*| "shufflevector" { SHUFFLEVECTOR }*) (*| "shufflevector" { SHUFFLEVECTOR }*)
(* aggregate operations *) (* aggregate operations *)
(*| "extractvalue" { EXTRACTVALUE }*) (*| "extractvalue" { EXTRACTVALUE }*)
(*| "insertvalue" { INSERTVALUE }*) (*| "insertvalue" { INSERTVALUE }*)
(* memory access and addressing operations *) (* memory access and addressing operations *)
(*| "alloca" { ALLOCA }*) (*| "alloca" { ALLOCA }*)
(*| "load" { LOAD }*) (*| "load" { LOAD }*)
(*| "store" { STORE }*) (*| "store" { STORE }*)
(*| "fence" { FENCE }*) (*| "fence" { FENCE }*)
(*| "cmpxchg" { CMPXCHG }*) (*| "cmpxchg" { CMPXCHG }*)
@ -128,31 +128,31 @@ rule token = parse
(*| "getelementptr" { GETELEMENTPTR }*) (*| "getelementptr" { GETELEMENTPTR }*)
(* conversion operations *) (* conversion operations *)
(*| "trunc" { TRUNC }*) (* e.g. trunc ... to ... *) (*| "trunc" { TRUNC }*) (* e.g. trunc ... to ... *)
(*| "zext" { ZEXT }*) (*| "zext" { ZEXT }*)
(*| "sext" { SEXT }*) (*| "sext" { SEXT }*)
(*| "fptrunc" { FPTRUNC }*) (*| "fptrunc" { FPTRUNC }*)
(*| "fpext" { FPEXT }*) (*| "fpext" { FPEXT }*)
(*| "fptoui" { FPTOUI }*) (*| "fptoui" { FPTOUI }*)
(*| "fptosi" { FPTOSI }*) (*| "fptosi" { FPTOSI }*)
(*| "uitofp" { UITOFP }*) (*| "uitofp" { UITOFP }*)
(*| "sitofp" { SITOFP }*) (*| "sitofp" { SITOFP }*)
(*| "ptrtoint" { PTRTOINT }*) (*| "ptrtoint" { PTRTOINT }*)
(*| "inttoptr" { INTTOPTR }*) (*| "inttoptr" { INTTOPTR }*)
(*| "bitcast" { BITCAST }*) (*| "bitcast" { BITCAST }*)
(*| "addrspacecast" { ADDRSPACECAST }*) (*| "addrspacecast" { ADDRSPACECAST }*)
(*| "to" { TO }*) (* all conversion operations include this keyword *) (*| "to" { TO }*) (* all conversion operations include this keyword *)
(* other operations *) (* other operations *)
(*| "icmp" { ICMP }*) (*| "icmp" { ICMP }*)
(*| "fcmp" { FCMP }*) (*| "fcmp" { FCMP }*)
(*| "phi" { PHI }*) (*| "phi" { PHI }*)
(*| "select" { SELECT }*) (*| "select" { SELECT }*)
(*| "call" { CALL }*) (*| "call" { CALL }*)
(*| "va_arg" { VA_ARG }*) (*| "va_arg" { VA_ARG }*)
(*| "landingpad" { LANDINGPAD }*) (*| "landingpad" { LANDINGPAD }*)
(* identifiers - make this complete *) (* identifiers *)
| '@' { AT } | '@' (id as str) { GLOBAL str }
| '%' { PERCENT } | '%' (id as str) { LOCAL str }
| id as str { IDENT str } | id as str { IDENT str }
| eof { EOF } | eof { EOF }

@ -27,8 +27,6 @@
%token EQUALS %token EQUALS
%token STAR %token STAR
%token X %token X
%token AT
%token PERCENT
(* TYPES *) (* TYPES *)
%token VOID %token VOID
@ -127,6 +125,8 @@
(*%token VA_ARG*) (*%token VA_ARG*)
(*%token LANDINGPAD*) (*%token LANDINGPAD*)
%token <string> GLOBAL
%token <string> LOCAL
%token <string> IDENT %token <string> IDENT
%token EOF %token EOF
@ -238,8 +238,8 @@ operand:
| const=constant { Const const } | const=constant { Const const }
variable: variable:
| AT id=IDENT { Global id } | id=GLOBAL { Global id }
| PERCENT id=IDENT { Local id } | id=LOCAL { Local id }
constant: constant:
| i=CONSTINT { Cint i } | i=CONSTINT { Cint i }

Loading…
Cancel
Save