Skip to content

Commit

Permalink
Add Make...Id functions for debugging (#4759)
Browse files Browse the repository at this point in the history
In practice, I am unable to call constructors like `SemIR::InstId` from
a debugger. I first tried to use
https://clang.llvm.org/docs/AttributeReference.html#noinline to make
some non-inline calls to the constructor, but that didn't work:

```
toolchain/sem_ir/dump.cpp:245:23: error: 'noinline' attribute is ignored because there exists no call expression inside the statement [-Werror,-Wignored-attributes]
  245 |   [[clang::noinline]] return InstId(inst);
      |          
```

Co-authored-by: Josh L <[email protected]>
  • Loading branch information
josh11b and josh11b authored Jan 7, 2025
1 parent ccf51ce commit fa9a07b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions toolchain/sem_ir/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,50 @@ LLVM_DUMP_METHOD auto Dump(const File& file, TypeId type_id) -> void {
llvm::errs() << '\n';
}

// Functions that can be used instead of the corresponding constructor, which is
// unavailable during debugging.
LLVM_DUMP_METHOD static auto MakeClassId(int id) -> ClassId {
return ClassId(id);
}
LLVM_DUMP_METHOD static auto MakeConstantId(int id) -> ConstantId {
return ConstantId(id);
}
LLVM_DUMP_METHOD static auto MakeEntityNameId(int id) -> EntityNameId {
return EntityNameId(id);
}
LLVM_DUMP_METHOD static auto MakeFacetTypeId(int id) -> FacetTypeId {
return FacetTypeId(id);
}
LLVM_DUMP_METHOD static auto MakeFunctionId(int id) -> FunctionId {
return FunctionId(id);
}
LLVM_DUMP_METHOD static auto MakeGenericId(int id) -> GenericId {
return GenericId(id);
}
LLVM_DUMP_METHOD static auto MakeImplId(int id) -> ImplId { return ImplId(id); }
LLVM_DUMP_METHOD static auto MakeInstBlockId(int id) -> InstBlockId {
return InstBlockId(id);
}
LLVM_DUMP_METHOD static auto MakeInstId(int id) -> InstId { return InstId(id); }
LLVM_DUMP_METHOD static auto MakeInterfaceId(int id) -> InterfaceId {
return InterfaceId(id);
}
LLVM_DUMP_METHOD static auto MakeNameId(int id) -> NameId { return NameId(id); }
LLVM_DUMP_METHOD static auto MakeNameScopeId(int id) -> NameScopeId {
return NameScopeId(id);
}
LLVM_DUMP_METHOD static auto MakeSpecificId(int id) -> SpecificId {
return SpecificId(id);
}
LLVM_DUMP_METHOD static auto MakeStructTypeFieldsId(int id)
-> StructTypeFieldsId {
return StructTypeFieldsId(id);
}
LLVM_DUMP_METHOD static auto MakeTypeBlockId(int id) -> TypeBlockId {
return TypeBlockId(id);
}
LLVM_DUMP_METHOD static auto MakeTypeId(int id) -> TypeId { return TypeId(id); }

} // namespace Carbon::SemIR

#endif // NDEBUG

0 comments on commit fa9a07b

Please sign in to comment.