Add optional alignment argument to alloca, load and store rules.

master
Rohan Jacob-Rao 9 years ago
parent 07d1f8b821
commit b8b62cbcb0

@ -40,8 +40,7 @@ type instr =
| CondBranch of operand * variable * variable | CondBranch of operand * variable * variable
| Load of variable * typ * variable | Load of variable * typ * variable
| Store of operand * typ * variable | Store of operand * typ * variable
| Alloc of variable * typ * int * int (* return variable, element type, | Alloc of variable * typ * int (* return variable, element type, number of elements *)
number of elements, alignment *)
| Binop | Binop
type func_def = FuncDef of variable * typ option * (typ * string) list * instr list type func_def = FuncDef of variable * typ option * (typ * string) list * instr list

@ -123,7 +123,8 @@ rule token = parse
(*| "extractvalue" { EXTRACTVALUE }*) (*| "extractvalue" { EXTRACTVALUE }*)
(*| "insertvalue" { INSERTVALUE }*) (*| "insertvalue" { INSERTVALUE }*)
(* memory access and addressing operations *) (* memory access and addressing operations *)
| "alloca" { ALLOCA } | "align" { ALIGN }
| "alloca" { ALLOCA }
| "load" { LOAD } | "load" { LOAD }
| "store" { STORE } | "store" { STORE }
(*| "fence" { FENCE }*) (*| "fence" { FENCE }*)

@ -93,8 +93,8 @@
(*%token EXTRACTVALUE*) (*%token EXTRACTVALUE*)
(*%token INSERTVALUE*) (*%token INSERTVALUE*)
(* memory access and addressing operations *) (* memory access and addressing operations *)
%token ALIGN (* argument for below operations *)
%token ALLOCA %token ALLOCA
%token ALIGN (* argument for alloca *)
%token LOAD %token LOAD
%token STORE %token STORE
(*%token FENCE*) (*%token FENCE*)
@ -190,17 +190,20 @@ block:
instr: instr:
(* terminator instructions *) (* terminator instructions *)
| 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) }
(* Memory access operations *) (* Memory access operations *)
| var=variable EQUALS ALLOCA tp=typ (*COMMA ALIGN sz=CONSTANT_INT*) { Alloc (var, tp, 1, 1) } | var = variable EQUALS ALLOCA tp = typ option(align) { Alloc (var, tp, 1) }
| var = variable EQUALS LOAD tp = ptr_typ ptr = variable { Load (var, tp, ptr) } | var = variable EQUALS LOAD tp = ptr_typ ptr = variable option(align) { 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 option(align) { 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 *)
| variable EQUALS binop { Binop } | variable EQUALS binop { Binop }
align:
| COMMA ALIGN sz = CONSTANT_INT { sz }
binop: binop:
| ADD arith_options binop_args { () } | ADD arith_options binop_args { () }
| FADD fast_math_flags binop_args { () } | FADD fast_math_flags binop_args { () }

@ -55,7 +55,8 @@ let rec trans_instrs (cfg : Cfg.cfg) (procdesc : Cfg.Procdesc.t)
let new_sil_instr = let new_sil_instr =
Sil.Set (trans_variable var, trans_typ tp, trans_operand op, Sil.dummy_location) in Sil.Set (trans_variable var, trans_typ tp, trans_operand op, Sil.dummy_location) in
(new_sil_instr :: sil_instrs, locals) (new_sil_instr :: sil_instrs, locals)
| Alloc (var, tp, _, _) -> | Alloc (var, tp, num_elems) ->
(* num_elems currently ignored *)
begin match var with begin match var with
| Global (Name var_name) | Local (Name var_name) -> | Global (Name var_name) | Local (Name var_name) ->
let new_local = (Mangled.from_string var_name, trans_typ (Tptr tp)) in let new_local = (Mangled.from_string var_name, trans_typ (Tptr tp)) in

Loading…
Cancel
Save