import_ir.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TOOLCHAIN_SEM_IR_IMPORT_IR_H_
  5. #define CARBON_TOOLCHAIN_SEM_IR_IMPORT_IR_H_
  6. #include "llvm/ADT/FoldingSet.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. #include "toolchain/sem_ir/inst.h"
  9. namespace Carbon::SemIR {
  10. // A reference to an imported IR.
  11. struct ImportIR : public Printable<ImportIR> {
  12. auto Print(llvm::raw_ostream& out) const -> void {
  13. out << "{decl_id: " << decl_id
  14. << ", is_export: " << (is_export ? "true" : "false") << "}";
  15. }
  16. // The `import` declaration.
  17. InstId decl_id;
  18. // True if this is part of an `export import`.
  19. bool is_export;
  20. // The imported IR.
  21. const File* sem_ir;
  22. };
  23. static_assert(sizeof(ImportIR) == 8 + sizeof(uintptr_t), "Unexpected size");
  24. // A reference to an instruction in an imported IR. Used for diagnostics with
  25. // LocId.
  26. struct ImportIRInst : public Printable<ImportIRInst> {
  27. auto Print(llvm::raw_ostream& out) const -> void {
  28. out << "{ir_id: " << ir_id << ", inst_id: " << inst_id << "}";
  29. }
  30. friend auto operator==(const ImportIRInst& lhs, const ImportIRInst& rhs)
  31. -> bool {
  32. return lhs.ir_id == rhs.ir_id && lhs.inst_id == rhs.inst_id;
  33. }
  34. ImportIRId ir_id;
  35. InstId inst_id;
  36. };
  37. } // namespace Carbon::SemIR
  38. #endif // CARBON_TOOLCHAIN_SEM_IR_IMPORT_IR_H_