blob: 31ac84e22361934f8f4c4c7b7fd6b0c72d25d494 [file] [log] [blame]
Zonr Changc383a502010-10-12 01:52:08 +08001/*
2 * Copyright 2010, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
zonr6315f762010-10-05 15:35:14 +080017#include "slang_rs_backend.h"
18
zonr6315f762010-10-05 15:35:14 +080019#include <string>
Stephen Hinese639eb52010-11-08 19:27:20 -080020#include <vector>
zonr6315f762010-10-05 15:35:14 +080021
22#include "llvm/ADT/Twine.h"
23#include "llvm/ADT/StringExtras.h"
24
Stephen Hinese639eb52010-11-08 19:27:20 -080025#include "llvm/Constant.h"
26#include "llvm/Constants.h"
27#include "llvm/DerivedTypes.h"
28#include "llvm/Function.h"
29#include "llvm/Metadata.h"
30#include "llvm/Module.h"
31
32#include "llvm/Support/IRBuilder.h"
33
Zonr Chang592a9542010-10-07 20:03:58 +080034#include "slang_rs.h"
zonr6315f762010-10-05 15:35:14 +080035#include "slang_rs_context.h"
zonr6315f762010-10-05 15:35:14 +080036#include "slang_rs_export_func.h"
37#include "slang_rs_export_type.h"
Stephen Hinese639eb52010-11-08 19:27:20 -080038#include "slang_rs_export_var.h"
39#include "slang_rs_metadata.h"
Shih-wei Liao462aefd2010-06-04 15:32:04 -070040
Stephen Hinese639eb52010-11-08 19:27:20 -080041namespace slang {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070042
43RSBackend::RSBackend(RSContext *Context,
Stephen Hinese639eb52010-11-08 19:27:20 -080044 clang::Diagnostic *Diags,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070045 const clang::CodeGenOptions &CodeGenOpts,
46 const clang::TargetOptions &TargetOpts,
47 const PragmaList &Pragmas,
48 llvm::raw_ostream *OS,
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080049 Slang::OutputType OT,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070050 clang::SourceManager &SourceMgr,
zonr6315f762010-10-05 15:35:14 +080051 bool AllowRSPrefix)
52 : Backend(Diags,
53 CodeGenOpts,
54 TargetOpts,
55 Pragmas,
56 OS,
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080057 OT),
zonr6315f762010-10-05 15:35:14 +080058 mContext(Context),
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080059 mSourceMgr(SourceMgr),
60 mAllowRSPrefix(AllowRSPrefix),
zonr6315f762010-10-05 15:35:14 +080061 mExportVarMetadata(NULL),
62 mExportFuncMetadata(NULL),
63 mExportTypeMetadata(NULL) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070064 return;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070065}
66
Stephen Hinescfae0f32010-11-01 18:57:31 -070067// 1) Add zero initialization of local RS object types
68void RSBackend::AnnotateFunction(clang::FunctionDecl *FD) {
69 if (FD &&
70 FD->hasBody() &&
71 !SlangRS::IsFunctionInRSHeaderFile(FD, mSourceMgr)) {
Stephen Hines1bdd4972010-11-08 17:35:08 -080072 mRefCount.Init(mContext->getASTContext());
Stephen Hines4b32ffd2010-11-05 18:47:11 -070073 mRefCount.Visit(FD->getBody());
Stephen Hinescfae0f32010-11-01 18:57:31 -070074 }
75 return;
76}
77
78void RSBackend::HandleTopLevelDecl(clang::DeclGroupRef D) {
79 // Disallow user-defined functions with prefix "rs"
80 if (!mAllowRSPrefix) {
81 // Iterate all function declarations in the program.
82 for (clang::DeclGroupRef::iterator I = D.begin(), E = D.end();
83 I != E; I++) {
84 clang::FunctionDecl *FD = dyn_cast<clang::FunctionDecl>(*I);
85 if (FD == NULL)
86 continue;
87 if (!FD->getName().startswith("rs")) // Check prefix
88 continue;
89 if (!SlangRS::IsFunctionInRSHeaderFile(FD, mSourceMgr))
90 mDiags.Report(clang::FullSourceLoc(FD->getLocation(), mSourceMgr),
91 mDiags.getCustomDiagID(clang::Diagnostic::Error,
92 "invalid function name prefix, "
93 "\"rs\" is reserved: '%0'"))
94 << FD->getName();
95 }
96 }
97
98 // Process any non-static function declarations
99 for (clang::DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; I++) {
100 AnnotateFunction(dyn_cast<clang::FunctionDecl>(*I));
101 }
102
103 Backend::HandleTopLevelDecl(D);
104 return;
105}
106
Stephen Hinesc97a3332010-11-30 15:31:08 -0800107namespace {
108
Stephen Hinese5e64432010-12-02 18:48:20 -0800109bool ValidateVar(clang::VarDecl *VD, clang::Diagnostic *Diags,
110 clang::SourceManager *SM) {
Stephen Hinesc97a3332010-11-30 15:31:08 -0800111 llvm::StringRef TypeName;
112 const clang::Type *T = VD->getType().getTypePtr();
Stephen Hinesdd6206b2010-12-09 19:39:22 -0800113 if (!RSExportType::NormalizeType(T, TypeName, Diags, SM, VD)) {
Stephen Hinesc97a3332010-11-30 15:31:08 -0800114 return false;
115 }
116 return true;
117}
118
119bool ValidateASTContext(clang::ASTContext &C, clang::Diagnostic &Diags) {
120 bool valid = true;
Stephen Hinesfcda2352010-10-19 16:49:32 -0700121 clang::TranslationUnitDecl *TUDecl = C.getTranslationUnitDecl();
Stephen Hinesc97a3332010-11-30 15:31:08 -0800122 for (clang::DeclContext::decl_iterator DI = TUDecl->decls_begin(),
123 DE = TUDecl->decls_end();
124 DI != DE;
125 DI++) {
126 if (DI->getKind() == clang::Decl::Var) {
127 clang::VarDecl *VD = (clang::VarDecl*) (*DI);
128 if (VD->getLinkage() == clang::ExternalLinkage) {
Stephen Hinese5e64432010-12-02 18:48:20 -0800129 if (!ValidateVar(VD, &Diags, &C.getSourceManager())) {
Stephen Hinesc97a3332010-11-30 15:31:08 -0800130 valid = false;
Stephen Hinesc97a3332010-11-30 15:31:08 -0800131 }
132 }
133 }
134 }
135
136 return valid;
137}
138
Stephen Hinese5e64432010-12-02 18:48:20 -0800139} // namespace
Stephen Hinesc97a3332010-11-30 15:31:08 -0800140
141void RSBackend::HandleTranslationUnitPre(clang::ASTContext &C) {
142 clang::TranslationUnitDecl *TUDecl = C.getTranslationUnitDecl();
143
144 if (!ValidateASTContext(C, mDiags)) {
145 return;
146 }
Stephen Hinesfcda2352010-10-19 16:49:32 -0700147
Stephen Hines96ab06c2011-01-05 15:29:26 -0800148 int version = mContext->getVersion();
149 if (version == 0) {
150 // Not setting a version is an error
151 mDiags.Report(mDiags.getCustomDiagID(clang::Diagnostic::Error,
152 "Missing pragma for version in source file"));
153 } else if (version > 1) {
154 mDiags.Report(mDiags.getCustomDiagID(clang::Diagnostic::Error,
155 "Pragma for version in source file must be set to 1"));
156 }
157
Stephen Hinescfae0f32010-11-01 18:57:31 -0700158 // Process any static function declarations
Stephen Hinesfcda2352010-10-19 16:49:32 -0700159 for (clang::DeclContext::decl_iterator I = TUDecl->decls_begin(),
160 E = TUDecl->decls_end(); I != E; I++) {
161 if ((I->getKind() >= clang::Decl::firstFunction) &&
162 (I->getKind() <= clang::Decl::lastFunction)) {
Stephen Hinescfae0f32010-11-01 18:57:31 -0700163 AnnotateFunction(static_cast<clang::FunctionDecl*>(*I));
Stephen Hinesfcda2352010-10-19 16:49:32 -0700164 }
165 }
166
167 return;
168}
169
170///////////////////////////////////////////////////////////////////////////////
Zonr Chang68fc02c2010-10-13 19:09:19 +0800171void RSBackend::HandleTranslationUnitPost(llvm::Module *M) {
Stephen Hinesc808a992010-11-29 17:20:42 -0800172 if (!mContext->processExport()) {
173 mDiags.Report(mDiags.getCustomDiagID(clang::Diagnostic::Error,
174 "elements cannot be exported"));
Stephen Hinesc97a3332010-11-30 15:31:08 -0800175 return;
Stephen Hinesc808a992010-11-29 17:20:42 -0800176 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700177
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700178 // Dump export variable info
179 if (mContext->hasExportVar()) {
180 if (mExportVarMetadata == NULL)
Zonr Chang68fc02c2010-10-13 19:09:19 +0800181 mExportVarMetadata = M->getOrInsertNamedMetadata(RS_EXPORT_VAR_MN);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700182
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700183 llvm::SmallVector<llvm::Value*, 2> ExportVarInfo;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700184
zonr6315f762010-10-05 15:35:14 +0800185 for (RSContext::const_export_var_iterator I = mContext->export_vars_begin(),
186 E = mContext->export_vars_end();
187 I != E;
188 I++) {
189 const RSExportVar *EV = *I;
190 const RSExportType *ET = EV->getType();
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700191
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700192 // Variable name
193 ExportVarInfo.push_back(
194 llvm::MDString::get(mLLVMContext, EV->getName().c_str()));
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700195
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700196 // Type name
Zonr Changa65ec162010-10-17 01:53:05 +0800197 switch (ET->getClass()) {
198 case RSExportType::ExportClassPrimitive: {
199 ExportVarInfo.push_back(
200 llvm::MDString::get(
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700201 mLLVMContext, llvm::utostr_32(
Zonr Changa65ec162010-10-17 01:53:05 +0800202 static_cast<const RSExportPrimitiveType*>(ET)->getType())));
203 break;
204 }
205 case RSExportType::ExportClassPointer: {
206 ExportVarInfo.push_back(
207 llvm::MDString::get(
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700208 mLLVMContext, ("*" + static_cast<const RSExportPointerType*>(ET)
Zonr Changa65ec162010-10-17 01:53:05 +0800209 ->getPointeeType()->getName()).c_str()));
210 break;
211 }
212 case RSExportType::ExportClassMatrix: {
213 ExportVarInfo.push_back(
214 llvm::MDString::get(
215 mLLVMContext, llvm::utostr_32(
216 RSExportPrimitiveType::DataTypeRSMatrix2x2 +
217 static_cast<const RSExportMatrixType*>(ET)->getDim() - 2)));
218 break;
219 }
220 case RSExportType::ExportClassVector:
221 case RSExportType::ExportClassConstantArray:
222 case RSExportType::ExportClassRecord: {
223 ExportVarInfo.push_back(
224 llvm::MDString::get(mLLVMContext,
225 EV->getType()->getName().c_str()));
226 break;
227 }
228 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700229
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700230 mExportVarMetadata->addOperand(
231 llvm::MDNode::get(mLLVMContext,
232 ExportVarInfo.data(),
233 ExportVarInfo.size()) );
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700234
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700235 ExportVarInfo.clear();
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700236 }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700237 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700238
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700239 // Dump export function info
240 if (mContext->hasExportFunc()) {
241 if (mExportFuncMetadata == NULL)
242 mExportFuncMetadata =
Zonr Chang68fc02c2010-10-13 19:09:19 +0800243 M->getOrInsertNamedMetadata(RS_EXPORT_FUNC_MN);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700244
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700245 llvm::SmallVector<llvm::Value*, 1> ExportFuncInfo;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700246
zonr6315f762010-10-05 15:35:14 +0800247 for (RSContext::const_export_func_iterator
248 I = mContext->export_funcs_begin(),
249 E = mContext->export_funcs_end();
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700250 I != E;
251 I++) {
zonr6315f762010-10-05 15:35:14 +0800252 const RSExportFunc *EF = *I;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700253
254 // Function name
zonr6315f762010-10-05 15:35:14 +0800255 if (!EF->hasParam()) {
256 ExportFuncInfo.push_back(llvm::MDString::get(mLLVMContext,
257 EF->getName().c_str()));
258 } else {
Zonr Chang68fc02c2010-10-13 19:09:19 +0800259 llvm::Function *F = M->getFunction(EF->getName());
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700260 llvm::Function *HelperFunction;
261 const std::string HelperFunctionName(".helper_" + EF->getName());
262
263 assert(F && "Function marked as exported disappeared in Bitcode");
264
265 // Create helper function
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700266 {
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800267 llvm::StructType *HelperFunctionParameterTy = NULL;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700268
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800269 if (!F->getArgumentList().empty()) {
270 std::vector<const llvm::Type*> HelperFunctionParameterTys;
271 for (llvm::Function::arg_iterator AI = F->arg_begin(),
272 AE = F->arg_end(); AI != AE; AI++)
273 HelperFunctionParameterTys.push_back(AI->getType());
274
275 HelperFunctionParameterTy =
276 llvm::StructType::get(mLLVMContext, HelperFunctionParameterTys);
277 }
278
279 if (!EF->checkParameterPacketType(HelperFunctionParameterTy)) {
280 fprintf(stderr, "Failed to export function %s: parameter type "
281 "mismatch during creation of helper function.\n",
282 EF->getName().c_str());
283
284 const RSExportRecordType *Expected = EF->getParamPacketType();
285 if (Expected) {
286 fprintf(stderr, "Expected:\n");
287 Expected->getLLVMType()->dump();
288 }
289 if (HelperFunctionParameterTy) {
290 fprintf(stderr, "Got:\n");
291 HelperFunctionParameterTy->dump();
292 }
293 }
294
295 std::vector<const llvm::Type*> Params;
296 if (HelperFunctionParameterTy) {
297 llvm::PointerType *HelperFunctionParameterTyP =
298 llvm::PointerType::getUnqual(HelperFunctionParameterTy);
299 Params.push_back(HelperFunctionParameterTyP);
300 }
301
302 llvm::FunctionType * HelperFunctionType =
303 llvm::FunctionType::get(F->getReturnType(),
304 Params,
305 /* IsVarArgs = */false);
Shih-wei Liaocecd11d2010-09-21 08:07:58 -0700306
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700307 HelperFunction =
308 llvm::Function::Create(HelperFunctionType,
309 llvm::GlobalValue::ExternalLinkage,
310 HelperFunctionName,
Zonr Chang68fc02c2010-10-13 19:09:19 +0800311 M);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700312
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700313 HelperFunction->addFnAttr(llvm::Attribute::NoInline);
314 HelperFunction->setCallingConv(F->getCallingConv());
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700315
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700316 // Create helper function body
317 {
318 llvm::Argument *HelperFunctionParameter =
319 &(*HelperFunction->arg_begin());
320 llvm::BasicBlock *BB =
321 llvm::BasicBlock::Create(mLLVMContext, "entry", HelperFunction);
322 llvm::IRBuilder<> *IB = new llvm::IRBuilder<>(BB);
323 llvm::SmallVector<llvm::Value*, 6> Params;
324 llvm::Value *Idx[2];
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700325
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700326 Idx[0] =
327 llvm::ConstantInt::get(llvm::Type::getInt32Ty(mLLVMContext), 0);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700328
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700329 // getelementptr and load instruction for all elements in
330 // parameter .p
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800331 for (size_t i = 0; i < EF->getNumParameters(); i++) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700332 // getelementptr
333 Idx[1] =
334 llvm::ConstantInt::get(
335 llvm::Type::getInt32Ty(mLLVMContext), i);
336 llvm::Value *Ptr = IB->CreateInBoundsGEP(HelperFunctionParameter,
337 Idx,
338 Idx + 2);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700339
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700340 // load
341 llvm::Value *V = IB->CreateLoad(Ptr);
342 Params.push_back(V);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700343 }
344
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700345 // Call and pass the all elements as paramter to F
346 llvm::CallInst *CI = IB->CreateCall(F,
347 Params.data(),
348 Params.data() + Params.size());
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700349
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700350 CI->setCallingConv(F->getCallingConv());
351
352 if (F->getReturnType() == llvm::Type::getVoidTy(mLLVMContext))
353 IB->CreateRetVoid();
354 else
355 IB->CreateRet(CI);
356
357 delete IB;
358 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700359 }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700360
361 ExportFuncInfo.push_back(
362 llvm::MDString::get(mLLVMContext, HelperFunctionName.c_str()));
363 }
364
365 mExportFuncMetadata->addOperand(
366 llvm::MDNode::get(mLLVMContext,
367 ExportFuncInfo.data(),
368 ExportFuncInfo.size()));
369
370 ExportFuncInfo.clear();
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700371 }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700372 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700373
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700374 // Dump export type info
375 if (mContext->hasExportType()) {
376 llvm::SmallVector<llvm::Value*, 1> ExportTypeInfo;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700377
zonr6315f762010-10-05 15:35:14 +0800378 for (RSContext::const_export_type_iterator
379 I = mContext->export_types_begin(),
380 E = mContext->export_types_end();
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700381 I != E;
382 I++) {
383 // First, dump type name list to export
384 const RSExportType *ET = I->getValue();
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700385
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700386 ExportTypeInfo.clear();
387 // Type name
388 ExportTypeInfo.push_back(
389 llvm::MDString::get(mLLVMContext, ET->getName().c_str()));
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700390
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700391 if (ET->getClass() == RSExportType::ExportClassRecord) {
392 const RSExportRecordType *ERT =
393 static_cast<const RSExportRecordType*>(ET);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700394
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700395 if (mExportTypeMetadata == NULL)
396 mExportTypeMetadata =
Zonr Chang68fc02c2010-10-13 19:09:19 +0800397 M->getOrInsertNamedMetadata(RS_EXPORT_TYPE_MN);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700398
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700399 mExportTypeMetadata->addOperand(
400 llvm::MDNode::get(mLLVMContext,
401 ExportTypeInfo.data(),
402 ExportTypeInfo.size()));
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700403
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700404 // Now, export struct field information to %[struct name]
405 std::string StructInfoMetadataName("%");
406 StructInfoMetadataName.append(ET->getName());
407 llvm::NamedMDNode *StructInfoMetadata =
Zonr Chang68fc02c2010-10-13 19:09:19 +0800408 M->getOrInsertNamedMetadata(StructInfoMetadataName);
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700409 llvm::SmallVector<llvm::Value*, 3> FieldInfo;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700410
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700411 assert(StructInfoMetadata->getNumOperands() == 0 &&
412 "Metadata with same name was created before");
zonr6315f762010-10-05 15:35:14 +0800413 for (RSExportRecordType::const_field_iterator FI = ERT->fields_begin(),
414 FE = ERT->fields_end();
415 FI != FE;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700416 FI++) {
417 const RSExportRecordType::Field *F = *FI;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700418
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700419 // 1. field name
420 FieldInfo.push_back(llvm::MDString::get(mLLVMContext,
421 F->getName().c_str()));
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700422
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700423 // 2. field type name
424 FieldInfo.push_back(
425 llvm::MDString::get(mLLVMContext,
426 F->getType()->getName().c_str()));
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700427
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700428 // 3. field kind
429 switch (F->getType()->getClass()) {
430 case RSExportType::ExportClassPrimitive:
431 case RSExportType::ExportClassVector: {
432 const RSExportPrimitiveType *EPT =
433 static_cast<const RSExportPrimitiveType*>(F->getType());
434 FieldInfo.push_back(
435 llvm::MDString::get(mLLVMContext,
436 llvm::itostr(EPT->getKind())));
437 break;
438 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700439
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700440 default: {
441 FieldInfo.push_back(
442 llvm::MDString::get(mLLVMContext,
443 llvm::itostr(
zonr6315f762010-10-05 15:35:14 +0800444 RSExportPrimitiveType::DataKindUser)));
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700445 break;
446 }
447 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700448
zonr6315f762010-10-05 15:35:14 +0800449 StructInfoMetadata->addOperand(llvm::MDNode::get(mLLVMContext,
450 FieldInfo.data(),
451 FieldInfo.size()));
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700452
453 FieldInfo.clear();
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700454 }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700455 } // ET->getClass() == RSExportType::ExportClassRecord
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700456 }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700457 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700458
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700459 return;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700460}
461
462RSBackend::~RSBackend() {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700463 return;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700464}
Stephen Hinese639eb52010-11-08 19:27:20 -0800465
466} // namespace slang