コード例 #1
0
def CSourceToInputPair(source: str) -> InputPair:
    """Create a graph and bytecode for the given C source string.
  This is a convenience method for generating test inputs. If this method fails,
  it is because graph construction or clang is broken.
  """
    bytecode = CSourceToBytecode(source)
    graph = llvm2graph.BuildProgramGraphNetworkX(bytecode)
    return InputPair(graph=graph, bytecode=bytecode)
コード例 #2
0
def Main():
    irs = [fs.Read(path) for path in LLVM_IR.iterdir()]
    ir_count = len(irs)

    with prof.ProfileToStdout(lambda t: (
            f"STAGE 1: Construct unlabelled graphs (llvm2graph)         "
            f"({humanize.Duration(t / ir_count)} / IR)")):
        graphs = [llvm2graph.BuildProgramGraphNetworkX(ir) for ir in irs]

    encoder = node_encoder.GraphNodeEncoder()
    with prof.ProfileToStdout(lambda t: (
            f"STAGE 2: Encode graphs (inst2vec)                         "
            f"({humanize.Duration(t / ir_count)} / IR)")):
        for graph, ir in zip(graphs, irs):
            encoder.EncodeNodes(graph, ir)

    features_count = 0
    features_lists = []
    with prof.ProfileToStdout(lambda t: (
            f"STAGE 3: Produce labelled graphs (reachability analysis)  "
            f"({humanize.Duration(t / features_count)} / graph)")):
        for graph in graphs:
            analysis = reachability.ReachabilityAnnotator(
                programl.NetworkXToProgramGraph(graph))
            features_list = analysis.MakeAnnotated(n=10).graphs
            features_count += len(features_list)
            features_lists.append(features_list)

    def iter():
        for features_list in features_lists:
            for graph in features_list:
                yield graph_tuple.GraphTuple.CreateFromNetworkX(graph)

    with prof.ProfileToStdout(lambda t: (
            f"STAGE 4: Construct graph tuples                           "
            f"({humanize.Duration(t / features_count)} / graph)")):
        batcher = graph_batcher.GraphBatcher(iter(), max_node_count=10000)
        graph_tuples = list(batcher)

    print("=================================")
    print(f"Unlabelled graphs count: {ir_count}")
    print(f"  Labelled graphs count: {features_count}")
    print(f"     Graph tuples count: {len(graph_tuples)}")
    print(
        f"       Total node count: {sum(gt.node_count for gt in graph_tuples)}"
    )
    print(
        f"       Total edge count: {sum(gt.edge_count for gt in graph_tuples)}"
    )
コード例 #3
0
def llvm_program_graph_nx(llvm_ir: str) -> nx.MultiDiGraph:
  """A test fixture which yields a nx program graph constructed from LLVM IR."""
  return llvm2graph.BuildProgramGraphNetworkX(llvm_ir)
コード例 #4
0
def test_400531():
    """Graph has no exit blocks."""
    llvm2graph.BuildProgramGraphNetworkX(
        fs.Read(REGRESSION_TESTS / "400531.ll"))
コード例 #5
0
def test_4180():
    """Graph takes more than 120 seconds to construct."""
    llvm2graph.BuildProgramGraphNetworkX(fs.Read(REGRESSION_TESTS / "4180.ll"))
コード例 #6
0
def test_115532():
    """Number of callsites does not correlate with callgraph."""
    llvm2graph.BuildProgramGraphNetworkX(
        fs.Read(REGRESSION_TESTS / "115532.ll"))
コード例 #7
0
def test_105975():
    """CFG has BBs without predecessors that need to be removed."""
    llvm2graph.BuildProgramGraphNetworkX(
        fs.Read(REGRESSION_TESTS / "105975.ll"))
コード例 #8
0
def test_53():
    """github.com/ChrisCummins/ProGraML/issues/53"""
    llvm2graph.BuildProgramGraphNetworkX(fs.Read(REGRESSION_TESTS / "53.ll"))