[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 <sstrickl@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
f8d1d003c9
commit
09ddcece30
@@ -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
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<intptr_t>* class_ids);
|
||||
|
||||
void PrintTo(BufferFormatter* f) const;
|
||||
void PrintTo(BaseTextBuffer* f) const;
|
||||
SExpression* ToSExpression(FlowGraphSerializer* s) const;
|
||||
void AddExtraInfoToSExpression(SExpList* sexp, FlowGraphSerializer* s) const;
|
||||
|
||||
|
||||
@@ -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<Definition*> 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;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<int>(2 * NestingDepth()), ' ');
|
||||
f.Print("loop%" Pd " B%" Pd " ", id_, header_->block_id());
|
||||
void LoopInfo::PrintTo(BaseTextBuffer* f) const {
|
||||
f->Printf("%*c", static_cast<int>(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);
|
||||
}
|
||||
|
||||
|
||||
@@ -128,6 +128,7 @@ class InductionVar : public ZoneAllocated {
|
||||
const GrowableArray<Bound>& 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:
|
||||
|
||||
@@ -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<BlockEntryInstr*>& preorder) {
|
||||
for (; loop != nullptr; loop = loop->next()) {
|
||||
intptr_t depth = loop->NestingDepth();
|
||||
f->Print("%*c[%" Pd "\n", static_cast<int>(2 * depth), ' ', loop->id());
|
||||
f->Printf("%*c[%" Pd "\n", static_cast<int>(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<int>(2 * depth), ' ',
|
||||
induc->ToCString());
|
||||
f->Printf("%*c%s", static_cast<int>(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<int>(2 * depth), ' ',
|
||||
induc->ToCString());
|
||||
f->Printf("%*c%s\n", static_cast<int>(2 * depth), ' ',
|
||||
induc->ToCString());
|
||||
}
|
||||
}
|
||||
}
|
||||
TestString(f, loop->inner(), preorder);
|
||||
f->Print("%*c]\n", static_cast<int>(2 * depth), ' ');
|
||||
f->Printf("%*c]\n", static_cast<int>(2 * depth), ' ');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
|
||||
@@ -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<char>(buffer_, capacity_, new_capacity);
|
||||
capacity_ = new_capacity;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace dart
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user