source: trunk/lib_c/cpp2c/cpp2c.rb @ 3396

Last change on this file since 3396 was 3396, checked in by linmengl, 6 years ago

handle bitblock_iterator.hpp correctly now

  • Property svn:executable set to *
File size: 1.5 KB
Line 
1#!/home/linmengl/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
2
3# Translate Cpp header files to C
4# Change IDISA calling signatures like esimd<8>::mergel into esimd_mergel_8
5# Ruby version 1.9.3
6
7# Opt parse, run me with `ruby cpp2c.rb -h` to see help
8require 'optparse'
9
10options = {:del_origin => false}
11OptionParser.new do |opts|
12        opts.banner = "Translate Cpp header files to C\nUsage: cpp2c.rb cpp_file [options]"
13
14        opts.on("-v", "--[no-]version", "Show version") do
15                puts "cpp2c.rb, Ver 1.0. By Meng Lin"
16                exit
17        end
18
19        opts.on("-o", "--output [OutFile]", String, "Output file") do |o_file|
20                options[:output] = o_file
21        end
22
23        opts.on("-d", "--delete", "Delete original file [Default: NO]") do 
24                options[:del_origin] = true
25        end
26
27        opts.on_tail("-h", "--help", "Show this message") do
28                puts opts
29                exit
30        end
31end.parse!
32
33if ARGV.size != 1
34        puts "Wrong arguments, run with -h to see help info."
35        exit
36end
37
38options[:input] = ARGV[0]
39
40unless options.has_key? :output
41        t = options[:input].gsub(/\.hpp/, ".h").gsub(/\.cpp/, ".c")
42        if t == options[:input]
43                t << ".c"
44        end
45        options[:output] = t
46end
47
48puts "Running with #{options.inspect}"
49
50# Translation Starts here
51
52require_relative 'passes'
53passes = [SharpPass.new, IDISAPass.new,
54                        ConditionWrapPass.new("BLOCK_SIZE", [128, 256]),
55                        ConditionWrapPass.new("FW", [8, 32]), 
56                        ConditionWrapPass1.new("sizeof(scanfield_t)", [1,2,4,8]),
57                        EvaluationPass.new]
58
59passes.each     do |pass|
60        pass.translate options
61        options[:input] = options[:output]
62end
63
64if options[:del_origin]
65        puts `rm #{options[:input]}`   
66end
Note: See TracBrowser for help on using the repository browser.