On Sat, Oct 22, 2011 at 11:11 PM, ???f任 <chenwj@xxxxxxxxxxxxxx> wrote: >> 恩,确实是可以这么写。 >> 对应高级语言,module是对应C++的class的吧,其实是class的子集,是这样么?一个class有多个func,生成一个含有多个func的module。这个我也没有搞的十分明白。 > > Module 在 LLVM 中是???F成一?? C++ class,你可以看 include/llvm/Module.h > 和 lib/VMCore/Module.cpp。 > > 我不懂你?f的 class 的子集是什?N意思。但是你可以看到底下我????出?淼拇??a, > ?? Module ??????比?^有清晰的概念。 > > --------------------- include/llvm/Module.h --------------------------- > class Module { > public: > typedef iplist<GlobalVariable> GlobalListType; > typedef iplist<Function> FunctionListType; > typedef iplist<GlobalAlias> AliasListType; > > Constant *getOrInsertFunction(StringRef Name, const FunctionType *T, > AttrListPtr AttributeList); > > Constant *getOrInsertFunction(StringRef Name, const FunctionType *T); > > private: > FunctionListType FunctionList; ///< The Functions in the module > ----------------------------------------------------------------------- > 对,就是这样,类似C++的class。 C++还有隐式构造函数等等,llvm里面都是显式的。对C++的处理确实很难。 > --------------------- lib/VMCore/Module.cpp --------------------------- > Constant *Module::getOrInsertFunction(StringRef Name, > const FunctionType *Ty, > AttrListPtr AttributeList) { > // See if we have a definition for the specified function already. > GlobalValue *F = getNamedValue(Name); > if (F == 0) { > // Nope, add it > Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, > Name); > if (!New->isIntrinsic()) // Intrinsics get attrs set on construction > New->setAttributes(AttributeList); > FunctionList.push_back(New); > return New; // Return the new prototype. > } > > ... > > } > > Constant *Module::getOrInsertFunction(StringRef Name, > const FunctionType *Ty) { > AttrListPtr AttributeList = AttrListPtr::get((AttributeWithIndex *)0, 0); > return getOrInsertFunction(Name, Ty, AttributeList); > } > ----------------------------------------------------------------------- > > -- > Wei-Ren Chen (???f任) > Computer Systems Lab, Institute of Information Science, > Academia Sinica, Taiwan (R.O.C.) > Tel:886-2-2788-3799 #1667 > >