diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-12-13 18:46:10 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-12-13 18:46:10 -0800 |
commit | bb28d3b483482618b818fd0bdd371f44ff51fb18 (patch) | |
tree | 5039989d4ccfce19ba6c8a8b56e1a359688ec2c5 /lib/Target/CppBackend/CPPBackend.cpp | |
parent | b3df7aac7d498e7948a9aa9259777ebc302ed822 (diff) |
support multiple global initializers
Diffstat (limited to 'lib/Target/CppBackend/CPPBackend.cpp')
-rw-r--r-- | lib/Target/CppBackend/CPPBackend.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp index c1e81d4b5a..094f3c1065 100644 --- a/lib/Target/CppBackend/CPPBackend.cpp +++ b/lib/Target/CppBackend/CPPBackend.cpp @@ -2532,7 +2532,19 @@ void CppWriter::parseConstant(std::string name, const Constant* CV, bool calcula } else if (isa<ConstantArray>(CV)) { assert(false); } else if (const ConstantStruct *CS = dyn_cast<ConstantStruct>(CV)) { - if (calculate) { + if (name == "__init_array_start") { + // this is the global static initializer + if (calculate) { + unsigned Num = CS->getNumOperands(); + for (unsigned i = 0; i < Num; i++) { + const Value* C = CS->getOperand(i); + if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { + C = CE->getOperand(0); // ignore bitcasts + } + GlobalInitializers.push_back(getCppName(C)); + } + } + } else if (calculate) { HeapData *GlobalData = allocateAddress(name); DataLayout DL(TheModule); unsigned Bytes = DL.getTypeStoreSize(CV->getType()); |