| 1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | #ifndef RUNTIME_VM_COMPILER_BACKEND_IL_PRINTER_H_ |
| 6 | #define RUNTIME_VM_COMPILER_BACKEND_IL_PRINTER_H_ |
| 7 | |
| 8 | #if defined(DART_PRECOMPILED_RUNTIME) |
| 9 | #error "AOT runtime should not use compiler sources (including header files)" |
| 10 | #endif // defined(DART_PRECOMPILED_RUNTIME) |
| 11 | |
| 12 | #include "platform/text_buffer.h" |
| 13 | #include "vm/compiler/backend/flow_graph.h" |
| 14 | #include "vm/compiler/backend/il.h" |
| 15 | |
| 16 | namespace dart { |
| 17 | |
| 18 | class ParsedFunction; |
| 19 | |
| 20 | const char* RepresentationToCString(Representation rep); |
| 21 | |
| 22 | // Graph printing. |
| 23 | class FlowGraphPrinter : public ValueObject { |
| 24 | public: |
| 25 | static const intptr_t kPrintAll = -1; |
| 26 | |
| 27 | explicit FlowGraphPrinter(const FlowGraph& flow_graph, |
| 28 | bool print_locations = false) |
| 29 | : function_(flow_graph.function()), |
| 30 | block_order_(flow_graph.reverse_postorder()), |
| 31 | print_locations_(print_locations) {} |
| 32 | |
| 33 | // Print the instructions in a block terminated by newlines. Add "goto N" |
| 34 | // to the end of the block if it ends with an unconditional jump to |
| 35 | // another block and that block is not next in reverse postorder. |
| 36 | void PrintBlocks(); |
| 37 | void PrintInstruction(Instruction* instr); |
| 38 | static void PrintOneInstruction(Instruction* instr, bool print_locations); |
| 39 | static void PrintTypeCheck(const ParsedFunction& parsed_function, |
| 40 | TokenPosition token_pos, |
| 41 | Value* value, |
| 42 | const AbstractType& dst_type, |
| 43 | const String& dst_name, |
| 44 | bool eliminated); |
| 45 | static void PrintBlock(BlockEntryInstr* block, bool print_locations); |
| 46 | |
| 47 | static void PrintGraph(const char* phase, FlowGraph* flow_graph); |
| 48 | |
| 49 | // Debugging helper function. If 'num_checks_to_print' is not specified |
| 50 | // all checks will be printed. |
| 51 | static void PrintICData(const ICData& ic_data, |
| 52 | intptr_t num_checks_to_print = kPrintAll); |
| 53 | |
| 54 | // Debugging helper function. If 'num_checks_to_print' is not specified |
| 55 | // all checks will be printed. |
| 56 | static void PrintCidRangeData(const CallTargets& ic_data, |
| 57 | intptr_t num_checks_to_print = kPrintAll); |
| 58 | |
| 59 | static bool ShouldPrint(const Function& function); |
| 60 | |
| 61 | private: |
| 62 | const Function& function_; |
| 63 | const GrowableArray<BlockEntryInstr*>& block_order_; |
| 64 | const bool print_locations_; |
| 65 | }; |
| 66 | |
| 67 | } // namespace dart |
| 68 | |
| 69 | #endif // RUNTIME_VM_COMPILER_BACKEND_IL_PRINTER_H_ |
| 70 | |