diff --git a/cbackend.cpp b/cbackend.cpp index 1acf512c..fcf3c28e 100644 --- a/cbackend.cpp +++ b/cbackend.cpp @@ -140,11 +140,14 @@ namespace { llvm::DenseSet VisitedMDNodes; #endif llvm::DenseSet VisitedTypes; - std::vector &ArrayTypes; + std::vector &IntegerTypes; + std::vector &IsVolatile; + std::vector &Alignment; public: - TypeFinder(std::vector &t) - : ArrayTypes(t) {} + TypeFinder(std::vector &t, std::vector &i, + std::vector &v, std::vector &a) + : ArrayTypes(t), IntegerTypes(i) , IsVolatile(v), Alignment(a){} void run(const llvm::Module &M) { // Get types from global variables. @@ -182,6 +185,13 @@ namespace { // Incorporate the type of the instruction and all its operands. incorporateType(I.getType()); + if (llvm::isa(&I)) + if (llvm::IntegerType *ITy = llvm::dyn_cast(I.getType())) { + IntegerTypes.push_back(ITy); +// llvm::StoreInst St = llvm::dyn_cast(I); +// IsVolatile.push_back(St.isVolatile()); +// Alignment.push_back(St.getAlignment()); + } for (llvm::User::const_op_iterator OI = I.op_begin(), OE = I.op_end(); OI != OE; ++OI) incorporateValue(*OI); @@ -288,8 +298,9 @@ namespace { }; } // end anonymous namespace -static void findUsedArrayTypes(const llvm::Module *m, std::vector &t) { - TypeFinder(t).run(*m); +static void findUsedArrayTypes(const llvm::Module *m, std::vector &t, std::vector &i, + std::vector &IsVolatile, std::vector &Alignment) { + TypeFinder(t, i, IsVolatile, Alignment).run(*m); } namespace { @@ -2741,17 +2752,15 @@ void CWriter::printModuleTypes() { // Get all of the array types used in the module std::vector ArrayTypes; - findUsedArrayTypes(TheModule, ArrayTypes); + std::vector IntegerTypes; + std::vector IsVolatile; + std::vector Alignment; + + findUsedArrayTypes(TheModule, ArrayTypes, IntegerTypes, IsVolatile, Alignment); if (StructTypes.empty() && ArrayTypes.empty()) return; - Out << "DEBUG_ME"; - for (llvm::Module::const_global_iterator I = TheModule->global_begin(), E = TheModule->global_end(); - I != E; ++I) { - Out << I << "^^^^^^^^^^^^^^^^^^^^^^^^^^\n"; - } - Out << "/* Structure and array forward declarations */\n"; unsigned NextTypeID = 0; @@ -2775,6 +2784,12 @@ void CWriter::printModuleTypes() { std::string Name = getArrayName(AT); Out << "struct " << Name << ";\n"; } + + for (unsigned i = 0, e = IntegerTypes.size(); i != e; ++i) { + llvm::IntegerType *IT = IntegerTypes[i]; + Out << "bitwidth: " << IT->getIntegerBitWidth () << "|" << IsVolatile[i] << "|" << Alignment[i] << ";\n"; + } + Out << '\n'; // Keep track of which types have been printed so far.