@@ -55,12 +55,14 @@ class ConversionRecordVisitor : public AstNodeVisitorWithDefault {
5555 public:
5656 ConversionRecordVisitor (Module* module , TypeInfo* type_info,
5757 bool include_tests, ProcIdFactory proc_id_factory,
58- AstNode* top)
58+ AstNode* top,
59+ std::optional<ResolvedProcAlias> resolved_proc_alias)
5960 : module_(module ),
6061 type_info_ (type_info),
6162 include_tests_(include_tests),
6263 proc_id_factory_(proc_id_factory),
63- top_(top) {}
64+ top_(top),
65+ resolved_proc_alias_(resolved_proc_alias) {}
6466
6567 absl::StatusOr<ConversionRecord> InvocationToConversionRecord (
6668 const Function* f, const Invocation* invocation,
@@ -235,6 +237,30 @@ class ConversionRecordVisitor : public AstNodeVisitorWithDefault {
235237 VLOG (5 ) << " HandleProc " << p->ToString ();
236238 const Function* next_fn = &p->next ();
237239
240+ if (top_ == next_fn && resolved_proc_alias_.has_value ()) {
241+ ProcId proc_id = proc_id_factory_.CreateProcId (
242+ /* parent=*/ std::nullopt , const_cast <Proc*>(p),
243+ /* count_as_new_instance=*/ false );
244+ proc_id.alias_name = resolved_proc_alias_->name ;
245+ XLS_ASSIGN_OR_RETURN (
246+ ConversionRecord config_record,
247+ MakeConversionRecord (
248+ const_cast <Function*>(&p->config ()), top_->owner (),
249+ resolved_proc_alias_->config_type_info , resolved_proc_alias_->env ,
250+ proc_id, /* invocation=*/ nullptr ,
251+ /* is_top=*/ false ));
252+ XLS_ASSIGN_OR_RETURN (
253+ ConversionRecord next_record,
254+ MakeConversionRecord (
255+ const_cast <Function*>(&p->next ()), top_->owner (),
256+ resolved_proc_alias_->next_type_info , resolved_proc_alias_->env ,
257+ proc_id, /* invocation=*/ nullptr ,
258+ /* is_top=*/ true ,
259+ std::make_unique<ConversionRecord>(std::move (config_record))));
260+ records_.push_back (std::move (next_record));
261+ return absl::OkStatus ();
262+ }
263+
238264 // This is required in order to process cross-module spawns; otherwise it
239265 // will never add procs from imported modules to the list of functions to
240266 // convert.
@@ -294,6 +320,9 @@ class ConversionRecordVisitor : public AstNodeVisitorWithDefault {
294320 ProcIdFactory proc_id_factory_;
295321 AstNode* top_;
296322
323+ // The proc alias that was used to specify the top proc, if any.
324+ std::optional<ResolvedProcAlias> resolved_proc_alias_;
325+
297326 std::vector<ConversionRecord> records_;
298327};
299328
@@ -319,23 +348,27 @@ absl::StatusOr<std::vector<ConversionRecord>> GetConversionRecords(
319348 // TODO: https://github.com/google/xls/issues/2078 - properly set
320349 // top instead of setting to nullptr.
321350 ConversionRecordVisitor visitor (module , type_info, include_tests,
322- proc_id_factory, /* top=*/ nullptr );
351+ proc_id_factory, /* top=*/ nullptr ,
352+ /* resolved_proc_alias=*/ std::nullopt );
323353 XLS_RETURN_IF_ERROR (module ->Accept (&visitor));
324354
325355 std::vector<ConversionRecord> records = visitor.records ();
326356 return RemoveFunctionDuplicates (records);
327357}
328358
329359absl::StatusOr<std::vector<ConversionRecord>> GetConversionRecordsForEntry (
330- std::variant<Proc*, Function*> entry, TypeInfo* type_info) {
360+ std::variant<Proc*, Function*> entry, TypeInfo* type_info,
361+ std::optional<ResolvedProcAlias> resolved_proc_alias) {
331362 ProcIdFactory proc_id_factory;
332363 if (std::holds_alternative<Function*>(entry)) {
364+ XLS_RET_CHECK (!resolved_proc_alias.has_value ());
333365 Function* f = std::get<Function*>(entry);
334366 Module* m = f->owner ();
335367 // We are only ever called for tests, so we set include_tests to
336368 // true, and make sure that this function is top.
337369 ConversionRecordVisitor visitor (m, type_info, /* include_tests=*/ true ,
338- proc_id_factory, f);
370+ proc_id_factory, f,
371+ /* resolved_proc_alias=*/ std::nullopt );
339372 XLS_RETURN_IF_ERROR (m->Accept (&visitor));
340373
341374 std::vector<ConversionRecord> records = visitor.records ();
@@ -349,7 +382,8 @@ absl::StatusOr<std::vector<ConversionRecord>> GetConversionRecordsForEntry(
349382 // We are only ever called for tests, so we set include_tests to true,
350383 // and make sure that this proc's next function is top.
351384 ConversionRecordVisitor visitor (m, new_ti, /* include_tests=*/ true ,
352- proc_id_factory, &p->next ());
385+ proc_id_factory, &p->next (),
386+ resolved_proc_alias);
353387 XLS_RETURN_IF_ERROR (m->Accept (&visitor));
354388
355389 std::vector<ConversionRecord> records = visitor.records ();
0 commit comments