**************************************************************************/
-#include "formatter.hpp"
#include "trace_model.hpp"
Call::~Call() {
for (unsigned i = 0; i < args.size(); ++i) {
- delete args[i];
+ delete args[i].value;
}
if (ret) {
}
}
+StackFrame::~StackFrame() {
+ if (module != NULL) {
+ delete [] module;
+ }
+ if (function != NULL) {
+ delete [] function;
+ }
+ if (filename != NULL) {
+ delete [] filename;
+ }
+}
+
// bool cast
bool Null ::toBool(void) const { return false; }
bool Array ::toBool(void) const { return true; }
bool Blob ::toBool(void) const { return true; }
bool Pointer::toBool(void) const { return value != 0; }
+bool Repr ::toBool(void) const { return static_cast<bool>(machineValue); }
// signed integer cast
signed long long UInt ::toSInt(void) const { assert(static_cast<signed long long>(value) >= 0); return static_cast<signed long long>(value); }
signed long long Float ::toSInt(void) const { return static_cast<signed long long>(value); }
signed long long Double ::toSInt(void) const { return static_cast<signed long long>(value); }
+signed long long Repr ::toSInt(void) const { return machineValue->toSInt(); }
// unsigned integer cast
unsigned long long UInt ::toUInt(void) const { return value; }
unsigned long long Float ::toUInt(void) const { return static_cast<unsigned long long>(value); }
unsigned long long Double ::toUInt(void) const { return static_cast<unsigned long long>(value); }
+unsigned long long Repr ::toUInt(void) const { return machineValue->toUInt(); }
// floating point cast
float UInt ::toFloat(void) const { return static_cast<float>(value); }
float Float ::toFloat(void) const { return value; }
float Double ::toFloat(void) const { return value; }
+float Repr ::toFloat(void) const { return machineValue->toFloat(); }
// floating point cast
double UInt ::toDouble(void) const { return static_cast<double>(value); }
double Float ::toDouble(void) const { return value; }
double Double ::toDouble(void) const { return value; }
+double Repr ::toDouble(void) const { return machineValue->toDouble(); }
// pointer cast
void * Null ::toPointer(void) const { return NULL; }
void * Blob ::toPointer(void) const { return buf; }
void * Pointer::toPointer(void) const { return (void *)value; }
+void * Repr ::toPointer(void) const { return machineValue->toPointer(); }
void * Value ::toPointer(bool bind) { assert(0); return NULL; }
void * Null ::toPointer(bool bind) { return NULL; }
void * Blob ::toPointer(bool bind) { if (bind) bound = true; return buf; }
void * Pointer::toPointer(bool bind) { return (void *)value; }
+void * Repr ::toPointer(bool bind) { return machineValue->toPointer(bind); }
-// pointer cast
+// unsigned int pointer cast
unsigned long long Value ::toUIntPtr(void) const { assert(0); return 0; }
unsigned long long Null ::toUIntPtr(void) const { return 0; }
unsigned long long Pointer::toUIntPtr(void) const { return value; }
+unsigned long long Repr ::toUIntPtr(void) const { return machineValue->toUIntPtr(); }
// string cast
const char * Value ::toString(void) const { assert(0); return NULL; }
const char * Null ::toString(void) const { return NULL; }
const char * String::toString(void) const { return value; }
+const char * Repr ::toString(void) const { return machineValue->toString(); }
// virtual Value::visit()
void Array ::visit(Visitor &visitor) { visitor.visit(this); }
void Blob ::visit(Visitor &visitor) { visitor.visit(this); }
void Pointer::visit(Visitor &visitor) { visitor.visit(this); }
+void Repr ::visit(Visitor &visitor) { visitor.visit(this); }
void Visitor::visit(Null *) { assert(0); }
void Visitor::visit(Array *) { assert(0); }
void Visitor::visit(Blob *) { assert(0); }
void Visitor::visit(Pointer *) { assert(0); }
-
-
-class Dumper : public Visitor
-{
-protected:
- std::ostream &os;
- formatter::Formatter *formatter;
- formatter::Attribute *normal;
- formatter::Attribute *bold;
- formatter::Attribute *italic;
- formatter::Attribute *strike;
- formatter::Attribute *red;
- formatter::Attribute *pointer;
- formatter::Attribute *literal;
-
-public:
- Dumper(std::ostream &_os, bool color) : os(_os) {
- formatter = formatter::defaultFormatter(color);
- normal = formatter->normal();
- bold = formatter->bold();
- italic = formatter->italic();
- strike = formatter->strike();
- red = formatter->color(formatter::RED);
- pointer = formatter->color(formatter::GREEN);
- literal = formatter->color(formatter::BLUE);
- }
-
- ~Dumper() {
- delete normal;
- delete bold;
- delete italic;
- delete strike;
- delete red;
- delete pointer;
- delete literal;
- delete formatter;
- }
-
- void visit(Null *) {
- os << "NULL";
- }
-
- void visit(Bool *node) {
- os << literal << (node->value ? "true" : "false") << normal;
- }
-
- void visit(SInt *node) {
- os << literal << node->value << normal;
- }
-
- void visit(UInt *node) {
- os << literal << node->value << normal;
- }
-
- void visit(Float *node) {
- os << literal << node->value << normal;
- }
-
- void visit(Double *node) {
- os << literal << node->value << normal;
- }
-
- void visit(String *node) {
- os << literal << "\"";
- for (const char *it = node->value; *it; ++it) {
- unsigned char c = (unsigned char) *it;
- if (c == '\"')
- os << "\\\"";
- else if (c == '\\')
- os << "\\\\";
- else if (c >= 0x20 && c <= 0x7e)
- os << c;
- else if (c == '\t') {
- os << "\t";
- } else if (c == '\r') {
- // Ignore carriage-return
- } else if (c == '\n') {
- // Reset formatting so that it looks correct with 'less -R'
- os << normal << '\n' << literal;
- } else {
- unsigned octal0 = c & 0x7;
- unsigned octal1 = (c >> 3) & 0x7;
- unsigned octal2 = (c >> 3) & 0x7;
- os << "\\";
- if (octal2)
- os << octal2;
- if (octal1)
- os << octal1;
- os << octal0;
- }
- }
- os << "\"" << normal;
- }
-
- void visit(Enum *node) {
- const EnumSig *sig = node->sig;
- for (const EnumValue *it = sig->values; it != sig->values + sig->num_values; ++it) {
- if (it->value == node->value) {
- os << literal << it->name << normal;
- return;
- }
- }
- os << literal << node->value << normal;
- }
-
- void visit(Bitmask *bitmask) {
- unsigned long long value = bitmask->value;
- const BitmaskSig *sig = bitmask->sig;
- bool first = true;
- for (const BitmaskFlag *it = sig->flags; value != 0 && it != sig->flags + sig->num_flags; ++it) {
- if ((it->value && (value & it->value) == it->value) ||
- (!it->value && value == 0)) {
- if (!first) {
- os << " | ";
- }
- os << literal << it->name << normal;
- value &= ~it->value;
- first = false;
- }
- }
- if (value || first) {
- if (!first) {
- os << " | ";
- }
- os << literal << "0x" << std::hex << value << std::dec << normal;
- }
- }
-
- void visit(Struct *s) {
- const char *sep = "";
- os << "{";
- for (unsigned i = 0; i < s->members.size(); ++i) {
- os << sep << italic << s->sig->member_names[i] << normal << " = ";
- _visit(s->members[i]);
- sep = ", ";
- }
- os << "}";
- }
-
- void visit(Array *array) {
- if (array->values.size() == 1) {
- os << "&";
- _visit(array->values[0]);
- }
- else {
- const char *sep = "";
- os << "{";
- for (std::vector<Value *>::iterator it = array->values.begin(); it != array->values.end(); ++it) {
- os << sep;
- _visit(*it);
- sep = ", ";
- }
- os << "}";
- }
- }
-
- void visit(Blob *blob) {
- os << pointer << "blob(" << blob->size << ")" << normal;
- }
-
- void visit(Pointer *p) {
- os << pointer << "0x" << std::hex << p->value << std::dec << normal;
- }
-
- void visit(Call *call) {
- CallFlags flags = call->flags;
-
- if (flags & CALL_FLAG_NON_REPRODUCIBLE) {
- os << strike;
- } else if (flags & (CALL_FLAG_FAKE | CALL_FLAG_NO_SIDE_EFFECTS)) {
- os << normal;
- } else {
- os << bold;
- }
- os << call->sig->name << normal;
-
- os << "(";
- const char *sep = "";
- for (unsigned i = 0; i < call->args.size(); ++i) {
- os << sep << italic << call->sig->arg_names[i] << normal << " = ";
- if (call->args[i]) {
- _visit(call->args[i]);
- } else {
- os << "?";
- }
- sep = ", ";
- }
- os << ")";
-
- if (call->ret) {
- os << " = ";
- _visit(call->ret);
- }
-
- if (flags & CALL_FLAG_INCOMPLETE) {
- os << " // " << red << "incomplete" << normal;
- }
-
- os << "\n";
-
- if (flags & CALL_FLAG_END_FRAME) {
- os << "\n";
- }
- }
-};
-
-
-void Value::dump(std::ostream &os, bool color) {
- Dumper d(os, color);
- visit(d);
-}
+void Visitor::visit(Repr *node) { node->machineValue->visit(*this); }
+void Visitor::visit(Backtrace *) { assert(0); }
+void Visitor::visit(StackFrame *) { assert(0); }
static Null null;
const Value & Value::operator[](size_t index) const {
- const Array *array = dynamic_cast<const Array *>(this);
+ const Array *array = toArray();
if (array) {
if (index < array->values.size()) {
return *array->values[index];
return null;
}
-void Call::dump(std::ostream &os, bool color) {
- Dumper d(os, color);
- os << no << " ";
- d.visit(this);
-}
-
-
} /* namespace trace */