diff --git a/toolchain/check/eval.cpp b/toolchain/check/eval.cpp index b90aa8ad814a8..ff4b41cce076c 100644 --- a/toolchain/check/eval.cpp +++ b/toolchain/check/eval.cpp @@ -1107,8 +1107,8 @@ static auto MakeConstantForBuiltinCall(Context& context, SemIRLoc loc, case SemIR::BuiltinFunctionKind::None: CARBON_FATAL("Not a builtin function."); - case SemIR::BuiltinFunctionKind::PrintInt: case SemIR::BuiltinFunctionKind::PrintChar: + case SemIR::BuiltinFunctionKind::PrintInt: case SemIR::BuiltinFunctionKind::ReadChar: { // These are runtime-only builtins. // TODO: Consider tracking this on the `BuiltinFunctionKind`. diff --git a/toolchain/lower/handle_call.cpp b/toolchain/lower/handle_call.cpp index bee2f30ef98ca..f3af55cb769c4 100644 --- a/toolchain/lower/handle_call.cpp +++ b/toolchain/lower/handle_call.cpp @@ -76,6 +76,21 @@ static auto HandleBuiltinCall(FunctionContext& context, SemIR::InstId inst_id, case SemIR::BuiltinFunctionKind::None: CARBON_FATAL("No callee in function call."); + case SemIR::BuiltinFunctionKind::PrintChar: { + auto* i32_type = llvm::IntegerType::getInt32Ty(context.llvm_context()); + llvm::Value* arg_value = context.builder().CreateSExtOrTrunc( + context.GetValue(arg_ids[0]), i32_type); + auto putchar = context.llvm_module().getOrInsertFunction( + "putchar", i32_type, i32_type); + auto* result = context.builder().CreateCall(putchar, {arg_value}); + context.SetLocal( + inst_id, + context.builder().CreateSExtOrTrunc( + result, context.GetType( + context.sem_ir().insts().Get(inst_id).type_id()))); + return; + } + case SemIR::BuiltinFunctionKind::PrintInt: { auto* i32_type = llvm::IntegerType::getInt32Ty(context.llvm_context()); auto* ptr_type = llvm::PointerType::get(context.llvm_context(), 0); @@ -93,21 +108,6 @@ static auto HandleBuiltinCall(FunctionContext& context, SemIR::InstId inst_id, return; } - case SemIR::BuiltinFunctionKind::PrintChar: { - auto* i32_type = llvm::IntegerType::getInt32Ty(context.llvm_context()); - llvm::Value* arg_value = context.builder().CreateSExtOrTrunc( - context.GetValue(arg_ids[0]), i32_type); - auto putchar = context.llvm_module().getOrInsertFunction( - "putchar", i32_type, i32_type); - auto* result = context.builder().CreateCall(putchar, {arg_value}); - context.SetLocal( - inst_id, - context.builder().CreateSExtOrTrunc( - result, context.GetType( - context.sem_ir().insts().Get(inst_id).type_id()))); - return; - } - case SemIR::BuiltinFunctionKind::ReadChar: { auto* i32_type = llvm::IntegerType::getInt32Ty(context.llvm_context()); auto getchar = diff --git a/toolchain/sem_ir/builtin_function_kind.cpp b/toolchain/sem_ir/builtin_function_kind.cpp index a092dda03146a..915c9cc9d6af2 100644 --- a/toolchain/sem_ir/builtin_function_kind.cpp +++ b/toolchain/sem_ir/builtin_function_kind.cpp @@ -195,14 +195,14 @@ using FloatT = TypeParam<0, AnyFloat>; // Not a builtin function. constexpr BuiltinInfo None = {"", nullptr}; -// Prints an argument. -constexpr BuiltinInfo PrintInt = {"print.int", - ValidateSignatureNoReturn>}; - // Prints a single character. constexpr BuiltinInfo PrintChar = {"print.char", ValidateSignatureAnyInt>}; +// Prints an integer. +constexpr BuiltinInfo PrintInt = {"print.int", + ValidateSignatureNoReturn>}; + // Reads a single character from stdin. constexpr BuiltinInfo ReadChar = {"read.char", ValidateSignatureAnyInt>}; diff --git a/toolchain/sem_ir/builtin_function_kind.def b/toolchain/sem_ir/builtin_function_kind.def index e4a47978a9918..d74d755da45f2 100644 --- a/toolchain/sem_ir/builtin_function_kind.def +++ b/toolchain/sem_ir/builtin_function_kind.def @@ -19,8 +19,8 @@ CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(None) // Temporary builtins for primitive IO. -CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(PrintInt) CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(PrintChar) +CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(PrintInt) CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(ReadChar) // Type factories.