//
class DIEInteger : public DIEValue {
private:
- int Integer;
+ uint64_t Integer;
public:
- DIEInteger(int I) : DIEValue(isInteger), Integer(I) {}
+ DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
// Implement isa/cast/dyncast.
static bool classof(const DIEInteger *) { return true; }
/// sibling.
unsigned SiblingOffset() const { return Offset + Size; }
- /// AddInt - Add a simple integer attribute data and value.
+ /// AddUInt - Add an unsigned integer attribute data and value.
///
- void AddInt(unsigned Attribute, unsigned Form,
- int Integer, bool IsSigned = false);
+ void AddUInt(unsigned Attribute, unsigned Form, uint64_t Integer);
+
+ /// AddSInt - Add an signed integer attribute data and value.
+ ///
+ void AddSInt(unsigned Attribute, unsigned Form, int64_t Integer);
/// AddString - Add a std::string attribute data and value.
///
///
void EmitLong(int Value) const;
+ /// EmitLongLong - Emit a long long directive and value.
+ ///
+ void EmitLongLong(uint64_t Value) const;
+
/// EmitString - Emit a string with quotes and a null terminator.
/// Special characters are emitted properly. (Eg. '\t')
void EmitString(const std::string &String) const;
/// CompileUnitWrapper - This class wraps a "lldb.compile_unit" global to
/// provide easy access to its attributes.
class CompileUnitWrapper : public DebugInfoWrapper {
+private:
+ // Operand indices.
+ enum {
+ Tag_op,
+ Version_op,
+ Language_op,
+ FileName_op,
+ Directory_op,
+ Producer_op,
+ Anchor_op, // ignored
+ N_op
+ };
+
public:
CompileUnitWrapper(GlobalVariable *G);
/// GlobalWrapper - This class wraps a "lldb.global" global to provide easy
/// access to its attributes.
class GlobalWrapper : public DebugInfoWrapper {
+private:
+ // Operand indices.
+ enum {
+ Tag_op,
+ Context_op,
+ Name_op,
+ Anchor_op, // ignored
+ Type_op,
+ Static_op,
+ Definition_op,
+ GlobalVariable_op,
+ N_op
+ };
+
public:
GlobalWrapper(GlobalVariable *G);
case DW_FORM_data1: DW.EmitByte(Integer); break;
case DW_FORM_data2: DW.EmitShort(Integer); break;
case DW_FORM_data4: DW.EmitLong(Integer); break;
+ case DW_FORM_data8: DW.EmitLongLong(Integer); break;
case DW_FORM_udata: DW.EmitULEB128Bytes(Integer); break;
case DW_FORM_sdata: DW.EmitSLEB128Bytes(Integer); break;
default: assert(0 && "DIE Value form not supported yet"); break;
case DW_FORM_data1: return sizeof(int8_t);
case DW_FORM_data2: return sizeof(int16_t);
case DW_FORM_data4: return sizeof(int32_t);
+ case DW_FORM_data8: return sizeof(int64_t);
case DW_FORM_udata: return DW.SizeULEB128(Integer);
case DW_FORM_sdata: return DW.SizeSLEB128(Integer);
default: assert(0 && "DIE Value form not supported yet"); break;
if (Context) delete Context;
}
-/// AddInt - Add a simple integer attribute data and value.
+/// AddUInt - Add an unsigned integer attribute data and value.
///
-void DIE::AddInt(unsigned Attribute, unsigned Form,
- int Integer, bool IsSigned) {
+void DIE::AddUInt(unsigned Attribute, unsigned Form, uint64_t Integer) {
if (Form == 0) {
- if (IsSigned) {
- if ((char)Integer == Integer) Form = DW_FORM_data1;
- else if ((short)Integer == Integer) Form = DW_FORM_data2;
- else Form = DW_FORM_data4;
- } else {
if ((unsigned char)Integer == Integer) Form = DW_FORM_data1;
else if ((unsigned short)Integer == Integer) Form = DW_FORM_data2;
- else Form = DW_FORM_data4;
- }
+ else if ((unsigned int)Integer == Integer) Form = DW_FORM_data4;
+ else Form = DW_FORM_data8;
+ }
+ Abbrev->AddAttribute(Attribute, Form);
+ Values.push_back(new DIEInteger(Integer));
+}
+
+/// AddSInt - Add an signed integer attribute data and value.
+///
+void DIE::AddSInt(unsigned Attribute, unsigned Form, int64_t Integer) {
+ if (Form == 0) {
+ if ((char)Integer == Integer) Form = DW_FORM_data1;
+ else if ((short)Integer == Integer) Form = DW_FORM_data2;
+ else if ((int)Integer == Integer) Form = DW_FORM_data4;
+ else Form = DW_FORM_data8;
}
Abbrev->AddAttribute(Attribute, Form);
Values.push_back(new DIEInteger(Integer));
// construct the type DIE.
TypeDie = new DIE(DW_TAG_base_type, DW_CHILDREN_no);
TypeDie->AddString(DW_AT_name, DW_FORM_string, Name);
- TypeDie->AddInt (DW_AT_byte_size, DW_FORM_data1, Size);
- TypeDie->AddInt (DW_AT_encoding, DW_FORM_data1, Encoding);
+ TypeDie->AddUInt (DW_AT_byte_size, DW_FORM_data1, Size);
+ TypeDie->AddUInt (DW_AT_encoding, DW_FORM_data1, Encoding);
TypeDie->Complete(DW);
// Add to context owner.
// FIXME - need source file name line number.
VariableDie = new DIE(DW_TAG_variable, DW_CHILDREN_no);
VariableDie->AddString (DW_AT_name, DW_FORM_string, Name);
- VariableDie->AddInt (DW_AT_decl_file, 0, 0);
- VariableDie->AddInt (DW_AT_decl_line, 0, 0);
+ VariableDie->AddUInt (DW_AT_decl_file, 0, 0);
+ VariableDie->AddUInt (DW_AT_decl_line, 0, 0);
VariableDie->AddDIEntry (DW_AT_type, DW_FORM_ref4, Type);
- VariableDie->AddInt (DW_AT_external, DW_FORM_flag, 1);
+ VariableDie->AddUInt (DW_AT_external, DW_FORM_flag, 1);
// FIXME - needs to be a proper expression.
VariableDie->AddObjectLabel(DW_AT_location, DW_FORM_block1, MangledName);
VariableDie->Complete(DW);
PrintHex(Value);
}
+/// EmitLongLong - Emit a long long directive and value.
+///
+void DwarfWriter::EmitLongLong(uint64_t Value) const {
+ if (Asm->Data64bitsDirective) {
+ O << Asm->Data64bitsDirective << "0x" << std::hex << Value << std::dec;
+ } else {
+ const TargetData &TD = Asm->TM.getTargetData();
+
+ if (TD.isBigEndian()) {
+ EmitLong(unsigned(Value >> 32)); O << "\n";
+ EmitLong(unsigned(Value));
+ } else {
+ EmitLong(unsigned(Value)); O << "\n";
+ EmitLong(unsigned(Value >> 32));
+ }
+ }
+}
+
/// EmitString - Emit a string with quotes and a null terminator.
/// Special characters are emitted properly. (Eg. '\t')
void DwarfWriter::EmitString(const std::string &String) const {
Unit->AddLabel (DW_AT_high_pc, DW_FORM_addr, DWLabel("text_end", 0));
Unit->AddLabel (DW_AT_low_pc, DW_FORM_addr, DWLabel("text_begin", 0));
Unit->AddString(DW_AT_producer, DW_FORM_string, CompileUnit.getProducer());
- Unit->AddInt (DW_AT_language, DW_FORM_data1, CompileUnit.getLanguage());
+ Unit->AddUInt (DW_AT_language, DW_FORM_data1, CompileUnit.getLanguage());
Unit->AddString(DW_AT_name, DW_FORM_string, CompileUnit.getFileName());
Unit->AddString(DW_AT_comp_dir, DW_FORM_string, CompileUnit.getDirectory());
Unit->Complete(*this);
}
return "";
}
+
+/// getGlobalValue - Return either a direct or cast Global value.
+///
+static GlobalVariable *getGlobalValue(Value *V) {
+ if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
+ return GV;
+ } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
+ return CE->getOpcode() == Instruction::Cast ? dyn_cast<GlobalVariable>(V)
+ : NULL;
+ }
+ return NULL;
+}
+
//===----------------------------------------------------------------------===//
: DebugInfoWrapper(G)
{
// FIXME - should probably ease up on the number of operands (version.)
- assert(IC->getNumOperands() == 7 &&
+ assert(IC->getNumOperands() == N_op &&
"Compile unit does not have correct number of operands");
}
/// getTag - Return the compile unit's tag number. Currently should be
/// DW_TAG_variable.
unsigned CompileUnitWrapper::getTag() const {
- ConstantUInt *CI = dyn_cast<ConstantUInt>(IC->getOperand(0));
- assert(CI && "Compile unit tag not an unsigned integer");
- return CI->getValue();
+ return cast<ConstantUInt>(IC->getOperand(Tag_op))->getValue();
}
/// isCorrectDebugVersion - Return true if is the correct llvm debug version.
/// Currently the value is 0 (zero.) If the value is is not correct then
/// ignore all debug information.
bool CompileUnitWrapper::isCorrectDebugVersion() const {
- ConstantUInt *CI = dyn_cast<ConstantUInt>(IC->getOperand(1));
- assert(CI && "Compile unit debug version not an unsigned integer");
- return CI->getValue() == 0;
+ return cast<ConstantUInt>(IC->getOperand(Version_op))->getValue();
}
/// getLanguage - Return the compile unit's language number (ex. DW_LANG_C89.)
///
unsigned CompileUnitWrapper::getLanguage() const {
- ConstantUInt *CI = dyn_cast<ConstantUInt>(IC->getOperand(2));
- assert(CI && "Compile unit language number not an unsigned integer");
- return CI->getValue();
+ return cast<ConstantUInt>(IC->getOperand(Language_op))->getValue();
}
/// getFileName - Return the compile unit's file name.
///
const std::string CompileUnitWrapper::getFileName() const {
- return getStringValue(IC->getOperand(3));
+ return getStringValue(IC->getOperand(FileName_op));
}
/// getDirectory - Return the compile unit's file directory.
///
const std::string CompileUnitWrapper::getDirectory() const {
- return getStringValue(IC->getOperand(4));
+ return getStringValue(IC->getOperand(Directory_op));
}
/// getProducer - Return the compile unit's generator name.
///
const std::string CompileUnitWrapper::getProducer() const {
- return getStringValue(IC->getOperand(5));
+ return getStringValue(IC->getOperand(Producer_op));
}
//===----------------------------------------------------------------------===//
: DebugInfoWrapper(G)
{
// FIXME - should probably ease up on the number of operands (version.)
- assert(IC->getNumOperands() == 8 &&
+ assert(IC->getNumOperands() == N_op &&
"Global does not have correct number of operands");
}
/// getTag - Return the global's tag number. Currently should be
/// DW_TAG_variable or DW_TAG_subprogram.
unsigned GlobalWrapper::getTag() const {
- ConstantUInt *CI = dyn_cast<ConstantUInt>(IC->getOperand(0));
- assert(CI && "Global tag not an unsigned integer");
- return CI->getValue();
+ return cast<ConstantUInt>(IC->getOperand(Tag_op))->getValue();
}
/// getContext - Return the "lldb.compile_unit" context global.
///
GlobalVariable *GlobalWrapper::getContext() const {
- return cast<GlobalVariable>(IC->getOperand(1));
+ return getGlobalValue(IC->getOperand(Context_op));
}
/// getName - Return the name of the global.
///
const std::string GlobalWrapper::getName() const {
- return getStringValue(IC->getOperand(2));
+ return getStringValue(IC->getOperand(Name_op));
}
/// getType - Return the type of the global.
///
const GlobalVariable *GlobalWrapper::getType() const {
- return cast<GlobalVariable>(IC->getOperand(4));
+ return getGlobalValue(IC->getOperand(Type_op));
}
/// isStatic - Return true if the global is static.
///
bool GlobalWrapper::isStatic() const {
- ConstantBool *CB = dyn_cast<ConstantBool>(IC->getOperand(5));
- assert(CB && "Global static flag is not boolean");
- return CB->getValue();
+ return cast<ConstantBool>(IC->getOperand(Static_op))->getValue();
}
/// isDefinition - Return true if the global is a definition.
///
bool GlobalWrapper::isDefinition() const {
- ConstantBool *CB = dyn_cast<ConstantBool>(IC->getOperand(6));
- assert(CB && "Global definition flag is not boolean");
- return CB->getValue();
+ return dyn_cast<ConstantBool>(IC->getOperand(Definition_op))->getValue();
}
/// getGlobalVariable - Return the global variable (tag == DW_TAG_variable.)
///
GlobalVariable *GlobalWrapper::getGlobalVariable() const {
- ConstantExpr *CE = dyn_cast<ConstantExpr>(IC->getOperand(7));
- assert(CE && CE->getOpcode() == Instruction::Cast &&
- "Global location is not a cast of GlobalVariable");
- GlobalVariable *GV = dyn_cast<GlobalVariable>(CE->getOperand(0));
- assert(GV && "Global location is not a cast of GlobalVariable");
- return GV;
+ return getGlobalValue(IC->getOperand(GlobalVariable_op));
}
//===----------------------------------------------------------------------===//