i32.carbon 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/function/call/i32.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/call/i32.carbon
  10. fn Echo(a: i32) -> i32 {
  11. return a;
  12. }
  13. fn Main() {
  14. var b: i32 = Echo(1);
  15. }
  16. // CHECK:STDOUT: --- i32.carbon
  17. // CHECK:STDOUT:
  18. // CHECK:STDOUT: constants {
  19. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  20. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  21. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  22. // CHECK:STDOUT: %Echo.type: type = fn_type @Echo [template]
  23. // CHECK:STDOUT: %Echo: %Echo.type = struct_value () [template]
  24. // CHECK:STDOUT: %Main.type: type = fn_type @Main [template]
  25. // CHECK:STDOUT: %Main: %Main.type = struct_value () [template]
  26. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  27. // CHECK:STDOUT: }
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: file {
  30. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  31. // CHECK:STDOUT: .Core = %Core
  32. // CHECK:STDOUT: .Echo = %Echo.decl
  33. // CHECK:STDOUT: .Main = %Main.decl
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  36. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  37. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  38. // CHECK:STDOUT: %Echo.decl: %Echo.type = fn_decl @Echo [template = constants.%Echo] {
  39. // CHECK:STDOUT: %int.make_type_32.loc11_12: init type = call constants.%Int32() [template = i32]
  40. // CHECK:STDOUT: %.loc11_12.1: type = value_of_initializer %int.make_type_32.loc11_12 [template = i32]
  41. // CHECK:STDOUT: %.loc11_12.2: type = converted %int.make_type_32.loc11_12, %.loc11_12.1 [template = i32]
  42. // CHECK:STDOUT: %a.loc11_9.1: i32 = param a
  43. // CHECK:STDOUT: @Echo.%a: i32 = bind_name a, %a.loc11_9.1
  44. // CHECK:STDOUT: %int.make_type_32.loc11_20: init type = call constants.%Int32() [template = i32]
  45. // CHECK:STDOUT: %.loc11_20.1: type = value_of_initializer %int.make_type_32.loc11_20 [template = i32]
  46. // CHECK:STDOUT: %.loc11_20.2: type = converted %int.make_type_32.loc11_20, %.loc11_20.1 [template = i32]
  47. // CHECK:STDOUT: @Echo.%return: ref i32 = var <return slot>
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [template = constants.%Main] {}
  50. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: fn @Echo(%a: i32) -> i32 {
  56. // CHECK:STDOUT: !entry:
  57. // CHECK:STDOUT: %a.ref: i32 = name_ref a, %a
  58. // CHECK:STDOUT: return %a.ref
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: fn @Main() {
  62. // CHECK:STDOUT: !entry:
  63. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  64. // CHECK:STDOUT: %.loc16_10.1: type = value_of_initializer %int.make_type_32 [template = i32]
  65. // CHECK:STDOUT: %.loc16_10.2: type = converted %int.make_type_32, %.loc16_10.1 [template = i32]
  66. // CHECK:STDOUT: %b.var: ref i32 = var b
  67. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  68. // CHECK:STDOUT: %Echo.ref: %Echo.type = name_ref Echo, file.%Echo.decl [template = constants.%Echo]
  69. // CHECK:STDOUT: %.loc16_21: i32 = int_literal 1 [template = constants.%.2]
  70. // CHECK:STDOUT: %Echo.call: init i32 = call %Echo.ref(%.loc16_21)
  71. // CHECK:STDOUT: assign %b.var, %Echo.call
  72. // CHECK:STDOUT: return
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: