> 恩,确实是可以这么写。 > 对应高级语言,module是对应C++的class的吧,其实是class的子集,是这样么?一个class有多个func,生成一个含有多个func的module。这个我也没有搞的十分明白。 Module 在 LLVM 中是實現成一個 C++ class,你可以看 include/llvm/Module.h 和 lib/VMCore/Module.cpp。 我不懂你說的 class 的子集是什麼意思。但是你可以看到底下我節錄出來的代碼, 對 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 ----------------------------------------------------------------------- --------------------- 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 (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667