public IntegerAttribute<Vertex> getLevels() {
		IntegerAttribute<Vertex> levels = new IntegerAttribute<>("Levels", this.vertices());
		DepthFirstSearch dfs = new DepthFirstSearch(this, this.getSources(), true, true, false);
		Vertex[] topologicalSort = dfs.topologicalSort();
		int numVertices = this.numVertices();
		int i, maxParentLevel;
		Vertex v, parent;
		Set<Vertex> parents;
		try {
			for (i = 0; i < numVertices; i++) {
				levels.setValue(topologicalSort[i], -1);
			}
			for (i = 0; i < numVertices; i++) {
				v = topologicalSort[i];
				parents = this.getParents(v);
				maxParentLevel = -1;
				Iterator<Vertex> iter = parents.iterator();
				while (iter.hasNext()) {
					parent = iter.next();
					if (levels.getValue(parent) > maxParentLevel) {
						maxParentLevel = levels.getValue(parent);
					}
				}
				levels.setValue(v, maxParentLevel + 1);
			}
		}
		catch (ghidra.util.exception.NoValueException exc) {
			Msg.error(this, "Bad set/get in getLevels()");
		}
		return levels;
	}
This method assigns levels in a top-down manner. Sources are on level 0.
Ghidra/Framework/Generic/src/main/java/ghidra/util/graph/DirectedGraph.java