3939#include " xls/common/status/ret_check.h"
4040#include " xls/common/status/status_macros.h"
4141#include " xls/dev_tools/extract_interface.h"
42+ #include " xls/interpreter/evaluator_options.h"
4243#include " xls/ir/block_elaboration.h"
4344#include " xls/ir/function.h"
4445#include " xls/ir/function_base.h"
5960#include " xls/jit/type_buffer_metadata.h"
6061#include " xls/jit/type_layout.pb.h"
6162
63+ static constexpr std::string_view kUsage = R"(
64+ aot_compiler <flags>
65+
66+ Compile the given IR file to an object file and a proto file.
67+
68+ If --output_proto/--output_textproto is given and all of --output_object,
69+ --output_llvm_ir, --output_llvm_opt_ir, and --output_asm are not given, the
70+ compilation will not be performed and only the proto will be generated. This is
71+ significantly faster than performing the compilation and can be used to quickly
72+ check the output of the compiler.
73+ )" ;
74+
6275ABSL_FLAG (std::string, input, " " , " Path to the IR to compile." );
6376ABSL_FLAG (std::string, symbol_salt, " " ,
6477 " Additional text to append to symbol names to ensure no collisions." );
@@ -264,11 +277,14 @@ absl::Status RealMain(const std::string& input_ir_path,
264277 }
265278
266279 std::optional<JitObjectCode> object_code;
280+ bool generate_skeleton = !output_object_path && !output_llvm_ir_path &&
281+ !output_llvm_opt_ir_path && !output_asm_path;
267282 JitEvaluatorOptions jit_opts;
268283 jit_opts.set_opt_level (llvm_opt_level)
269284 .set_jit_observer (&obs)
270285 .set_symbol_salt (absl::GetFlag (FLAGS_symbol_salt))
271- .set_include_msan (include_msan);
286+ .set_include_msan (include_msan)
287+ .set_generate_skeleton (generate_skeleton);
272288 if (f->IsFunction ()) {
273289 XLS_ASSIGN_OR_RETURN (
274290 object_code, FunctionJit::CreateObjectCode (
@@ -288,33 +304,35 @@ absl::Status RealMain(const std::string& input_ir_path,
288304 XLS_ASSIGN_OR_RETURN (object_code,
289305 BlockJit::CreateObjectCode (elab, jit_opts));
290306 }
291- AotPackageEntrypointsProto all_entrypoints;
292307 if (output_object_path) {
293308 XLS_RETURN_IF_ERROR (SetFileContents (
294309 *output_object_path, std::string (object_code->object_code .begin (),
295310 object_code->object_code .end ())));
296311 }
297312
298- *all_entrypoints.mutable_data_layout () =
299- object_code->data_layout .getStringRepresentation ();
313+ if (output_proto_path || output_textproto_path) {
314+ AotPackageEntrypointsProto all_entrypoints;
315+ *all_entrypoints.mutable_data_layout () =
316+ object_code->data_layout .getStringRepresentation ();
300317
301- auto context = std::make_unique<llvm::LLVMContext>();
302- LlvmTypeConverter type_converter (context.get (), object_code->data_layout );
303- for (const FunctionEntrypoint& oc : object_code->entrypoints ) {
304- XLS_ASSIGN_OR_RETURN (
305- *all_entrypoints.add_entrypoint (),
306- GenerateEntrypointProto (
307- object_code->package ? object_code->package .get () : package.get (),
308- oc, include_msan, type_converter));
309- }
310- if (output_textproto_path) {
311- std::string text;
312- XLS_RET_CHECK (google::protobuf::TextFormat::PrintToString (all_entrypoints, &text));
313- XLS_RETURN_IF_ERROR (SetFileContents (*output_textproto_path, text));
314- }
315- if (output_proto_path) {
316- XLS_RETURN_IF_ERROR (SetFileContents (*output_proto_path,
317- all_entrypoints.SerializeAsString ()));
318+ auto context = std::make_unique<llvm::LLVMContext>();
319+ LlvmTypeConverter type_converter (context.get (), object_code->data_layout );
320+ for (const FunctionEntrypoint& oc : object_code->entrypoints ) {
321+ XLS_ASSIGN_OR_RETURN (
322+ *all_entrypoints.add_entrypoint (),
323+ GenerateEntrypointProto (
324+ object_code->package ? object_code->package .get () : package.get (),
325+ oc, include_msan, type_converter));
326+ }
327+ if (output_textproto_path) {
328+ std::string text;
329+ XLS_RET_CHECK (google::protobuf::TextFormat::PrintToString (all_entrypoints, &text));
330+ XLS_RETURN_IF_ERROR (SetFileContents (*output_textproto_path, text));
331+ }
332+ if (output_proto_path) {
333+ XLS_RETURN_IF_ERROR (SetFileContents (*output_proto_path,
334+ all_entrypoints.SerializeAsString ()));
335+ }
318336 }
319337 if (output_llvm_ir_path) {
320338 XLS_RETURN_IF_ERROR (
@@ -335,7 +353,7 @@ absl::Status RealMain(const std::string& input_ir_path,
335353} // namespace xls
336354
337355int main (int argc, char ** argv) {
338- xls::InitXls (argv[ 0 ] , argc, argv);
356+ xls::InitXls (kUsage , argc, argv);
339357 std::string input_ir_path = absl::GetFlag (FLAGS_input);
340358 QCHECK (!input_ir_path.empty ()) << " --input must be specified." ;
341359
0 commit comments