【问题标题】:Draw a program dependence graph with graphviz使用 graphviz 绘制程序依赖图
【发布时间】:2018-04-03 00:11:05
【问题描述】:

我正在尝试绘制一个 PDG,但是当我添加数据依赖项时,它会出现格式错误。

我有什么

当我只绘制控件依赖关系时,图表看起来很好:

digraph {
4[label="4. int x=1"];
5[label="5. int y=2"];
6[label="6. while(x>0)"];
8[label="8. x=(y+x)"];
10[label="10. z=x+y"];
ENTRY -> 4[rank=same, splines=line];
ENTRY -> 5[rank=same, splines=line];
ENTRY -> 6[rank=same, splines=line];
ENTRY -> 10[rank=same, splines=line];
6 -> 8[splines=line];
}

当我尝试添加数据依赖关系时,图表格式错误:

digraph {
4[label="4. int x=1"];
5[label="5. int y=2"];
6[label="6. while(x>0)"];
8[label="8. x=(y+x)"];
10[label="10. z=x+y"];
ENTRY -> 4[rank=same, splines=line];
ENTRY -> 5[rank=same, splines=line];
ENTRY -> 6[rank=same, splines=line];
ENTRY -> 10[rank=same, splines=line];
6 -> 8[splines=line];
4 -> 6[style=dashed, splines=curved, color=red];
8 -> 6[style=dashed, splines=curved, color=red];
4 -> 8[style=dashed, splines=curved, color=red];
5 -> 8[style=dashed, splines=curved, color=red];
4 -> 10[style=dashed, splines=curved, color=red];
5 -> 10[style=dashed, splines=curved, color=red];
8 -> 10[style=dashed, splines=curved, color=red];
}

我尝试添加属性“splines=line”来绘制直线(控制部门),但它并没有像预期的那样工作。我还试验了属性“权重”和“排名”...

谁能给我一个提示?是否可以为节点设置顺序? 喜欢: 条目 = 第一行和第一个元素 节点 4 = 第二行和第一个元素 ... 节点 8 = 第三行和第一个元素

预期

【问题讨论】:

    标签: graphviz


    【解决方案1】:

    正确使用rank = same,加上不可见的边缘来保持中间节点的顺序应该会有所帮助:

    digraph so
    {
        splines=true;
    
        4[label="4. int x=1"];
        5[label="5. int y=2"];
        6[label="6. while(x>0)"];
        8[label="8. x=(y+x)"];
        10[label="10. z=x+y"];
    
        { rank = same; 4 5 6 10 }
        ENTRY -> { 4 5 6 10 }
        6 -> 8;
    
        edge[style=dashed, color=red];
        { 4 8 } -> 6;
        { 4 5 } -> 8;
        { 4 5 8 } -> 10;
        // keep graphViz from re-ordering these nodes:
        4 -> 5 -> 6 -> 10[ style = invis ];
    }
    

    产量

    【讨论】:

      猜你喜欢
      • 2021-07-27
      • 1970-01-01
      • 2014-01-16
      • 2019-10-27
      • 2020-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多