All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Lib.Krakatau.ssa.graph.pyc Maven / Gradle / Ivy

There is a newer version: 1.1
Show newest version
?
?HRc@s(ddlZddlZddlZejZddlmZmZmZm	Z	m
Z
ddlmZmZddl
mZddlmZddlmZdd	lmZdd
lmZmZddlmZmZmZdefd
??YZdefd??YZd?Zd?Zd?ZdS(i????Ni(t
blockmakertconstraintst
variablegraphtobjtypestsubproc(t	ssa_jumpstssa_opsi(tparseUnboundMethodDescriptor(t
graph_util(topnames(tverifier_types(t
SSA_OBJECTt	SSA_MONAD(tslots_tt
BasicBlocktverifierToSSATypetSSA_VariablecBs/eZd	Zd
dd?Zd?Zd?ZRS(ttypetorigintnametconsttdecltypetcCs1||_||_||_d|_d|_dS(N(RRRtNoneRR(tselfttype_RR((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyt__init__s
				cCs#|jr|jStt|?j?S(N(RtsupertVariablet__str__(R((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyRscCs5|jr|jndtt|??}dj|?S(Nt@sVar {}(Rthextidtformat(RR((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyt__repr__s((stypesoriginsnamesconstsdecltypeN(t__name__t
__module__t	__slots__RRRR"(((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyRs	t	SSA_GraphcBs?eZd\ZZZd?Zd?Zd?Zd?Zd?Z	d?Z
d	?Zd
?Zd?Z
d?Zd
?Zd?Zd?Zejej?Zd?Zd?Zd?Zd?Zd?Zd?ZRS(i????i????i????c	Cs]i|_||_|j|_|jj|_|j}t|j|jj|j?\}}g|D]}|j	|i?^qa}|j
t?}td|d|dg?}|g||_
t|jdgdtj|d??}	tdtf|fg?|	_g|j
D]}
|
dk	r|
^q|	_|	`|j
t?}g|d D]}|j	|i?^qI}t|jdgdtj||g|??}
td|dgd|?|
_g|
_|j
t?|j
t?g}}t|jdgdtj||g|??}td|dgd|?|_g|_|	|
||_|_|_ d|_!dS(Ntmonadtlocalststacktlinestjumpii("t_internstcodetclass_tenvtmethodRt
descriptorRtstatictmakeVarFromVtypetmakeVariableRR
t	inputArgsRtentryKeyRtGototODicttFalsetsuccessorStatesRttempvarstsourceStatest	returnKeytReturntinslotsRt
rethrowKeytRethrowt
entryBlocktreturnBlocktrethrowBlocktblocks(RR-R0t
inputTypestreturnTypestvttfuncArgstfuncInMonadt
entryslotstentrybtxtnewmonadtnewstacktreturnbtrethrowb((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyR5s2			$%'+).	".	cs?|j}tj|jgd??}tt|??}ttjjt	t|???|_t
|j?t
|?ks{t?t|j?t|?kr?t
|j??xF|jD];}x2|j
D]&}|d?kr?|j|?q?q?Wq?W|j?kr	d|_n|j?kr$d|_nx?|jD]?}t?fd?|jj?D??|_|jr}|j?ks}t?n|j?kr.x/|jj?D]}tj||j?|_q?Wd|_q.q.Wg|jD]}|jr?|^q?|_ndS(NcSs
|jj?S(N(R+t
getSuccessors(tblock((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyt_sic3s-|]#\}}|?kr||fVqdS(N((t.0topRS(tkept(s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pys	rs(RERt	tarjanSCCRBtlisttreversedt	itertoolstchaint
from_iterabletmaptsettAssertionErrortlentpredecessorstremovePredPairRCRRDtprocsR8tcallopstitemsttargettretblocktvaluesRR7R+(RtoldtsccsRStpairtproc((RWs9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pytcondenseBlocksZs0	$!(	cs?|jst?g|jD]}|dk	r|^q}x!|jD]}||jj7}qBWtj|d??}t	|??d?ks?t??fd?}xB|jD]7}||j
?|_
||j?|_|j??q?WdS(NcSs|jr|jjSgS(N(Rtparams(tvar((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyRT?scs?g}x?|D]?}?j|j?o8?j|j??}|r?|j|?xT|j?D](}|r[|?kr[|j|?q[q[Wq
?j|j??s
t?q
W|S(N(t
issupersetRot
isdisjointt
getOutputstappendtremoveOutputR`(toldopstnewopsRVtkeeptv(tkeepset(s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyt	filterOps?s
(
(
RdR`R5RRER+RoRttopologicalSortR_tphisR*tfilterVarConstraints(RRMtrootsRSt	reachableR{((Rzs9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pytremoveUnusedVariables{s(cCsOtjt?}x9|jD].}x%|j?D]}||j|?q,WqW|S(N(tcollectionstdefaultdictR_RERRtadd(RtsourcesRStchild((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyt_getSources?s
csO|jst?i}t?}|j?}x\|jD]Q??|krMq5nx6t?jj??}t|?dkr{Pnt?jt	j
?r?Pn|j?\?}t|??dkr?Pn?jj
?j?x??jD]?}t|j?dks?t?|j|j?|f?}}|j||?}||||j?D]/}x&|||kr?|||||?x%?j?jD]}|j|?qW?jj|?qWndS(Nic3s3|])\}}||?kr$?n|fVqdS(N((RURVRj(RSR?(s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pys	?s(RdR`R_R?RER+tgetSuccessorPairsRat
isinstanceRtOnExceptiontpoptunaryConstraintstupdateR}tdicttrvaltgetRtjoinR*RCRDRhR8ReRftreplacePredPairR?tkeystreplaceVars(RtreplacetremovedR?t
successorstjtypetphiRjtnewtuc1tuc2Rmt	successortttbRV((RSR?s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pytmergeSingleSuccessorBlocks?sZ	


!!!/ +cCsx|jD]?}x?|jj?D]?\}}|jdk	r d}|jddkru|j|jkr?|j}q?n+|jddkr?|j?r?d}q?n|dk	r?|jj	|?d|_||_
q?q q Wg|jD]}|jdk	r?|^q?|_q
W|j
?dS(Nitinttobjtnull(RER?RfRRRtmintmaxtisConstNullRuRR}R?t
_conscheck(RRSRptuctnewvalR?((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pytdisconnectConstantVariables?s 	2cCs|j?}x?|jD]?}||d?|jD?ks?t?x?|jD]u}|jdksv|j|jksvt?xE|jj	?D]4\}}|j
dks?||djks?t?q?WqIWqWxL|jD]A}x8|jD]-}t
|jj?t
|j?ks?t?q?Wq?WdS(sSanity checkcSsh|]\}}|?qS(((RUtkR?((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pys	?s	iN(R?RERbR`R}R?RR?R?RfRRdReR_tretoptinputtout(RR?RSR?R?RyRmtcallop((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyR??s#'4cCs?|jst?tj|j|j?}tj|?x?|jD]?}x?|jj?D]?\}}||j	d}|dkr?|j|=|jdk	r?|jj|?d|_nd|_
qUtj||?}||j|9s(R?RER+R?RcRthasattrRoR`R^R?R?R?R_treduceSuccessorsR?Rn(
RR?RSR?R?toldEdgestUCstnewEdgesRMtprunedt	badblockstnewbadtbadpairs((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyt
simplifyJumpssB
	%!		:
cCs
tj|?S(N(tcopy(RRp((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyt_copyVarJscs?t|j?dkst?|jj?d\}}|j|j}}|j?|j}?fd?}tj	|g|?}?|kr?||kr?||kr?||ks?t?|j
|ks?t?i?i?x?|D]?}	td|	j|jfdgdd?}
|
`|
?|	<|jj|
?x0|	jj?D]\}}|j|??|||_q>q>Wq?Wt#|	jt$j%?s?t?|	jj&?}|j ??d	?|j'?D?}|j(??|j)|?||
_x?|
jD]4}|jdks?|j|
j|
jks?t?q?Wq&W?j*|t+f?x"?jD]}??j*|?q8W???|_|_|j|=t$j,?||j?}||j|<|j-j|?t|j?td
?|jD??ks?t?dS(Niics*|jr&|?kr&t|j?dSgS(Ni(Rbtzip(RS(Rg(s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyRTUstkeyR*R+c3s%|]\}}?||fVqdS(N((RURptUC(tvarmap(s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pys	dscsCi|]9\\}}}?j||??j||?|f?qS((R?(RUtsbR?Rp(tblockmapR?(s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pys
us	cSsi|]}||?qS(((RUR?((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pys
?s	cSsh|]}|j?qS((R?(RUR?((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pys	?s	(.RaReR`RfRhR?RgtfallthroughRR|RBRR?RR<RERtR?R?R8R+R?RbR}R?R?R?RtPhiRR*R?R?treplaceOutVarsRsR?Rt
ProcCallOptcloneRRR?t
replaceBlocksRcR9tProcInfoRd(RRmR?t	callblockRhR?tftblocktgetpredstregionRStnewbRpR?tblock2R?R?R?tvalsR?R?RVtoutVarttempmapRltproc2((R?RgR?s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyt
_splitSubProcLsz		6
'
,

3

7	"





	6

c	s?t|j?dkst?|jj?d\}}|j|j?}|j?|j}?fd?}tj	?g|?}?|kr??|kr?||kr?||ks?t??j
|ks?t?g|jjD]}|j|t
f?^q?}	g|	D]??j|k	r??^q?}	?fd?tj|	|?D??x?tj|	|?D]?\?}
|
?kr?|
j|t
fgks?t??fd?|
jD?}n??fd?|
jD?}??|
f}tj?|
||?|_}|
jj|?|j?|
j|?s	csi|]}?|?qS(((RUR?(Rp(s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pys
?s	cs'i|]}??|df|?qS(i((RUR?(tsvarcopyRp(s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pys
?s	cs#i|]}?|?f|?qS(((RURy(RhR?(s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pys
?s	(RaReR`RfRhR?RgR?RR|RBR}R?R9RR[tproductRbRR?RtR?R?R?RR7R+R?R?(RRmR?R?R?R?R?R?R?tskipvarsRSR?R?t
outreplaceR?Ry((RhRR?RgRps9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyt_inlineSubProc?s<		6.("cs?|j?|jsdS|j??i}xZ|jD]O?tj?jg??fd??}|j|ksrt?t|?|??s	trepeatitparentssSWarning, nesting subprocedures detected! This method may take forever to decompile.it	splittingtinlining(R?RdR?RR|RhRBR`t	frozensetR[R?RrReRiRtR?tanyR?RaR?R?(RtregionsR?R?RMty((RmR?s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pytinlineSubprocs?s2
	$%			cOs%t||?}|ddd}|S(Ni(R(RtargstkwargsRptpref((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyR4?scCsq|j||?}t|?}|dk	rm|j|?}|tkritj|?}|j|?|_n|SdS(N(	R?RRR4RRtverifierToSynthetict	_internedR(RtvtypetinitMapRRpttt((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyR3?scCsMy|j|SWn7tk
rHt|j?dkrD||j|s	(RfRR?(tparentRStoutvartdRtpairs((Rs9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pytmakePhiFromODictscCs||jkp||jkS(N(RCRD(RRS((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyt
isTerminalsc-	s?t|??i}x3|D]+}|jtjkr|j||jqen|j;j??|_>|j@}%tA?||%j#|j;d
??|%j#_BxSt-|%j!?D]B\?}&|&dk	r?tA?||&|j;?fd??|&_Bq?q?Wxkt-|%j"?D]Z\?}&|&dk	r:tA?||&|j;?fd??|&_B|&jBjC|&ks?t?q:q:W|`;|`@|%j#g|%j!|%j"}'g|'D]}(|(dk	r?|(jB^q?|_=x^|j=D]S})g|)jDD]}(|(jE^q}*|*s?t2|*?t2|)jCjEg?ks?t?q?WqeWi?fd
?}+x?|D]?}tF|j&?},|`&d|,ks?t?|,g|j=D]})|)jC^q?7},xM|jGD]B}|,|jD7},|,g|jH?D]}|dk	r?|^q?7},q?W|,|jjD7},x!|,D]}(|+|(?|jI|(#s	css?|]5}t|jtj?r|jjtj|?fVqdS(N(R?R+RtDummyRetRgR?(RURS((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pys	'siR'R(R)t	fillvaluecss$|]}t|jj??VqdS(N(R_R?R?(RURV((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pys	Tsc3s-|]#\}}|?kr||fVqdS(N((RUR?Ry(R?(s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pys	VscSs|jS(N(R'(ti((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyRTrscs|j?S(N(R)(R(R?(s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyRTuscs|j?S(N(R((R(R?(s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyRTxscsZ|j|j|jf}y||SWn/tk
rUtj?j|?||<}|SXdS(N(RRRR?RtfromVariableR/(Rpt_cacheR?ttemp(R(s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pytmakeConstraint?s
(NR&RVR	tNEWttarget_typet	push_typeR
tT_OBJECTR.Rt
T_UNINIT_THIStvisitedRtfromInstructionRBRCRDR?R+RR?R8tiNodeR?treturnedFromR`R
R:R?R9tnext_instructionR^R?R)R(R'R
tregisterOutsR;R?RiR[tizip_longestRtmaskst	enumerateReRgRhR?R_tintersectionR?RfRdR	tgetNormalSuccessorstgetExceptSuccessorsR?R<R?R}RbR?R?RRR?RoRRYR*RsR?R?RER,R?(-R-tiNodesR?tnodeRREt	blockDictRStjsrsRdRgR?RhR?tjsrslotstretslotsROt	newlocalsRNtnewslotstzippedtentrytmaskRRMR?tmergedtmerged_slotsRmtopsRVR?toR?texctoutstatetdesttinsRytphivarsRpR?ttypesRtbvars((R?R?Rs9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pytssaFromVerifieds?
1 .
		
8=

6

		
0	
UU"
'

			'.'+6	
#
3

	
(R[R?R?tOrderedDictR8RRRRRRRRtverifier.descriptorsRRR	tverifierR
t	ssa_typesRRR
RRtobjectRR&RR	R8(((s9/home/alex/projects/github/krakatau/Krakatau/ssa/graph.pyts$	($??		




© 2015 - 2025 Weber Informatics LLC | Privacy Policy