00001 //===-- codegen/SRInfo.h -------------------------------------- -*- C++ -*-===// 00002 // 00003 // This file is distributed under the MIT license. See LICENSE.txt for details. 00004 // 00005 // Copyright (C) 2009-2010, Stephen Wilson 00006 // 00007 //===----------------------------------------------------------------------===// 00008 00009 //===----------------------------------------------------------------------===// 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef COMMA_CODEGEN_SRINFO_HDR_GUARD 00017 #define COMMA_CODEGEN_SRINFO_HDR_GUARD 00018 00019 #include "CodeGen.h" 00020 #include "comma/ast/Decl.h" 00021 00022 #include "llvm/ADT/StringRef.h" 00023 00024 namespace comma { 00025 00026 class SRInfo { 00027 00028 public: 00058 00060 00061 SubroutineDecl *getDeclaration() { return srDecl; } 00062 const SubroutineDecl *getDeclaration() const { return srDecl; } 00064 00066 llvm::StringRef getLinkName() const { return llvmFn->getName(); } 00067 00069 llvm::Function *getLLVMFunction() const { return llvmFn; } 00070 00072 llvm::Module *getLLVMModule() const { return llvmFn->getParent(); } 00073 00075 bool isaFunction() const { return llvm::isa<FunctionDecl>(srDecl); } 00076 00078 bool isaProcedure() const { return llvm::isa<ProcedureDecl>(srDecl); } 00079 00082 bool hasSRet() const { return llvmFn->hasStructRetAttr(); } 00083 00086 bool usesVRet() const { 00087 // If this is a function returning void but does not use the sret 00088 // convention, then the value must be returned on the vstack. 00089 // 00090 // FIXME: llvm-2.6-svn and up has Type::isVoidTy predicate. Use it. 00091 if (isaFunction() && 00092 (llvmFn->getReturnType()->getTypeID() == llvm::Type::VoidTyID)) 00093 return !hasSRet(); 00094 return false; 00095 } 00096 00098 bool hasAggRet() const { return hasSRet() || usesVRet(); } 00099 00105 bool isImported() const { return srDecl->hasPragma(pragma::Import); } 00106 00107 private: 00109 SRInfo(SubroutineDecl *decl, llvm::Function *fn) 00110 : srDecl(decl), llvmFn(fn) { } 00111 friend class InstanceInfo; 00112 00113 SubroutineDecl *srDecl; 00114 llvm::Function *llvmFn; 00115 }; 00116 00117 } // end comma namespace. 00118 00119 #endif