On Nov 18, 2009, at 5:41 PM, Liu Jian wrote:

Hi, David

but, how to use? maybe need to write javascript?

I looked a little more closely and found that the |write_dot_graph| function isn't really general-purpose, it's more of a demo that prints live range data. I simplified it a bit so that it can print CFGs alone. Here is the resulting Treehydra script. Note that it prints all the CFGs to the same file, simply overwriting them; to get them all you will need to select unique file names.


// Run after CFG-building pass so that we have CFGs.
require({ after_gcc_pass: 'cfg' });

include('gcc_util.js');
include('gcc_print.js');

// Treehyra calls this callback for each function defined.
function process_tree(fndecl) {
  // Get the CFG for the function
  var cfg = function_decl_cfg(fndecl);
  // Write a DOT graph representation of the CFG
  my_write_dot_graph(cfg, 'My CFG', '/tmp/cfg.dot');
}

// I copied this from analysis.js and removed a line that prints out
// live ranges based on a previous analysis.
/** Write a DOT representation of the cfg to the given file. */
function my_write_dot_graph(cfg, name, filename) {
  let content = 'digraph ' + name + ' {\n';
  content += '\tnode [shape="rect", fontname="Helvetica"];\n'
  for (let bb in cfg_bb_iterator(cfg)) {
//content += '\t' + bb.index + '[label="' + bb_label(cfg, bb) + '"];\n';
    let items = [
      bb_label(bb),
      [ isn_display(isn) for (isn in bb_isn_iterator(bb)) ].join('\\n')
    ];
    let label = '{' + items.join('|') + '}';
    // Dot requires escaping with record shapes.
    label = label.replace('>', '\\>')
    label = label.replace('<', '\\<')
content += '\t' + bb.index + '[shape=record,label="' + label + '"];\n'
    for (let bb_succ in bb_succs(bb)) {
      content += '\t' + bb.index + ' -> ' + bb_succ.index + ';\n'
    }
  }
  content += '}\n';
  write_file(filename, content);
}

_______________________________________________
dev-static-analysis mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-static-analysis

Reply via email to