print.carbon 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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/print.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/builtins/print.carbon
  10. fn Print(a: i32) = "print.int";
  11. fn Main() {
  12. Print(1);
  13. Core.Print(2);
  14. }
  15. // CHECK:STDOUT: --- print.carbon
  16. // CHECK:STDOUT:
  17. // CHECK:STDOUT: constants {
  18. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  19. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  20. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  21. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  22. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  23. // CHECK:STDOUT: %Print.type.1: type = fn_type @Print.1 [template]
  24. // CHECK:STDOUT: %Print.1: %Print.type.1 = struct_value () [template]
  25. // CHECK:STDOUT: %Main.type: type = fn_type @Main [template]
  26. // CHECK:STDOUT: %Main: %Main.type = struct_value () [template]
  27. // CHECK:STDOUT: %.2: Core.IntLiteral = int_value 1 [template]
  28. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  29. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  30. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  31. // CHECK:STDOUT: %.22: <witness> = interface_witness (%Convert.14) [template]
  32. // CHECK:STDOUT: %.23: <bound method> = bound_method %.2, %Convert.14 [template]
  33. // CHECK:STDOUT: %.24: <specific function> = specific_function %.23, @Convert.2(%.1) [template]
  34. // CHECK:STDOUT: %.25: %i32 = int_value 1 [template]
  35. // CHECK:STDOUT: %Print.type.2: type = fn_type @Print.2 [template]
  36. // CHECK:STDOUT: %Print.2: %Print.type.2 = struct_value () [template]
  37. // CHECK:STDOUT: %.26: Core.IntLiteral = int_value 2 [template]
  38. // CHECK:STDOUT: %.27: <bound method> = bound_method %.26, %Convert.14 [template]
  39. // CHECK:STDOUT: %.28: <specific function> = specific_function %.27, @Convert.2(%.1) [template]
  40. // CHECK:STDOUT: %.29: %i32 = int_value 2 [template]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: imports {
  44. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  45. // CHECK:STDOUT: .Int = %import_ref.1
  46. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  47. // CHECK:STDOUT: .Print = %import_ref.38
  48. // CHECK:STDOUT: import Core//prelude
  49. // CHECK:STDOUT: import Core//prelude/...
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %import_ref.38: %Print.type.2 = import_ref Core//prelude, inst+57, loaded [template = constants.%Print.2]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: file {
  55. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  56. // CHECK:STDOUT: .Core = imports.%Core
  57. // CHECK:STDOUT: .Print = %Print.decl
  58. // CHECK:STDOUT: .Main = %Main.decl
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %Core.import = import Core
  61. // CHECK:STDOUT: %Print.decl: %Print.type.1 = fn_decl @Print.1 [template = constants.%Print.1] {
  62. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  63. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, runtime_param0
  64. // CHECK:STDOUT: } {
  65. // CHECK:STDOUT: %.loc11_13.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  66. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc11_13.1) [template = constants.%i32]
  67. // CHECK:STDOUT: %.loc11_13.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  68. // CHECK:STDOUT: %.loc11_13.3: type = converted %int.make_type_signed, %.loc11_13.2 [template = constants.%i32]
  69. // CHECK:STDOUT: %a.param: %i32 = value_param runtime_param0
  70. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [template = constants.%Main] {} {}
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: fn @Print.1(%a.param_patt: %i32) = "print.int";
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: fn @Main() {
  78. // CHECK:STDOUT: !entry:
  79. // CHECK:STDOUT: %Print.ref.loc14: %Print.type.1 = name_ref Print, file.%Print.decl [template = constants.%Print.1]
  80. // CHECK:STDOUT: %.loc14_9.1: Core.IntLiteral = int_value 1 [template = constants.%.2]
  81. // CHECK:STDOUT: %.loc14_9.2: %Convert.type.2 = interface_witness_access constants.%.22, element0 [template = constants.%Convert.14]
  82. // CHECK:STDOUT: %.loc14_9.3: <bound method> = bound_method %.loc14_9.1, %.loc14_9.2 [template = constants.%.23]
  83. // CHECK:STDOUT: %.loc14_9.4: <specific function> = specific_function %.loc14_9.3, @Convert.2(constants.%.1) [template = constants.%.24]
  84. // CHECK:STDOUT: %int.convert_checked.loc14: init %i32 = call %.loc14_9.4(%.loc14_9.1) [template = constants.%.25]
  85. // CHECK:STDOUT: %.loc14_9.5: %i32 = value_of_initializer %int.convert_checked.loc14 [template = constants.%.25]
  86. // CHECK:STDOUT: %.loc14_9.6: %i32 = converted %.loc14_9.1, %.loc14_9.5 [template = constants.%.25]
  87. // CHECK:STDOUT: %print.int.loc14: init %empty_tuple.type = call %Print.ref.loc14(%.loc14_9.6)
  88. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, imports.%Core [template = imports.%Core]
  89. // CHECK:STDOUT: %Print.ref.loc16: %Print.type.2 = name_ref Print, imports.%import_ref.38 [template = constants.%Print.2]
  90. // CHECK:STDOUT: %.loc16_14.1: Core.IntLiteral = int_value 2 [template = constants.%.26]
  91. // CHECK:STDOUT: %.loc16_14.2: %Convert.type.2 = interface_witness_access constants.%.22, element0 [template = constants.%Convert.14]
  92. // CHECK:STDOUT: %.loc16_14.3: <bound method> = bound_method %.loc16_14.1, %.loc16_14.2 [template = constants.%.27]
  93. // CHECK:STDOUT: %.loc16_14.4: <specific function> = specific_function %.loc16_14.3, @Convert.2(constants.%.1) [template = constants.%.28]
  94. // CHECK:STDOUT: %int.convert_checked.loc16: init %i32 = call %.loc16_14.4(%.loc16_14.1) [template = constants.%.29]
  95. // CHECK:STDOUT: %.loc16_14.5: %i32 = value_of_initializer %int.convert_checked.loc16 [template = constants.%.29]
  96. // CHECK:STDOUT: %.loc16_14.6: %i32 = converted %.loc16_14.1, %.loc16_14.5 [template = constants.%.29]
  97. // CHECK:STDOUT: %print.int.loc16: init %empty_tuple.type = call %Print.ref.loc16(%.loc16_14.6)
  98. // CHECK:STDOUT: return
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT: