llvm-project
49 строк · 1.4 Кб
1#!/usr/bin/env python
2"""A ladder graph creation program.
3
4This is a python program that creates c source code that will generate
5CFGs that are ladder graphs. Ladder graphs are generally the worst case
6for a lot of dominance related algorithms (Dominance frontiers, etc),
7and often generate N^2 or worse behavior.
8
9One good use of this program is to test whether your linear time algorithm is
10really behaving linearly.
11"""
12
13from __future__ import print_function14
15import argparse16
17
18def main():19parser = argparse.ArgumentParser(description=__doc__)20parser.add_argument(21"rungs", type=int, help="Number of ladder rungs. Must be a multiple of 2"22)23args = parser.parse_args()24if (args.rungs % 2) != 0:25print("Rungs must be a multiple of 2")26return27print("int ladder(int *foo, int *bar, int x) {")28rung1 = range(0, args.rungs, 2)29rung2 = range(1, args.rungs, 2)30for i in rung1:31print("rung1%d:" % i)32print("*foo = x++;")33if i != rung1[-1]:34print("if (*bar) goto rung1%d;" % (i + 2))35print("else goto rung2%d;" % (i + 1))36else:37print("goto rung2%d;" % (i + 1))38for i in rung2:39print("rung2%d:" % i)40print("*foo = x++;")41if i != rung2[-1]:42print("goto rung2%d;" % (i + 2))43else:44print("return *foo;")45print("}")46
47
48if __name__ == "__main__":49main()50