2015-04-14 20:14:38 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""A ladder graph creation program.
|
|
|
|
|
|
|
|
This is a python program that creates c source code that will generate
|
|
|
|
CFGs that are ladder graphs. Ladder graphs are generally the worst case
|
|
|
|
for a lot of dominance related algorithms (Dominance frontiers, etc),
|
|
|
|
and often generate N^2 or worse behavior.
|
|
|
|
|
|
|
|
One good use of this program is to test whether your linear time algorithm is
|
|
|
|
really behaving linearly.
|
|
|
|
"""
|
|
|
|
|
2019-01-03 15:11:33 +01:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2015-04-14 20:14:38 +02:00
|
|
|
import argparse
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
|
|
parser.add_argument('rungs', type=int,
|
|
|
|
help="Number of ladder rungs. Must be a multiple of 2")
|
|
|
|
args = parser.parse_args()
|
|
|
|
if (args.rungs % 2) != 0:
|
2019-01-03 15:11:33 +01:00
|
|
|
print("Rungs must be a multiple of 2")
|
2015-04-14 20:14:38 +02:00
|
|
|
return
|
2019-01-03 15:11:33 +01:00
|
|
|
print("int ladder(int *foo, int *bar, int x) {")
|
2019-01-03 15:11:58 +01:00
|
|
|
rung1 = range(0, args.rungs, 2)
|
|
|
|
rung2 = range(1, args.rungs, 2)
|
2015-04-14 20:14:38 +02:00
|
|
|
for i in rung1:
|
2019-01-03 15:11:33 +01:00
|
|
|
print("rung1%d:" % i)
|
|
|
|
print("*foo = x++;")
|
2015-04-14 20:14:38 +02:00
|
|
|
if i != rung1[-1]:
|
2019-01-03 15:11:33 +01:00
|
|
|
print("if (*bar) goto rung1%d;" % (i+2))
|
|
|
|
print("else goto rung2%d;" % (i+1))
|
2015-04-14 20:14:38 +02:00
|
|
|
else:
|
2019-01-03 15:11:33 +01:00
|
|
|
print("goto rung2%d;" % (i+1))
|
2015-04-14 20:14:38 +02:00
|
|
|
for i in rung2:
|
2019-01-03 15:11:33 +01:00
|
|
|
print("rung2%d:" % i)
|
|
|
|
print("*foo = x++;")
|
2015-04-14 20:14:38 +02:00
|
|
|
if i != rung2[-1]:
|
2019-01-03 15:11:33 +01:00
|
|
|
print("goto rung2%d;" % (i+2))
|
2015-04-14 20:14:38 +02:00
|
|
|
else:
|
2019-01-03 15:11:33 +01:00
|
|
|
print("return *foo;")
|
|
|
|
print("}")
|
2015-04-14 20:14:38 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|