int.carbon 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 = %import_ref.187
  32. // CHECK:STDOUT: .ReadChar = %import_ref.12c
  33. // CHECK:STDOUT: import Core//prelude
  34. // CHECK:STDOUT: import Core//io
  35. // CHECK:STDOUT: import Core//prelude/...
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT: %import_ref.12c: %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: %ReadChar.ref.loc16: %ReadChar.type.fa8 = name_ref ReadChar, file.%ReadChar.decl [template = constants.%ReadChar.7f4]
  64. // CHECK:STDOUT: %read.char.loc16: init %i32 = call %ReadChar.ref.loc16()
  65. // CHECK:STDOUT: %.loc16_26.1: %i32 = value_of_initializer %read.char.loc16
  66. // CHECK:STDOUT: %.loc16_26.2: %i32 = converted %read.char.loc16, %.loc16_26.1
  67. // CHECK:STDOUT: %n: %i32 = bind_name n, %.loc16_26.2
  68. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  69. // CHECK:STDOUT: %ReadChar.ref.loc17: %ReadChar.type.9f3 = name_ref ReadChar, imports.%import_ref.12c [template = constants.%ReadChar.01f]
  70. // CHECK:STDOUT: %read.char.loc17: init %i32 = call %ReadChar.ref.loc17()
  71. // CHECK:STDOUT: %.loc17_31.1: %i32 = value_of_initializer %read.char.loc17
  72. // CHECK:STDOUT: %.loc17_31.2: %i32 = converted %read.char.loc17, %.loc17_31.1
  73. // CHECK:STDOUT: %m: %i32 = bind_name m, %.loc17_31.2
  74. // CHECK:STDOUT: return
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: