Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file primus_greedy_main.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596openCore_kernelopenBap.StdopenBap_primus.StdopenMonads.StdopenFormatincludeSelf()(* continue with the same context, until a path terminates,
then switch to a next thread that is not yet terminated.
*)moduleId=Monad.State.Multi.IdmoduleIds=Id.Settypestate={halted:Ids.t;}letstate=Primus.Machine.State.declare~uuid:"328fd42b-1ffd-44da-8400-8494732dcfa3"~name:"greedy-scheduler-state"(fun_->{halted=Ids.empty})moduleGreedy(Machine:Primus.Machine.S)=structopenMachine.SyntaxmoduleEval=Primus.Interpreter.Make(Machine)letpp_haltedppfhalted=Set.iterhalted~f:(funid->fprintfppf"%a"Machine.Id.ppid)letlast=Seq.fold~init:None~f:(fun_x->Somex)letreschedule()=Machine.Global.getstate>>=fun{halted}->Machine.forks()>>=funforks->letactive=Seq.filterforks~f:(funid->not(Set.memhaltedid))inlettotal=Seq.lengthactive+Set.lengthhaltedinletstage=Set.lengthhalted-1inreport_progress~stage~total();matchlastactivewith|None->info"no more pending machines";Machine.switchMachine.global|Somecid->Machine.current()>>=funpid->info"switch to machine %a from %a"Id.ppcidId.pppid;info"killing previous machine %a"Id.pppid;Machine.killpid>>=fun()->Machine.switchcidlethalt()=Machine.current()>>=funpid->Machine.Global.updatestate~f:(fun{halted}->{halted=Set.addhaltedpid})>>=fun()->reschedule()letinit()=Primus.System.fini>>>haltendletdesc="The greedy scheduling strategy will continue with the same state, \
unless the machine reaches a termination state, i.e., when the \
$(b,next) value in a context becomes $(b,None). In that case \
another alive state that has a $(b,next) value that is not $(b,None) is \
chosen. If such state doesn't exist, then the Machine finally \
terminates. Thus this strategy will perform a depth-first \
traversal of the state tree, and guarantees that all paths \
are explored. The greedy scheduler will attempt to reschedule \
every time a basic block is evaluated."letregisterenabled=ifenabledthenPrimus.Machine.add_component(moduleGreedy)[@warning"-D"];Primus.Components.register_generic"greedy-scheduler"(moduleGreedy)~package:"bap"~desc:("Enables the greedy scheduler. "^desc)openConfig;;let()=manpage[`S"DESCRIPTION";`Pdesc;];;letenabled=flag"scheduler"~doc:"Enable the scheduler."let()=when_ready(fun{get=(!!)}->register!!enabled)