basic.carbon 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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: %F: type = fn_type @F [template]
  24. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  25. // CHECK:STDOUT: %struct.1: F = struct_value () [template]
  26. // CHECK:STDOUT: %G: type = fn_type @G [template]
  27. // CHECK:STDOUT: %struct.2: G = struct_value () [template]
  28. // CHECK:STDOUT: %.2: type = unbound_element_type Class, i32 [template]
  29. // CHECK:STDOUT: %.3: type = struct_type {.k: i32} [template]
  30. // CHECK:STDOUT: %Run: type = fn_type @Run [template]
  31. // CHECK:STDOUT: %struct.3: Run = struct_value () [template]
  32. // CHECK:STDOUT: %.4: i32 = int_literal 4 [template]
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: file {
  36. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  37. // CHECK:STDOUT: .Core = %Core
  38. // CHECK:STDOUT: .Class = %Class.decl
  39. // CHECK:STDOUT: .Run = %Run.decl
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  42. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {}
  43. // CHECK:STDOUT: %G.decl: G = fn_decl @G [template = constants.%struct.2] {
  44. // CHECK:STDOUT: %n.loc17_12.1: i32 = param n
  45. // CHECK:STDOUT: @G.%n: i32 = bind_name n, %n.loc17_12.1
  46. // CHECK:STDOUT: @G.%return: ref i32 = var <return slot>
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %Run.decl: Run = fn_decl @Run [template = constants.%struct.3] {
  49. // CHECK:STDOUT: @Run.%return: ref i32 = var <return slot>
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: class @Class {
  54. // CHECK:STDOUT: %F.decl: F = fn_decl @F [template = constants.%struct.1] {
  55. // CHECK:STDOUT: %n.loc8_8.1: i32 = param n
  56. // CHECK:STDOUT: %n.loc8_8.2: i32 = bind_name n, %n.loc8_8.1
  57. // CHECK:STDOUT: %return.var.loc8: ref i32 = var <return slot>
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %G.decl: G = fn_decl @G [template = constants.%struct.2] {
  60. // CHECK:STDOUT: %n.loc12_8.1: i32 = param n
  61. // CHECK:STDOUT: %n.loc12_8.2: i32 = bind_name n, %n.loc12_8.1
  62. // CHECK:STDOUT: %return.var.loc12: ref i32 = var <return slot>
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %.loc14: <unbound element of class Class> = field_decl k, element0 [template]
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: !members:
  67. // CHECK:STDOUT: .Self = constants.%Class
  68. // CHECK:STDOUT: .F = %F.decl
  69. // CHECK:STDOUT: .G = %G.decl
  70. // CHECK:STDOUT: .k = %.loc14
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: fn @F(@Class.%n.loc8_8.2: i32) -> i32 {
  74. // CHECK:STDOUT: !entry:
  75. // CHECK:STDOUT: %n.ref: i32 = name_ref n, @Class.%n.loc8_8.2
  76. // CHECK:STDOUT: return %n.ref
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: fn @G(%n: i32) -> i32 {
  80. // CHECK:STDOUT: !entry:
  81. // CHECK:STDOUT: %n.ref: i32 = name_ref n, %n
  82. // CHECK:STDOUT: return %n.ref
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: fn @Run() -> i32 {
  86. // CHECK:STDOUT: !entry:
  87. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  88. // CHECK:STDOUT: %F.ref: F = name_ref F, @Class.%F.decl [template = constants.%struct.1]
  89. // CHECK:STDOUT: %.loc22_18: i32 = int_literal 4 [template = constants.%.4]
  90. // CHECK:STDOUT: %F.call: init i32 = call %F.ref(%.loc22_18)
  91. // CHECK:STDOUT: %.loc22_20.1: i32 = value_of_initializer %F.call
  92. // CHECK:STDOUT: %.loc22_20.2: i32 = converted %F.call, %.loc22_20.1
  93. // CHECK:STDOUT: return %.loc22_20.2
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: