textual_ir.carbon 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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: --include-diagnostic-kind compile --no-prelude-import --phase=check --dump-sem-ir %s
  6. //
  7. // Check that the command-line flag to dump textual IR works.
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/driver/testdata/compile/textual_ir.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/driver/testdata/compile/textual_ir.carbon
  14. fn Foo(n: ()) -> ((), ()) {
  15. return (n, ());
  16. }
  17. // CHECK:STDOUT: --- textual_ir.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  21. // CHECK:STDOUT: %tuple.type: type = tuple_type (%empty_tuple.type, %empty_tuple.type) [template]
  22. // CHECK:STDOUT: %Foo.type: type = fn_type @Foo [template]
  23. // CHECK:STDOUT: %Foo: %Foo.type = struct_value () [template]
  24. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [template]
  25. // CHECK:STDOUT: %tuple: %tuple.type = tuple_value (%empty_tuple, %empty_tuple) [template]
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: file {
  29. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  30. // CHECK:STDOUT: .Foo = %Foo.decl
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT: %Foo.decl: %Foo.type = fn_decl @Foo [template = constants.%Foo] {
  33. // CHECK:STDOUT: %n.patt: %empty_tuple.type = binding_pattern n
  34. // CHECK:STDOUT: %n.param_patt: %empty_tuple.type = value_param_pattern %n.patt, runtime_param0
  35. // CHECK:STDOUT: %return.patt: %tuple.type = return_slot_pattern
  36. // CHECK:STDOUT: %return.param_patt: %tuple.type = out_param_pattern %return.patt, runtime_param1
  37. // CHECK:STDOUT: } {
  38. // CHECK:STDOUT: %.loc15_20: %empty_tuple.type = tuple_literal ()
  39. // CHECK:STDOUT: %.loc15_24: %empty_tuple.type = tuple_literal ()
  40. // CHECK:STDOUT: %.loc15_25.1: %tuple.type = tuple_literal (%.loc15_20, %.loc15_24)
  41. // CHECK:STDOUT: %.loc15_25.2: type = converted %.loc15_20, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
  42. // CHECK:STDOUT: %.loc15_25.3: type = converted %.loc15_24, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
  43. // CHECK:STDOUT: %.loc15_25.4: type = converted %.loc15_25.1, constants.%tuple.type [template = constants.%tuple.type]
  44. // CHECK:STDOUT: %n.param: %empty_tuple.type = value_param runtime_param0
  45. // CHECK:STDOUT: %.loc15_12.1: type = splice_block %.loc15_12.3 [template = constants.%empty_tuple.type] {
  46. // CHECK:STDOUT: %.loc15_12.2: %empty_tuple.type = tuple_literal ()
  47. // CHECK:STDOUT: %.loc15_12.3: type = converted %.loc15_12.2, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %n: %empty_tuple.type = bind_name n, %n.param
  50. // CHECK:STDOUT: %return.param: ref %tuple.type = out_param runtime_param1
  51. // CHECK:STDOUT: %return: ref %tuple.type = return_slot %return.param
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: fn @Foo(%n.param_patt: %empty_tuple.type) -> %return.param_patt: %tuple.type {
  56. // CHECK:STDOUT: !entry:
  57. // CHECK:STDOUT: %n.ref: %empty_tuple.type = name_ref n, %n
  58. // CHECK:STDOUT: %.loc16_15.1: %empty_tuple.type = tuple_literal ()
  59. // CHECK:STDOUT: %.loc16_16.1: %tuple.type = tuple_literal (%n.ref, %.loc16_15.1)
  60. // CHECK:STDOUT: %tuple.elem0: ref %empty_tuple.type = tuple_access %return, element0
  61. // CHECK:STDOUT: %.loc16_11: init %empty_tuple.type = tuple_init () to %tuple.elem0 [template = constants.%empty_tuple]
  62. // CHECK:STDOUT: %.loc16_16.2: init %empty_tuple.type = converted %n.ref, %.loc16_11 [template = constants.%empty_tuple]
  63. // CHECK:STDOUT: %tuple.elem1: ref %empty_tuple.type = tuple_access %return, element1
  64. // CHECK:STDOUT: %.loc16_15.2: init %empty_tuple.type = tuple_init () to %tuple.elem1 [template = constants.%empty_tuple]
  65. // CHECK:STDOUT: %.loc16_16.3: init %empty_tuple.type = converted %.loc16_15.1, %.loc16_15.2 [template = constants.%empty_tuple]
  66. // CHECK:STDOUT: %.loc16_16.4: init %tuple.type = tuple_init (%.loc16_16.2, %.loc16_16.3) to %return [template = constants.%tuple]
  67. // CHECK:STDOUT: %.loc16_17: init %tuple.type = converted %.loc16_16.1, %.loc16_16.4 [template = constants.%tuple]
  68. // CHECK:STDOUT: return %.loc16_17 to %return
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: