From 58d74910c6b82e622ecbb57d6644d48fec5a5c0f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 12 Mar 2008 17:45:29 +0000 Subject: Reimplement the parameter attributes support, phase #1. hilights: 1. There is now a "PAListPtr" class, which is a smart pointer around the underlying uniqued parameter attribute list object, and manages its refcount. It is now impossible to mess up the refcount. 2. PAListPtr is now the main interface to the underlying object, and the underlying object is now completely opaque. 3. Implementation details like SmallVector and FoldingSet are now no longer part of the interface. 4. You can create a PAListPtr with an arbitrary sequence of ParamAttrsWithIndex's, no need to make a SmallVector of a specific size (you can just use an array or scalar or vector if you wish). 5. All the client code that had to check for a null pointer before dereferencing the pointer is simplified to just access the PAListPtr directly. 6. The interfaces for adding attrs to a list and removing them is a bit simpler. Phase #2 will rename some stuff (e.g. PAListPtr) and do other less invasive changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48289 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm2cpp/CppWriter.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'tools/llvm2cpp/CppWriter.cpp') diff --git a/tools/llvm2cpp/CppWriter.cpp b/tools/llvm2cpp/CppWriter.cpp index 45810c36d0..a10fec00fd 100644 --- a/tools/llvm2cpp/CppWriter.cpp +++ b/tools/llvm2cpp/CppWriter.cpp @@ -18,7 +18,6 @@ #include "llvm/InlineAsm.h" #include "llvm/Instruction.h" #include "llvm/Instructions.h" -#include "llvm/ParamAttrsList.h" #include "llvm/Module.h" #include "llvm/TypeSymbolTable.h" #include "llvm/ADT/StringExtras.h" @@ -125,7 +124,7 @@ private: std::string getCppName(const Value* val); inline void printCppName(const Value* val); - void printParamAttrs(const ParamAttrsList* PAL, const std::string &name); + void printParamAttrs(const PAListPtr &PAL, const std::string &name); bool printTypeInternal(const Type* Ty); inline void printType(const Type* Ty); void printTypes(const Module* M); @@ -438,16 +437,16 @@ CppWriter::printCppName(const Value* val) { } void -CppWriter::printParamAttrs(const ParamAttrsList* PAL, const std::string &name) { - Out << "ParamAttrsList *" << name << "_PAL = 0;"; +CppWriter::printParamAttrs(const PAListPtr &PAL, const std::string &name) { + Out << "PAListPtr " << name << "_PAL = 0;"; nl(Out); - if (PAL) { + if (!PAL.isEmpty()) { Out << '{'; in(); nl(Out); - Out << "ParamAttrsVector Attrs;"; nl(Out); + Out << "SmallVector Attrs;"; nl(Out); Out << "ParamAttrsWithIndex PAWI;"; nl(Out); - for (unsigned i = 0; i < PAL->size(); ++i) { - uint16_t index = PAL->getParamIndex(i); - ParameterAttributes attrs = PAL->getParamAttrs(index); + for (unsigned i = 0; i < PAL.getNumSlots(); ++i) { + uint16_t index = PAL.getSlot(i).Index; + ParameterAttributes attrs = PAL.getSlot(i).Attrs; Out << "PAWI.index = " << index << "; PAWI.attrs = 0 "; if (attrs & ParamAttr::SExt) Out << " | ParamAttr::SExt"; @@ -466,7 +465,7 @@ CppWriter::printParamAttrs(const ParamAttrsList* PAL, const std::string &name) { Out << "Attrs.push_back(PAWI);"; nl(Out); } - Out << name << "_PAL = ParamAttrsList::get(Attrs);"; + Out << name << "_PAL = PAListPtr::get(Attrs.begin(), Attrs.end());"; nl(Out); out(); nl(Out); Out << '}'; nl(Out); @@ -1748,7 +1747,6 @@ void CppWriter::printProgram( Out << "#include \n"; Out << "#include \n"; Out << "#include \n"; - Out << "#include \n"; Out << "#include \n"; Out << "#include \n"; Out << "#include \n"; -- cgit v1.2.3-18-g5258