Permalink
Browse files

Integration of Pretty printer (-f) for IR prepending scope names

  • Loading branch information...
1 parent c65eed5 commit 1cba32b62f5ca13a79bd9e40ac08c417ba5ba9f3 @komax committed Jul 11, 2013
Showing with 31 additions and 0 deletions.
  1. +31 −0 bin/ast
View
31 bin/ast
@@ -10,6 +10,7 @@ options = {
:print_ast => true,
:print_ir => false,
:print_pass => nil,
+ :pretty_ir => true,
:dot_format => false
}
@@ -41,6 +42,10 @@ OptionParser.new do |opts|
opts.on('-p', "--pass #{ir_passes}", ir_passes, 'Dump IR after running a pass') do |pass|
options[:print_pass] = pass
end
+
+ opts.on('-f', '--formatted-ir', 'Pretty printer for IR (without CFG)') do |f|
+ options[:pretty_ir] = f
+ end
opts.on('-s', '--sexp', 'Display the S-Expression for the AST') do |t|
options[:print_sexp] = true
@@ -202,6 +207,32 @@ def ir_setup(root)
[scope, passes]
end
+module IRPrettyPrinter
+
+ def self.ir_instrs(scope, indent="")
+ instrs = scope.instrs.map do |instr|
+ indent + instr.to_s
+ end
+ scope.lexical_scopes.each do |lex_scope|
+ instrs += ir_instrs(lex_scope, indent + "\s" * 4)
+ end
+ instrs
+ end
+
+ def self.print_ir(scope)
+ instrs = ir_instrs(scope)
+ instrs.each do |instr|
+ puts instr
+ end
+ end
+end
+
+if options[:pretty_ir]
+ scope, passes = ir_setup(root)
+ puts "IR:"
+ IRPrettyPrinter.print_ir(scope)
+end
+
if options[:print_pass]
scope, passes = ir_setup(root)
pass_name = options[:print_pass]

0 comments on commit 1cba32b

Please sign in to comment.