Good algorithm for generating call graphs?

I am writing code to generate call graphs for a specific intermediate representation without executing it by static scanning of the IR code . The IR code itself is not too complicated, and I understand well what function call sequences look like this, so all I need to do is track calls. I am currently doing this as follows:

  • Keep track of where we are
  • If we meet a function call, go to this place, execute and return
  • While branching places an edge between the caller and the callee

I am pleased with where I am, but I want to make sure that I do not reinvent the wheel here and do not encounter angular matters. I am wondering if there are any acceptable good algorithms (and / or design patterns) that do this efficiently?

UPDATE: IR code is a disassembler with byte code in a Java language like Java, and looks like a Jasmine specification .

+3
source share
2 answers

Scientifically, here are some considerations:

  • /? , , , , . , . , , , " " " ".

  • . IR , , , . , , .

  • , (, , ). , (.. - "" , ).

.

6 :

, :

  • . , , . , , . : , ArrayList<A>, class B extends A. A B. x.foo() x , foo() - A B. , , , A.foo, B.foo .
+4

, pycallgraph . . .

+2

Source: https://habr.com/ru/post/1796593/


All Articles