literal.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. #include "toolchain/check/literal.h"
  5. #include "toolchain/check/call.h"
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/check/convert.h"
  8. #include "toolchain/check/name_lookup.h"
  9. #include "toolchain/check/type.h"
  10. namespace Carbon::Check {
  11. auto MakeIntLiteral(Context& context, Parse::NodeId node_id, IntId int_id)
  12. -> SemIR::InstId {
  13. return AddInst<SemIR::IntValue>(
  14. context, node_id,
  15. {.type_id = GetSingletonType(context, SemIR::IntLiteralType::TypeInstId),
  16. .int_id = int_id});
  17. }
  18. auto MakeIntTypeLiteral(Context& context, Parse::NodeId node_id,
  19. SemIR::IntKind int_kind, IntId size_id)
  20. -> SemIR::InstId {
  21. auto width_id = MakeIntLiteral(context, node_id, size_id);
  22. auto fn_inst_id = LookupNameInCore(
  23. context, node_id, int_kind == SemIR::IntKind::Signed ? "Int" : "UInt");
  24. return PerformCall(context, node_id, fn_inst_id, {width_id});
  25. }
  26. auto MakeIntType(Context& context, Parse::NodeId node_id,
  27. SemIR::IntKind int_kind, IntId size_id) -> SemIR::TypeId {
  28. auto type_inst_id = MakeIntTypeLiteral(context, node_id, int_kind, size_id);
  29. return ExprAsType(context, node_id, type_inst_id).type_id;
  30. }
  31. } // namespace Carbon::Check