|
|
@ -125,8 +125,10 @@
|
|
|
|
(*%token VA_ARG*)
|
|
|
|
(*%token VA_ARG*)
|
|
|
|
(*%token LANDINGPAD*)
|
|
|
|
(*%token LANDINGPAD*)
|
|
|
|
|
|
|
|
|
|
|
|
%token <string> GLOBAL
|
|
|
|
%token <string> NAMED_GLOBAL
|
|
|
|
%token <string> LOCAL
|
|
|
|
%token <string> NAMED_LOCAL
|
|
|
|
|
|
|
|
%token <int> NUMBERED_GLOBAL
|
|
|
|
|
|
|
|
%token <int> NUMBERED_LOCAL
|
|
|
|
%token <string> IDENT
|
|
|
|
%token <string> IDENT
|
|
|
|
|
|
|
|
|
|
|
|
%token EOF
|
|
|
|
%token EOF
|
|
|
@ -140,32 +142,32 @@
|
|
|
|
%%
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
|
|
prog:
|
|
|
|
prog:
|
|
|
|
| defs=list(func_def) EOF { Prog defs }
|
|
|
|
| defs = list(func_def) EOF { Prog defs }
|
|
|
|
|
|
|
|
|
|
|
|
func_def:
|
|
|
|
func_def:
|
|
|
|
| DEFINE ret_tp=ret_typ name=variable LPAREN params=separated_list(COMMA, pair(typ, IDENT)) RPAREN instrs=block {
|
|
|
|
| DEFINE ret_tp = ret_typ name = variable LPAREN params = separated_list(COMMA, pair(typ, IDENT)) RPAREN instrs = block {
|
|
|
|
FuncDef (name, ret_tp, params, instrs) }
|
|
|
|
FuncDef (name, ret_tp, params, instrs) }
|
|
|
|
|
|
|
|
|
|
|
|
ret_typ:
|
|
|
|
ret_typ:
|
|
|
|
| VOID { None }
|
|
|
|
| VOID { None }
|
|
|
|
| tp=typ { Some tp }
|
|
|
|
| tp = typ { Some tp }
|
|
|
|
|
|
|
|
|
|
|
|
typ:
|
|
|
|
typ:
|
|
|
|
| tp=element_typ { tp }
|
|
|
|
| tp = element_typ { tp }
|
|
|
|
(*| X86_MMX { () }*)
|
|
|
|
(*| X86_MMX { () }*)
|
|
|
|
| tp=vector_typ { tp }
|
|
|
|
| tp = vector_typ { tp }
|
|
|
|
| LSQBRACK sz=SIZE X tp=element_typ RSQBRACK { Tarray (sz, tp) } (* array type *)
|
|
|
|
| LSQBRACK sz = SIZE X tp = element_typ RSQBRACK { Tarray (sz, tp) } (* array type *)
|
|
|
|
| LABEL { Tlabel }
|
|
|
|
| LABEL { Tlabel }
|
|
|
|
| METADATA { Tmetadata }
|
|
|
|
| METADATA { Tmetadata }
|
|
|
|
(* TODO structs *)
|
|
|
|
(* TODO structs *)
|
|
|
|
|
|
|
|
|
|
|
|
vector_typ:
|
|
|
|
vector_typ:
|
|
|
|
| LANGLE sz=SIZE X tp=element_typ RANGLE { Tvector (sz, tp) }
|
|
|
|
| LANGLE sz = SIZE X tp = element_typ RANGLE { Tvector (sz, tp) }
|
|
|
|
|
|
|
|
|
|
|
|
element_typ:
|
|
|
|
element_typ:
|
|
|
|
| width=INT { Tint width }
|
|
|
|
| width = INT { Tint width }
|
|
|
|
| floating_typ { Tfloat }
|
|
|
|
| floating_typ { Tfloat }
|
|
|
|
| tp=ptr_typ { Tptr tp }
|
|
|
|
| tp = ptr_typ { Tptr tp }
|
|
|
|
|
|
|
|
|
|
|
|
floating_typ:
|
|
|
|
floating_typ:
|
|
|
|
| HALF { () }
|
|
|
|
| HALF { () }
|
|
|
@ -176,23 +178,23 @@ floating_typ:
|
|
|
|
| PPC_FP128 { () }
|
|
|
|
| PPC_FP128 { () }
|
|
|
|
|
|
|
|
|
|
|
|
ptr_typ:
|
|
|
|
ptr_typ:
|
|
|
|
| tp=typ STAR { tp }
|
|
|
|
| tp = typ STAR { tp }
|
|
|
|
|
|
|
|
|
|
|
|
block:
|
|
|
|
block:
|
|
|
|
| LBRACE instrs=list(instr) RBRACE { instrs }
|
|
|
|
| LBRACE instrs = list(instr) RBRACE { instrs }
|
|
|
|
|
|
|
|
|
|
|
|
instr:
|
|
|
|
instr:
|
|
|
|
| term=terminator { term }
|
|
|
|
| term = terminator { term }
|
|
|
|
| variable EQUALS binop { Ret None } (* TODO *)
|
|
|
|
| variable EQUALS binop { Ret None } (* TODO *)
|
|
|
|
| var=variable EQUALS LOAD tp=ptr_typ ptr=variable { Load (var, tp, ptr) }
|
|
|
|
| var = variable EQUALS LOAD tp = ptr_typ ptr = variable { Load (var, tp, ptr) }
|
|
|
|
| STORE val_tp=typ value=operand COMMA ptr_tp=ptr_typ var=variable { Store (value, val_tp, var) }
|
|
|
|
| STORE val_tp = typ value = operand COMMA ptr_tp = ptr_typ var = variable { Store (value, val_tp, var) }
|
|
|
|
(* don't yet know why val_tp and ptr_tp would be different *)
|
|
|
|
(* don't yet know why val_tp and ptr_tp would be different *)
|
|
|
|
|
|
|
|
|
|
|
|
terminator:
|
|
|
|
terminator:
|
|
|
|
| RET tp=typ op=operand { Ret (Some (tp, op)) }
|
|
|
|
| RET tp = typ op = operand { Ret (Some (tp, op)) }
|
|
|
|
| RET VOID { Ret None }
|
|
|
|
| RET VOID { Ret None }
|
|
|
|
| BR LABEL lbl=variable { UncondBranch lbl }
|
|
|
|
| BR LABEL lbl = variable { UncondBranch lbl }
|
|
|
|
| BR BIT op=operand COMMA LABEL lbl1=variable COMMA LABEL lbl2=variable { CondBranch (op, lbl1, lbl2) }
|
|
|
|
| BR BIT op = operand COMMA LABEL lbl1 = variable COMMA LABEL lbl2 = variable { CondBranch (op, lbl1, lbl2) }
|
|
|
|
(*
|
|
|
|
(*
|
|
|
|
| switch
|
|
|
|
| switch
|
|
|
|
| indirectbr
|
|
|
|
| indirectbr
|
|
|
@ -237,13 +239,15 @@ binop_args:
|
|
|
|
(* below is fuzzy *)
|
|
|
|
(* below is fuzzy *)
|
|
|
|
|
|
|
|
|
|
|
|
operand:
|
|
|
|
operand:
|
|
|
|
| var=variable { Var var }
|
|
|
|
| var = variable { Var var }
|
|
|
|
| const=constant { Const const }
|
|
|
|
| const = constant { Const const }
|
|
|
|
|
|
|
|
|
|
|
|
variable:
|
|
|
|
variable:
|
|
|
|
| id=GLOBAL { Global id }
|
|
|
|
| name = NAMED_GLOBAL { Global (Name name) }
|
|
|
|
| id=LOCAL { Local id }
|
|
|
|
| name = NAMED_LOCAL { Local (Name name) }
|
|
|
|
|
|
|
|
| num = NUMBERED_GLOBAL { Global (Number num) }
|
|
|
|
|
|
|
|
| num = NUMBERED_LOCAL { Local (Number num) }
|
|
|
|
|
|
|
|
|
|
|
|
constant:
|
|
|
|
constant:
|
|
|
|
| i=CONSTINT { Cint i }
|
|
|
|
| i = CONSTINT { Cint i }
|
|
|
|
| NULL { Cnull }
|
|
|
|
| NULL { Cnull }
|
|
|
|