import.carbon 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. // --- core.carbon
  7. package Core library "test";
  8. fn TestAdd(a: i32, b: i32) -> i32 = "int.sadd";
  9. // --- use.carbon
  10. import Core library "test";
  11. var arr: [i32; Core.TestAdd(1, 2)] = (1, 2, 3);
  12. // CHECK:STDOUT: --- core.carbon
  13. // CHECK:STDOUT:
  14. // CHECK:STDOUT: constants {
  15. // CHECK:STDOUT: %TestAdd: type = fn_type @TestAdd [template]
  16. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  17. // CHECK:STDOUT: %struct: TestAdd = struct_value () [template]
  18. // CHECK:STDOUT: }
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: file {
  21. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  22. // CHECK:STDOUT: .TestAdd = %TestAdd.decl
  23. // CHECK:STDOUT: }
  24. // CHECK:STDOUT: %TestAdd.decl: TestAdd = fn_decl @TestAdd [template = constants.%struct] {
  25. // CHECK:STDOUT: %a.loc4_12.1: i32 = param a
  26. // CHECK:STDOUT: @TestAdd.%a: i32 = bind_name a, %a.loc4_12.1
  27. // CHECK:STDOUT: %b.loc4_20.1: i32 = param b
  28. // CHECK:STDOUT: @TestAdd.%b: i32 = bind_name b, %b.loc4_20.1
  29. // CHECK:STDOUT: @TestAdd.%return: ref i32 = var <return slot>
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: fn @TestAdd(%a: i32, %b: i32) -> i32 = "int.sadd";
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: --- use.carbon
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: constants {
  38. // CHECK:STDOUT: %TestAdd: type = fn_type @TestAdd [template]
  39. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  40. // CHECK:STDOUT: %struct: TestAdd = struct_value () [template]
  41. // CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
  42. // CHECK:STDOUT: %.3: i32 = int_literal 2 [template]
  43. // CHECK:STDOUT: %.4: i32 = int_literal 3 [template]
  44. // CHECK:STDOUT: %.5: type = array_type %.4, i32 [template]
  45. // CHECK:STDOUT: %.6: type = ptr_type [i32; 3] [template]
  46. // CHECK:STDOUT: %.7: type = tuple_type (i32, i32, i32) [template]
  47. // CHECK:STDOUT: %.8: i32 = int_literal 0 [template]
  48. // CHECK:STDOUT: %array: [i32; 3] = tuple_value (%.2, %.3, %.4) [template]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: file {
  52. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  53. // CHECK:STDOUT: .Core = %Core
  54. // CHECK:STDOUT: .arr = %arr
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  57. // CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, %Core [template = %Core]
  58. // CHECK:STDOUT: %import_ref: TestAdd = import_ref ir2, inst+6, loaded [template = constants.%struct]
  59. // CHECK:STDOUT: %TestAdd.ref: TestAdd = name_ref TestAdd, %import_ref [template = constants.%struct]
  60. // CHECK:STDOUT: %.loc4_29: i32 = int_literal 1 [template = constants.%.2]
  61. // CHECK:STDOUT: %.loc4_32: i32 = int_literal 2 [template = constants.%.3]
  62. // CHECK:STDOUT: %int.sadd: init i32 = call %TestAdd.ref(%.loc4_29, %.loc4_32) [template = constants.%.4]
  63. // CHECK:STDOUT: %.loc4_34: type = array_type %int.sadd, i32 [template = constants.%.5]
  64. // CHECK:STDOUT: %arr.var: ref [i32; 3] = var arr
  65. // CHECK:STDOUT: %arr: ref [i32; 3] = bind_name arr, %arr.var
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: fn @TestAdd(%a: i32, %b: i32) -> i32 = "int.sadd";
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: fn @__global_init() {
  71. // CHECK:STDOUT: !entry:
  72. // CHECK:STDOUT: %.loc4_39: i32 = int_literal 1 [template = constants.%.2]
  73. // CHECK:STDOUT: %.loc4_42: i32 = int_literal 2 [template = constants.%.3]
  74. // CHECK:STDOUT: %.loc4_45: i32 = int_literal 3 [template = constants.%.4]
  75. // CHECK:STDOUT: %.loc4_46.1: (i32, i32, i32) = tuple_literal (%.loc4_39, %.loc4_42, %.loc4_45)
  76. // CHECK:STDOUT: %.loc4_46.2: i32 = int_literal 0 [template = constants.%.8]
  77. // CHECK:STDOUT: %.loc4_46.3: ref i32 = array_index file.%arr.var, %.loc4_46.2
  78. // CHECK:STDOUT: %.loc4_46.4: init i32 = initialize_from %.loc4_39 to %.loc4_46.3 [template = constants.%.2]
  79. // CHECK:STDOUT: %.loc4_46.5: i32 = int_literal 1 [template = constants.%.2]
  80. // CHECK:STDOUT: %.loc4_46.6: ref i32 = array_index file.%arr.var, %.loc4_46.5
  81. // CHECK:STDOUT: %.loc4_46.7: init i32 = initialize_from %.loc4_42 to %.loc4_46.6 [template = constants.%.3]
  82. // CHECK:STDOUT: %.loc4_46.8: i32 = int_literal 2 [template = constants.%.3]
  83. // CHECK:STDOUT: %.loc4_46.9: ref i32 = array_index file.%arr.var, %.loc4_46.8
  84. // CHECK:STDOUT: %.loc4_46.10: init i32 = initialize_from %.loc4_45 to %.loc4_46.9 [template = constants.%.4]
  85. // CHECK:STDOUT: %.loc4_46.11: init [i32; 3] = array_init (%.loc4_46.4, %.loc4_46.7, %.loc4_46.10) to file.%arr.var [template = constants.%array]
  86. // CHECK:STDOUT: %.loc4_47: init [i32; 3] = converted %.loc4_46.1, %.loc4_46.11 [template = constants.%array]
  87. // CHECK:STDOUT: assign file.%arr.var, %.loc4_47
  88. // CHECK:STDOUT: return
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: