while.carbon 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/while/while.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/while/while.carbon
  10. fn Cond() -> bool;
  11. fn F();
  12. fn G();
  13. fn H();
  14. fn While() {
  15. F();
  16. while (Cond()) {
  17. G();
  18. }
  19. H();
  20. }
  21. // CHECK:STDOUT: --- while.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  25. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  26. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  27. // CHECK:STDOUT: %Cond.type: type = fn_type @Cond [template]
  28. // CHECK:STDOUT: %Cond: %Cond.type = struct_value () [template]
  29. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  30. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  31. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  32. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  33. // CHECK:STDOUT: %H.type: type = fn_type @H [template]
  34. // CHECK:STDOUT: %H: %H.type = struct_value () [template]
  35. // CHECK:STDOUT: %While.type: type = fn_type @While [template]
  36. // CHECK:STDOUT: %While: %While.type = struct_value () [template]
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: imports {
  40. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  41. // CHECK:STDOUT: .Bool = %import_ref
  42. // CHECK:STDOUT: import Core//prelude
  43. // CHECK:STDOUT: import Core//prelude/operators
  44. // CHECK:STDOUT: import Core//prelude/types
  45. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  46. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  47. // CHECK:STDOUT: import Core//prelude/operators/comparison
  48. // CHECK:STDOUT: import Core//prelude/types/bool
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %import_ref: %Bool.type = import_ref Core//prelude/types/bool, inst+2, loaded [template = constants.%Bool]
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: file {
  54. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  55. // CHECK:STDOUT: .Core = imports.%Core
  56. // CHECK:STDOUT: .Cond = %Cond.decl
  57. // CHECK:STDOUT: .F = %F.decl
  58. // CHECK:STDOUT: .G = %G.decl
  59. // CHECK:STDOUT: .H = %H.decl
  60. // CHECK:STDOUT: .While = %While.decl
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: %Core.import = import Core
  63. // CHECK:STDOUT: %Cond.decl: %Cond.type = fn_decl @Cond [template = constants.%Cond] {
  64. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  65. // CHECK:STDOUT: %.loc11_14.1: type = value_of_initializer %bool.make_type [template = bool]
  66. // CHECK:STDOUT: %.loc11_14.2: type = converted %bool.make_type, %.loc11_14.1 [template = bool]
  67. // CHECK:STDOUT: @Cond.%return: ref bool = var <return slot>
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {}
  70. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {}
  71. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {}
  72. // CHECK:STDOUT: %While.decl: %While.type = fn_decl @While [template = constants.%While] {}
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: fn @Bool() -> type = "bool.make_type";
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: fn @Cond() -> bool;
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: fn @F();
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @G();
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: fn @H();
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: fn @While() {
  86. // CHECK:STDOUT: !entry:
  87. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  88. // CHECK:STDOUT: %F.call: init %.1 = call %F.ref()
  89. // CHECK:STDOUT: br !while.cond
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: !while.cond:
  92. // CHECK:STDOUT: %Cond.ref: %Cond.type = name_ref Cond, file.%Cond.decl [template = constants.%Cond]
  93. // CHECK:STDOUT: %Cond.call: init bool = call %Cond.ref()
  94. // CHECK:STDOUT: %.loc19_16.1: bool = value_of_initializer %Cond.call
  95. // CHECK:STDOUT: %.loc19_16.2: bool = converted %Cond.call, %.loc19_16.1
  96. // CHECK:STDOUT: if %.loc19_16.2 br !while.body else br !while.done
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: !while.body:
  99. // CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [template = constants.%G]
  100. // CHECK:STDOUT: %G.call: init %.1 = call %G.ref()
  101. // CHECK:STDOUT: br !while.cond
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: !while.done:
  104. // CHECK:STDOUT: %H.ref: %H.type = name_ref H, file.%H.decl [template = constants.%H]
  105. // CHECK:STDOUT: %H.call: init %.1 = call %H.ref()
  106. // CHECK:STDOUT: return
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: