5 #ifndef V8_TORQUE_CFG_H_ 6 #define V8_TORQUE_CFG_H_ 10 #include <unordered_map> 13 #include "src/torque/ast.h" 14 #include "src/torque/instructions.h" 15 #include "src/torque/source-positions.h" 16 #include "src/torque/types.h" 22 class ControlFlowGraph;
30 input_types_(std::move(input_types)),
32 is_deferred_(is_deferred) {}
34 DCHECK(!IsComplete());
35 instructions_.push_back(std::move(instruction));
38 bool HasInputTypes()
const {
return input_types_ != base::nullopt; }
43 for (
const Instruction& instruction : instructions()) {
44 instruction.TypeInstruction(¤t_stack, cfg_);
48 const std::vector<Instruction>& instructions()
const {
return instructions_; }
49 bool IsComplete()
const {
50 return !instructions_.empty() && instructions_.back()->IsBlockTerminator();
52 size_t id()
const {
return id_; }
53 bool IsDeferred()
const {
return is_deferred_; }
57 std::vector<Instruction> instructions_;
66 start_ = NewBlock(std::move(input_types),
false);
72 blocks_.emplace_back(
this, next_block_id_++, std::move(input_types),
74 return &blocks_.back();
76 void PlaceBlock(
Block* block) { placed_blocks_.push_back(block); }
77 Block* start()
const {
return start_; }
79 void set_end(
Block* end) { end_ = end; }
80 void SetReturnType(
const Type* t) {
85 if (t != *return_type_) {
86 ReportError(
"expected return type ", **return_type_,
" instead of ", *t);
89 const std::vector<Block*>& blocks()
const {
return placed_blocks_; }
92 std::list<Block> blocks_;
94 std::vector<Block*> placed_blocks_;
97 size_t next_block_id_ = 0;
103 : current_stack_(std::move(input_types)), cfg_(current_stack_) {}
106 if (!CurrentBlockIsComplete()) {
107 cfg_.set_end(current_block_);
114 bool is_deferred =
false) {
115 return cfg_.NewBlock(std::move(input_types), is_deferred);
118 bool CurrentBlockIsComplete()
const {
return current_block_->IsComplete(); }
121 instruction.TypeInstruction(¤t_stack_, &cfg_);
122 current_block_->Add(std::move(instruction));
127 StackRange TopRange(
size_t slot_count)
const {
128 return CurrentStack().TopRange(slot_count);
131 void Bind(
Block* block);
132 void Goto(
Block* block);
147 void Print(std::string s);
148 void AssertionFailure(std::string message);
152 void PrintCurrentStack(std::ostream& s) { s <<
"stack: " << current_stack_; }
158 Block* current_block_ = cfg_.start();
164 : assembler_(assembler), saved_block_(block) {
165 saved_stack_ = block->InputTypes();
166 DCHECK(!assembler->CurrentBlockIsComplete());
167 std::swap(saved_block_, assembler->current_block_);
168 std::swap(saved_stack_, assembler->current_stack_);
169 assembler->cfg_.PlaceBlock(block);
173 DCHECK(assembler_->CurrentBlockIsComplete());
174 std::swap(saved_block_, assembler_->current_block_);
175 std::swap(saved_stack_, assembler_->current_stack_);
188 #endif // V8_TORQUE_CFG_H_