diff options
author | Mark Seaborn <mseaborn@chromium.org> | 2013-09-06 15:34:50 -0700 |
---|---|---|
committer | Mark Seaborn <mseaborn@chromium.org> | 2013-09-06 15:34:50 -0700 |
commit | 083eeaf1e9fc4e929b8f805deb4d3d3d0be038fc (patch) | |
tree | 8458b12bd1b72f3746e81d16ef475dc0b5f2e473 /lib/Bitcode | |
parent | 68cb3f7eca7536d85301f92314dbb5db6757cd94 (diff) |
PNaCl bitcode: Use function type not ptr-to-function type to declare function
This is a step towards removing TYPE_CODE_POINTER from the types
table. This will make the format simpler. It will also make bitcode
files a little smaller, because we won't need to use type IDs for
referring to pointer types.
BUG=https://code.google.com/p/nativeclient/issues/detail?id=3671
TEST=test/NaCl/Bitcode/*.ll
Review URL: https://codereview.chromium.org/24049002
Diffstat (limited to 'lib/Bitcode')
-rw-r--r-- | lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp | 14 | ||||
-rw-r--r-- | lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp | 5 |
2 files changed, 13 insertions, 6 deletions
diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp index 8b8e9072a8..276d1d59b3 100644 --- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp +++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp @@ -945,12 +945,16 @@ bool NaClBitcodeReader::ParseModule(bool Resume) { return Error("Invalid MODULE_CODE_FUNCTION record"); Type *Ty = getTypeByID(Record[0]); if (!Ty) return Error("Invalid MODULE_CODE_FUNCTION record"); - if (!Ty->isPointerTy()) - return Error("Function not a pointer type!"); - FunctionType *FTy = - dyn_cast<FunctionType>(cast<PointerType>(Ty)->getElementType()); + FunctionType *FTy; + if (GetPNaClVersion() == 1) { + if (!Ty->isPointerTy()) + return Error("Function not a pointer type!"); + FTy = dyn_cast<FunctionType>(cast<PointerType>(Ty)->getElementType()); + } else { + FTy = dyn_cast<FunctionType>(Ty); + } if (!FTy) - return Error("Function not a pointer to function type!"); + return Error("Function not declared with a function type!"); Function *Func = Function::Create(FTy, GlobalValue::ExternalLinkage, "", TheModule); diff --git a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp index 3355bc757c..6280e5ccfc 100644 --- a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp +++ b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp @@ -418,7 +418,10 @@ static void WriteModuleInfo(const Module *M, const NaClValueEnumerator &VE, SmallVector<unsigned, 64> Vals; for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) { // FUNCTION: [type, callingconv, isproto, linkage] - Vals.push_back(VE.getTypeID(F->getType())); + Type *Ty = F->getType(); + if (PNaClVersion >= 2) + Ty = Ty->getPointerElementType(); + Vals.push_back(VE.getTypeID(Ty)); Vals.push_back(GetEncodedCallingConv(F->getCallingConv())); Vals.push_back(F->isDeclaration()); Vals.push_back(getEncodedLinkage(F)); |