print.carbon 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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: %Int32.type: type = fn_type @Int32 [template]
  19. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  20. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  21. // CHECK:STDOUT: %Print.type.1: type = fn_type @Print.1 [template]
  22. // CHECK:STDOUT: %Print.1: %Print.type.1 = 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: %.2: i32 = int_literal 1 [template]
  26. // CHECK:STDOUT: %Print.type.2: type = fn_type @Print.2 [template]
  27. // CHECK:STDOUT: %Print.2: %Print.type.2 = struct_value () [template]
  28. // CHECK:STDOUT: %.3: i32 = int_literal 2 [template]
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: file {
  32. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  33. // CHECK:STDOUT: .Core = %Core
  34. // CHECK:STDOUT: .Print = %Print.decl
  35. // CHECK:STDOUT: .Main = %Main.decl
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  38. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  39. // CHECK:STDOUT: %Print.decl: %Print.type.1 = fn_decl @Print.1 [template = constants.%Print.1] {
  40. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  41. // CHECK:STDOUT: %.loc11_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  42. // CHECK:STDOUT: %.loc11_13.2: type = converted %int.make_type_32, %.loc11_13.1 [template = i32]
  43. // CHECK:STDOUT: %a.loc11_10.1: i32 = param a
  44. // CHECK:STDOUT: @Print.1.%a: i32 = bind_name a, %a.loc11_10.1
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [template = constants.%Main] {}
  47. // CHECK:STDOUT: %import_ref.2: %Print.type.2 = import_ref ir1, inst+42, loaded [template = constants.%Print.2]
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: fn @Print.1(%a: i32) = "print.int";
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: fn @Main() {
  55. // CHECK:STDOUT: !entry:
  56. // CHECK:STDOUT: %Print.ref.loc14: %Print.type.1 = name_ref Print, file.%Print.decl [template = constants.%Print.1]
  57. // CHECK:STDOUT: %.loc14: i32 = int_literal 1 [template = constants.%.2]
  58. // CHECK:STDOUT: %print.int.loc14: init %.1 = call %Print.ref.loc14(%.loc14)
  59. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, file.%Core [template = file.%Core]
  60. // CHECK:STDOUT: %Print.ref.loc16: %Print.type.2 = name_ref Print, file.%import_ref.2 [template = constants.%Print.2]
  61. // CHECK:STDOUT: %.loc16: i32 = int_literal 2 [template = constants.%.3]
  62. // CHECK:STDOUT: %print.int.loc16: init %.1 = call %Print.ref.loc16(%.loc16)
  63. // CHECK:STDOUT: return
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: fn @Print.2(%x: i32) = "print.int";
  67. // CHECK:STDOUT: