blob: 89dec36b8372b0b08ddaef9dc44cdaf258f47b62 [file] [log] [blame]
Reid Spencere497ff12006-05-30 19:56:31 +00001=pod
2
3=head1 NAME
4
Reid Spencer48f70682006-08-10 21:02:25 +00005llvm2xpp - LLVM bytecode to LLVM C++ IR translator
Reid Spencere497ff12006-05-30 19:56:31 +00006
7=head1 SYNOPSIS
8
9B<llvm2cpp> [I<options>] [I<filename>]
10
11=head1 DESCRIPTION
12
Reid Spencer48f70682006-08-10 21:02:25 +000013B<llvm2cpp> translates from LLVM bytecode (.bc files) to a
Reid Spencere497ff12006-05-30 19:56:31 +000014corresponding C++ source file that will make calls against the LLVM C++ API to
15build the same module as the input. By default, the C++ output is a complete
16program that builds the module, verifies it and then emits the module as
Reid Spencer48f70682006-08-10 21:02:25 +000017LLVM assembly. This technique assists with testing because the input to
Reid Spencere497ff12006-05-30 19:56:31 +000018B<llvm2cpp> and the output of the generated C++ program should be identical.
19
20If F<filename> is omitted or is C<->, then B<llvm2cpp> reads its input from
21standard input.
22
23If an output file is not specified with the B<-o> option, then
Reid Spencer48f70682006-08-10 21:02:25 +000024B<llvm2cpp> sends its output to a file or standard output by following
Reid Spencere497ff12006-05-30 19:56:31 +000025these rules:
26
27=over
28
29=item *
30
31If the input is standard input, then the output is standard output.
32
33=item *
34
Reid Spencer48f70682006-08-10 21:02:25 +000035If the input is a file that ends with C<.bc>, then the output file is of
Reid Spencere497ff12006-05-30 19:56:31 +000036the same name, except that the suffix is changed to C<.cpp>.
37
38=item *
39
Reid Spencer48f70682006-08-10 21:02:25 +000040If the input is a file that does not end with the C<.bc> suffix, then the
Reid Spencere497ff12006-05-30 19:56:31 +000041output file has the same name as the input file, except that the C<.cpp>
42suffix is appended.
43
44=back
45
46=head1 OPTIONS
47
48=over
49
50=item B<-f>
51
52Force overwrite. Normally, B<llvm2cpp> will refuse to overwrite an
53output file that already exists. With this option, B<llvm2cpp>
54will overwrite the output file and replace it with new C++ source code.
55
56=item B<--help>
57
58Print a summary of command line options.
59
Reid Spencer178a8152006-05-31 17:32:21 +000060=item B<-f>
61
62Normally, B<llvm2cpp> will not overwrite an existing output file. With this
63option, that default behavior is changed and the program will overwrite existing
64output files.
65
Reid Spencere497ff12006-05-30 19:56:31 +000066=item B<-o> F<filename>
67
68Specify the output file name. If F<filename> is C<->, then B<llvm2cpp>
69sends its output to standard output.
70
Reid Spencera0b85152006-05-30 21:19:29 +000071=item B<-funcname> F<functionName>
72
73Specify the name of the function to be generated. The generated code contains a
74single function that produces the input module. By default its name is
75I<makeLLVMModule>. The B<-funcname> option overrides this default and allows
76you to control the name of the generated function. This is handy in conjunction
77with the B<-fragment> option when you only want B<llvm2cpp> to generate a
78single function that produces the module. With both options, such generated code
79could be I<#included> into another program.
80
Reid Spencer178a8152006-05-31 17:32:21 +000081=item B<-for>
Reid Spencera0b85152006-05-30 21:19:29 +000082
Reid Spencer178a8152006-05-31 17:32:21 +000083Specify the name of the thing for which C++ code should be generated. By default
84the entire input module is re-generated. However, use of the various B<-gen-*>
85options can restrict what is produced. This option indicates what that
86restriction is.
87
88=item B<-gen-program>
89
90Specify that the output should be a complete program. Such program will recreate
91B<llvm2cpp>'s input as an LLVM module, verify that module, and then write out
92the module in LLVM assembly format. This is useful for doing identity tests
93where the output of the generated program is identical to the input to
94B<llvm2cpp>. The LLVM DejaGnu test suite can make use of this fact. This is the
95default form of generated output.
96
97If the B<-for> option is given with this option, it specifies the module
98identifier to use for the module created.
99
100=item B<-gen-module>
101
102Specify that the output should be a function that regenerates the module. It is
103assumed that this output will be #included into another program that has already
104arranged for the correct header files to be #included. The function generated
105takes no arguments and returns a I<Module*>.
106
107If the B<-for> option is given with this option, it specifies the module
108identifier to use in creating the module returned by the generated function.
109
110=item B<-gen-contents>
111
112Specify that the output should be a function that adds the contents of the input
113module to another module. It is assumed that the output will be #included into
114another program that has already arranged for the correct header files to be
115#included. The function generated takes a single argument of type I<Module*> and
116returns that argument. Note that Module level attributes such as endianess,
117pointer size, target triple and inline asm are not passed on from the input
118module to the destination module. Only the sub-elements of the module (types,
119constants, functions, global variables) will be added to the input module.
120
121If the B<-for> option is given with this option, it specifies the module
122identifier to set in the input module by the generated function.
123
124=item B<-gen-function>
125
126Specify that the output should be a function that produces the definitions
127necessary for a specific function to be added to a module. It is assumed that
128the output will be #included into another program that has already arranged
129for the correct header files to be #included. The function generated takes a
130single argument of type I<Module*> and returns the I<Function*> that it added to
131the module. Note that only those things (types, constants, etc.) directly
132needed in the definition of the function will be placed in the generated
133function.
134
135The B<-for> option must be given with this option or an error will be produced.
136The value of the option must be the name of a function in the input module for
137which code should be generated. If the named function does not exist an error
138will be produced.
139
Reid Spencer8f5591a2006-06-01 23:46:30 +0000140=item B<-gen-inline>
141
142This option is very analagous to B<-gen-function> except that the generated
143function will not re-produce the target function's definition. Instead, the body
144of the target function is inserted into some other function passed as an
145argument to the generated function. Similarly any arguments to the function must
146be passed to the generated function. The result of the generated function is the
147first basic block of the target function.
148
149The B<-for> option works the same way as it does for B<-gen-function>.
150
Reid Spencer178a8152006-05-31 17:32:21 +0000151=item B<-gen-variable>
152
153Specify that the output should be a function that produces the definitions
154necessary for a specific global variable to be added to a module. It is assumed
155that the output will be #included into another program that has already arranged
156for the correct header files to be #included. The function generated takes a
157single argument of type I<Module*> and returns the I<GlobalVariable*> that it
158added to the module. Note that only those things (types, constants, etc.)
159directly needed in the definition of the global variable will be placed in the
160generated function.
161
162The B<-for> option must be given with this option or an error will be produced.
163THe value of the option must be the name of a global variable in the input
164module for which code should be generated. If the named global variable does not
165exist an error will be produced.
166
167=item B<-gen-type>
168
169Specify that the output should be a function that produces the definitions
170necessary for specific type to be added to a module. It is assumed that the
171otuput will be #included into another program that has already arranged for the
172correct header files to be #included. The function generated take a single
173argument of type I<Module*> and returns the I<Type*> that it added to the
174module. Note that the generated function will only add the necessary type
175definitions to (possibly recursively) define the requested type.
176
177The B<-for> option must be given with this option or an error will be produced.
178The value of the option must be the name of a global type in the input module
179for which code should be generated. If the named type does not exist an error
180will be produced.
181
182=item B<-stats>
183
184Show pass statistics (not interesting in this program).
185
186=item B<-time-passes>
187
188Show pass timing statistics (not interesting in this program).
189
190=item B<-version>
191
192Show the version number of this program.
Reid Spencera0b85152006-05-30 21:19:29 +0000193
Reid Spencere497ff12006-05-30 19:56:31 +0000194=back
195
196=head1 EXIT STATUS
197
198If B<llvm2cpp> succeeds, it will exit with 0. Otherwise, if an error
199occurs, it will exit with a non-zero value.
200
201=head1 SEE ALSO
202
Reid Spencer178a8152006-05-31 17:32:21 +0000203L<llvm-as|llvm-as> L<tblgen|tblgen>
Reid Spencere497ff12006-05-30 19:56:31 +0000204
205=head1 AUTHORS
206
Reid Spencer178a8152006-05-31 17:32:21 +0000207Written by Reid Spencer (L<http://hlvm.org>).
Reid Spencere497ff12006-05-30 19:56:31 +0000208
209=cut