Skip to content

Commit 8e1cb72

Browse files
authored
fixes C.ABI.Args popn and align_even operators (#1328)
The `popn` was always poping from the first register and `align_even` was also doing `popn` instead of aligning.
1 parent 4263cb1 commit 8e1cb72

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/bap_c/bap_c_abi.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,12 @@ module Arg = struct
330330
| Some (k,x) ->
331331
Some ({self with args = Map.remove self.args k},x)
332332

333-
let popn n self = match Map.split self.args n with
334-
| _,None,_ -> None
335-
| lt,Some (k,x),rt ->
336-
Some ({self with args = Map.add_exn rt k x}, Map.data lt)
333+
let popn n self = match Map.min_elt self.args with
334+
| None -> None
335+
| Some (k,_) -> match Map.split self.args (k+n) with
336+
| _,None,_ -> None
337+
| lt,Some (k,x),rt ->
338+
Some ({self with args = Map.add_exn rt k x}, Map.data lt)
337339

338340
let align n self = match Map.min_elt self.args with
339341
| None -> None
@@ -448,6 +450,7 @@ module Arg = struct
448450
Arg.return res
449451
let pop s n = update s n File.pop
450452
let popn ~n s a = update s a (File.popn n)
453+
let align ~n s a = update s a (File.align n)
451454
let deplet s n = update s n @@ fun s -> Some (File.deplet s,())
452455
end
453456

@@ -504,7 +507,7 @@ module Arg = struct
504507

505508
let align_even file =
506509
let* s = Arg.get () in
507-
Arena.popn ~n:2 s file >>| ignore
510+
Arena.align ~n:2 s file >>| ignore
508511

509512
let deplet file =
510513
let* s = Arg.get () in

lib/bap_c/bap_c_abi.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ end
107107
function. The DSL describes the semantics of argument passing that
108108
is then reified to the [args] structure. The [DSL] is a choice
109109
monad that enables describing the argument passing grammar using
110-
backtracing when the chosen strategy doesn't fit. The [reject ()]
110+
backtracking when the chosen strategy doesn't fit. The [reject ()]
111111
operator will reject the current computation up until the nearest
112112
choice prompt, e.g., in the following example, computations [e1],
113113
[e2], and [e3] are rejected and any side-effects that they might

0 commit comments

Comments
 (0)