The Mother-of-All code review:
1. Fix AllowRSPrefix bug
2. Remove member mRS*Pragma in class RSContext
3. No longer only support 2x2, 3x3, 4x4 arrays
4. Fix Export All code for victorhsieh
5. Improve readability and maintainability
6. size_t -> int in calculating padding
Change-Id: I772aebd1440af66a89e2d2e688b193e500f38d69
diff --git a/slang_rs_export_func.cpp b/slang_rs_export_func.cpp
index dab29b2..a36b915 100644
--- a/slang_rs_export_func.cpp
+++ b/slang_rs_export_func.cpp
@@ -2,90 +2,121 @@
#include "slang_rs_export_func.hpp"
#include "slang_rs_export_type.hpp"
-#include "llvm/Target/TargetData.h" /* for class llvm::TargetData */
+#include "llvm/Target/TargetData.h"
-#include "clang/AST/Decl.h" /* for clang::*Decl */
+#include "clang/AST/Decl.h"
-namespace slang {
+using namespace slang;
-RSExportFunc* RSExportFunc::Create(RSContext* Context, const FunctionDecl* FD) {
- llvm::StringRef Name = FD->getName();
- RSExportFunc* F;
+RSExportFunc *RSExportFunc::Create(RSContext *Context,
+ const clang::FunctionDecl *FD) {
+ llvm::StringRef Name = FD->getName();
+ RSExportFunc *F;
- assert(!Name.empty() && "Function must have a name");
+ assert(!Name.empty() && "Function must have a name");
- F = new RSExportFunc(Context, Name);
+ F = new RSExportFunc(Context, Name);
- /* Check whether the parameters passed to the function is exportable */
- for(unsigned i=0;i<FD->getNumParams();i++) {
- const ParmVarDecl* PVD = FD->getParamDecl(i);
- const llvm::StringRef ParamName = PVD->getName();
+ // Check whether the parameters passed to the function is exportable
+ for(unsigned i = 0;i < FD->getNumParams(); i++) {
+ const clang::ParmVarDecl *PVD = FD->getParamDecl(i);
+ const llvm::StringRef ParamName = PVD->getName();
- assert(!ParamName.empty() && "Parameter must have a name");
+ assert(!ParamName.empty() && "Parameter must have a name");
- if(PVD->hasDefaultArg())
- printf("Note: parameter '%s' in function '%s' has default value will not support\n", ParamName.str().c_str(), Name.str().c_str());
+ if (PVD->hasDefaultArg())
+ fprintf(stderr,
+ "Note: parameter '%s' in function '%s' has default value "
+ "will not support\n",
+ ParamName.str().c_str(),
+ Name.str().c_str());
- /* Check type */
- RSExportType* PET = RSExportType::CreateFromDecl(Context, PVD);
- if(PET != NULL) {
- F->mParams.push_back(new Parameter(PET, ParamName));
- } else {
- printf("Note: parameter '%s' in function '%s' uses unsupported type\n", ParamName.str().c_str(), Name.str().c_str());
- delete F;
- return NULL;
- }
+ // Check type
+ RSExportType *PET = RSExportType::CreateFromDecl(Context, PVD);
+ if (PET != NULL) {
+ F->mParams.push_back(new Parameter(PET, ParamName));
+ } else {
+ fprintf(stderr, "Note: parameter '%s' in function '%s' uses unsupported "
+ "type\n", ParamName.str().c_str(), Name.str().c_str());
+ delete F;
+ return NULL;
}
+ }
- return F;
+ return F;
}
-const RSExportRecordType* RSExportFunc::getParamPacketType() const {
- /* Pack parameters */
- if((mParamPacketType == NULL) && hasParam()) {
- RSExportRecordType* ParamPacketType = new RSExportRecordType(mContext, "", false /* IsPacked */, true /* IsArtificial */);
- int Index = 0;
+const RSExportRecordType *RSExportFunc::getParamPacketType() const {
+ // Pack parameters
+ if ((mParamPacketType == NULL) && hasParam()) {
+ int Index = 0;
+ RSExportRecordType *ParamPacketType =
+ new RSExportRecordType(mContext,
+ "",
+ /* IsPacked = */false,
+ /* IsArtificial = */true);
- for(const_param_iterator PI = params_begin();
- PI != params_end();
- PI++, Index++) {
- const RSExportFunc::Parameter* P = *PI;
- std::string nam = P->getName();
- const RSExportType* typ = P->getType();
- std::string typNam = typ->getName();
- /* If (type conversion is needed) */
- if (typNam.find("rs_") == 0) {
- /* P's type set to [1 x i32]; */
- RSExportConstantArrayType* ECT = new RSExportConstantArrayType(mContext, "addObj",
- RSExportPrimitiveType::DataTypeSigned32,
- RSExportPrimitiveType::DataKindUser,
- false,
- 1);
- //printf("datatype = %d\n", ECT->getType());
- ParamPacketType->mFields.push_back( new RSExportRecordType::Field(ECT, nam, ParamPacketType, Index) );
- } else {
- ParamPacketType->mFields.push_back( new RSExportRecordType::Field(P->getType(), nam, ParamPacketType, Index) );
- }
- }
+ for (const_param_iterator PI = params_begin(),
+ PE = params_end();
+ PI != PE;
+ PI++, Index++) {
+ //For-Loop's body should be:
+ const RSExportFunc::Parameter* P = *PI;
+ std::string nam = P->getName();
+ const RSExportType* typ = P->getType();
+ std::string typNam = typ->getName();
+ // If (type conversion is needed)
+ if (typNam.find("rs_") == 0) {
+ // P's type set to [1 x i32];
+ RSExportConstantArrayType* ECT = new RSExportConstantArrayType
+ (mContext, "addObj",
+ RSExportPrimitiveType::DataTypeSigned32,
+ RSExportPrimitiveType::DataKindUser,
+ false,
+ 1);
+ ParamPacketType->mFields.push_back(
+ new RSExportRecordType::Field(ECT,
+ nam,
+ ParamPacketType,
+ Index) );
+ } else {
+ ParamPacketType->mFields.push_back(
+ new RSExportRecordType::Field(P->getType(),
+ nam,
+ ParamPacketType,
+ Index) );
+ }
- ParamPacketType->AllocSize = mContext->getTargetData()->getTypeAllocSize(ParamPacketType->getLLVMType());
-
- mParamPacketType = ParamPacketType;
+ // ParamPacketType->mFields.push_back(
+ // new RSExportRecordType::Field((*PI)->getType(),
+ // (*PI)->getName(),
+ // ParamPacketType,
+ // Index
+ // ));
}
- return mParamPacketType;
+
+
+ ParamPacketType->AllocSize =
+ mContext->getTargetData()->getTypeAllocSize(
+ ParamPacketType->getLLVMType()
+ );
+
+ mParamPacketType = ParamPacketType;
+ }
+
+ return mParamPacketType;
}
RSExportFunc::~RSExportFunc() {
- for(const_param_iterator PI = params_begin();
- PI != params_end();
- PI++)
- delete *PI;
+ for (const_param_iterator PI = params_begin(),
+ PE = params_end();
+ PI != params_end();
+ PI++)
+ delete *PI;
- if(mParamPacketType != NULL)
- delete mParamPacketType;
+ if(mParamPacketType != NULL)
+ delete mParamPacketType;
- return;
+ return;
}
-
-} /* namespace slang */