textual_ir.carbon 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 --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/check/testdata/basics/no_prelude/textual_ir.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/basics/no_prelude/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: %.1: type = tuple_type () [template]
  21. // CHECK:STDOUT: %.2: type = tuple_type (%.1, %.1) [template]
  22. // CHECK:STDOUT: %Foo.type: type = fn_type @Foo [template]
  23. // CHECK:STDOUT: %Foo: %Foo.type = struct_value () [template]
  24. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  25. // CHECK:STDOUT: %tuple.1: %.1 = tuple_value () [template]
  26. // CHECK:STDOUT: %tuple.2: %.2 = tuple_value (%tuple.1, %tuple.1) [template]
  27. // CHECK:STDOUT: }
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: file {
  30. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  31. // CHECK:STDOUT: .Foo = %Foo.decl
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT: %Foo.decl: %Foo.type = fn_decl @Foo [template = constants.%Foo] {
  34. // CHECK:STDOUT: %.loc15_12.1: %.1 = tuple_literal ()
  35. // CHECK:STDOUT: %.loc15_12.2: type = converted %.loc15_12.1, constants.%.1 [template = constants.%.1]
  36. // CHECK:STDOUT: %n.loc15_8.1: %.1 = param n
  37. // CHECK:STDOUT: @Foo.%n: %.1 = bind_name n, %n.loc15_8.1
  38. // CHECK:STDOUT: %.loc15_20: %.1 = tuple_literal ()
  39. // CHECK:STDOUT: %.loc15_24: %.1 = tuple_literal ()
  40. // CHECK:STDOUT: %.loc15_25.1: %.2 = tuple_literal (%.loc15_20, %.loc15_24)
  41. // CHECK:STDOUT: %.loc15_25.2: type = converted %.loc15_20, constants.%.1 [template = constants.%.1]
  42. // CHECK:STDOUT: %.loc15_25.3: type = converted %.loc15_24, constants.%.1 [template = constants.%.1]
  43. // CHECK:STDOUT: %.loc15_25.4: type = converted %.loc15_25.1, constants.%.2 [template = constants.%.2]
  44. // CHECK:STDOUT: @Foo.%return: ref %.2 = var <return slot>
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: fn @Foo(%n: %.1) -> %return: %.2 {
  49. // CHECK:STDOUT: !entry:
  50. // CHECK:STDOUT: %n.ref: %.1 = name_ref n, %n
  51. // CHECK:STDOUT: %.loc16_15.1: %.1 = tuple_literal ()
  52. // CHECK:STDOUT: %.loc16_16.1: %.2 = tuple_literal (%n.ref, %.loc16_15.1)
  53. // CHECK:STDOUT: %.loc16_16.2: ref %.1 = tuple_access %return, element0
  54. // CHECK:STDOUT: %.loc16_11: init %.1 = tuple_init () to %.loc16_16.2 [template = constants.%tuple.1]
  55. // CHECK:STDOUT: %.loc16_16.3: init %.1 = converted %n.ref, %.loc16_11 [template = constants.%tuple.1]
  56. // CHECK:STDOUT: %.loc16_16.4: ref %.1 = tuple_access %return, element1
  57. // CHECK:STDOUT: %.loc16_15.2: init %.1 = tuple_init () to %.loc16_16.4 [template = constants.%tuple.1]
  58. // CHECK:STDOUT: %.loc16_16.5: init %.1 = converted %.loc16_15.1, %.loc16_15.2 [template = constants.%tuple.1]
  59. // CHECK:STDOUT: %.loc16_16.6: init %.2 = tuple_init (%.loc16_16.3, %.loc16_16.5) to %return [template = constants.%tuple.2]
  60. // CHECK:STDOUT: %.loc16_17: init %.2 = converted %.loc16_16.1, %.loc16_16.6 [template = constants.%tuple.2]
  61. // CHECK:STDOUT: return %.loc16_17 to %return
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: