Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_IL_PRINTER_H_ | 5 #ifndef VM_IL_PRINTER_H_ |
| 6 #define VM_IL_PRINTER_H_ | 6 #define VM_IL_PRINTER_H_ |
| 7 | 7 |
| 8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 class BufferFormatter : public ValueObject { | |
| 13 public: | |
| 14 BufferFormatter(char* buffer, int size) | |
| 15 : position_(0), | |
| 16 buffer_(buffer), | |
| 17 size_(size) { } | |
| 18 | |
| 19 void Print(const char* format, ...) { | |
|
srdjan
2012/05/17 22:59:22
Move the code into .cc
Florian Schneider
2012/05/18 00:28:38
Done.
| |
| 20 int available = size_ - position_; | |
| 21 if (available <= 0) return; | |
| 22 va_list args; | |
| 23 va_start(args, format); | |
| 24 int written = OS::VSNPrint(buffer_ + position_, available, format, args); | |
|
srdjan
2012/05/17 22:59:22
intptr_t
| |
| 25 if (written >= 0) position_ += (available <= written) ? available : written; | |
|
srdjan
2012/05/17 22:59:22
Use { }
Florian Schneider
2012/05/18 00:28:38
Done.
| |
| 26 va_end(args); | |
| 27 } | |
| 28 | |
| 29 private: | |
| 30 int position_; | |
| 31 char* buffer_; | |
| 32 int size_; | |
|
srdjan
2012/05/17 22:59:22
make size intptr_t
Florian Schneider
2012/05/18 00:28:38
Done.
| |
| 33 }; | |
| 34 | |
| 35 | |
| 12 // Graph printing. | 36 // Graph printing. |
| 13 class FlowGraphPrinter : public FlowGraphVisitor { | 37 class FlowGraphPrinter : public ValueObject { |
| 14 public: | 38 public: |
| 15 FlowGraphPrinter(const Function& function, | 39 FlowGraphPrinter(const Function& function, |
| 16 const GrowableArray<BlockEntryInstr*>& block_order) | 40 const GrowableArray<BlockEntryInstr*>& block_order) |
| 17 : FlowGraphVisitor(block_order), function_(function) { } | 41 : function_(function), block_order_(block_order) { } |
| 18 | 42 |
| 19 virtual ~FlowGraphPrinter() {} | 43 virtual ~FlowGraphPrinter() {} |
| 20 | 44 |
| 21 // Print the instructions in a block terminated by newlines. Add "goto N" | 45 // Print the instructions in a block terminated by newlines. Add "goto N" |
| 22 // to the end of the block if it ends with an unconditional jump to | 46 // to the end of the block if it ends with an unconditional jump to |
| 23 // another block and that block is not next in reverse postorder. | 47 // another block and that block is not next in reverse postorder. |
| 24 void VisitBlocks(); | 48 void PrintBlocks(); |
| 25 | 49 void Print(Instruction* instr); |
| 26 // Visiting a computation prints it with no indentation or newline. | |
| 27 #define DECLARE_VISIT_COMPUTATION(ShortName, ClassName) \ | |
| 28 virtual void Visit##ShortName(ClassName* comp); | |
| 29 | |
| 30 // Visiting an instruction prints it with a four space indent and no | |
| 31 // trailing newline. Basic block entries are labeled with their block | |
| 32 // number. | |
| 33 #define DECLARE_VISIT_INSTRUCTION(ShortName) \ | |
| 34 virtual void Visit##ShortName(ShortName##Instr* instr); | |
| 35 | |
| 36 FOR_EACH_COMPUTATION(DECLARE_VISIT_COMPUTATION) | |
| 37 FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) | |
| 38 | |
| 39 #undef DECLARE_VISIT_COMPUTATION | |
| 40 #undef DECLARE_VISIT_INSTRUCTION | |
| 41 | 50 |
| 42 private: | 51 private: |
| 43 const Function& function_; | 52 const Function& function_; |
| 44 | 53 const GrowableArray<BlockEntryInstr*>& block_order_; |
| 45 DISALLOW_COPY_AND_ASSIGN(FlowGraphPrinter); | |
| 46 }; | 54 }; |
| 47 | 55 |
| 48 } // namespace dart | 56 } // namespace dart |
| 49 | 57 |
| 50 #endif // VM_IL_PRINTER_H_ | 58 #endif // VM_IL_PRINTER_H_ |
| OLD | NEW |