int.carbon 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. //
  5. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/builtins/read/int.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/read/int.carbon
  10. import Core library "io";
  11. fn ReadChar() -> i32 = "read.char";
  12. fn Main() {
  13. let n: i32 = ReadChar();
  14. let m: i32 = Core.ReadChar();
  15. }
  16. // CHECK:STDOUT: --- int.carbon
  17. // CHECK:STDOUT:
  18. // CHECK:STDOUT: constants {
  19. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  20. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  21. // CHECK:STDOUT: %ReadChar.type.fa8: type = fn_type @ReadChar.1 [template]
  22. // CHECK:STDOUT: %ReadChar.7f4: %ReadChar.type.fa8 = struct_value () [template]
  23. // CHECK:STDOUT: %Main.type: type = fn_type @Main [template]
  24. // CHECK:STDOUT: %Main: %Main.type = struct_value () [template]
  25. // CHECK:STDOUT: %ReadChar.type.9f3: type = fn_type @ReadChar.2 [template]
  26. // CHECK:STDOUT: %ReadChar.01f: %ReadChar.type.9f3 = struct_value () [template]
  27. // CHECK:STDOUT: }
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: imports {
  30. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  31. // CHECK:STDOUT: .Int = %Core.Int
  32. // CHECK:STDOUT: .ReadChar = %Core.ReadChar
  33. // CHECK:STDOUT: import Core//prelude
  34. // CHECK:STDOUT: import Core//io
  35. // CHECK:STDOUT: import Core//prelude/...
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT: %Core.ReadChar: %ReadChar.type.9f3 = import_ref Core//io, ReadChar, loaded [template = constants.%ReadChar.01f]
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: file {
  41. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  42. // CHECK:STDOUT: .Core = imports.%Core
  43. // CHECK:STDOUT: .ReadChar = %ReadChar.decl
  44. // CHECK:STDOUT: .Main = %Main.decl
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: %Core.import = import Core
  47. // CHECK:STDOUT: %ReadChar.decl: %ReadChar.type.fa8 = fn_decl @ReadChar.1 [template = constants.%ReadChar.7f4] {
  48. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  49. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  50. // CHECK:STDOUT: } {
  51. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  52. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  53. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  54. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [template = constants.%Main] {} {}
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: fn @ReadChar.1() -> %i32 = "read.char";
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: fn @Main() {
  62. // CHECK:STDOUT: !entry:
  63. // CHECK:STDOUT: name_binding_decl {
  64. // CHECK:STDOUT: %n.patt: %i32 = binding_pattern n
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: %ReadChar.ref.loc16: %ReadChar.type.fa8 = name_ref ReadChar, file.%ReadChar.decl [template = constants.%ReadChar.7f4]
  67. // CHECK:STDOUT: %read.char.loc16: init %i32 = call %ReadChar.ref.loc16()
  68. // CHECK:STDOUT: %.loc16_10: type = splice_block %i32.loc16 [template = constants.%i32] {
  69. // CHECK:STDOUT: %int_32.loc16: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  70. // CHECK:STDOUT: %i32.loc16: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %.loc16_25.1: ref %i32 = temporary_storage
  73. // CHECK:STDOUT: %.loc16_25.2: ref %i32 = temporary %.loc16_25.1, %read.char.loc16
  74. // CHECK:STDOUT: %n: ref %i32 = bind_name n, %.loc16_25.2
  75. // CHECK:STDOUT: name_binding_decl {
  76. // CHECK:STDOUT: %m.patt: %i32 = binding_pattern m
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  79. // CHECK:STDOUT: %ReadChar.ref.loc17: %ReadChar.type.9f3 = name_ref ReadChar, imports.%Core.ReadChar [template = constants.%ReadChar.01f]
  80. // CHECK:STDOUT: %read.char.loc17: init %i32 = call %ReadChar.ref.loc17()
  81. // CHECK:STDOUT: %.loc17_10: type = splice_block %i32.loc17 [template = constants.%i32] {
  82. // CHECK:STDOUT: %int_32.loc17: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  83. // CHECK:STDOUT: %i32.loc17: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT: %.loc17_30.1: ref %i32 = temporary_storage
  86. // CHECK:STDOUT: %.loc17_30.2: ref %i32 = temporary %.loc17_30.1, %read.char.loc17
  87. // CHECK:STDOUT: %m: ref %i32 = bind_name m, %.loc17_30.2
  88. // CHECK:STDOUT: return
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: