Skip to content

Commit

Permalink
Alphabetize
Browse files Browse the repository at this point in the history
  • Loading branch information
zygoloid committed Dec 17, 2024
1 parent 3cc8a9f commit 1a2d734
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion toolchain/check/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
30 changes: 15 additions & 15 deletions toolchain/lower/handle_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 =
Expand Down
8 changes: 4 additions & 4 deletions toolchain/sem_ir/builtin_function_kind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
ValidateSignature<auto(AnyInt)->NoReturn>};

// Prints a single character.
constexpr BuiltinInfo PrintChar = {"print.char",
ValidateSignature<auto(AnyInt)->AnyInt>};

// Prints an integer.
constexpr BuiltinInfo PrintInt = {"print.int",
ValidateSignature<auto(AnyInt)->NoReturn>};

// Reads a single character from stdin.
constexpr BuiltinInfo ReadChar = {"read.char",
ValidateSignature<auto()->AnyInt>};
Expand Down
2 changes: 1 addition & 1 deletion toolchain/sem_ir/builtin_function_kind.def
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1a2d734

Please sign in to comment.