basic.carbon 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. class Class {
  7. fn F(n: i32) -> i32 {
  8. return n;
  9. }
  10. fn G(n: i32) -> i32;
  11. var k: i32;
  12. }
  13. fn Class.G(n: i32) -> i32 {
  14. return n;
  15. }
  16. fn Run() -> i32 {
  17. return Class.F(4);
  18. }
  19. // CHECK:STDOUT: --- basic.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  23. // CHECK:STDOUT: %Int32: type = fn_type @Int32 [template]
  24. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  25. // CHECK:STDOUT: %struct.1: Int32 = struct_value () [template]
  26. // CHECK:STDOUT: %F: type = fn_type @F [template]
  27. // CHECK:STDOUT: %struct.2: F = struct_value () [template]
  28. // CHECK:STDOUT: %G: type = fn_type @G [template]
  29. // CHECK:STDOUT: %struct.3: G = struct_value () [template]
  30. // CHECK:STDOUT: %.2: type = unbound_element_type Class, i32 [template]
  31. // CHECK:STDOUT: %.3: type = struct_type {.k: i32} [template]
  32. // CHECK:STDOUT: %Run: type = fn_type @Run [template]
  33. // CHECK:STDOUT: %struct.4: Run = struct_value () [template]
  34. // CHECK:STDOUT: %.4: i32 = int_literal 4 [template]
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: file {
  38. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  39. // CHECK:STDOUT: .Core = %Core
  40. // CHECK:STDOUT: .Class = %Class.decl
  41. // CHECK:STDOUT: .Run = %Run.decl
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  44. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {}
  45. // CHECK:STDOUT: %import_ref.1: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
  46. // CHECK:STDOUT: %import_ref.2: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
  47. // CHECK:STDOUT: %import_ref.3: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
  48. // CHECK:STDOUT: %import_ref.4: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
  49. // CHECK:STDOUT: %import_ref.5: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
  50. // CHECK:STDOUT: %import_ref.6: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
  51. // CHECK:STDOUT: %import_ref.7: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
  52. // CHECK:STDOUT: %G.decl: G = fn_decl @G [template = constants.%struct.3] {
  53. // CHECK:STDOUT: %int.make_type_32.loc17_15: init type = call constants.%struct.1() [template = i32]
  54. // CHECK:STDOUT: %.loc17_15.1: type = value_of_initializer %int.make_type_32.loc17_15 [template = i32]
  55. // CHECK:STDOUT: %.loc17_15.2: type = converted %int.make_type_32.loc17_15, %.loc17_15.1 [template = i32]
  56. // CHECK:STDOUT: %n.loc17_12.1: i32 = param n
  57. // CHECK:STDOUT: @G.%n: i32 = bind_name n, %n.loc17_12.1
  58. // CHECK:STDOUT: %int.make_type_32.loc17_23: init type = call constants.%struct.1() [template = i32]
  59. // CHECK:STDOUT: %.loc17_23.1: type = value_of_initializer %int.make_type_32.loc17_23 [template = i32]
  60. // CHECK:STDOUT: %.loc17_23.2: type = converted %int.make_type_32.loc17_23, %.loc17_23.1 [template = i32]
  61. // CHECK:STDOUT: @G.%return: ref i32 = var <return slot>
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %import_ref.8: Int32 = import_ref ir3, inst+3, loaded [template = constants.%struct.1]
  64. // CHECK:STDOUT: %Run.decl: Run = fn_decl @Run [template = constants.%struct.4] {
  65. // CHECK:STDOUT: %int.make_type_32.loc21: init type = call constants.%struct.1() [template = i32]
  66. // CHECK:STDOUT: %.loc21_13.1: type = value_of_initializer %int.make_type_32.loc21 [template = i32]
  67. // CHECK:STDOUT: %.loc21_13.2: type = converted %int.make_type_32.loc21, %.loc21_13.1 [template = i32]
  68. // CHECK:STDOUT: @Run.%return: ref i32 = var <return slot>
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: class @Class {
  73. // CHECK:STDOUT: %F.decl: F = fn_decl @F [template = constants.%struct.2] {
  74. // CHECK:STDOUT: %int.make_type_32.loc8_11: init type = call constants.%struct.1() [template = i32]
  75. // CHECK:STDOUT: %.loc8_11.1: type = value_of_initializer %int.make_type_32.loc8_11 [template = i32]
  76. // CHECK:STDOUT: %.loc8_11.2: type = converted %int.make_type_32.loc8_11, %.loc8_11.1 [template = i32]
  77. // CHECK:STDOUT: %n.loc8_8.1: i32 = param n
  78. // CHECK:STDOUT: %n.loc8_8.2: i32 = bind_name n, %n.loc8_8.1
  79. // CHECK:STDOUT: %int.make_type_32.loc8_19: init type = call constants.%struct.1() [template = i32]
  80. // CHECK:STDOUT: %.loc8_19.1: type = value_of_initializer %int.make_type_32.loc8_19 [template = i32]
  81. // CHECK:STDOUT: %.loc8_19.2: type = converted %int.make_type_32.loc8_19, %.loc8_19.1 [template = i32]
  82. // CHECK:STDOUT: %return.var.loc8: ref i32 = var <return slot>
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: %G.decl: G = fn_decl @G [template = constants.%struct.3] {
  85. // CHECK:STDOUT: %int.make_type_32.loc12_11: init type = call constants.%struct.1() [template = i32]
  86. // CHECK:STDOUT: %.loc12_11.1: type = value_of_initializer %int.make_type_32.loc12_11 [template = i32]
  87. // CHECK:STDOUT: %.loc12_11.2: type = converted %int.make_type_32.loc12_11, %.loc12_11.1 [template = i32]
  88. // CHECK:STDOUT: %n.loc12_8.1: i32 = param n
  89. // CHECK:STDOUT: %n.loc12_8.2: i32 = bind_name n, %n.loc12_8.1
  90. // CHECK:STDOUT: %int.make_type_32.loc12_19: init type = call constants.%struct.1() [template = i32]
  91. // CHECK:STDOUT: %.loc12_19.1: type = value_of_initializer %int.make_type_32.loc12_19 [template = i32]
  92. // CHECK:STDOUT: %.loc12_19.2: type = converted %int.make_type_32.loc12_19, %.loc12_19.1 [template = i32]
  93. // CHECK:STDOUT: %return.var.loc12: ref i32 = var <return slot>
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: %int.make_type_32.loc14: init type = call constants.%struct.1() [template = i32]
  96. // CHECK:STDOUT: %.loc14_10.1: type = value_of_initializer %int.make_type_32.loc14 [template = i32]
  97. // CHECK:STDOUT: %.loc14_10.2: type = converted %int.make_type_32.loc14, %.loc14_10.1 [template = i32]
  98. // CHECK:STDOUT: %.loc14_8: <unbound element of class Class> = field_decl k, element0 [template]
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: !members:
  101. // CHECK:STDOUT: .Self = constants.%Class
  102. // CHECK:STDOUT: .F = %F.decl
  103. // CHECK:STDOUT: .G = %G.decl
  104. // CHECK:STDOUT: .k = %.loc14_8
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: fn @F(@Class.%n.loc8_8.2: i32) -> i32 {
  110. // CHECK:STDOUT: !entry:
  111. // CHECK:STDOUT: %n.ref: i32 = name_ref n, @Class.%n.loc8_8.2
  112. // CHECK:STDOUT: return %n.ref
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: fn @G(%n: i32) -> i32 {
  116. // CHECK:STDOUT: !entry:
  117. // CHECK:STDOUT: %n.ref: i32 = name_ref n, %n
  118. // CHECK:STDOUT: return %n.ref
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: fn @Run() -> i32 {
  122. // CHECK:STDOUT: !entry:
  123. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  124. // CHECK:STDOUT: %F.ref: F = name_ref F, @Class.%F.decl [template = constants.%struct.2]
  125. // CHECK:STDOUT: %.loc22_18: i32 = int_literal 4 [template = constants.%.4]
  126. // CHECK:STDOUT: %F.call: init i32 = call %F.ref(%.loc22_18)
  127. // CHECK:STDOUT: %.loc22_20.1: i32 = value_of_initializer %F.call
  128. // CHECK:STDOUT: %.loc22_20.2: i32 = converted %F.call, %.loc22_20.1
  129. // CHECK:STDOUT: return %.loc22_20.2
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT: