raw_and_textual_ir.carbon 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. // ARGS: compile --phase=check --dump-sem-ir --dump-raw-sem-ir %s
  6. //
  7. // Check that we can combine textual IR and raw IR dumping in one compile.
  8. //
  9. // AUTOUPDATE
  10. fn Foo(n: i32) -> (i32, i32, f64) {
  11. return (n, 2, 3.4);
  12. }
  13. // CHECK:STDOUT: ---
  14. // CHECK:STDOUT: filename: raw_and_textual_ir.carbon
  15. // CHECK:STDOUT: sem_ir:
  16. // CHECK:STDOUT: import_irs_size: 1
  17. // CHECK:STDOUT: name_scopes:
  18. // CHECK:STDOUT: name_scope0: {inst: inst+0, enclosing_scope: name_scope<invalid>, has_error: false, extended_scopes: [], names: {name0: inst+9}}
  19. // CHECK:STDOUT: bind_names:
  20. // CHECK:STDOUT: bindName0: {name: name1, enclosing_scope: name_scope<invalid>}
  21. // CHECK:STDOUT: functions:
  22. // CHECK:STDOUT: function0: {name: name0, enclosing_scope: name_scope0, param_refs: block3, return_type: type4, return_slot: inst+7, body: [block6]}
  23. // CHECK:STDOUT: classes: {}
  24. // CHECK:STDOUT: types:
  25. // CHECK:STDOUT: type0: {constant: template instNamespaceType, value_rep: {kind: copy, type: type0}}
  26. // CHECK:STDOUT: type1: {constant: template instIntType, value_rep: {kind: copy, type: type1}}
  27. // CHECK:STDOUT: type2: {constant: template inst+3, value_rep: {kind: unknown, type: type<invalid>}}
  28. // CHECK:STDOUT: type3: {constant: template instFloatType, value_rep: {kind: copy, type: type3}}
  29. // CHECK:STDOUT: type4: {constant: template inst+5, value_rep: {kind: pointer, type: type5}}
  30. // CHECK:STDOUT: type5: {constant: template inst+8, value_rep: {kind: copy, type: type5}}
  31. // CHECK:STDOUT: type6: {constant: template instFunctionType, value_rep: {kind: copy, type: type6}}
  32. // CHECK:STDOUT: type_blocks:
  33. // CHECK:STDOUT: typeBlock0:
  34. // CHECK:STDOUT: 0: typeTypeType
  35. // CHECK:STDOUT: 1: typeTypeType
  36. // CHECK:STDOUT: 2: typeTypeType
  37. // CHECK:STDOUT: typeBlock1:
  38. // CHECK:STDOUT: 0: type1
  39. // CHECK:STDOUT: 1: type1
  40. // CHECK:STDOUT: 2: type3
  41. // CHECK:STDOUT: typeBlock2:
  42. // CHECK:STDOUT: 0: type1
  43. // CHECK:STDOUT: 1: type1
  44. // CHECK:STDOUT: 2: type3
  45. // CHECK:STDOUT: insts:
  46. // CHECK:STDOUT: inst+0: {kind: Namespace, arg0: name_scope0, arg1: inst<invalid>, type: type0}
  47. // CHECK:STDOUT: inst+1: {kind: Param, arg0: name1, type: type1}
  48. // CHECK:STDOUT: inst+2: {kind: BindName, arg0: bindName0, arg1: inst+1, type: type1}
  49. // CHECK:STDOUT: inst+3: {kind: TupleType, arg0: typeBlock0, type: typeTypeType}
  50. // CHECK:STDOUT: inst+4: {kind: TupleLiteral, arg0: block4, type: type2}
  51. // CHECK:STDOUT: inst+5: {kind: TupleType, arg0: typeBlock1, type: typeTypeType}
  52. // CHECK:STDOUT: inst+6: {kind: Converted, arg0: inst+4, arg1: inst+5, type: typeTypeType}
  53. // CHECK:STDOUT: inst+7: {kind: VarStorage, arg0: nameReturnSlot, type: type4}
  54. // CHECK:STDOUT: inst+8: {kind: PointerType, arg0: type4, type: typeTypeType}
  55. // CHECK:STDOUT: inst+9: {kind: FunctionDecl, arg0: function0, arg1: block5, type: type6}
  56. // CHECK:STDOUT: inst+10: {kind: NameRef, arg0: name1, arg1: inst+2, type: type1}
  57. // CHECK:STDOUT: inst+11: {kind: IntLiteral, arg0: int5, type: type1}
  58. // CHECK:STDOUT: inst+12: {kind: IntLiteral, arg0: int5, type: type1}
  59. // CHECK:STDOUT: inst+13: {kind: RealLiteral, arg0: real0, type: type3}
  60. // CHECK:STDOUT: inst+14: {kind: RealLiteral, arg0: real0, type: type3}
  61. // CHECK:STDOUT: inst+15: {kind: TupleLiteral, arg0: block7, type: type4}
  62. // CHECK:STDOUT: inst+16: {kind: TupleAccess, arg0: inst+7, arg1: element0, type: type1}
  63. // CHECK:STDOUT: inst+17: {kind: InitializeFrom, arg0: inst+10, arg1: inst+16, type: type1}
  64. // CHECK:STDOUT: inst+18: {kind: TupleAccess, arg0: inst+7, arg1: element1, type: type1}
  65. // CHECK:STDOUT: inst+19: {kind: InitializeFrom, arg0: inst+11, arg1: inst+18, type: type1}
  66. // CHECK:STDOUT: inst+20: {kind: TupleAccess, arg0: inst+7, arg1: element2, type: type3}
  67. // CHECK:STDOUT: inst+21: {kind: InitializeFrom, arg0: inst+13, arg1: inst+20, type: type3}
  68. // CHECK:STDOUT: inst+22: {kind: TupleInit, arg0: block8, arg1: inst+7, type: type4}
  69. // CHECK:STDOUT: inst+23: {kind: Converted, arg0: inst+15, arg1: inst+22, type: type4}
  70. // CHECK:STDOUT: inst+24: {kind: ReturnExpr, arg0: inst+23}
  71. // CHECK:STDOUT: constant_values:
  72. // CHECK:STDOUT: inst+0: template inst+0
  73. // CHECK:STDOUT: inst+3: template inst+3
  74. // CHECK:STDOUT: inst+5: template inst+5
  75. // CHECK:STDOUT: inst+6: template inst+5
  76. // CHECK:STDOUT: inst+8: template inst+8
  77. // CHECK:STDOUT: inst+9: template inst+9
  78. // CHECK:STDOUT: inst+11: template inst+12
  79. // CHECK:STDOUT: inst+12: template inst+12
  80. // CHECK:STDOUT: inst+13: template inst+14
  81. // CHECK:STDOUT: inst+14: template inst+14
  82. // CHECK:STDOUT: inst+19: template inst+12
  83. // CHECK:STDOUT: inst+21: template inst+14
  84. // CHECK:STDOUT: inst_blocks:
  85. // CHECK:STDOUT: empty: {}
  86. // CHECK:STDOUT: exports:
  87. // CHECK:STDOUT: 0: inst+9
  88. // CHECK:STDOUT: global_init: {}
  89. // CHECK:STDOUT: block3:
  90. // CHECK:STDOUT: 0: inst+2
  91. // CHECK:STDOUT: block4:
  92. // CHECK:STDOUT: 0: instIntType
  93. // CHECK:STDOUT: 1: instIntType
  94. // CHECK:STDOUT: 2: instFloatType
  95. // CHECK:STDOUT: block5:
  96. // CHECK:STDOUT: 0: inst+1
  97. // CHECK:STDOUT: 1: inst+2
  98. // CHECK:STDOUT: 2: inst+4
  99. // CHECK:STDOUT: 3: inst+6
  100. // CHECK:STDOUT: 4: inst+7
  101. // CHECK:STDOUT: block6:
  102. // CHECK:STDOUT: 0: inst+10
  103. // CHECK:STDOUT: 1: inst+11
  104. // CHECK:STDOUT: 2: inst+13
  105. // CHECK:STDOUT: 3: inst+15
  106. // CHECK:STDOUT: 4: inst+16
  107. // CHECK:STDOUT: 5: inst+17
  108. // CHECK:STDOUT: 6: inst+18
  109. // CHECK:STDOUT: 7: inst+19
  110. // CHECK:STDOUT: 8: inst+20
  111. // CHECK:STDOUT: 9: inst+21
  112. // CHECK:STDOUT: 10: inst+22
  113. // CHECK:STDOUT: 11: inst+23
  114. // CHECK:STDOUT: 12: inst+24
  115. // CHECK:STDOUT: block7:
  116. // CHECK:STDOUT: 0: inst+10
  117. // CHECK:STDOUT: 1: inst+11
  118. // CHECK:STDOUT: 2: inst+13
  119. // CHECK:STDOUT: block8:
  120. // CHECK:STDOUT: 0: inst+17
  121. // CHECK:STDOUT: 1: inst+19
  122. // CHECK:STDOUT: 2: inst+21
  123. // CHECK:STDOUT: block9:
  124. // CHECK:STDOUT: 0: inst+0
  125. // CHECK:STDOUT: 1: inst+9
  126. // CHECK:STDOUT: ...
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: --- raw_and_textual_ir.carbon
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: constants {
  131. // CHECK:STDOUT: %.1: type = tuple_type (type, type, type) [template]
  132. // CHECK:STDOUT: %.2: type = tuple_type (i32, i32, f64) [template]
  133. // CHECK:STDOUT: %.3: type = ptr_type (i32, i32, f64) [template]
  134. // CHECK:STDOUT: %.4: i32 = int_literal 2 [template]
  135. // CHECK:STDOUT: %.5: f64 = real_literal 34e-1 [template]
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: file {
  139. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  140. // CHECK:STDOUT: .Foo = %Foo
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT: %Foo: <function> = fn_decl @Foo [template] {
  143. // CHECK:STDOUT: %n.loc11_8.1: i32 = param n
  144. // CHECK:STDOUT: @Foo.%n: i32 = bind_name n, %n.loc11_8.1
  145. // CHECK:STDOUT: %.loc11_33.1: (type, type, type) = tuple_literal (i32, i32, f64)
  146. // CHECK:STDOUT: %.loc11_33.2: type = converted %.loc11_33.1, constants.%.2 [template = constants.%.2]
  147. // CHECK:STDOUT: @Foo.%return: ref (i32, i32, f64) = var <return slot>
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: fn @Foo(%n: i32) -> %return: (i32, i32, f64) {
  152. // CHECK:STDOUT: !entry:
  153. // CHECK:STDOUT: %n.ref: i32 = name_ref n, %n
  154. // CHECK:STDOUT: %.loc12_14: i32 = int_literal 2 [template = constants.%.4]
  155. // CHECK:STDOUT: %.loc12_17: f64 = real_literal 34e-1 [template = constants.%.5]
  156. // CHECK:STDOUT: %.loc12_20.1: (i32, i32, f64) = tuple_literal (%n.ref, %.loc12_14, %.loc12_17)
  157. // CHECK:STDOUT: %.loc12_20.2: ref i32 = tuple_access %return, element0
  158. // CHECK:STDOUT: %.loc12_20.3: init i32 = initialize_from %n.ref to %.loc12_20.2
  159. // CHECK:STDOUT: %.loc12_20.4: ref i32 = tuple_access %return, element1
  160. // CHECK:STDOUT: %.loc12_20.5: init i32 = initialize_from %.loc12_14 to %.loc12_20.4 [template = constants.%.4]
  161. // CHECK:STDOUT: %.loc12_20.6: ref f64 = tuple_access %return, element2
  162. // CHECK:STDOUT: %.loc12_20.7: init f64 = initialize_from %.loc12_17 to %.loc12_20.6 [template = constants.%.5]
  163. // CHECK:STDOUT: %.loc12_20.8: init (i32, i32, f64) = tuple_init (%.loc12_20.3, %.loc12_20.5, %.loc12_20.7) to %return
  164. // CHECK:STDOUT: %.loc12_20.9: init (i32, i32, f64) = converted %.loc12_20.1, %.loc12_20.8
  165. // CHECK:STDOUT: return %.loc12_20.9
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT: