zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 1 | #include "slang_rs_backend.h" |
| 2 | |
| 3 | #include <vector> |
| 4 | #include <string> |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 5 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 6 | #include "llvm/Metadata.h" |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 7 | #include "llvm/Constant.h" |
| 8 | #include "llvm/Constants.h" |
| 9 | #include "llvm/Module.h" |
| 10 | #include "llvm/Function.h" |
| 11 | #include "llvm/DerivedTypes.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 12 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 13 | #include "llvm/Support/IRBuilder.h" |
| 14 | |
| 15 | #include "llvm/ADT/Twine.h" |
| 16 | #include "llvm/ADT/StringExtras.h" |
| 17 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 18 | #include "clang/AST/DeclGroup.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 19 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 20 | #include "slang_rs_context.h" |
| 21 | #include "slang_rs_export_var.h" |
| 22 | #include "slang_rs_export_func.h" |
| 23 | #include "slang_rs_export_type.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 24 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 25 | using namespace slang; |
| 26 | |
| 27 | RSBackend::RSBackend(RSContext *Context, |
| 28 | clang::Diagnostic &Diags, |
| 29 | const clang::CodeGenOptions &CodeGenOpts, |
| 30 | const clang::TargetOptions &TargetOpts, |
| 31 | const PragmaList &Pragmas, |
| 32 | llvm::raw_ostream *OS, |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame^] | 33 | Slang::OutputType OT, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 34 | clang::SourceManager &SourceMgr, |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 35 | bool AllowRSPrefix) |
| 36 | : Backend(Diags, |
| 37 | CodeGenOpts, |
| 38 | TargetOpts, |
| 39 | Pragmas, |
| 40 | OS, |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame^] | 41 | OT), |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 42 | mContext(Context), |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame^] | 43 | mSourceMgr(SourceMgr), |
| 44 | mAllowRSPrefix(AllowRSPrefix), |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 45 | mExportVarMetadata(NULL), |
| 46 | mExportFuncMetadata(NULL), |
| 47 | mExportTypeMetadata(NULL) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 48 | return; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 51 | void RSBackend::HandleTopLevelDecl(clang::DeclGroupRef D) { |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame^] | 52 | // Disallow user-defined functions with prefix "rs" |
| 53 | if (!mAllowRSPrefix) { |
| 54 | clang::DeclGroupRef::iterator I; |
| 55 | for (I = D.begin(); I != D.end(); I++) { |
| 56 | clang::FunctionDecl *FD = dyn_cast<clang::FunctionDecl>(*I); |
| 57 | if (!FD || !FD->isThisDeclarationADefinition()) continue; |
| 58 | if (FD->getName().startswith("rs")) { |
| 59 | mDiags.Report(clang::FullSourceLoc(FD->getLocStart(), mSourceMgr), |
| 60 | mDiags.getCustomDiagID(clang::Diagnostic::Error, |
| 61 | "invalid function name prefix," |
| 62 | " \"rs\" is reserved: '%0'") |
| 63 | ) |
| 64 | << FD->getNameAsString(); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 69 | Backend::HandleTopLevelDecl(D); |
| 70 | return; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 73 | void RSBackend::HandleTranslationUnitEx(clang::ASTContext &Ctx) { |
| 74 | assert((&Ctx == mContext->getASTContext()) && "Unexpected AST context change" |
| 75 | " during LLVM IR generation"); |
| 76 | mContext->processExport(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 77 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 78 | // Dump export variable info |
| 79 | if (mContext->hasExportVar()) { |
| 80 | if (mExportVarMetadata == NULL) |
| 81 | mExportVarMetadata = mpModule->getOrInsertNamedMetadata("#rs_export_var"); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 82 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 83 | llvm::SmallVector<llvm::Value*, 2> ExportVarInfo; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 84 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 85 | for (RSContext::const_export_var_iterator I = mContext->export_vars_begin(), |
| 86 | E = mContext->export_vars_end(); |
| 87 | I != E; |
| 88 | I++) { |
| 89 | const RSExportVar *EV = *I; |
| 90 | const RSExportType *ET = EV->getType(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 91 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 92 | // Variable name |
| 93 | ExportVarInfo.push_back( |
| 94 | llvm::MDString::get(mLLVMContext, EV->getName().c_str())); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 95 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 96 | // Type name |
| 97 | if (ET->getClass() == RSExportType::ExportClassPrimitive) |
| 98 | ExportVarInfo.push_back( |
| 99 | llvm::MDString::get( |
| 100 | mLLVMContext, llvm::utostr_32( |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 101 | static_cast<const RSExportPrimitiveType*>(ET)->getType()))); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 102 | else if (ET->getClass() == RSExportType::ExportClassPointer) |
| 103 | ExportVarInfo.push_back( |
| 104 | llvm::MDString::get( |
| 105 | mLLVMContext, ("*" + static_cast<const RSExportPointerType*>(ET) |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 106 | ->getPointeeType()->getName()).c_str())); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 107 | else |
| 108 | ExportVarInfo.push_back( |
| 109 | llvm::MDString::get(mLLVMContext, |
| 110 | EV->getType()->getName().c_str())); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 111 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 112 | mExportVarMetadata->addOperand( |
| 113 | llvm::MDNode::get(mLLVMContext, |
| 114 | ExportVarInfo.data(), |
| 115 | ExportVarInfo.size()) ); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 116 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 117 | ExportVarInfo.clear(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 118 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 119 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 120 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 121 | // Dump export function info |
| 122 | if (mContext->hasExportFunc()) { |
| 123 | if (mExportFuncMetadata == NULL) |
| 124 | mExportFuncMetadata = |
| 125 | mpModule->getOrInsertNamedMetadata("#rs_export_func"); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 126 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 127 | llvm::SmallVector<llvm::Value*, 1> ExportFuncInfo; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 128 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 129 | for (RSContext::const_export_func_iterator |
| 130 | I = mContext->export_funcs_begin(), |
| 131 | E = mContext->export_funcs_end(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 132 | I != E; |
| 133 | I++) { |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 134 | const RSExportFunc *EF = *I; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 135 | |
| 136 | // Function name |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 137 | if (!EF->hasParam()) { |
| 138 | ExportFuncInfo.push_back(llvm::MDString::get(mLLVMContext, |
| 139 | EF->getName().c_str())); |
| 140 | } else { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 141 | llvm::Function *F = mpModule->getFunction(EF->getName()); |
| 142 | llvm::Function *HelperFunction; |
| 143 | const std::string HelperFunctionName(".helper_" + EF->getName()); |
| 144 | |
| 145 | assert(F && "Function marked as exported disappeared in Bitcode"); |
| 146 | |
| 147 | // Create helper function |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 148 | { |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 149 | llvm::StructType *HelperFunctionParameterTy = NULL; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 150 | |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 151 | if (!F->getArgumentList().empty()) { |
| 152 | std::vector<const llvm::Type*> HelperFunctionParameterTys; |
| 153 | for (llvm::Function::arg_iterator AI = F->arg_begin(), |
| 154 | AE = F->arg_end(); AI != AE; AI++) |
| 155 | HelperFunctionParameterTys.push_back(AI->getType()); |
| 156 | |
| 157 | HelperFunctionParameterTy = |
| 158 | llvm::StructType::get(mLLVMContext, HelperFunctionParameterTys); |
| 159 | } |
| 160 | |
| 161 | if (!EF->checkParameterPacketType(HelperFunctionParameterTy)) { |
| 162 | fprintf(stderr, "Failed to export function %s: parameter type " |
| 163 | "mismatch during creation of helper function.\n", |
| 164 | EF->getName().c_str()); |
| 165 | |
| 166 | const RSExportRecordType *Expected = EF->getParamPacketType(); |
| 167 | if (Expected) { |
| 168 | fprintf(stderr, "Expected:\n"); |
| 169 | Expected->getLLVMType()->dump(); |
| 170 | } |
| 171 | if (HelperFunctionParameterTy) { |
| 172 | fprintf(stderr, "Got:\n"); |
| 173 | HelperFunctionParameterTy->dump(); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | std::vector<const llvm::Type*> Params; |
| 178 | if (HelperFunctionParameterTy) { |
| 179 | llvm::PointerType *HelperFunctionParameterTyP = |
| 180 | llvm::PointerType::getUnqual(HelperFunctionParameterTy); |
| 181 | Params.push_back(HelperFunctionParameterTyP); |
| 182 | } |
| 183 | |
| 184 | llvm::FunctionType * HelperFunctionType = |
| 185 | llvm::FunctionType::get(F->getReturnType(), |
| 186 | Params, |
| 187 | /* IsVarArgs = */false); |
Shih-wei Liao | cecd11d | 2010-09-21 08:07:58 -0700 | [diff] [blame] | 188 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 189 | HelperFunction = |
| 190 | llvm::Function::Create(HelperFunctionType, |
| 191 | llvm::GlobalValue::ExternalLinkage, |
| 192 | HelperFunctionName, |
| 193 | mpModule); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 194 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 195 | HelperFunction->addFnAttr(llvm::Attribute::NoInline); |
| 196 | HelperFunction->setCallingConv(F->getCallingConv()); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 197 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 198 | // Create helper function body |
| 199 | { |
| 200 | llvm::Argument *HelperFunctionParameter = |
| 201 | &(*HelperFunction->arg_begin()); |
| 202 | llvm::BasicBlock *BB = |
| 203 | llvm::BasicBlock::Create(mLLVMContext, "entry", HelperFunction); |
| 204 | llvm::IRBuilder<> *IB = new llvm::IRBuilder<>(BB); |
| 205 | llvm::SmallVector<llvm::Value*, 6> Params; |
| 206 | llvm::Value *Idx[2]; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 207 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 208 | Idx[0] = |
| 209 | llvm::ConstantInt::get(llvm::Type::getInt32Ty(mLLVMContext), 0); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 210 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 211 | // getelementptr and load instruction for all elements in |
| 212 | // parameter .p |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 213 | for (size_t i = 0; i < EF->getNumParameters(); i++) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 214 | // getelementptr |
| 215 | Idx[1] = |
| 216 | llvm::ConstantInt::get( |
| 217 | llvm::Type::getInt32Ty(mLLVMContext), i); |
| 218 | llvm::Value *Ptr = IB->CreateInBoundsGEP(HelperFunctionParameter, |
| 219 | Idx, |
| 220 | Idx + 2); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 221 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 222 | // load |
| 223 | llvm::Value *V = IB->CreateLoad(Ptr); |
| 224 | Params.push_back(V); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 227 | // Call and pass the all elements as paramter to F |
| 228 | llvm::CallInst *CI = IB->CreateCall(F, |
| 229 | Params.data(), |
| 230 | Params.data() + Params.size()); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 231 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 232 | CI->setCallingConv(F->getCallingConv()); |
| 233 | |
| 234 | if (F->getReturnType() == llvm::Type::getVoidTy(mLLVMContext)) |
| 235 | IB->CreateRetVoid(); |
| 236 | else |
| 237 | IB->CreateRet(CI); |
| 238 | |
| 239 | delete IB; |
| 240 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 241 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 242 | |
| 243 | ExportFuncInfo.push_back( |
| 244 | llvm::MDString::get(mLLVMContext, HelperFunctionName.c_str())); |
| 245 | } |
| 246 | |
| 247 | mExportFuncMetadata->addOperand( |
| 248 | llvm::MDNode::get(mLLVMContext, |
| 249 | ExportFuncInfo.data(), |
| 250 | ExportFuncInfo.size())); |
| 251 | |
| 252 | ExportFuncInfo.clear(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 253 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 254 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 255 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 256 | // Dump export type info |
| 257 | if (mContext->hasExportType()) { |
| 258 | llvm::SmallVector<llvm::Value*, 1> ExportTypeInfo; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 259 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 260 | for (RSContext::const_export_type_iterator |
| 261 | I = mContext->export_types_begin(), |
| 262 | E = mContext->export_types_end(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 263 | I != E; |
| 264 | I++) { |
| 265 | // First, dump type name list to export |
| 266 | const RSExportType *ET = I->getValue(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 267 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 268 | ExportTypeInfo.clear(); |
| 269 | // Type name |
| 270 | ExportTypeInfo.push_back( |
| 271 | llvm::MDString::get(mLLVMContext, ET->getName().c_str())); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 272 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 273 | if (ET->getClass() == RSExportType::ExportClassRecord) { |
| 274 | const RSExportRecordType *ERT = |
| 275 | static_cast<const RSExportRecordType*>(ET); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 276 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 277 | if (mExportTypeMetadata == NULL) |
| 278 | mExportTypeMetadata = |
| 279 | mpModule->getOrInsertNamedMetadata("#rs_export_type"); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 280 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 281 | mExportTypeMetadata->addOperand( |
| 282 | llvm::MDNode::get(mLLVMContext, |
| 283 | ExportTypeInfo.data(), |
| 284 | ExportTypeInfo.size())); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 285 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 286 | // Now, export struct field information to %[struct name] |
| 287 | std::string StructInfoMetadataName("%"); |
| 288 | StructInfoMetadataName.append(ET->getName()); |
| 289 | llvm::NamedMDNode *StructInfoMetadata = |
| 290 | mpModule->getOrInsertNamedMetadata(StructInfoMetadataName); |
| 291 | llvm::SmallVector<llvm::Value*, 3> FieldInfo; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 292 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 293 | assert(StructInfoMetadata->getNumOperands() == 0 && |
| 294 | "Metadata with same name was created before"); |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 295 | for (RSExportRecordType::const_field_iterator FI = ERT->fields_begin(), |
| 296 | FE = ERT->fields_end(); |
| 297 | FI != FE; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 298 | FI++) { |
| 299 | const RSExportRecordType::Field *F = *FI; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 300 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 301 | // 1. field name |
| 302 | FieldInfo.push_back(llvm::MDString::get(mLLVMContext, |
| 303 | F->getName().c_str())); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 304 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 305 | // 2. field type name |
| 306 | FieldInfo.push_back( |
| 307 | llvm::MDString::get(mLLVMContext, |
| 308 | F->getType()->getName().c_str())); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 309 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 310 | // 3. field kind |
| 311 | switch (F->getType()->getClass()) { |
| 312 | case RSExportType::ExportClassPrimitive: |
| 313 | case RSExportType::ExportClassVector: { |
| 314 | const RSExportPrimitiveType *EPT = |
| 315 | static_cast<const RSExportPrimitiveType*>(F->getType()); |
| 316 | FieldInfo.push_back( |
| 317 | llvm::MDString::get(mLLVMContext, |
| 318 | llvm::itostr(EPT->getKind()))); |
| 319 | break; |
| 320 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 321 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 322 | default: { |
| 323 | FieldInfo.push_back( |
| 324 | llvm::MDString::get(mLLVMContext, |
| 325 | llvm::itostr( |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 326 | RSExportPrimitiveType::DataKindUser))); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 327 | break; |
| 328 | } |
| 329 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 330 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 331 | StructInfoMetadata->addOperand(llvm::MDNode::get(mLLVMContext, |
| 332 | FieldInfo.data(), |
| 333 | FieldInfo.size())); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 334 | |
| 335 | FieldInfo.clear(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 336 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 337 | } // ET->getClass() == RSExportType::ExportClassRecord |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 338 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 339 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 340 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 341 | return; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | RSBackend::~RSBackend() { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 345 | return; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 346 | } |