From 09ddcece300e635c4a75f3a1543d914a48436c5a Mon Sep 17 00:00:00 2001 From: Tess Strickland Date: Fri, 7 Aug 2020 21:40:45 +0000 Subject: [PATCH] [vm] Make BufferFormatter also a subclass of BaseTextBuffer. Change-Id: I4d2759ffa80c0106838ad0ddbc6dd086fddda1dd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/157742 Commit-Queue: Tess Strickland Reviewed-by: Ryan Macnak --- runtime/platform/text_buffer.cc | 32 +- runtime/platform/text_buffer.h | 35 +- runtime/vm/compiler/assembler/disassembler.cc | 6 +- runtime/vm/compiler/backend/compile_type.h | 4 +- runtime/vm/compiler/backend/il.h | 18 +- runtime/vm/compiler/backend/il_printer.cc | 733 +++++++++--------- runtime/vm/compiler/backend/locations.cc | 34 +- runtime/vm/compiler/backend/locations.h | 6 +- runtime/vm/compiler/backend/loops.cc | 50 +- runtime/vm/compiler/backend/loops.h | 2 + runtime/vm/compiler/backend/loops_test.cc | 18 +- runtime/vm/compiler/backend/range_analysis.cc | 16 +- runtime/vm/compiler/backend/range_analysis.h | 4 +- .../vm/compiler/backend/type_propagator.cc | 6 +- runtime/vm/compiler/ffi/native_location.cc | 37 +- runtime/vm/compiler/ffi/native_location.h | 10 +- runtime/vm/compiler/ffi/native_type.cc | 8 +- runtime/vm/compiler/ffi/native_type.h | 6 +- runtime/vm/zone_text_buffer.cc | 3 +- runtime/vm/zone_text_buffer.h | 4 +- 20 files changed, 520 insertions(+), 512 deletions(-) diff --git a/runtime/platform/text_buffer.cc b/runtime/platform/text_buffer.cc index 608df76912a..5d08892a418 100644 --- a/runtime/platform/text_buffer.cc +++ b/runtime/platform/text_buffer.cc @@ -19,7 +19,11 @@ intptr_t BaseTextBuffer::Printf(const char* format, ...) { intptr_t len = Utils::VSNPrint(buffer_ + length_, remaining, format, args); va_end(args); if (len >= remaining) { - EnsureCapacity(len); + if (!EnsureCapacity(len)) { + length_ = capacity_ - 1; + buffer_[length_] = '\0'; + return remaining - 1; + } remaining = capacity_ - length_; ASSERT(remaining > len); va_list args2; @@ -35,14 +39,16 @@ intptr_t BaseTextBuffer::Printf(const char* format, ...) { } void BaseTextBuffer::AddChar(char ch) { - EnsureCapacity(sizeof(ch)); + if (!EnsureCapacity(sizeof(ch))) return; buffer_[length_] = ch; length_++; buffer_[length_] = '\0'; } void BaseTextBuffer::AddRaw(const uint8_t* buffer, intptr_t buffer_length) { - EnsureCapacity(buffer_length); + if (!EnsureCapacity(buffer_length)) { + buffer_length = capacity_ - length_ - 1; // Copy what fits. + } memmove(&buffer_[length_], buffer, buffer_length); length_ += buffer_length; buffer_[length_] = '\0'; @@ -128,7 +134,7 @@ char* TextBuffer::Steal() { return r; } -void TextBuffer::EnsureCapacity(intptr_t len) { +bool TextBuffer::EnsureCapacity(intptr_t len) { intptr_t remaining = capacity_ - length_; if (remaining <= len) { intptr_t new_size = capacity_ + Utils::Maximum(capacity_, len + 1); @@ -139,23 +145,7 @@ void TextBuffer::EnsureCapacity(intptr_t len) { buffer_ = new_buf; capacity_ = new_size; } -} - -void BufferFormatter::Print(const char* format, ...) { - va_list args; - va_start(args, format); - VPrint(format, args); - va_end(args); -} - -void BufferFormatter::VPrint(const char* format, va_list args) { - intptr_t available = size_ - position_; - if (available <= 0) return; - intptr_t written = - Utils::VSNPrint(buffer_ + position_, available, format, args); - if (written >= 0) { - position_ += (available <= written) ? available : written; - } + return true; } } // namespace dart diff --git a/runtime/platform/text_buffer.h b/runtime/platform/text_buffer.h index 098540942a7..c44d9555a74 100644 --- a/runtime/platform/text_buffer.h +++ b/runtime/platform/text_buffer.h @@ -14,6 +14,9 @@ namespace dart { // to append text. Internal buffer management is handled by subclasses. class BaseTextBuffer : public ValueObject { public: + BaseTextBuffer() : buffer_(nullptr), capacity_(0), length_(0) {} + BaseTextBuffer(char* buffer, intptr_t capacity) + : buffer_(buffer), capacity_(capacity), length_(0) {} virtual ~BaseTextBuffer() {} intptr_t Printf(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); @@ -34,11 +37,13 @@ class BaseTextBuffer : public ValueObject { virtual void Clear() = 0; protected: - virtual void EnsureCapacity(intptr_t len) = 0; + virtual bool EnsureCapacity(intptr_t len) = 0; - char* buffer_ = nullptr; - intptr_t capacity_ = 0; - intptr_t length_ = 0; + char* buffer_; + intptr_t capacity_; + intptr_t length_; + + DISALLOW_COPY_AND_ASSIGN(BaseTextBuffer); }; // TextBuffer uses manual memory management for the character buffer. Unless @@ -64,21 +69,25 @@ class TextBuffer : public BaseTextBuffer { char* Steal(); private: - void EnsureCapacity(intptr_t len); + bool EnsureCapacity(intptr_t len); + + DISALLOW_COPY_AND_ASSIGN(TextBuffer); }; -class BufferFormatter : public ValueObject { +class BufferFormatter : public BaseTextBuffer { public: - BufferFormatter(char* buffer, intptr_t size) - : position_(0), buffer_(buffer), size_(size) {} + BufferFormatter(char* buffer, intptr_t size) : BaseTextBuffer(buffer, size) { + buffer_[length_] = '\0'; + } - void VPrint(const char* format, va_list args); - void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); + void Clear() { + length_ = 0; + buffer_[length_] = '\0'; + } private: - intptr_t position_; - char* buffer_; - const intptr_t size_; + // We can't extend, so only return true if there's room. + bool EnsureCapacity(intptr_t len) { return length_ + len <= capacity_ - 1; } DISALLOW_COPY_AND_ASSIGN(BufferFormatter); }; diff --git a/runtime/vm/compiler/assembler/disassembler.cc b/runtime/vm/compiler/assembler/disassembler.cc index 522e5052851..2d1515fd67a 100644 --- a/runtime/vm/compiler/assembler/disassembler.cc +++ b/runtime/vm/compiler/assembler/disassembler.cc @@ -191,14 +191,14 @@ void Disassembler::Disassemble(uword start, for (intptr_t i = 1; i < inlined_functions.length(); i++) { const char* name = inlined_functions[i]->ToQualifiedCString(); if (first) { - f.Print(" ;; Inlined [%s", name); + f.Printf(" ;; Inlined [%s", name); first = false; } else { - f.Print(" -> %s", name); + f.Printf(" -> %s", name); } } if (!first) { - f.Print("]\n"); + f.AddString("]\n"); formatter->Print("%s", str); } } diff --git a/runtime/vm/compiler/backend/compile_type.h b/runtime/vm/compiler/backend/compile_type.h index 32c9949864d..3a7d6aa63b0 100644 --- a/runtime/vm/compiler/backend/compile_type.h +++ b/runtime/vm/compiler/backend/compile_type.h @@ -16,7 +16,7 @@ namespace dart { class AbstractType; -class BufferFormatter; +class BaseTextBuffer; class Definition; class FlowGraphSerializer; class SExpression; @@ -247,7 +247,7 @@ class CompileType : public ZoneAllocated { bool Specialize(GrowableArray* class_ids); - void PrintTo(BufferFormatter* f) const; + void PrintTo(BaseTextBuffer* f) const; SExpression* ToSExpression(FlowGraphSerializer* s) const; void AddExtraInfoToSExpression(SExpList* sexp, FlowGraphSerializer* s) const; diff --git a/runtime/vm/compiler/backend/il.h b/runtime/vm/compiler/backend/il.h index 8c76dada1fb..8b3cc81bd28 100644 --- a/runtime/vm/compiler/backend/il.h +++ b/runtime/vm/compiler/backend/il.h @@ -35,12 +35,12 @@ namespace dart { +class BaseTextBuffer; class BinaryFeedback; class BitVector; class BlockEntryInstr; class BlockEntryWithInitialDefs; class BoxIntegerInstr; -class BufferFormatter; class CallTargets; class CatchBlockEntryInstr; class CheckBoundBase; @@ -145,7 +145,7 @@ class Value : public ZoneAllocated { void RefineReachingType(CompileType* type); #if !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER) - void PrintTo(BufferFormatter* f) const; + void PrintTo(BaseTextBuffer* f) const; #endif // !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER) SExpression* ToSExpression(FlowGraphSerializer* s) const; @@ -550,14 +550,14 @@ FOR_EACH_ABSTRACT_INSTRUCTION(FORWARD_DECLARATION) DECLARE_COMPARISON_METHODS #if !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER) -#define PRINT_TO_SUPPORT virtual void PrintTo(BufferFormatter* f) const; +#define PRINT_TO_SUPPORT virtual void PrintTo(BaseTextBuffer* f) const; #else #define PRINT_TO_SUPPORT #endif // !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER) #if !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER) #define PRINT_OPERANDS_TO_SUPPORT \ - virtual void PrintOperandsTo(BufferFormatter* f) const; + virtual void PrintOperandsTo(BaseTextBuffer* f) const; #else #define PRINT_OPERANDS_TO_SUPPORT #endif // !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER) @@ -911,8 +911,8 @@ class Instruction : public ZoneAllocated { // Printing support. const char* ToCString() const; #if !defined(PRODUCT) || defined(FORCE_INCLUDE_DISASSEMBLER) - virtual void PrintTo(BufferFormatter* f) const; - virtual void PrintOperandsTo(BufferFormatter* f) const; + virtual void PrintTo(BaseTextBuffer* f) const; + virtual void PrintOperandsTo(BaseTextBuffer* f) const; #endif virtual SExpression* ToSExpression(FlowGraphSerializer* s) const; virtual void AddOperandsToSExpression(SExpList* sexp, @@ -1614,7 +1614,7 @@ class BlockEntryWithInitialDefs : public BlockEntryInstr { } protected: - void PrintInitialDefinitionsTo(BufferFormatter* f) const; + void PrintInitialDefinitionsTo(BaseTextBuffer* f) const; private: GrowableArray initial_definitions_; @@ -5864,7 +5864,7 @@ class StoreIndexedInstr : public TemplateInstruction<3, NoThrow> { virtual bool HasUnknownSideEffects() const { return false; } - void PrintOperandsTo(BufferFormatter* f) const; + void PrintOperandsTo(BaseTextBuffer* f) const; virtual Instruction* Canonicalize(FlowGraph* flow_graph); @@ -9330,7 +9330,7 @@ class Environment : public ZoneAllocated { Definition* dead, Definition* result) const; - void PrintTo(BufferFormatter* f) const; + void PrintTo(BaseTextBuffer* f) const; SExpression* ToSExpression(FlowGraphSerializer* s) const; const char* ToCString() const; diff --git a/runtime/vm/compiler/backend/il_printer.cc b/runtime/vm/compiler/backend/il_printer.cc index a1289a91995..b3260573fe1 100644 --- a/runtime/vm/compiler/backend/il_printer.cc +++ b/runtime/vm/compiler/backend/il_printer.cc @@ -103,11 +103,11 @@ void FlowGraphPrinter::PrintTypeCheck(const ParsedFunction& parsed_function, String::Handle(dst_type.Name()).ToCString(), dst_name.ToCString()); } -static void PrintTargetsHelper(BufferFormatter* f, +static void PrintTargetsHelper(BaseTextBuffer* f, const CallTargets& targets, intptr_t num_checks_to_print) { - f->Print(" Targets["); - f->Print("%" Pd ": ", targets.length()); + f->AddString(" Targets["); + f->Printf("%" Pd ": ", targets.length()); Function& target = Function::Handle(); if ((num_checks_to_print == FlowGraphPrinter::kPrintAll) || (num_checks_to_print > targets.length())) { @@ -119,36 +119,36 @@ static void PrintTargetsHelper(BufferFormatter* f, const intptr_t count = target_info->count; target = target_info->target->raw(); if (i > 0) { - f->Print(" | "); + f->AddString(" | "); } if (range.IsSingleCid()) { const Class& cls = Class::Handle(Isolate::Current()->class_table()->At(range.cid_start)); - f->Print("%s", String::Handle(cls.Name()).ToCString()); - f->Print(" cid %" Pd " cnt:%" Pd " trgt:'%s'", range.cid_start, count, - target.ToQualifiedCString()); + f->Printf("%s", String::Handle(cls.Name()).ToCString()); + f->Printf(" cid %" Pd " cnt:%" Pd " trgt:'%s'", range.cid_start, count, + target.ToQualifiedCString()); } else { const Class& cls = Class::Handle(target.Owner()); - f->Print("cid %" Pd "-%" Pd " %s", range.cid_start, range.cid_end, - String::Handle(cls.Name()).ToCString()); - f->Print(" cnt:%" Pd " trgt:'%s'", count, target.ToQualifiedCString()); + f->Printf("cid %" Pd "-%" Pd " %s", range.cid_start, range.cid_end, + String::Handle(cls.Name()).ToCString()); + f->Printf(" cnt:%" Pd " trgt:'%s'", count, target.ToQualifiedCString()); } if (target_info->exactness.IsTracking()) { - f->Print(" %s", target_info->exactness.ToCString()); + f->Printf(" %s", target_info->exactness.ToCString()); } } if (num_checks_to_print < targets.length()) { - f->Print("..."); + f->AddString("..."); } - f->Print("]"); + f->AddString("]"); } -static void PrintCidsHelper(BufferFormatter* f, +static void PrintCidsHelper(BaseTextBuffer* f, const Cids& targets, intptr_t num_checks_to_print) { - f->Print(" Cids["); - f->Print("%" Pd ": ", targets.length()); + f->AddString(" Cids["); + f->Printf("%" Pd ": ", targets.length()); if ((num_checks_to_print == FlowGraphPrinter::kPrintAll) || (num_checks_to_print > targets.length())) { num_checks_to_print = targets.length(); @@ -156,32 +156,33 @@ static void PrintCidsHelper(BufferFormatter* f, for (intptr_t i = 0; i < num_checks_to_print; i++) { const CidRange& range = targets[i]; if (i > 0) { - f->Print(" | "); + f->AddString(" | "); } const Class& cls = Class::Handle(Isolate::Current()->class_table()->At(range.cid_start)); - f->Print("%s etc. ", String::Handle(cls.Name()).ToCString()); + f->Printf("%s etc. ", String::Handle(cls.Name()).ToCString()); if (range.IsSingleCid()) { - f->Print(" cid %" Pd, range.cid_start); + f->Printf(" cid %" Pd, range.cid_start); } else { - f->Print(" cid %" Pd "-%" Pd, range.cid_start, range.cid_end); + f->Printf(" cid %" Pd "-%" Pd, range.cid_start, range.cid_end); } } if (num_checks_to_print < targets.length()) { - f->Print("..."); + f->AddString("..."); } - f->Print("]"); + f->AddString("]"); } -static void PrintICDataHelper(BufferFormatter* f, +static void PrintICDataHelper(BaseTextBuffer* f, const ICData& ic_data, intptr_t num_checks_to_print) { - f->Print(" IC["); + f->AddString(" IC["); if (ic_data.is_tracking_exactness()) { - f->Print("(%s) ", - AbstractType::Handle(ic_data.receivers_static_type()).ToCString()); + f->Printf( + "(%s) ", + AbstractType::Handle(ic_data.receivers_static_type()).ToCString()); } - f->Print("%" Pd ": ", ic_data.NumberOfChecks()); + f->Printf("%" Pd ": ", ic_data.NumberOfChecks()); Function& target = Function::Handle(); if ((num_checks_to_print == FlowGraphPrinter::kPrintAll) || (num_checks_to_print > ic_data.NumberOfChecks())) { @@ -192,40 +193,40 @@ static void PrintICDataHelper(BufferFormatter* f, ic_data.GetCheckAt(i, &class_ids, &target); const intptr_t count = ic_data.GetCountAt(i); if (i > 0) { - f->Print(" | "); + f->AddString(" | "); } for (intptr_t k = 0; k < class_ids.length(); k++) { if (k > 0) { - f->Print(", "); + f->AddString(", "); } const Class& cls = Class::Handle(Isolate::Current()->class_table()->At(class_ids[k])); - f->Print("%s", String::Handle(cls.Name()).ToCString()); + f->Printf("%s", String::Handle(cls.Name()).ToCString()); } - f->Print(" cnt:%" Pd " trgt:'%s'", count, target.ToQualifiedCString()); + f->Printf(" cnt:%" Pd " trgt:'%s'", count, target.ToQualifiedCString()); if (ic_data.is_tracking_exactness()) { - f->Print(" %s", ic_data.GetExactnessAt(i).ToCString()); + f->Printf(" %s", ic_data.GetExactnessAt(i).ToCString()); } } if (num_checks_to_print < ic_data.NumberOfChecks()) { - f->Print("..."); + f->AddString("..."); } - f->Print("]"); + f->AddString("]"); } -static void PrintICDataSortedHelper(BufferFormatter* f, +static void PrintICDataSortedHelper(BaseTextBuffer* f, const ICData& ic_data_orig) { const ICData& ic_data = ICData::Handle(ic_data_orig.AsUnaryClassChecksSortedByCount()); - f->Print(" IC[n:%" Pd "; ", ic_data.NumberOfChecks()); + f->Printf(" IC[n:%" Pd "; ", ic_data.NumberOfChecks()); for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) { const intptr_t count = ic_data.GetCountAt(i); const intptr_t cid = ic_data.GetReceiverClassIdAt(i); const Class& cls = Class::Handle(Isolate::Current()->class_table()->At(cid)); - f->Print("%s : %" Pd ", ", String::Handle(cls.Name()).ToCString(), count); + f->Printf("%s : %" Pd ", ", String::Handle(cls.Name()).ToCString(), count); } - f->Print("]"); + f->AddString("]"); } void FlowGraphPrinter::PrintICData(const ICData& ic_data, @@ -247,16 +248,16 @@ void FlowGraphPrinter::PrintCidRangeData(const CallTargets& targets, // TODO(erikcorry): Print args descriptor. } -static void PrintUse(BufferFormatter* f, const Definition& definition) { +static void PrintUse(BaseTextBuffer* f, const Definition& definition) { if (definition.HasSSATemp()) { if (definition.HasPairRepresentation()) { - f->Print("(v%" Pd ", v%" Pd ")", definition.ssa_temp_index(), - definition.ssa_temp_index() + 1); + f->Printf("(v%" Pd ", v%" Pd ")", definition.ssa_temp_index(), + definition.ssa_temp_index() + 1); } else { - f->Print("v%" Pd "", definition.ssa_temp_index()); + f->Printf("v%" Pd "", definition.ssa_temp_index()); } } else if (definition.HasTemp()) { - f->Print("t%" Pd "", definition.temp_index()); + f->Printf("t%" Pd "", definition.temp_index()); } } @@ -267,114 +268,114 @@ const char* Instruction::ToCString() const { return Thread::Current()->zone()->MakeCopyOfString(buffer); } -void Instruction::PrintTo(BufferFormatter* f) const { +void Instruction::PrintTo(BaseTextBuffer* f) const { if (GetDeoptId() != DeoptId::kNone) { - f->Print("%s:%" Pd "(", DebugName(), GetDeoptId()); + f->Printf("%s:%" Pd "(", DebugName(), GetDeoptId()); } else { - f->Print("%s(", DebugName()); + f->Printf("%s(", DebugName()); } PrintOperandsTo(f); - f->Print(")"); + f->AddString(")"); } -void Instruction::PrintOperandsTo(BufferFormatter* f) const { +void Instruction::PrintOperandsTo(BaseTextBuffer* f) const { for (int i = 0; i < InputCount(); ++i) { - if (i > 0) f->Print(", "); + if (i > 0) f->AddString(", "); if (InputAt(i) != NULL) InputAt(i)->PrintTo(f); } } -void Definition::PrintTo(BufferFormatter* f) const { +void Definition::PrintTo(BaseTextBuffer* f) const { PrintUse(f, *this); - if (HasSSATemp() || HasTemp()) f->Print(" <- "); + if (HasSSATemp() || HasTemp()) f->AddString(" <- "); if (GetDeoptId() != DeoptId::kNone) { - f->Print("%s:%" Pd "(", DebugName(), GetDeoptId()); + f->Printf("%s:%" Pd "(", DebugName(), GetDeoptId()); } else { - f->Print("%s(", DebugName()); + f->Printf("%s(", DebugName()); } PrintOperandsTo(f); - f->Print(")"); + f->AddString(")"); if (range_ != NULL) { - f->Print(" "); + f->AddString(" "); range_->PrintTo(f); } if (type_ != NULL) { - f->Print(" "); + f->AddString(" "); type_->PrintTo(f); } } -void CheckNullInstr::PrintOperandsTo(BufferFormatter* f) const { +void CheckNullInstr::PrintOperandsTo(BaseTextBuffer* f) const { Definition::PrintOperandsTo(f); switch (exception_type()) { case kNoSuchMethod: - f->Print(", NoSuchMethodError"); + f->AddString(", NoSuchMethodError"); break; case kArgumentError: - f->Print(", ArgumentError"); + f->AddString(", ArgumentError"); break; case kCastError: - f->Print(", CastError"); + f->AddString(", CastError"); break; } } -void Definition::PrintOperandsTo(BufferFormatter* f) const { +void Definition::PrintOperandsTo(BaseTextBuffer* f) const { for (int i = 0; i < InputCount(); ++i) { - if (i > 0) f->Print(", "); + if (i > 0) f->AddString(", "); if (InputAt(i) != NULL) { InputAt(i)->PrintTo(f); } } } -void RedefinitionInstr::PrintOperandsTo(BufferFormatter* f) const { +void RedefinitionInstr::PrintOperandsTo(BaseTextBuffer* f) const { Definition::PrintOperandsTo(f); if (constrained_type_ != nullptr) { - f->Print(" ^ %s", constrained_type_->ToCString()); + f->Printf(" ^ %s", constrained_type_->ToCString()); } } -void ReachabilityFenceInstr::PrintOperandsTo(BufferFormatter* f) const { +void ReachabilityFenceInstr::PrintOperandsTo(BaseTextBuffer* f) const { value()->PrintTo(f); } -void Value::PrintTo(BufferFormatter* f) const { +void Value::PrintTo(BaseTextBuffer* f) const { PrintUse(f, *definition()); if ((reaching_type_ != NULL) && (reaching_type_ != definition()->type_)) { - f->Print(" "); + f->AddString(" "); reaching_type_->PrintTo(f); } } -void ConstantInstr::PrintOperandsTo(BufferFormatter* f) const { +void ConstantInstr::PrintOperandsTo(BaseTextBuffer* f) const { const char* cstr = value().ToCString(); const char* new_line = strchr(cstr, '\n'); if (new_line == NULL) { - f->Print("#%s", cstr); + f->Printf("#%s", cstr); } else { const intptr_t pos = new_line - cstr; char* buffer = Thread::Current()->zone()->Alloc(pos + 1); strncpy(buffer, cstr, pos); buffer[pos] = '\0'; - f->Print("#%s\\n...", buffer); + f->Printf("#%s\\n...", buffer); } } -void ConstraintInstr::PrintOperandsTo(BufferFormatter* f) const { +void ConstraintInstr::PrintOperandsTo(BaseTextBuffer* f) const { value()->PrintTo(f); - f->Print(" ^ "); + f->AddString(" ^ "); constraint()->PrintTo(f); } -void Range::PrintTo(BufferFormatter* f) const { - f->Print("["); +void Range::PrintTo(BaseTextBuffer* f) const { + f->AddString("["); min_.PrintTo(f); - f->Print(", "); + f->AddString(", "); max_.PrintTo(f); - f->Print("]"); + f->AddString("]"); } const char* Range::ToCString(const Range* range) { @@ -386,24 +387,24 @@ const char* Range::ToCString(const Range* range) { return Thread::Current()->zone()->MakeCopyOfString(buffer); } -void RangeBoundary::PrintTo(BufferFormatter* f) const { +void RangeBoundary::PrintTo(BaseTextBuffer* f) const { switch (kind_) { case kSymbol: - f->Print("v%" Pd "", - reinterpret_cast(value_)->ssa_temp_index()); - if (offset_ != 0) f->Print("%+" Pd64 "", offset_); + f->Printf("v%" Pd "", + reinterpret_cast(value_)->ssa_temp_index()); + if (offset_ != 0) f->Printf("%+" Pd64 "", offset_); break; case kNegativeInfinity: - f->Print("-inf"); + f->AddString("-inf"); break; case kPositiveInfinity: - f->Print("+inf"); + f->AddString("+inf"); break; case kConstant: - f->Print("%" Pd64 "", value_); + f->Printf("%" Pd64 "", value_); break; case kUnknown: - f->Print("_|_"); + f->AddString("_|_"); break; } } @@ -415,61 +416,61 @@ const char* RangeBoundary::ToCString() const { return Thread::Current()->zone()->MakeCopyOfString(buffer); } -void MakeTempInstr::PrintOperandsTo(BufferFormatter* f) const {} +void MakeTempInstr::PrintOperandsTo(BaseTextBuffer* f) const {} -void DropTempsInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%" Pd "", num_temps()); +void DropTempsInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%" Pd "", num_temps()); if (value() != NULL) { - f->Print(", "); + f->AddString(", "); value()->PrintTo(f); } } -void AssertAssignableInstr::PrintOperandsTo(BufferFormatter* f) const { +void AssertAssignableInstr::PrintOperandsTo(BaseTextBuffer* f) const { value()->PrintTo(f); - f->Print(", "); + f->AddString(", "); dst_type()->PrintTo(f); - f->Print(", '%s',", dst_name().ToCString()); - f->Print(" instantiator_type_args("); + f->Printf(", '%s',", dst_name().ToCString()); + f->AddString(" instantiator_type_args("); instantiator_type_arguments()->PrintTo(f); - f->Print("), function_type_args("); + f->AddString("), function_type_args("); function_type_arguments()->PrintTo(f); - f->Print(")"); + f->AddString(")"); } -void AssertSubtypeInstr::PrintOperandsTo(BufferFormatter* f) const { +void AssertSubtypeInstr::PrintOperandsTo(BaseTextBuffer* f) const { sub_type()->PrintTo(f); - f->Print(", "); + f->AddString(", "); super_type()->PrintTo(f); - f->Print(", '%s', ", dst_name().ToCString()); - f->Print(" instantiator_type_args("); + f->Printf(", '%s', ", dst_name().ToCString()); + f->AddString(" instantiator_type_args("); instantiator_type_arguments()->PrintTo(f); - f->Print("), function_type_args("); + f->AddString("), function_type_args("); function_type_arguments()->PrintTo(f); - f->Print(")"); + f->AddString(")"); } -void AssertBooleanInstr::PrintOperandsTo(BufferFormatter* f) const { +void AssertBooleanInstr::PrintOperandsTo(BaseTextBuffer* f) const { value()->PrintTo(f); } -void ClosureCallInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print(" function="); +void ClosureCallInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->AddString(" function="); InputAt(InputCount() - 1)->PrintTo(f); - f->Print("<%" Pd ">", type_args_len()); + f->Printf("<%" Pd ">", type_args_len()); for (intptr_t i = 0; i < ArgumentCount(); ++i) { - f->Print(", "); + f->AddString(", "); ArgumentValueAt(i)->PrintTo(f); } if (entry_kind() == Code::EntryKind::kUnchecked) { - f->Print(" using unchecked entrypoint"); + f->AddString(" using unchecked entrypoint"); } } -void InstanceCallInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print(" %s<%" Pd ">", function_name().ToCString(), type_args_len()); +void InstanceCallInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf(" %s<%" Pd ">", function_name().ToCString(), type_args_len()); for (intptr_t i = 0; i < ArgumentCount(); ++i) { - f->Print(", "); + f->AddString(", "); ArgumentValueAt(i)->PrintTo(f); } if (HasICData()) { @@ -480,287 +481,287 @@ void InstanceCallInstr::PrintOperandsTo(BufferFormatter* f) const { } } if (result_type() != nullptr) { - f->Print(", result_type = %s", result_type()->ToCString()); + f->Printf(", result_type = %s", result_type()->ToCString()); } if (entry_kind() == Code::EntryKind::kUnchecked) { - f->Print(" using unchecked entrypoint"); + f->AddString(" using unchecked entrypoint"); } } -void PolymorphicInstanceCallInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print(" %s<%" Pd ">", function_name().ToCString(), type_args_len()); +void PolymorphicInstanceCallInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf(" %s<%" Pd ">", function_name().ToCString(), type_args_len()); for (intptr_t i = 0; i < ArgumentCount(); ++i) { - f->Print(", "); + f->AddString(", "); ArgumentValueAt(i)->PrintTo(f); } PrintTargetsHelper(f, targets_, FlowGraphPrinter::kPrintAll); if (complete()) { - f->Print(" COMPLETE"); + f->AddString(" COMPLETE"); } if (entry_kind() == Code::EntryKind::kUnchecked) { - f->Print(" using unchecked entrypoint"); + f->AddString(" using unchecked entrypoint"); } } -void DispatchTableCallInstr::PrintOperandsTo(BufferFormatter* f) const { +void DispatchTableCallInstr::PrintOperandsTo(BaseTextBuffer* f) const { const String& name = String::Handle(interface_target().QualifiedUserVisibleName()); - f->Print(" cid="); + f->AddString(" cid="); class_id()->PrintTo(f); - f->Print(" %s<%" Pd ">", name.ToCString(), type_args_len()); + f->Printf(" %s<%" Pd ">", name.ToCString(), type_args_len()); for (intptr_t i = 0; i < ArgumentCount(); ++i) { - f->Print(", "); + f->AddString(", "); ArgumentValueAt(i)->PrintTo(f); } } -void StrictCompareInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s, ", Token::Str(kind())); +void StrictCompareInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s, ", Token::Str(kind())); left()->PrintTo(f); - f->Print(", "); + f->AddString(", "); right()->PrintTo(f); if (needs_number_check()) { - f->Print(", with number check"); + f->Printf(", with number check"); } } -void TestCidsInstr::PrintOperandsTo(BufferFormatter* f) const { +void TestCidsInstr::PrintOperandsTo(BaseTextBuffer* f) const { left()->PrintTo(f); - f->Print(" %s [", Token::Str(kind())); + f->Printf(" %s [", Token::Str(kind())); intptr_t length = cid_results().length(); for (intptr_t i = 0; i < length; i += 2) { - f->Print("0x%" Px ":%s ", cid_results()[i], - cid_results()[i + 1] == 0 ? "false" : "true"); + f->Printf("0x%" Px ":%s ", cid_results()[i], + cid_results()[i + 1] == 0 ? "false" : "true"); } - f->Print("] "); + f->AddString("] "); if (CanDeoptimize()) { ASSERT(deopt_id() != DeoptId::kNone); - f->Print("else deoptimize "); + f->AddString("else deoptimize "); } else { ASSERT(deopt_id() == DeoptId::kNone); - f->Print("else %s ", cid_results()[length - 1] != 0 ? "false" : "true"); + f->Printf("else %s ", cid_results()[length - 1] != 0 ? "false" : "true"); } } -void EqualityCompareInstr::PrintOperandsTo(BufferFormatter* f) const { +void EqualityCompareInstr::PrintOperandsTo(BaseTextBuffer* f) const { left()->PrintTo(f); - f->Print(" %s ", Token::Str(kind())); + f->Printf(" %s ", Token::Str(kind())); right()->PrintTo(f); } -void StaticCallInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print(" %s<%" Pd "> ", String::Handle(function().name()).ToCString(), - type_args_len()); +void StaticCallInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf(" %s<%" Pd "> ", String::Handle(function().name()).ToCString(), + type_args_len()); for (intptr_t i = 0; i < ArgumentCount(); ++i) { - if (i > 0) f->Print(", "); + if (i > 0) f->AddString(", "); ArgumentValueAt(i)->PrintTo(f); } if (entry_kind() == Code::EntryKind::kUnchecked) { - f->Print(", using unchecked entrypoint"); + f->AddString(", using unchecked entrypoint"); } if (function().recognized_kind() != MethodRecognizer::kUnknown) { - f->Print(", recognized_kind = %s", - MethodRecognizer::KindToCString(function().recognized_kind())); + f->Printf(", recognized_kind = %s", + MethodRecognizer::KindToCString(function().recognized_kind())); } if (result_type() != nullptr) { - f->Print(", result_type = %s", result_type()->ToCString()); + f->Printf(", result_type = %s", result_type()->ToCString()); } } -void LoadLocalInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s @%d", local().name().ToCString(), local().index().value()); +void LoadLocalInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s @%d", local().name().ToCString(), local().index().value()); } -void StoreLocalInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s @%d, ", local().name().ToCString(), local().index().value()); +void StoreLocalInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s @%d, ", local().name().ToCString(), local().index().value()); value()->PrintTo(f); } -void NativeCallInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s", native_name().ToCString()); +void NativeCallInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s", native_name().ToCString()); } -void GuardFieldInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s %s, ", String::Handle(field().name()).ToCString(), - field().GuardedPropertiesAsCString()); +void GuardFieldInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s %s, ", String::Handle(field().name()).ToCString(), + field().GuardedPropertiesAsCString()); value()->PrintTo(f); } -void StoreInstanceFieldInstr::PrintOperandsTo(BufferFormatter* f) const { +void StoreInstanceFieldInstr::PrintOperandsTo(BaseTextBuffer* f) const { instance()->PrintTo(f); - f->Print(" . %s = ", slot().Name()); + f->Printf(" . %s = ", slot().Name()); value()->PrintTo(f); // Here, we just print the value of the enum field. We would prefer to get // the final decision on whether a store barrier will be emitted by calling // ShouldEmitStoreBarrier(), but that can change parts of the flow graph. if (emit_store_barrier_ == kNoStoreBarrier) { - f->Print(", NoStoreBarrier"); + f->AddString(", NoStoreBarrier"); } } -void IfThenElseInstr::PrintOperandsTo(BufferFormatter* f) const { +void IfThenElseInstr::PrintOperandsTo(BaseTextBuffer* f) const { comparison()->PrintOperandsTo(f); - f->Print(" ? %" Pd " : %" Pd, if_true_, if_false_); + f->Printf(" ? %" Pd " : %" Pd, if_true_, if_false_); } -void LoadStaticFieldInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s", String::Handle(field().name()).ToCString()); +void LoadStaticFieldInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s", String::Handle(field().name()).ToCString()); if (calls_initializer()) { - f->Print(", CallsInitializer"); + f->AddString(", CallsInitializer"); } } -void StoreStaticFieldInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s, ", String::Handle(field().name()).ToCString()); +void StoreStaticFieldInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s, ", String::Handle(field().name()).ToCString()); value()->PrintTo(f); } -void InstanceOfInstr::PrintOperandsTo(BufferFormatter* f) const { +void InstanceOfInstr::PrintOperandsTo(BaseTextBuffer* f) const { value()->PrintTo(f); - f->Print(" IS %s,", String::Handle(type().Name()).ToCString()); - f->Print(" instantiator_type_args("); + f->Printf(" IS %s,", String::Handle(type().Name()).ToCString()); + f->AddString(" instantiator_type_args("); instantiator_type_arguments()->PrintTo(f); - f->Print("), function_type_args("); + f->AddString("), function_type_args("); function_type_arguments()->PrintTo(f); - f->Print(")"); + f->AddString(")"); } -void RelationalOpInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s, ", Token::Str(kind())); +void RelationalOpInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s, ", Token::Str(kind())); left()->PrintTo(f); - f->Print(", "); + f->AddString(", "); right()->PrintTo(f); } -void AllocateObjectInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s", String::Handle(cls().ScrubbedName()).ToCString()); +void AllocateObjectInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s", String::Handle(cls().ScrubbedName()).ToCString()); for (intptr_t i = 0; i < InputCount(); ++i) { - f->Print(", "); + f->AddString(", "); InputAt(i)->PrintTo(f); } if (Identity().IsNotAliased()) { - f->Print(" "); + f->AddString(" "); } } -void MaterializeObjectInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s", String::Handle(cls_.ScrubbedName()).ToCString()); +void MaterializeObjectInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s", String::Handle(cls_.ScrubbedName()).ToCString()); for (intptr_t i = 0; i < InputCount(); i++) { - f->Print(", "); - f->Print("%s: ", slots_[i]->Name()); + f->AddString(", "); + f->Printf("%s: ", slots_[i]->Name()); InputAt(i)->PrintTo(f); } } -void LoadFieldInstr::PrintOperandsTo(BufferFormatter* f) const { +void LoadFieldInstr::PrintOperandsTo(BaseTextBuffer* f) const { instance()->PrintTo(f); - f->Print(" . %s%s", slot().Name(), slot().is_immutable() ? " {final}" : ""); + f->Printf(" . %s%s", slot().Name(), slot().is_immutable() ? " {final}" : ""); if (calls_initializer()) { - f->Print(", CallsInitializer"); + f->AddString(", CallsInitializer"); } } -void LoadUntaggedInstr::PrintOperandsTo(BufferFormatter* f) const { +void LoadUntaggedInstr::PrintOperandsTo(BaseTextBuffer* f) const { object()->PrintTo(f); - f->Print(", %" Pd, offset()); + f->Printf(", %" Pd, offset()); } -void InstantiateTypeInstr::PrintOperandsTo(BufferFormatter* f) const { +void InstantiateTypeInstr::PrintOperandsTo(BaseTextBuffer* f) const { const String& type_name = String::Handle(type().Name()); - f->Print("%s,", type_name.ToCString()); - f->Print(" instantiator_type_args("); + f->Printf("%s,", type_name.ToCString()); + f->AddString(" instantiator_type_args("); instantiator_type_arguments()->PrintTo(f); - f->Print("), function_type_args("); + f->AddString("), function_type_args("); function_type_arguments()->PrintTo(f); - f->Print(")"); + f->AddString(")"); } -void InstantiateTypeArgumentsInstr::PrintOperandsTo(BufferFormatter* f) const { +void InstantiateTypeArgumentsInstr::PrintOperandsTo(BaseTextBuffer* f) const { const String& type_args = String::Handle(type_arguments().Name()); - f->Print("%s,", type_args.ToCString()); - f->Print(" instantiator_type_args("); + f->Printf("%s,", type_args.ToCString()); + f->AddString(" instantiator_type_args("); instantiator_type_arguments()->PrintTo(f); - f->Print("), function_type_args("); + f->AddString("), function_type_args("); function_type_arguments()->PrintTo(f); - f->Print("), instantiator_class(%s)", instantiator_class().ToCString()); + f->Printf("), instantiator_class(%s)", instantiator_class().ToCString()); } -void AllocateContextInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%" Pd "", num_context_variables()); +void AllocateContextInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%" Pd "", num_context_variables()); } void AllocateUninitializedContextInstr::PrintOperandsTo( - BufferFormatter* f) const { - f->Print("%" Pd "", num_context_variables()); + BaseTextBuffer* f) const { + f->Printf("%" Pd "", num_context_variables()); if (Identity().IsNotAliased()) { - f->Print(" "); + f->AddString(" "); } } -void MathUnaryInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("'%s', ", MathUnaryInstr::KindToCString(kind())); +void MathUnaryInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("'%s', ", MathUnaryInstr::KindToCString(kind())); value()->PrintTo(f); } -void TruncDivModInstr::PrintOperandsTo(BufferFormatter* f) const { +void TruncDivModInstr::PrintOperandsTo(BaseTextBuffer* f) const { Definition::PrintOperandsTo(f); } -void ExtractNthOutputInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("Extract %" Pd " from ", index()); +void ExtractNthOutputInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("Extract %" Pd " from ", index()); Definition::PrintOperandsTo(f); } -void UnaryIntegerOpInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s, ", Token::Str(op_kind())); +void UnaryIntegerOpInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s, ", Token::Str(op_kind())); value()->PrintTo(f); } -void CheckedSmiOpInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s", Token::Str(op_kind())); - f->Print(", "); +void CheckedSmiOpInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s", Token::Str(op_kind())); + f->AddString(", "); left()->PrintTo(f); - f->Print(", "); + f->AddString(", "); right()->PrintTo(f); } -void CheckedSmiComparisonInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s", Token::Str(kind())); - f->Print(", "); +void CheckedSmiComparisonInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s", Token::Str(kind())); + f->AddString(", "); left()->PrintTo(f); - f->Print(", "); + f->AddString(", "); right()->PrintTo(f); } -void BinaryIntegerOpInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s", Token::Str(op_kind())); +void BinaryIntegerOpInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s", Token::Str(op_kind())); if (is_truncating()) { - f->Print(" [tr]"); + f->AddString(" [tr]"); } else if (!can_overflow()) { - f->Print(" [-o]"); + f->AddString(" [-o]"); } - f->Print(", "); + f->AddString(", "); left()->PrintTo(f); - f->Print(", "); + f->AddString(", "); right()->PrintTo(f); } -void BinaryDoubleOpInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s, ", Token::Str(op_kind())); +void BinaryDoubleOpInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s, ", Token::Str(op_kind())); left()->PrintTo(f); - f->Print(", "); + f->AddString(", "); right()->PrintTo(f); } -void DoubleTestOpInstr::PrintOperandsTo(BufferFormatter* f) const { +void DoubleTestOpInstr::PrintOperandsTo(BaseTextBuffer* f) const { switch (op_kind()) { case MethodRecognizer::kDouble_getIsNaN: - f->Print("IsNaN "); + f->AddString("IsNaN "); break; case MethodRecognizer::kDouble_getIsInfinite: - f->Print("IsInfinite "); + f->AddString("IsInfinite "); break; default: UNREACHABLE(); @@ -774,131 +775,131 @@ static const char* simd_op_kind_string[] = { #undef CASE }; -void SimdOpInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s", simd_op_kind_string[kind()]); +void SimdOpInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s", simd_op_kind_string[kind()]); if (HasMask()) { - f->Print(", mask = %" Pd "", mask()); + f->Printf(", mask = %" Pd "", mask()); } for (intptr_t i = 0; i < InputCount(); i++) { - f->Print(", "); + f->AddString(", "); InputAt(i)->PrintTo(f); } } -void UnaryDoubleOpInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s, ", Token::Str(op_kind())); +void UnaryDoubleOpInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s, ", Token::Str(op_kind())); value()->PrintTo(f); } -void LoadClassIdInstr::PrintOperandsTo(BufferFormatter* f) const { +void LoadClassIdInstr::PrintOperandsTo(BaseTextBuffer* f) const { if (!input_can_be_smi_) { - f->Print(" "); + f->AddString(" "); } object()->PrintTo(f); } -void CheckClassIdInstr::PrintOperandsTo(BufferFormatter* f) const { +void CheckClassIdInstr::PrintOperandsTo(BaseTextBuffer* f) const { value()->PrintTo(f); const Class& cls = Class::Handle(Isolate::Current()->class_table()->At(cids().cid_start)); const String& name = String::Handle(cls.ScrubbedName()); if (cids().IsSingleCid()) { - f->Print(", %s", name.ToCString()); + f->Printf(", %s", name.ToCString()); } else { const Class& cls2 = Class::Handle(Isolate::Current()->class_table()->At(cids().cid_end)); const String& name2 = String::Handle(cls2.ScrubbedName()); - f->Print(", cid %" Pd "-%" Pd " %s-%s", cids().cid_start, cids().cid_end, - name.ToCString(), name2.ToCString()); + f->Printf(", cid %" Pd "-%" Pd " %s-%s", cids().cid_start, cids().cid_end, + name.ToCString(), name2.ToCString()); } } -void CheckClassInstr::PrintOperandsTo(BufferFormatter* f) const { +void CheckClassInstr::PrintOperandsTo(BaseTextBuffer* f) const { value()->PrintTo(f); PrintCidsHelper(f, cids_, FlowGraphPrinter::kPrintAll); if (IsNullCheck()) { - f->Print(" nullcheck"); + f->AddString(" nullcheck"); } } -void CheckConditionInstr::PrintOperandsTo(BufferFormatter* f) const { +void CheckConditionInstr::PrintOperandsTo(BaseTextBuffer* f) const { comparison()->PrintOperandsTo(f); } -void InvokeMathCFunctionInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s, ", MethodRecognizer::KindToCString(recognized_kind_)); +void InvokeMathCFunctionInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s, ", MethodRecognizer::KindToCString(recognized_kind_)); Definition::PrintOperandsTo(f); } void BlockEntryWithInitialDefs::PrintInitialDefinitionsTo( - BufferFormatter* f) const { + BaseTextBuffer* f) const { const GrowableArray& defns = initial_definitions_; if (defns.length() > 0) { - f->Print(" {"); + f->AddString(" {"); for (intptr_t i = 0; i < defns.length(); ++i) { Definition* def = defns[i]; - f->Print("\n "); + f->AddString("\n "); def->PrintTo(f); } - f->Print("\n}"); + f->AddString("\n}"); } } -void GraphEntryInstr::PrintTo(BufferFormatter* f) const { - f->Print("B%" Pd "[graph]:%" Pd, block_id(), GetDeoptId()); +void GraphEntryInstr::PrintTo(BaseTextBuffer* f) const { + f->Printf("B%" Pd "[graph]:%" Pd, block_id(), GetDeoptId()); BlockEntryWithInitialDefs::PrintInitialDefinitionsTo(f); } -void JoinEntryInstr::PrintTo(BufferFormatter* f) const { +void JoinEntryInstr::PrintTo(BaseTextBuffer* f) const { if (try_index() != kInvalidTryIndex) { - f->Print("B%" Pd "[join try_idx %" Pd "]:%" Pd " pred(", block_id(), - try_index(), GetDeoptId()); + f->Printf("B%" Pd "[join try_idx %" Pd "]:%" Pd " pred(", block_id(), + try_index(), GetDeoptId()); } else { - f->Print("B%" Pd "[join]:%" Pd " pred(", block_id(), GetDeoptId()); + f->Printf("B%" Pd "[join]:%" Pd " pred(", block_id(), GetDeoptId()); } for (intptr_t i = 0; i < predecessors_.length(); ++i) { - if (i > 0) f->Print(", "); - f->Print("B%" Pd, predecessors_[i]->block_id()); + if (i > 0) f->AddString(", "); + f->Printf("B%" Pd, predecessors_[i]->block_id()); } - f->Print(")"); + f->AddString(")"); if (phis_ != NULL) { - f->Print(" {"); + f->AddString(" {"); for (intptr_t i = 0; i < phis_->length(); ++i) { if ((*phis_)[i] == NULL) continue; - f->Print("\n "); + f->AddString("\n "); (*phis_)[i]->PrintTo(f); } - f->Print("\n}"); + f->AddString("\n}"); } if (HasParallelMove()) { - f->Print(" "); + f->AddString(" "); parallel_move()->PrintTo(f); } } -void IndirectEntryInstr::PrintTo(BufferFormatter* f) const { - f->Print("B%" Pd "[join indirect", block_id()); +void IndirectEntryInstr::PrintTo(BaseTextBuffer* f) const { + f->Printf("B%" Pd "[join indirect", block_id()); if (try_index() != kInvalidTryIndex) { - f->Print(" try_idx %" Pd, try_index()); + f->Printf(" try_idx %" Pd, try_index()); } - f->Print("]:%" Pd " pred(", GetDeoptId()); + f->Printf("]:%" Pd " pred(", GetDeoptId()); for (intptr_t i = 0; i < predecessors_.length(); ++i) { - if (i > 0) f->Print(", "); - f->Print("B%" Pd, predecessors_[i]->block_id()); + if (i > 0) f->AddString(", "); + f->Printf("B%" Pd, predecessors_[i]->block_id()); } - f->Print(")"); + f->AddString(")"); if (phis_ != NULL) { - f->Print(" {"); + f->AddString(" {"); for (intptr_t i = 0; i < phis_->length(); ++i) { if ((*phis_)[i] == NULL) continue; - f->Print("\n "); + f->AddString("\n "); (*phis_)[i]->PrintTo(f); } - f->Print("\n}"); + f->AddString("\n}"); } if (HasParallelMove()) { - f->Print(" "); + f->AddString(" "); parallel_move()->PrintTo(f); } } @@ -935,62 +936,58 @@ const char* RepresentationToCString(Representation rep) { return "?"; } -void PhiInstr::PrintTo(BufferFormatter* f) const { +void PhiInstr::PrintTo(BaseTextBuffer* f) const { if (HasPairRepresentation()) { - f->Print("(v%" Pd ", v%" Pd ") <- phi(", ssa_temp_index(), - ssa_temp_index() + 1); + f->Printf("(v%" Pd ", v%" Pd ") <- phi(", ssa_temp_index(), + ssa_temp_index() + 1); } else { - f->Print("v%" Pd " <- phi(", ssa_temp_index()); + f->Printf("v%" Pd " <- phi(", ssa_temp_index()); } for (intptr_t i = 0; i < inputs_.length(); ++i) { if (inputs_[i] != NULL) inputs_[i]->PrintTo(f); - if (i < inputs_.length() - 1) f->Print(", "); - } - f->Print(")"); - if (is_alive()) { - f->Print(" alive"); - } else { - f->Print(" dead"); + if (i < inputs_.length() - 1) f->AddString(", "); } + f->AddString(")"); + f->AddString(is_alive() ? " alive" : " dead"); if (range_ != NULL) { - f->Print(" "); + f->AddString(" "); range_->PrintTo(f); } if (representation() != kNoRepresentation && representation() != kTagged) { - f->Print(" %s", RepresentationToCString(representation())); + f->Printf(" %s", RepresentationToCString(representation())); } if (HasType()) { - f->Print(" %s", TypeAsCString()); + f->Printf(" %s", TypeAsCString()); } } -void UnboxIntegerInstr::PrintOperandsTo(BufferFormatter* f) const { +void UnboxIntegerInstr::PrintOperandsTo(BaseTextBuffer* f) const { if (is_truncating()) { - f->Print("[tr], "); + f->AddString("[tr], "); } Definition::PrintOperandsTo(f); } -void IntConverterInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s->%s%s, ", RepresentationToCString(from()), - RepresentationToCString(to()), is_truncating() ? "[tr]" : ""); +void IntConverterInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s->%s%s, ", RepresentationToCString(from()), + RepresentationToCString(to()), is_truncating() ? "[tr]" : ""); Definition::PrintOperandsTo(f); } -void BitCastInstr::PrintOperandsTo(BufferFormatter* f) const { +void BitCastInstr::PrintOperandsTo(BaseTextBuffer* f) const { Definition::PrintOperandsTo(f); - f->Print(" (%s -> %s)", RepresentationToCString(from()), - RepresentationToCString(to())); + f->Printf(" (%s -> %s)", RepresentationToCString(from()), + RepresentationToCString(to())); } -void ParameterInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%" Pd, index()); +void ParameterInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%" Pd, index()); } -void SpecialParameterInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s", KindToCString(kind())); +void SpecialParameterInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s", KindToCString(kind())); } const char* SpecialParameterInstr::ToCString() const { @@ -1000,125 +997,125 @@ const char* SpecialParameterInstr::ToCString() const { return Thread::Current()->zone()->MakeCopyOfString(buffer); } -void CheckStackOverflowInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("stack=%" Pd ", loop=%" Pd, stack_depth(), loop_depth()); +void CheckStackOverflowInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("stack=%" Pd ", loop=%" Pd, stack_depth(), loop_depth()); } -void TargetEntryInstr::PrintTo(BufferFormatter* f) const { +void TargetEntryInstr::PrintTo(BaseTextBuffer* f) const { if (try_index() != kInvalidTryIndex) { - f->Print("B%" Pd "[target try_idx %" Pd "]:%" Pd, block_id(), try_index(), - GetDeoptId()); + f->Printf("B%" Pd "[target try_idx %" Pd "]:%" Pd, block_id(), try_index(), + GetDeoptId()); } else { - f->Print("B%" Pd "[target]:%" Pd, block_id(), GetDeoptId()); + f->Printf("B%" Pd "[target]:%" Pd, block_id(), GetDeoptId()); } if (HasParallelMove()) { - f->Print(" "); + f->AddString(" "); parallel_move()->PrintTo(f); } } -void OsrEntryInstr::PrintTo(BufferFormatter* f) const { - f->Print("B%" Pd "[osr entry]:%" Pd " stack_depth=%" Pd, block_id(), - GetDeoptId(), stack_depth()); +void OsrEntryInstr::PrintTo(BaseTextBuffer* f) const { + f->Printf("B%" Pd "[osr entry]:%" Pd " stack_depth=%" Pd, block_id(), + GetDeoptId(), stack_depth()); if (HasParallelMove()) { - f->Print("\n"); + f->AddString("\n"); parallel_move()->PrintTo(f); } BlockEntryWithInitialDefs::PrintInitialDefinitionsTo(f); } -void FunctionEntryInstr::PrintTo(BufferFormatter* f) const { - f->Print("B%" Pd "[function entry]:%" Pd, block_id(), GetDeoptId()); +void FunctionEntryInstr::PrintTo(BaseTextBuffer* f) const { + f->Printf("B%" Pd "[function entry]:%" Pd, block_id(), GetDeoptId()); if (HasParallelMove()) { - f->Print("\n"); + f->AddString("\n"); parallel_move()->PrintTo(f); } BlockEntryWithInitialDefs::PrintInitialDefinitionsTo(f); } -void NativeEntryInstr::PrintTo(BufferFormatter* f) const { - f->Print("B%" Pd "[native function entry]:%" Pd, block_id(), GetDeoptId()); +void NativeEntryInstr::PrintTo(BaseTextBuffer* f) const { + f->Printf("B%" Pd "[native function entry]:%" Pd, block_id(), GetDeoptId()); if (HasParallelMove()) { - f->Print("\n"); + f->AddString("\n"); parallel_move()->PrintTo(f); } BlockEntryWithInitialDefs::PrintInitialDefinitionsTo(f); } -void ReturnInstr::PrintOperandsTo(BufferFormatter* f) const { +void ReturnInstr::PrintOperandsTo(BaseTextBuffer* f) const { Instruction::PrintOperandsTo(f); if (yield_index() != PcDescriptorsLayout::kInvalidYieldIndex) { - f->Print(", yield_index = %" Pd "", yield_index()); + f->Printf(", yield_index = %" Pd "", yield_index()); } } -void FfiCallInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print(" pointer="); +void FfiCallInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->AddString(" pointer="); InputAt(TargetAddressIndex())->PrintTo(f); for (intptr_t i = 0, n = InputCount(); i < n - 1; ++i) { - f->Print(", "); + f->AddString(", "); InputAt(i)->PrintTo(f); - f->Print(" (@"); + f->AddString(" (@"); marshaller_.Location(i).PrintTo(f); - f->Print(")"); + f->AddString(")"); } } -void EnterHandleScopeInstr::PrintOperandsTo(BufferFormatter* f) const { +void EnterHandleScopeInstr::PrintOperandsTo(BaseTextBuffer* f) const { if (kind_ == Kind::kEnterHandleScope) { - f->Print(""); + f->AddString(""); } else { - f->Print(""); + f->AddString(""); } } -void NativeReturnInstr::PrintOperandsTo(BufferFormatter* f) const { +void NativeReturnInstr::PrintOperandsTo(BaseTextBuffer* f) const { value()->PrintTo(f); - f->Print(" (@"); + f->AddString(" (@"); marshaller_.Location(compiler::ffi::kResultIndex).PrintTo(f); - f->Print(")"); + f->AddString(")"); } -void NativeParameterInstr::PrintOperandsTo(BufferFormatter* f) const { +void NativeParameterInstr::PrintOperandsTo(BaseTextBuffer* f) const { // Where the calling convention puts it. marshaller_.Location(index_).PrintTo(f); - f->Print(" at "); + f->AddString(" at "); // Where the arguments are when pushed on the stack. marshaller_.NativeLocationOfNativeParameter(index_).PrintTo(f); } -void CatchBlockEntryInstr::PrintTo(BufferFormatter* f) const { - f->Print("B%" Pd "[target catch try_idx %" Pd " catch_try_idx %" Pd "]", - block_id(), try_index(), catch_try_index()); +void CatchBlockEntryInstr::PrintTo(BaseTextBuffer* f) const { + f->Printf("B%" Pd "[target catch try_idx %" Pd " catch_try_idx %" Pd "]", + block_id(), try_index(), catch_try_index()); if (HasParallelMove()) { - f->Print("\n"); + f->AddString("\n"); parallel_move()->PrintTo(f); } BlockEntryWithInitialDefs::PrintInitialDefinitionsTo(f); } -void LoadIndexedUnsafeInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s[", RegisterNames::RegisterName(base_reg())); +void LoadIndexedUnsafeInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s[", RegisterNames::RegisterName(base_reg())); index()->PrintTo(f); - f->Print(" + %" Pd "]", offset()); + f->Printf(" + %" Pd "]", offset()); } -void StoreIndexedUnsafeInstr::PrintOperandsTo(BufferFormatter* f) const { - f->Print("%s[", RegisterNames::RegisterName(base_reg())); +void StoreIndexedUnsafeInstr::PrintOperandsTo(BaseTextBuffer* f) const { + f->Printf("%s[", RegisterNames::RegisterName(base_reg())); index()->PrintTo(f); - f->Print(" + %" Pd "], ", offset()); + f->Printf(" + %" Pd "], ", offset()); value()->PrintTo(f); } -void StoreIndexedInstr::PrintOperandsTo(BufferFormatter* f) const { +void StoreIndexedInstr::PrintOperandsTo(BaseTextBuffer* f) const { Instruction::PrintOperandsTo(f); if (!ShouldEmitStoreBarrier()) { - f->Print(", NoStoreBarrier"); + f->AddString(", NoStoreBarrier"); } } -void TailCallInstr::PrintOperandsTo(BufferFormatter* f) const { +void TailCallInstr::PrintOperandsTo(BaseTextBuffer* f) const { const char* name = ""; if (code_.IsStubCode()) { name = StubCode::NameOfStub(code_.EntryPoint()); @@ -1129,78 +1126,78 @@ void TailCallInstr::PrintOperandsTo(BufferFormatter* f) const { .ToFullyQualifiedCString(); } } - f->Print("%s(", name); + f->Printf("%s(", name); InputAt(0)->PrintTo(f); - f->Print(")"); + f->AddString(")"); } -void PushArgumentInstr::PrintOperandsTo(BufferFormatter* f) const { +void PushArgumentInstr::PrintOperandsTo(BaseTextBuffer* f) const { value()->PrintTo(f); } -void GotoInstr::PrintTo(BufferFormatter* f) const { +void GotoInstr::PrintTo(BaseTextBuffer* f) const { if (HasParallelMove()) { parallel_move()->PrintTo(f); - f->Print(" "); + f->AddString(" "); } if (GetDeoptId() != DeoptId::kNone) { - f->Print("goto:%" Pd " B%" Pd "", GetDeoptId(), successor()->block_id()); + f->Printf("goto:%" Pd " B%" Pd "", GetDeoptId(), successor()->block_id()); } else { - f->Print("goto: B%" Pd "", successor()->block_id()); + f->Printf("goto: B%" Pd "", successor()->block_id()); } } -void IndirectGotoInstr::PrintTo(BufferFormatter* f) const { +void IndirectGotoInstr::PrintTo(BaseTextBuffer* f) const { if (GetDeoptId() != DeoptId::kNone) { - f->Print("igoto:%" Pd "(", GetDeoptId()); + f->Printf("igoto:%" Pd "(", GetDeoptId()); } else { - f->Print("igoto:("); + f->AddString("igoto:("); } InputAt(0)->PrintTo(f); - f->Print(")"); + f->AddString(")"); } -void BranchInstr::PrintTo(BufferFormatter* f) const { - f->Print("%s ", DebugName()); - f->Print("if "); +void BranchInstr::PrintTo(BaseTextBuffer* f) const { + f->Printf("%s ", DebugName()); + f->AddString("if "); comparison()->PrintTo(f); - f->Print(" goto (%" Pd ", %" Pd ")", true_successor()->block_id(), - false_successor()->block_id()); + f->Printf(" goto (%" Pd ", %" Pd ")", true_successor()->block_id(), + false_successor()->block_id()); } -void ParallelMoveInstr::PrintTo(BufferFormatter* f) const { - f->Print("%s ", DebugName()); +void ParallelMoveInstr::PrintTo(BaseTextBuffer* f) const { + f->Printf("%s ", DebugName()); for (intptr_t i = 0; i < moves_.length(); i++) { - if (i != 0) f->Print(", "); + if (i != 0) f->AddString(", "); moves_[i]->dest().PrintTo(f); - f->Print(" <- "); + f->AddString(" <- "); moves_[i]->src().PrintTo(f); } } -void Utf8ScanInstr::PrintTo(BufferFormatter* f) const { +void Utf8ScanInstr::PrintTo(BaseTextBuffer* f) const { Definition::PrintTo(f); - f->Print(" [%s]", scan_flags_field_.Name()); + f->Printf(" [%s]", scan_flags_field_.Name()); } -void Environment::PrintTo(BufferFormatter* f) const { - f->Print(" env={ "); +void Environment::PrintTo(BaseTextBuffer* f) const { + f->AddString(" env={ "); int arg_count = 0; for (intptr_t i = 0; i < values_.length(); ++i) { - if (i > 0) f->Print(", "); + if (i > 0) f->AddString(", "); if (values_[i]->definition()->IsPushArgument()) { - f->Print("a%d", arg_count++); + f->Printf("a%d", arg_count++); } else { values_[i]->PrintTo(f); } if ((locations_ != NULL) && !locations_[i].IsInvalid()) { - f->Print(" ["); + f->AddString(" ["); locations_[i].PrintTo(f); - f->Print("]"); + f->AddString("]"); } } - f->Print(" }"); + f->AddString(" }"); if (outer_ != NULL) outer_->PrintTo(f); } diff --git a/runtime/vm/compiler/backend/locations.cc b/runtime/vm/compiler/backend/locations.cc index 8d7c75918cb..2c40969dfaa 100644 --- a/runtime/vm/compiler/backend/locations.cc +++ b/runtime/vm/compiler/backend/locations.cc @@ -249,24 +249,24 @@ const char* Location::Name() const { return "?"; } -void Location::PrintTo(BufferFormatter* f) const { +void Location::PrintTo(BaseTextBuffer* f) const { if (!FLAG_support_il_printer) { return; } if (kind() == kStackSlot) { - f->Print("S%+" Pd "", stack_index()); + f->Printf("S%+" Pd "", stack_index()); } else if (kind() == kDoubleStackSlot) { - f->Print("DS%+" Pd "", stack_index()); + f->Printf("DS%+" Pd "", stack_index()); } else if (kind() == kQuadStackSlot) { - f->Print("QS%+" Pd "", stack_index()); + f->Printf("QS%+" Pd "", stack_index()); } else if (IsPairLocation()) { - f->Print("("); + f->AddString("("); AsPairLocation()->At(0).PrintTo(f); - f->Print(", "); + f->AddString(", "); AsPairLocation()->At(1).PrintTo(f); - f->Print(")"); + f->AddString(")"); } else { - f->Print("%s", Name()); + f->Printf("%s", Name()); } } @@ -371,34 +371,34 @@ Location LocationRemapForSlowPath(Location loc, return loc; } -void LocationSummary::PrintTo(BufferFormatter* f) const { +void LocationSummary::PrintTo(BaseTextBuffer* f) const { if (!FLAG_support_il_printer) { return; } if (input_count() > 0) { - f->Print(" ("); + f->AddString(" ("); for (intptr_t i = 0; i < input_count(); i++) { - if (i != 0) f->Print(", "); + if (i != 0) f->AddString(", "); in(i).PrintTo(f); } - f->Print(")"); + f->AddString(")"); } if (temp_count() > 0) { - f->Print(" ["); + f->AddString(" ["); for (intptr_t i = 0; i < temp_count(); i++) { - if (i != 0) f->Print(", "); + if (i != 0) f->AddString(", "); temp(i).PrintTo(f); } - f->Print("]"); + f->AddString("]"); } if (!out(0).IsInvalid()) { - f->Print(" => "); + f->AddString(" => "); out(0).PrintTo(f); } - if (always_calls()) f->Print(" C"); + if (always_calls()) f->AddString(" C"); } #if defined(DEBUG) diff --git a/runtime/vm/compiler/backend/locations.h b/runtime/vm/compiler/backend/locations.h index d685250298f..34edf4c510a 100644 --- a/runtime/vm/compiler/backend/locations.h +++ b/runtime/vm/compiler/backend/locations.h @@ -18,7 +18,7 @@ namespace dart { -class BufferFormatter; +class BaseTextBuffer; class ConstantInstr; class Definition; class PairLocation; @@ -351,7 +351,7 @@ class Location : public ValueObject { intptr_t ToStackSlotOffset() const; const char* Name() const; - void PrintTo(BufferFormatter* f) const; + void PrintTo(BaseTextBuffer* f) const; void Print() const; const char* ToCString() const; @@ -723,7 +723,7 @@ class LocationSummary : public ZoneAllocated { return contains_call_ == kCallOnSharedSlowPath; } - void PrintTo(BufferFormatter* f) const; + void PrintTo(BaseTextBuffer* f) const; static LocationSummary* Make(Zone* zone, intptr_t input_count, diff --git a/runtime/vm/compiler/backend/loops.cc b/runtime/vm/compiler/backend/loops.cc index 21a4a7734fd..4ff2dc8805c 100644 --- a/runtime/vm/compiler/backend/loops.cc +++ b/runtime/vm/compiler/backend/loops.cc @@ -941,28 +941,32 @@ bool InductionVar::CanComputeBounds(LoopInfo* loop, return false; } -const char* InductionVar::ToCString() const { - char buffer[1024]; - BufferFormatter f(buffer, sizeof(buffer)); +void InductionVar::PrintTo(BaseTextBuffer* f) const { switch (kind_) { case kInvariant: if (mult_ != 0) { - f.Print("(%" Pd64 " + %" Pd64 " x %.4s)", offset_, mult_, - def_->ToCString()); + f->Printf("(%" Pd64 " + %" Pd64 " x %.4s)", offset_, mult_, + def_->ToCString()); } else { - f.Print("%" Pd64, offset_); + f->Printf("%" Pd64, offset_); } break; case kLinear: - f.Print("LIN(%s + %s * i)", initial_->ToCString(), next_->ToCString()); + f->Printf("LIN(%s + %s * i)", initial_->ToCString(), next_->ToCString()); break; case kWrapAround: - f.Print("WRAP(%s, %s)", initial_->ToCString(), next_->ToCString()); + f->Printf("WRAP(%s, %s)", initial_->ToCString(), next_->ToCString()); break; case kPeriodic: - f.Print("PERIOD(%s, %s)", initial_->ToCString(), next_->ToCString()); + f->Printf("PERIOD(%s, %s)", initial_->ToCString(), next_->ToCString()); break; } +} + +const char* InductionVar::ToCString() const { + char buffer[1024]; + BufferFormatter f(buffer, sizeof(buffer)); + PrintTo(&f); return Thread::Current()->zone()->MakeCopyOfString(buffer); } @@ -1112,24 +1116,28 @@ bool LoopInfo::IsInRange(Instruction* pos, Value* index, Value* length) { return false; } -const char* LoopInfo::ToCString() const { - char buffer[1024]; - BufferFormatter f(buffer, sizeof(buffer)); - f.Print("%*c", static_cast(2 * NestingDepth()), ' '); - f.Print("loop%" Pd " B%" Pd " ", id_, header_->block_id()); +void LoopInfo::PrintTo(BaseTextBuffer* f) const { + f->Printf("%*c", static_cast(2 * NestingDepth()), ' '); + f->Printf("loop%" Pd " B%" Pd " ", id_, header_->block_id()); intptr_t num_blocks = 0; for (BitVector::Iterator it(blocks_); !it.Done(); it.Advance()) { num_blocks++; } - f.Print("#blocks=%" Pd, num_blocks); - if (outer_ != nullptr) f.Print(" outer=%" Pd, outer_->id_); - if (inner_ != nullptr) f.Print(" inner=%" Pd, inner_->id_); - if (next_ != nullptr) f.Print(" next=%" Pd, next_->id_); - f.Print(" ["); + f->Printf("#blocks=%" Pd, num_blocks); + if (outer_ != nullptr) f->Printf(" outer=%" Pd, outer_->id_); + if (inner_ != nullptr) f->Printf(" inner=%" Pd, inner_->id_); + if (next_ != nullptr) f->Printf(" next=%" Pd, next_->id_); + f->AddString(" ["); for (intptr_t i = 0, n = back_edges_.length(); i < n; i++) { - f.Print(" B%" Pd, back_edges_[i]->block_id()); + f->Printf(" B%" Pd, back_edges_[i]->block_id()); } - f.Print(" ]"); + f->AddString(" ]"); +} + +const char* LoopInfo::ToCString() const { + char buffer[1024]; + BufferFormatter f(buffer, sizeof(buffer)); + PrintTo(&f); return Thread::Current()->zone()->MakeCopyOfString(buffer); } diff --git a/runtime/vm/compiler/backend/loops.h b/runtime/vm/compiler/backend/loops.h index 704508b84a7..9a70102f5c8 100644 --- a/runtime/vm/compiler/backend/loops.h +++ b/runtime/vm/compiler/backend/loops.h @@ -128,6 +128,7 @@ class InductionVar : public ZoneAllocated { const GrowableArray& bounds() { return bounds_; } // For debugging. + void PrintTo(BaseTextBuffer* f) const; const char* ToCString() const; // Returns true if x is invariant. @@ -258,6 +259,7 @@ class LoopInfo : public ZoneAllocated { LoopInfo* next() const { return next_; } // For debugging. + void PrintTo(BaseTextBuffer* f) const; const char* ToCString() const; private: diff --git a/runtime/vm/compiler/backend/loops_test.cc b/runtime/vm/compiler/backend/loops_test.cc index 3898334c104..8f1201ec63c 100644 --- a/runtime/vm/compiler/backend/loops_test.cc +++ b/runtime/vm/compiler/backend/loops_test.cc @@ -24,12 +24,12 @@ namespace dart { // Helper method to construct an induction debug string for loop hierarchy. -void TestString(BufferFormatter* f, +void TestString(BaseTextBuffer* f, LoopInfo* loop, const GrowableArray& preorder) { for (; loop != nullptr; loop = loop->next()) { intptr_t depth = loop->NestingDepth(); - f->Print("%*c[%" Pd "\n", static_cast(2 * depth), ' ', loop->id()); + f->Printf("%*c[%" Pd "\n", static_cast(2 * depth), ' ', loop->id()); for (BitVector::Iterator block_it(loop->blocks()); !block_it.Done(); block_it.Advance()) { BlockEntryInstr* block = preorder[block_it.Current()]; @@ -38,12 +38,12 @@ void TestString(BufferFormatter* f, InductionVar* induc = loop->LookupInduction(it.Current()); if (induc != nullptr) { // Obtain the debug string for induction and bounds. - f->Print("%*c%s", static_cast(2 * depth), ' ', - induc->ToCString()); + f->Printf("%*c%s", static_cast(2 * depth), ' ', + induc->ToCString()); for (auto bound : induc->bounds()) { - f->Print(" %s", bound.limit_->ToCString()); + f->Printf(" %s", bound.limit_->ToCString()); } - f->Print("\n"); + f->AddString("\n"); } } } @@ -51,13 +51,13 @@ void TestString(BufferFormatter* f, InductionVar* induc = loop->LookupInduction(it.Current()->AsDefinition()); if (InductionVar::IsInduction(induc)) { - f->Print("%*c%s\n", static_cast(2 * depth), ' ', - induc->ToCString()); + f->Printf("%*c%s\n", static_cast(2 * depth), ' ', + induc->ToCString()); } } } TestString(f, loop->inner(), preorder); - f->Print("%*c]\n", static_cast(2 * depth), ' '); + f->Printf("%*c]\n", static_cast(2 * depth), ' '); } } diff --git a/runtime/vm/compiler/backend/range_analysis.cc b/runtime/vm/compiler/backend/range_analysis.cc index a802eaacb2d..281e3c9d547 100644 --- a/runtime/vm/compiler/backend/range_analysis.cc +++ b/runtime/vm/compiler/backend/range_analysis.cc @@ -1310,22 +1310,22 @@ class BoundsCheckGeneralizer { } #ifndef PRODUCT - static void PrettyPrintIndexBoundRecursively(BufferFormatter* f, + static void PrettyPrintIndexBoundRecursively(BaseTextBuffer* f, Definition* index_bound) { BinarySmiOpInstr* binary_op = index_bound->AsBinarySmiOp(); if (binary_op != NULL) { - f->Print("("); + f->AddString("("); PrettyPrintIndexBoundRecursively(f, binary_op->left()->definition()); - f->Print(" %s ", Token::Str(binary_op->op_kind())); + f->Printf(" %s ", Token::Str(binary_op->op_kind())); PrettyPrintIndexBoundRecursively(f, binary_op->right()->definition()); - f->Print(")"); + f->AddString(")"); } else if (index_bound->IsConstant()) { - f->Print("%" Pd "", - Smi::Cast(index_bound->AsConstant()->value()).Value()); + f->Printf("%" Pd "", + Smi::Cast(index_bound->AsConstant()->value()).Value()); } else { - f->Print("v%" Pd "", index_bound->ssa_temp_index()); + f->Printf("v%" Pd "", index_bound->ssa_temp_index()); } - f->Print(" {%s}", Range::ToCString(index_bound->range())); + f->Printf(" {%s}", Range::ToCString(index_bound->range())); } static const char* IndexBoundToCString(Definition* index_bound) { diff --git a/runtime/vm/compiler/backend/range_analysis.h b/runtime/vm/compiler/backend/range_analysis.h index 0ed49366388..0f8cc42ffa3 100644 --- a/runtime/vm/compiler/backend/range_analysis.h +++ b/runtime/vm/compiler/backend/range_analysis.h @@ -244,7 +244,7 @@ class RangeBoundary : public ValueObject { // IsSymbol() -> upper bound computed from definition + offset. RangeBoundary UpperBound() const; - void PrintTo(BufferFormatter* f) const; + void PrintTo(BaseTextBuffer* f) const; const char* ToCString() const; SExpression* ToSExpression(FlowGraphSerializer* s); @@ -345,7 +345,7 @@ class Range : public ZoneAllocated { RangeBoundary::MaxConstant(size)); } - void PrintTo(BufferFormatter* f) const; + void PrintTo(BaseTextBuffer* f) const; static const char* ToCString(const Range* range); SExpression* ToSExpression(FlowGraphSerializer* s); diff --git a/runtime/vm/compiler/backend/type_propagator.cc b/runtime/vm/compiler/backend/type_propagator.cc index 8d2bb7aaa8a..f3fcd25d9e0 100644 --- a/runtime/vm/compiler/backend/type_propagator.cc +++ b/runtime/vm/compiler/backend/type_propagator.cc @@ -877,10 +877,10 @@ bool CompileType::CanBeSmi() { return CanPotentiallyBeSmi(*ToAbstractType(), /*recurse=*/true); } -void CompileType::PrintTo(BufferFormatter* f) const { +void CompileType::PrintTo(BaseTextBuffer* f) const { const char* type_name = "?"; if (IsNone()) { - f->Print("T{}"); + f->AddString("T{}"); return; } else if ((cid_ != kIllegalCid) && (cid_ != kDynamicCid)) { const Class& cls = @@ -894,7 +894,7 @@ void CompileType::PrintTo(BufferFormatter* f) const { type_name = "!null"; } - f->Print("T{%s%s}", type_name, is_nullable_ ? "?" : ""); + f->Printf("T{%s%s}", type_name, is_nullable_ ? "?" : ""); } const char* CompileType::ToCString() const { diff --git a/runtime/vm/compiler/ffi/native_location.cc b/runtime/vm/compiler/ffi/native_location.cc index 0c7fb1687d4..bbc762e55b5 100644 --- a/runtime/vm/compiler/ffi/native_location.cc +++ b/runtime/vm/compiler/ffi/native_location.cc @@ -210,47 +210,46 @@ compiler::Address NativeLocationToStackSlotAddress( return compiler::Address(loc.base_register(), loc.offset_in_bytes()); } -static void PrintRepresentations(BufferFormatter* f, - const NativeLocation& loc) { - f->Print(" "); +static void PrintRepresentations(BaseTextBuffer* f, const NativeLocation& loc) { + f->AddString(" "); loc.container_type().PrintTo(f); if (!loc.container_type().Equals(loc.payload_type())) { - f->Print("["); + f->AddString("["); loc.payload_type().PrintTo(f); - f->Print("]"); + f->AddString("]"); } } -void NativeLocation::PrintTo(BufferFormatter* f) const { - f->Print("I"); +void NativeLocation::PrintTo(BaseTextBuffer* f) const { + f->AddString("I"); PrintRepresentations(f, *this); } -void NativeRegistersLocation::PrintTo(BufferFormatter* f) const { +void NativeRegistersLocation::PrintTo(BaseTextBuffer* f) const { if (num_regs() == 1) { - f->Print("%s", RegisterNames::RegisterName(regs_->At(0))); + f->Printf("%s", RegisterNames::RegisterName(regs_->At(0))); } else { - f->Print("("); + f->AddString("("); for (intptr_t i = 0; i < num_regs(); i++) { - if (i != 0) f->Print(", "); - f->Print("%s", RegisterNames::RegisterName(regs_->At(i))); + if (i != 0) f->Printf(", "); + f->Printf("%s", RegisterNames::RegisterName(regs_->At(i))); } - f->Print(")"); + f->AddString(")"); } PrintRepresentations(f, *this); } -void NativeFpuRegistersLocation::PrintTo(BufferFormatter* f) const { +void NativeFpuRegistersLocation::PrintTo(BaseTextBuffer* f) const { switch (fpu_reg_kind()) { case kQuadFpuReg: - f->Print("%s", RegisterNames::FpuRegisterName(fpu_reg())); + f->Printf("%s", RegisterNames::FpuRegisterName(fpu_reg())); break; #if defined(TARGET_ARCH_ARM) case kDoubleFpuReg: - f->Print("%s", RegisterNames::FpuDRegisterName(fpu_d_reg())); + f->Printf("%s", RegisterNames::FpuDRegisterName(fpu_d_reg())); break; case kSingleFpuReg: - f->Print("%s", RegisterNames::FpuSRegisterName(fpu_s_reg())); + f->Printf("%s", RegisterNames::FpuSRegisterName(fpu_s_reg())); break; #endif // defined(TARGET_ARCH_ARM) default: @@ -260,8 +259,8 @@ void NativeFpuRegistersLocation::PrintTo(BufferFormatter* f) const { PrintRepresentations(f, *this); } -void NativeStackLocation::PrintTo(BufferFormatter* f) const { - f->Print("S%+" Pd, offset_in_bytes_); +void NativeStackLocation::PrintTo(BaseTextBuffer* f) const { + f->Printf("S%+" Pd, offset_in_bytes_); PrintRepresentations(f, *this); } diff --git a/runtime/vm/compiler/ffi/native_location.h b/runtime/vm/compiler/ffi/native_location.h index 7db24e6b85d..fefee765a7e 100644 --- a/runtime/vm/compiler/ffi/native_location.h +++ b/runtime/vm/compiler/ffi/native_location.h @@ -16,7 +16,7 @@ namespace dart { -class BufferFormatter; +class BaseTextBuffer; namespace compiler { @@ -94,7 +94,7 @@ class NativeLocation : public ZoneAllocated { UNREACHABLE(); } - virtual void PrintTo(BufferFormatter* f) const; + virtual void PrintTo(BaseTextBuffer* f) const; const char* ToCString() const; const NativeRegistersLocation& AsRegisters() const; @@ -169,7 +169,7 @@ class NativeRegistersLocation : public NativeLocation { virtual NativeRegistersLocation& Split(intptr_t index, Zone* zone) const; - virtual void PrintTo(BufferFormatter* f) const; + virtual void PrintTo(BaseTextBuffer* f) const; virtual bool Equals(const NativeLocation& other) const; @@ -254,7 +254,7 @@ class NativeFpuRegistersLocation : public NativeLocation { bool IsLowestBits() const; #endif // defined(TARGET_ARCH_ARM) - virtual void PrintTo(BufferFormatter* f) const; + virtual void PrintTo(BaseTextBuffer* f) const; virtual bool Equals(const NativeLocation& other) const; @@ -303,7 +303,7 @@ class NativeStackLocation : public NativeLocation { virtual NativeStackLocation& Split(intptr_t index, Zone* zone) const; - virtual void PrintTo(BufferFormatter* f) const; + virtual void PrintTo(BaseTextBuffer* f) const; virtual bool Equals(const NativeLocation& other) const; diff --git a/runtime/vm/compiler/ffi/native_type.cc b/runtime/vm/compiler/ffi/native_type.cc index 57db124d2fb..e4daa4765ab 100644 --- a/runtime/vm/compiler/ffi/native_type.cc +++ b/runtime/vm/compiler/ffi/native_type.cc @@ -316,12 +316,12 @@ static const char* FundamentalTypeToCString(FundamentalType rep) { } } -void NativeType::PrintTo(BufferFormatter* f) const { - f->Print("I"); +void NativeType::PrintTo(BaseTextBuffer* f) const { + f->AddString("I"); } -void NativeFundamentalType::PrintTo(BufferFormatter* f) const { - f->Print("%s", FundamentalTypeToCString(representation_)); +void NativeFundamentalType::PrintTo(BaseTextBuffer* f) const { + f->Printf("%s", FundamentalTypeToCString(representation_)); } const NativeType& NativeType::WidenTo4Bytes(Zone* zone) const { diff --git a/runtime/vm/compiler/ffi/native_type.h b/runtime/vm/compiler/ffi/native_type.h index 0eee4deb05a..b0dc39b6fd6 100644 --- a/runtime/vm/compiler/ffi/native_type.h +++ b/runtime/vm/compiler/ffi/native_type.h @@ -17,7 +17,7 @@ namespace dart { -class BufferFormatter; +class BaseTextBuffer; namespace compiler { @@ -102,7 +102,7 @@ class NativeType : public ZoneAllocated { // Otherwise, return original representation. const NativeType& WidenTo4Bytes(Zone* zone) const; - virtual void PrintTo(BufferFormatter* f) const; + virtual void PrintTo(BaseTextBuffer* f) const; const char* ToCString() const; virtual ~NativeType() {} @@ -153,7 +153,7 @@ class NativeFundamentalType : public NativeType { virtual bool Equals(const NativeType& other) const; virtual NativeFundamentalType& Split(intptr_t part, Zone* zone) const; - virtual void PrintTo(BufferFormatter* f) const; + virtual void PrintTo(BaseTextBuffer* f) const; virtual ~NativeFundamentalType() {} diff --git a/runtime/vm/zone_text_buffer.cc b/runtime/vm/zone_text_buffer.cc index 8b3d267c56a..f265937ea7b 100644 --- a/runtime/vm/zone_text_buffer.cc +++ b/runtime/vm/zone_text_buffer.cc @@ -29,13 +29,14 @@ void ZoneTextBuffer::Clear() { buffer_[length_] = '\0'; } -void ZoneTextBuffer::EnsureCapacity(intptr_t len) { +bool ZoneTextBuffer::EnsureCapacity(intptr_t len) { intptr_t remaining = capacity_ - length_; if (remaining <= len) { intptr_t new_capacity = capacity_ + Utils::Maximum(capacity_, len); buffer_ = zone_->Realloc(buffer_, capacity_, new_capacity); capacity_ = new_capacity; } + return true; } } // namespace dart diff --git a/runtime/vm/zone_text_buffer.h b/runtime/vm/zone_text_buffer.h index 7f152675d69..21e6739c92a 100644 --- a/runtime/vm/zone_text_buffer.h +++ b/runtime/vm/zone_text_buffer.h @@ -26,8 +26,10 @@ class ZoneTextBuffer : public BaseTextBuffer { void Clear(); private: - void EnsureCapacity(intptr_t len); + bool EnsureCapacity(intptr_t len); Zone* zone_; + + DISALLOW_COPY_AND_ASSIGN(ZoneTextBuffer); }; } // namespace dart