Chromium Code Reviews| Index: src/llvm2ice.cpp |
| diff --git a/src/llvm2ice.cpp b/src/llvm2ice.cpp |
| index c3a98dfed6b2d13a06f6dbeeb054d700990864ab..9b7e5ffda68bc7d72afc754fdf4763993bd86dd0 100644 |
| --- a/src/llvm2ice.cpp |
| +++ b/src/llvm2ice.cpp |
| @@ -726,6 +726,55 @@ int main(int argc, char **argv) { |
| raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); |
| Ls->SetUnbuffered(); |
| + Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix); |
| + |
| + Ice::TargetGlobalInitLowering *GlobalLowering = |
|
jvoung (off chromium)
2014/06/27 19:29:27
Maybe use a smart pointer and .reset() it at the e
Jim Stichnoth
2014/06/28 00:28:13
Done.
|
| + Ice::TargetGlobalInitLowering::createLowering(TargetArch, &Ctx); |
| + for (Module::const_global_iterator I = Mod->global_begin(), |
| + E = Mod->global_end(); |
| + I != E; ++I) { |
| + if (!I->hasInitializer()) |
|
jvoung (off chromium)
2014/06/27 19:29:27
I believe that, for PNaCl, every global value must
Jim Stichnoth
2014/06/28 00:28:13
That's true for PNaCl, but we are also supporting
|
| + continue; |
| + const Constant *Initializer = I->getInitializer(); |
| + Ice::IceString Name = I->getName(); |
| + unsigned Align = I->getAlignment(); |
| + uint64_t NumElements = 0; |
| + const char *Data = NULL; |
| + bool DeleteData = false; |
| + bool IsInternal = I->hasInternalLinkage(); |
| + bool IsConst = I->isConstant(); |
| + bool IsZeroInitializer = false; |
| + |
| + if (const ConstantDataArray *CDA = |
| + dyn_cast<ConstantDataArray>(Initializer)) { |
| + NumElements = CDA->getNumElements(); |
| + assert(isa<IntegerType>(CDA->getElementType()) && |
| + cast<IntegerType>(CDA->getElementType())->getBitWidth() == 8); |
| + Data = CDA->getRawDataValues().data(); |
| + } else if (isa<ConstantAggregateZero>(Initializer)) { |
| + if (const ArrayType *AT = dyn_cast<ArrayType>(Initializer->getType())) { |
| + assert(isa<IntegerType>(AT->getElementType()) && |
| + cast<IntegerType>(AT->getElementType())->getBitWidth() == 8); |
| + NumElements = AT->getNumElements(); |
| + char *MyData = new char[NumElements]; |
| + memset(MyData, 0, NumElements); |
| + Data = MyData; |
| + DeleteData = true; |
| + IsZeroInitializer = true; |
|
jvoung (off chromium)
2014/06/27 19:29:27
Does this need to have a real zero-filled data arr
Jim Stichnoth
2014/06/28 00:28:13
Done.
|
| + } else { |
| + llvm_unreachable("Unhandled constant aggregate zero type"); |
| + } |
| + } else { |
| + llvm_unreachable("Unhandled global initializer"); |
| + } |
| + |
| + GlobalLowering->lower(Name, Align, IsInternal, IsConst, IsZeroInitializer, |
| + NumElements, Data, DisableTranslation); |
| + if (DeleteData) |
| + delete Data; |
|
wala
2014/06/27 21:35:25
delete[]
Jim Stichnoth
2014/06/28 00:28:13
Yikes, done.
|
| + } |
| + delete GlobalLowering; |
| + |
| // Ideally, Func would be declared inside the loop and its object |
| // would be automatically deleted at the end of the loop iteration. |
| // However, emitting the constant pool requires a valid Cfg object, |
| @@ -735,7 +784,6 @@ int main(int argc, char **argv) { |
| // object, change all Ice::Constant related functions to use |
| // GlobalContext instead of Cfg, and then clean up this loop. |
| OwningPtr<Ice::Cfg> Func; |
| - Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix); |
| for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { |
| if (I->empty()) |