7 usage
="USAGE: voodooc [options] <input file>"
9 Input file denotes the file to compile. The special name '-' causes
10 voodooc to read from standard input. In that case, the -o option is
17 --architecture <architecture>
18 Select target architecture. Use -a help to get a list of
19 supported architectures.
23 --output-format <format>
24 Select output format. Use -a <architecture> -f help to get a list of
25 supported output formats for architecture.
28 Lists the features supported by this implementation. The features
29 are listed in the format <feature name><tab><version>, ordered
30 by feature name. The program exits after printing the list of
31 features; no compilation is performed.
35 Display usage information and exit. No compilation will be performed.
38 --output <output file>
39 --output-file <output file>
40 Set output file name. The special name '-' causes voodooc to write
44 Display version information and exit. No compilation will be performed.
49 architecture
= Voodoo
::Config.default_architecture
50 output_format
= Voodoo
::Config.default_format
54 # Process command line
57 opts
= GetoptLong
.new(
58 ['--help', '-h', GetoptLong
::NO_ARGUMENT ],
59 ['--arch', '--architecture', '-a', GetoptLong
::REQUIRED_ARGUMENT ],
60 ['--features', GetoptLong
::NO_ARGUMENT],
61 ['--output-file', '--output', '-o', GetoptLong
::REQUIRED_ARGUMENT ],
62 ['--output-format', '--format', '-f', GetoptLong
::REQUIRED_ARGUMENT ],
63 ['--version', GetoptLong
::NO_ARGUMENT]
67 opts
.each
do |opt
, arg
|
74 architecture
= arg
.to_sym
79 when '--output-format'
80 output_format
= arg
.to_sym
82 puts
"#{Voodoo::Config::IMPLEMENTATION_NAME} version " +
83 Voodoo
::Config::IMPLEMENTATION_VERSION
88 if architecture
== :help
89 # List supported architectures
90 puts
"Supported architectures:"
91 puts Voodoo
::CodeGenerator.architectures
.map
{|arch
| arch
.to_s
}.sort
95 if output_format
== :help
96 # List supported output formats
97 puts
"Supported output formats for architecture #{architecture}:"
98 puts Voodoo
::CodeGenerator.formats(architecture
).map
{|f
| f
.to_s
}.sort
102 # Select code generator based on output format
104 generator
= Voodoo
::CodeGenerator.get_generator
:architecture => architecture
,
105 :format => output_format
106 rescue NotImplementedError
107 if Voodoo
::CodeGenerator.architecture_supported
? architecture
108 $stderr.puts
"Format #{output_format} is not supported for architecture #{architecture}"
109 $stderr.puts
"Supported formats for #{architecture} are:"
110 $stderr.puts Voodoo
::CodeGenerator.formats(architecture
)
112 $stderr.puts
"Architecture #{architecture} is not supported."
113 $stderr.puts
"Supported architectures are:"
114 $stderr.puts Voodoo
::CodeGenerator.architectures
119 # If requested, show features and exit
121 generator
.features
.to_a
.sort
{|x
,y
| x
[0].to_s
<=> y
[0].to_s
}.each
do |feature
|
122 puts
"#{feature[0]}\t#{feature[1]}"
127 # Get input file name
132 $stderr.puts
"no input files"
134 $stderr.puts
"Too many arguments"
149 $stderr.puts
"The -o option is mandatory when reading from standard input"
153 infile
= open input_file
154 # Set output_file if not already set
155 output_file
= generator
.output_file_name input_file
unless output_file
158 if output_file
== '-'
161 outfile
= open output_file
, 'w'
165 parser
= Voodoo
::Parser.new infile
166 compiler
= Voodoo
::Compiler.new parser
, generator
, outfile
170 if output_file
!= '-'
171 File
::unlink(output_file
) if File
::exists?(output_file
)
174 # If e is a compiler error, iterate over all child errors and
175 # print user-friendly messages. Else, re-raise so that the default
176 # handling is performed.
177 if e
.kind_of
? Voodoo
::Compiler::Error
178 e
.errors
.each
do |error
|
180 if error
.start_line
!= nil
181 message
<< "#{error.start_line}: "
182 if error
.input_name
!= nil
183 message
= "#{error.input_name}:#{message}"
185 message
= "line #{message}"
188 message
<< error
.message
191 $stderr.print
"\n #{error.text.gsub("\n", "\n ")}\n"