scyther/scripts/if2spdl/Spdl.py

58 lines
1.0 KiB
Python
Raw Normal View History

2005-12-04 14:46:37 +00:00
#!/usr/bin/python
#
# Spdl generator
#
import If
2005-12-04 16:41:43 +00:00
from misc import *
2005-12-04 14:46:37 +00:00
2005-12-04 18:42:24 +00:00
def action(protocol, actiontype, rule, fact):
res = actiontype + "_"
res += str(fact.step)
res += fact.spdl()
res += ";\n"
return res
def processRole(protocol, role):
2005-12-04 14:46:37 +00:00
2005-12-04 18:42:24 +00:00
res = ""
2005-12-04 14:46:37 +00:00
print "Role", role
2005-12-04 18:42:24 +00:00
# initial knowledge
for rule in protocol:
2005-12-04 16:41:43 +00:00
if role in rule.getActors():
2005-12-04 18:42:24 +00:00
for fact in rule.left:
if type(fact) == If.PrincipalFact:
print fact
# derive message sequence
for rule in protocol:
if role in rule.getActors():
for fact in rule.left:
if type(fact) == If.MessageFact:
res += action(protocol, "read", rule, fact)
for fact in rule.right:
2005-12-04 16:41:43 +00:00
if type(fact) == If.MessageFact:
2005-12-04 18:42:24 +00:00
res += action(protocol, "send", rule, fact)
2005-12-04 14:46:37 +00:00
2005-12-04 18:42:24 +00:00
print res
2005-12-04 14:46:37 +00:00
return ""
2005-12-04 18:42:24 +00:00
def getRoles(protocol):
2005-12-04 14:46:37 +00:00
roles = []
2005-12-04 18:42:24 +00:00
for rule in protocol:
2005-12-04 16:41:43 +00:00
roles += rule.getActors()
return uniq(roles)
2005-12-04 14:46:37 +00:00
2005-12-04 18:42:24 +00:00
def generator(protocol):
roles = getRoles(protocol)
print "Found",len(protocol),"rules."
2005-12-04 14:46:37 +00:00
print "Roles:", roles
res = ""
for role in roles:
2005-12-04 18:42:24 +00:00
res += processRole(protocol,role)
2005-12-04 14:46:37 +00:00
return res