i32.carbon 6.1 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/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: %int_32: Core.IntLiteral = int_value 32 [template]
  20. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  21. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  22. // CHECK:STDOUT: %i32: type = int_type signed, %int_32 [template]
  23. // CHECK:STDOUT: %Echo.type: type = fn_type @Echo [template]
  24. // CHECK:STDOUT: %Echo: %Echo.type = 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: %int_1.1: 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(%int_32) [template]
  30. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  31. // CHECK:STDOUT: %interface.9: <witness> = interface_witness (%Convert.14) [template]
  32. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_1.1, %Convert.14 [template]
  33. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(%int_32) [template]
  34. // CHECK:STDOUT: %int_1.2: %i32 = int_value 1 [template]
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: imports {
  38. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  39. // CHECK:STDOUT: .Int = %import_ref.1
  40. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  41. // CHECK:STDOUT: import Core//prelude
  42. // CHECK:STDOUT: import Core//prelude/...
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: file {
  47. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  48. // CHECK:STDOUT: .Core = imports.%Core
  49. // CHECK:STDOUT: .Echo = %Echo.decl
  50. // CHECK:STDOUT: .Main = %Main.decl
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %Core.import = import Core
  53. // CHECK:STDOUT: %Echo.decl: %Echo.type = fn_decl @Echo [template = constants.%Echo] {
  54. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  55. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, runtime_param0
  56. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  57. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
  58. // CHECK:STDOUT: } {
  59. // CHECK:STDOUT: %int_32.loc11_12: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  60. // CHECK:STDOUT: %int.make_type_signed.loc11_12: init type = call constants.%Int(%int_32.loc11_12) [template = constants.%i32]
  61. // CHECK:STDOUT: %.loc11_12.1: type = value_of_initializer %int.make_type_signed.loc11_12 [template = constants.%i32]
  62. // CHECK:STDOUT: %.loc11_12.2: type = converted %int.make_type_signed.loc11_12, %.loc11_12.1 [template = constants.%i32]
  63. // CHECK:STDOUT: %int_32.loc11_20: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  64. // CHECK:STDOUT: %int.make_type_signed.loc11_20: init type = call constants.%Int(%int_32.loc11_20) [template = constants.%i32]
  65. // CHECK:STDOUT: %.loc11_20.1: type = value_of_initializer %int.make_type_signed.loc11_20 [template = constants.%i32]
  66. // CHECK:STDOUT: %.loc11_20.2: type = converted %int.make_type_signed.loc11_20, %.loc11_20.1 [template = constants.%i32]
  67. // CHECK:STDOUT: %a.param: %i32 = value_param runtime_param0
  68. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  69. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  70. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.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 @Echo(%a.param_patt: %i32) -> %i32 {
  76. // CHECK:STDOUT: !entry:
  77. // CHECK:STDOUT: %a.ref: %i32 = name_ref a, %a
  78. // CHECK:STDOUT: return %a.ref
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @Main() {
  82. // CHECK:STDOUT: !entry:
  83. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  84. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%int_32) [template = constants.%i32]
  85. // CHECK:STDOUT: %.loc16_10.1: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  86. // CHECK:STDOUT: %.loc16_10.2: type = converted %int.make_type_signed, %.loc16_10.1 [template = constants.%i32]
  87. // CHECK:STDOUT: %b.var: ref %i32 = var b
  88. // CHECK:STDOUT: %b: ref %i32 = bind_name b, %b.var
  89. // CHECK:STDOUT: %Echo.ref: %Echo.type = name_ref Echo, file.%Echo.decl [template = constants.%Echo]
  90. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1.1]
  91. // CHECK:STDOUT: %impl.elem0: %Convert.type.2 = interface_witness_access constants.%interface.9, element0 [template = constants.%Convert.14]
  92. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_1, %impl.elem0 [template = constants.%Convert.bound]
  93. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  94. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_1) [template = constants.%int_1.2]
  95. // CHECK:STDOUT: %.loc16_21.1: %i32 = value_of_initializer %int.convert_checked [template = constants.%int_1.2]
  96. // CHECK:STDOUT: %.loc16_21.2: %i32 = converted %int_1, %.loc16_21.1 [template = constants.%int_1.2]
  97. // CHECK:STDOUT: %Echo.call: init %i32 = call %Echo.ref(%.loc16_21.2)
  98. // CHECK:STDOUT: assign %b.var, %Echo.call
  99. // CHECK:STDOUT: return
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: