-//===----------------------------------------------------------------------===//
-/// DISerializeVisitor - This DIVisitor serializes all the fields in
-/// the supplied DebugInfoDesc.
-class DISerializeVisitor : public DIVisitor {
-private:
- DISerializer &SR; // Active serializer.
- std::vector<Constant*> &Elements; // Element accumulator.
-
-public:
- DISerializeVisitor(DISerializer &S, std::vector<Constant*> &E)
- : DIVisitor()
- , SR(S)
- , Elements(E)
- {}
-
- /// Apply - Set the value of each of the fields.
- ///
- virtual void Apply(int &Field) {
- Elements.push_back(ConstantInt::get(Type::Int32Ty, int32_t(Field)));
- }
- virtual void Apply(unsigned &Field) {
- Elements.push_back(ConstantInt::get(Type::Int32Ty, uint32_t(Field)));
- }
- virtual void Apply(int64_t &Field) {
- Elements.push_back(ConstantInt::get(Type::Int64Ty, int64_t(Field)));
- }
- virtual void Apply(uint64_t &Field) {
- Elements.push_back(ConstantInt::get(Type::Int64Ty, uint64_t(Field)));
- }
- virtual void Apply(bool &Field) {
- Elements.push_back(ConstantInt::get(Type::Int1Ty, Field));
- }
- virtual void Apply(std::string &Field) {
- Elements.push_back(SR.getString(Field));
- }
- virtual void Apply(DebugInfoDesc *&Field) {
- GlobalVariable *GV = NULL;
-
- // If non-NULL then convert to global.
- if (Field) GV = SR.Serialize(Field);
-
- // FIXME - At some point should use specific type.
- const PointerType *EmptyTy = SR.getEmptyStructPtrType();
-
- if (GV) {
- // Set to pointer to global.
- Elements.push_back(ConstantExpr::getBitCast(GV, EmptyTy));
- } else {
- // Use NULL.
- Elements.push_back(ConstantPointerNull::get(EmptyTy));
- }
- }
- virtual void Apply(GlobalVariable *&Field) {
- const PointerType *EmptyTy = SR.getEmptyStructPtrType();
- if (Field) {
- Elements.push_back(ConstantExpr::getBitCast(Field, EmptyTy));
- } else {
- Elements.push_back(ConstantPointerNull::get(EmptyTy));
- }
- }
- virtual void Apply(std::vector<DebugInfoDesc *> &Field) {
- const PointerType *EmptyTy = SR.getEmptyStructPtrType();
- unsigned N = Field.size();
- ArrayType *AT = ArrayType::get(EmptyTy, N);
- std::vector<Constant *> ArrayElements;
-
- for (unsigned i = 0; i < N; ++i) {
- if (DebugInfoDesc *Element = Field[i]) {
- GlobalVariable *GVE = SR.Serialize(Element);
- Constant *CE = ConstantExpr::getBitCast(GVE, EmptyTy);
- ArrayElements.push_back(cast<Constant>(CE));
- } else {
- ArrayElements.push_back(ConstantPointerNull::get(EmptyTy));
- }
- }
-
- Constant *CA = ConstantArray::get(AT, ArrayElements);
- GlobalVariable *CAGV = new GlobalVariable(AT, true,
- GlobalValue::InternalLinkage,
- CA, "llvm.dbg.array",
- SR.getModule());
- CAGV->setSection("llvm.metadata");
- Constant *CAE = ConstantExpr::getBitCast(CAGV, EmptyTy);
- Elements.push_back(CAE);
- }