call.carbon 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/builtin/call.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/builtin/call.carbon
  10. fn Add(a: i32, b: i32) -> i32 = "int.sadd";
  11. var arr: [i32; Add(1, 2)];
  12. // CHECK:STDOUT: --- call.carbon
  13. // CHECK:STDOUT:
  14. // CHECK:STDOUT: constants {
  15. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  16. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  17. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  18. // CHECK:STDOUT: %Add.type: type = fn_type @Add [template]
  19. // CHECK:STDOUT: %Add: %Add.type = struct_value () [template]
  20. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  21. // CHECK:STDOUT: %.3: i32 = int_literal 2 [template]
  22. // CHECK:STDOUT: %.4: i32 = int_literal 3 [template]
  23. // CHECK:STDOUT: %.5: type = array_type %.4, i32 [template]
  24. // CHECK:STDOUT: %.6: type = ptr_type %.5 [template]
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: imports {
  28. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  29. // CHECK:STDOUT: .Int32 = %import_ref
  30. // CHECK:STDOUT: import Core//prelude
  31. // CHECK:STDOUT: import Core//prelude/operators
  32. // CHECK:STDOUT: import Core//prelude/types
  33. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  34. // CHECK:STDOUT: import Core//prelude/operators/as
  35. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  36. // CHECK:STDOUT: import Core//prelude/operators/comparison
  37. // CHECK:STDOUT: import Core//prelude/types/bool
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: file {
  43. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  44. // CHECK:STDOUT: .Core = imports.%Core
  45. // CHECK:STDOUT: .Add = %Add.decl
  46. // CHECK:STDOUT: .arr = %arr
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %Core.import = import Core
  49. // CHECK:STDOUT: %Add.decl: %Add.type = fn_decl @Add [template = constants.%Add] {
  50. // CHECK:STDOUT: %a.patt: i32 = binding_pattern a
  51. // CHECK:STDOUT: %b.patt: i32 = binding_pattern b
  52. // CHECK:STDOUT: } {
  53. // CHECK:STDOUT: %int.make_type_32.loc11_11: init type = call constants.%Int32() [template = i32]
  54. // CHECK:STDOUT: %.loc11_11.1: type = value_of_initializer %int.make_type_32.loc11_11 [template = i32]
  55. // CHECK:STDOUT: %.loc11_11.2: type = converted %int.make_type_32.loc11_11, %.loc11_11.1 [template = i32]
  56. // CHECK:STDOUT: %a.param: i32 = param a, runtime_param0
  57. // CHECK:STDOUT: %a: i32 = bind_name a, %a.param
  58. // CHECK:STDOUT: %int.make_type_32.loc11_19: init type = call constants.%Int32() [template = i32]
  59. // CHECK:STDOUT: %.loc11_19.1: type = value_of_initializer %int.make_type_32.loc11_19 [template = i32]
  60. // CHECK:STDOUT: %.loc11_19.2: type = converted %int.make_type_32.loc11_19, %.loc11_19.1 [template = i32]
  61. // CHECK:STDOUT: %b.param: i32 = param b, runtime_param1
  62. // CHECK:STDOUT: %b: i32 = bind_name b, %b.param
  63. // CHECK:STDOUT: %int.make_type_32.loc11_27: init type = call constants.%Int32() [template = i32]
  64. // CHECK:STDOUT: %.loc11_27.1: type = value_of_initializer %int.make_type_32.loc11_27 [template = i32]
  65. // CHECK:STDOUT: %.loc11_27.2: type = converted %int.make_type_32.loc11_27, %.loc11_27.1 [template = i32]
  66. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  69. // CHECK:STDOUT: %Add.ref: %Add.type = name_ref Add, %Add.decl [template = constants.%Add]
  70. // CHECK:STDOUT: %.loc13_20: i32 = int_literal 1 [template = constants.%.2]
  71. // CHECK:STDOUT: %.loc13_23: i32 = int_literal 2 [template = constants.%.3]
  72. // CHECK:STDOUT: %int.sadd: init i32 = call %Add.ref(%.loc13_20, %.loc13_23) [template = constants.%.4]
  73. // CHECK:STDOUT: %.loc13_11.1: type = value_of_initializer %int.make_type_32 [template = i32]
  74. // CHECK:STDOUT: %.loc13_11.2: type = converted %int.make_type_32, %.loc13_11.1 [template = i32]
  75. // CHECK:STDOUT: %.loc13_25: type = array_type %int.sadd, i32 [template = constants.%.5]
  76. // CHECK:STDOUT: %arr.var: ref %.5 = var arr
  77. // CHECK:STDOUT: %arr: ref %.5 = bind_name arr, %arr.var
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: fn @Add(%a: i32, %b: i32) -> i32 = "int.sadd";
  83. // CHECK:STDOUT: