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
| Load of variable * typ * variable
| Store of operand * typ * variable
| Alloc of variable * typ * int * int (* return variable, element type,
number of elements, alignment *)
| Alloc of variable * typ * int (* return variable, element type, number of elements *)
| Binop
type func_def = FuncDef of variable * typ option * (typ * string) list * instr list

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

@ -93,8 +93,8 @@
(*%token EXTRACTVALUE*)
(*%token INSERTVALUE*)
(* memory access and addressing operations *)
%token ALIGN (* argument for below operations *)
%token ALLOCA
%token ALIGN (* argument for alloca *)
%token LOAD
%token STORE
(*%token FENCE*)
@ -190,17 +190,20 @@ block:
instr:
(* terminator instructions *)
| RET tp=typ op=operand { Ret (Some (tp, op)) }
| RET tp = typ op = operand { Ret (Some (tp, op)) }
| RET VOID { Ret None }
| BR LABEL lbl=variable { UncondBranch lbl }
| BR BIT op=operand COMMA LABEL lbl1=variable COMMA LABEL lbl2=variable { CondBranch (op, lbl1, lbl2) }
| BR LABEL lbl = variable { UncondBranch lbl }
| BR BIT op = operand COMMA LABEL lbl1 = variable COMMA LABEL lbl2 = variable { CondBranch (op, lbl1, lbl2) }
(* Memory access operations *)
| var=variable EQUALS ALLOCA tp=typ (*COMMA ALIGN sz=CONSTANT_INT*) { Alloc (var, tp, 1, 1) }
| 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) }
| var = variable EQUALS ALLOCA tp = typ option(align) { Alloc (var, tp, 1) }
| 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 option(align) { Store (value, val_tp, var) }
(* don't yet know why val_tp and ptr_tp would be different *)
| variable EQUALS binop { Binop }
align:
| COMMA ALIGN sz = CONSTANT_INT { sz }
binop:
| ADD arith_options 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 =
Sil.Set (trans_variable var, trans_typ tp, trans_operand op, Sil.dummy_location) in
(new_sil_instr :: sil_instrs, locals)
| Alloc (var, tp, _, _) ->
| Alloc (var, tp, num_elems) ->
(* num_elems currently ignored *)
begin match var with
| Global (Name var_name) | Local (Name var_name) ->
let new_local = (Mangled.from_string var_name, trans_typ (Tptr tp)) in

Loading…
Cancel
Save