textual_ir.carbon 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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: %n.patt: %.1 = binding_pattern n
  35. // CHECK:STDOUT: } {
  36. // CHECK:STDOUT: %.loc15_12.1: %.1 = tuple_literal ()
  37. // CHECK:STDOUT: %.loc15_12.2: type = converted %.loc15_12.1, constants.%.1 [template = constants.%.1]
  38. // CHECK:STDOUT: %n.param: %.1 = param n, runtime_param0
  39. // CHECK:STDOUT: %n: %.1 = bind_name n, %n.param
  40. // CHECK:STDOUT: %.loc15_20: %.1 = tuple_literal ()
  41. // CHECK:STDOUT: %.loc15_24: %.1 = tuple_literal ()
  42. // CHECK:STDOUT: %.loc15_25.1: %.2 = tuple_literal (%.loc15_20, %.loc15_24)
  43. // CHECK:STDOUT: %.loc15_25.2: type = converted %.loc15_20, constants.%.1 [template = constants.%.1]
  44. // CHECK:STDOUT: %.loc15_25.3: type = converted %.loc15_24, constants.%.1 [template = constants.%.1]
  45. // CHECK:STDOUT: %.loc15_25.4: type = converted %.loc15_25.1, constants.%.2 [template = constants.%.2]
  46. // CHECK:STDOUT: %return: ref %.2 = var <return slot>
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: fn @Foo(%n: %.1) -> %return: %.2 {
  51. // CHECK:STDOUT: !entry:
  52. // CHECK:STDOUT: %n.ref: %.1 = name_ref n, %n
  53. // CHECK:STDOUT: %.loc16_15.1: %.1 = tuple_literal ()
  54. // CHECK:STDOUT: %.loc16_16.1: %.2 = tuple_literal (%n.ref, %.loc16_15.1)
  55. // CHECK:STDOUT: %.loc16_16.2: ref %.1 = tuple_access %return, element0
  56. // CHECK:STDOUT: %.loc16_11: init %.1 = tuple_init () to %.loc16_16.2 [template = constants.%tuple.1]
  57. // CHECK:STDOUT: %.loc16_16.3: init %.1 = converted %n.ref, %.loc16_11 [template = constants.%tuple.1]
  58. // CHECK:STDOUT: %.loc16_16.4: ref %.1 = tuple_access %return, element1
  59. // CHECK:STDOUT: %.loc16_15.2: init %.1 = tuple_init () to %.loc16_16.4 [template = constants.%tuple.1]
  60. // CHECK:STDOUT: %.loc16_16.5: init %.1 = converted %.loc16_15.1, %.loc16_15.2 [template = constants.%tuple.1]
  61. // CHECK:STDOUT: %.loc16_16.6: init %.2 = tuple_init (%.loc16_16.3, %.loc16_16.5) to %return [template = constants.%tuple.2]
  62. // CHECK:STDOUT: %.loc16_17: init %.2 = converted %.loc16_16.1, %.loc16_16.6 [template = constants.%tuple.2]
  63. // CHECK:STDOUT: return %.loc16_17 to %return
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: