textual_ir.carbon 4.3 KB

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