raw_and_textual_ir.carbon 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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: cross_ref_irs_size: 1
  17. // CHECK:STDOUT: functions:
  18. // CHECK:STDOUT: function0: {name: name0, param_refs: block1, return_type: type4, return_slot: inst+6, body: [block4]}
  19. // CHECK:STDOUT: classes: {}
  20. // CHECK:STDOUT: types:
  21. // CHECK:STDOUT: type0: {inst: instNamespaceType, value_rep: {kind: copy, type: type0}}
  22. // CHECK:STDOUT: type1: {inst: instIntType, value_rep: {kind: copy, type: type1}}
  23. // CHECK:STDOUT: type2: {inst: inst+2, value_rep: {kind: unknown, type: type<invalid>}}
  24. // CHECK:STDOUT: type3: {inst: instFloatType, value_rep: {kind: copy, type: type3}}
  25. // CHECK:STDOUT: type4: {inst: inst+4, value_rep: {kind: pointer, type: type5}}
  26. // CHECK:STDOUT: type5: {inst: inst+7, value_rep: {kind: copy, type: type5}}
  27. // CHECK:STDOUT: type6: {inst: instFunctionType, value_rep: {kind: copy, type: type6}}
  28. // CHECK:STDOUT: type_blocks:
  29. // CHECK:STDOUT: typeBlock0:
  30. // CHECK:STDOUT: 0: typeTypeType
  31. // CHECK:STDOUT: 1: typeTypeType
  32. // CHECK:STDOUT: 2: typeTypeType
  33. // CHECK:STDOUT: typeBlock1:
  34. // CHECK:STDOUT: 0: type1
  35. // CHECK:STDOUT: 1: type1
  36. // CHECK:STDOUT: 2: type3
  37. // CHECK:STDOUT: insts:
  38. // CHECK:STDOUT: inst+0: {kind: Namespace, arg0: name_scope0, type: type0}
  39. // CHECK:STDOUT: inst+1: {kind: Param, arg0: name1, type: type1}
  40. // CHECK:STDOUT: inst+2: {kind: TupleType, arg0: typeBlock0, type: typeTypeType}
  41. // CHECK:STDOUT: inst+3: {kind: TupleLiteral, arg0: block2, type: type2}
  42. // CHECK:STDOUT: inst+4: {kind: TupleType, arg0: typeBlock1, type: typeTypeType}
  43. // CHECK:STDOUT: inst+5: {kind: Converted, arg0: inst+3, arg1: inst+4, type: typeTypeType}
  44. // CHECK:STDOUT: inst+6: {kind: VarStorage, arg0: nameReturnSlot, type: type4}
  45. // CHECK:STDOUT: inst+7: {kind: PointerType, arg0: type4, type: typeTypeType}
  46. // CHECK:STDOUT: inst+8: {kind: FunctionDecl, arg0: function0, type: type6}
  47. // CHECK:STDOUT: inst+9: {kind: NameRef, arg0: name1, arg1: inst+1, type: type1}
  48. // CHECK:STDOUT: inst+10: {kind: IntLiteral, arg0: int4, type: type1}
  49. // CHECK:STDOUT: inst+11: {kind: RealLiteral, arg0: real0, type: type3}
  50. // CHECK:STDOUT: inst+12: {kind: TupleLiteral, arg0: block5, type: type4}
  51. // CHECK:STDOUT: inst+13: {kind: TupleAccess, arg0: inst+6, arg1: element0, type: type1}
  52. // CHECK:STDOUT: inst+14: {kind: InitializeFrom, arg0: inst+9, arg1: inst+13, type: type1}
  53. // CHECK:STDOUT: inst+15: {kind: TupleAccess, arg0: inst+6, arg1: element1, type: type1}
  54. // CHECK:STDOUT: inst+16: {kind: InitializeFrom, arg0: inst+10, arg1: inst+15, type: type1}
  55. // CHECK:STDOUT: inst+17: {kind: TupleAccess, arg0: inst+6, arg1: element2, type: type3}
  56. // CHECK:STDOUT: inst+18: {kind: InitializeFrom, arg0: inst+11, arg1: inst+17, type: type3}
  57. // CHECK:STDOUT: inst+19: {kind: TupleInit, arg0: block6, arg1: inst+6, type: type4}
  58. // CHECK:STDOUT: inst+20: {kind: Converted, arg0: inst+12, arg1: inst+19, type: type4}
  59. // CHECK:STDOUT: inst+21: {kind: ReturnExpr, arg0: inst+20}
  60. // CHECK:STDOUT: inst_blocks:
  61. // CHECK:STDOUT: block0: {}
  62. // CHECK:STDOUT: block1:
  63. // CHECK:STDOUT: 0: inst+1
  64. // CHECK:STDOUT: block2:
  65. // CHECK:STDOUT: 0: instIntType
  66. // CHECK:STDOUT: 1: instIntType
  67. // CHECK:STDOUT: 2: instFloatType
  68. // CHECK:STDOUT: block3:
  69. // CHECK:STDOUT: 0: inst+1
  70. // CHECK:STDOUT: 1: inst+3
  71. // CHECK:STDOUT: 2: inst+5
  72. // CHECK:STDOUT: 3: inst+6
  73. // CHECK:STDOUT: block4:
  74. // CHECK:STDOUT: 0: inst+9
  75. // CHECK:STDOUT: 1: inst+10
  76. // CHECK:STDOUT: 2: inst+11
  77. // CHECK:STDOUT: 3: inst+12
  78. // CHECK:STDOUT: 4: inst+13
  79. // CHECK:STDOUT: 5: inst+14
  80. // CHECK:STDOUT: 6: inst+15
  81. // CHECK:STDOUT: 7: inst+16
  82. // CHECK:STDOUT: 8: inst+17
  83. // CHECK:STDOUT: 9: inst+18
  84. // CHECK:STDOUT: 10: inst+19
  85. // CHECK:STDOUT: 11: inst+20
  86. // CHECK:STDOUT: 12: inst+21
  87. // CHECK:STDOUT: block5:
  88. // CHECK:STDOUT: 0: inst+9
  89. // CHECK:STDOUT: 1: inst+10
  90. // CHECK:STDOUT: 2: inst+11
  91. // CHECK:STDOUT: block6:
  92. // CHECK:STDOUT: 0: inst+14
  93. // CHECK:STDOUT: 1: inst+16
  94. // CHECK:STDOUT: 2: inst+18
  95. // CHECK:STDOUT: block7:
  96. // CHECK:STDOUT: 0: inst+0
  97. // CHECK:STDOUT: 1: inst+8
  98. // CHECK:STDOUT: ...
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: --- raw_and_textual_ir.carbon
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: constants {
  103. // CHECK:STDOUT: %.loc11_33.1: type = tuple_type (type, type, type)
  104. // CHECK:STDOUT: %.loc11_33.2: type = tuple_type (i32, i32, f64)
  105. // CHECK:STDOUT: %.loc11_33.3: type = ptr_type (i32, i32, f64)
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: file {
  109. // CHECK:STDOUT: package: <namespace> = namespace {.Foo = %Foo}
  110. // CHECK:STDOUT: %Foo: <function> = fn_decl @Foo
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: fn @Foo(%n: i32) -> %return: (i32, i32, f64) {
  114. // CHECK:STDOUT: !entry:
  115. // CHECK:STDOUT: %n.ref: i32 = name_ref n, %n
  116. // CHECK:STDOUT: %.loc12_14: i32 = int_literal 2
  117. // CHECK:STDOUT: %.loc12_17: f64 = real_literal 34e-1
  118. // CHECK:STDOUT: %.loc12_20.1: (i32, i32, f64) = tuple_literal (%n.ref, %.loc12_14, %.loc12_17)
  119. // CHECK:STDOUT: %.loc12_20.2: ref i32 = tuple_access %return, element0
  120. // CHECK:STDOUT: %.loc12_20.3: init i32 = initialize_from %n.ref to %.loc12_20.2
  121. // CHECK:STDOUT: %.loc12_20.4: ref i32 = tuple_access %return, element1
  122. // CHECK:STDOUT: %.loc12_20.5: init i32 = initialize_from %.loc12_14 to %.loc12_20.4
  123. // CHECK:STDOUT: %.loc12_20.6: ref f64 = tuple_access %return, element2
  124. // CHECK:STDOUT: %.loc12_20.7: init f64 = initialize_from %.loc12_17 to %.loc12_20.6
  125. // CHECK:STDOUT: %.loc12_20.8: init (i32, i32, f64) = tuple_init (%.loc12_20.3, %.loc12_20.5, %.loc12_20.7) to %return
  126. // CHECK:STDOUT: %.loc12_20.9: init (i32, i32, f64) = converted %.loc12_20.1, %.loc12_20.8
  127. // CHECK:STDOUT: return %.loc12_20.9
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT: