compiler/codegen/symbol.cpp
// forHeader == true when generating the C header.
forHeader == true when generating the C header.
forHeader == true when generating the C header .
GenRet FnSymbol::codegenFunctionType(bool forHeader) {
  GenInfo* info = gGenInfo;
  GenRet ret;
  ret.chplType = typeInfo();
  INT_ASSERT(ret.chplType == dtUnknown); 
  if( info->cfile ) {
    std::string str;
    std::string retString = transformTypeForPointer(retType);
    str += retString.c_str();
    if( forHeader ) {
      str += " ";
      str += cname;
    } else str += "(*)";
    str += "(";
    if(numFormals() == 0) {
      str += "void";
    } else {
      int count = 0;
      for_formals(formal, this) {
        if (formal->hasFlag(FLAG_NO_CODEGEN))
          continue; 
        if (count > 0)
          str += ",\n";
        str += formal->codegenType().c;
        if( forHeader ) {
          str += " ";
          str += formal->cname;
        }
        if (fGenIDS) {
          str += " ";
          str += idCommentTemp(formal);
        }
        count++;
      }
    }
    str += ")";
    ret.c = str;
  } else {
#ifdef HAVE_LLVM
    llvm::Type *returnType;
    std::vector<llvm::Type *> argumentTypes;
    int count = 0;
    for_formals(formal, this) {
      if (formal->hasFlag(FLAG_NO_CODEGEN))
        continue; 
      argumentTypes.push_back(formal->codegenType().type);
      count++;
    }
    if( 0 == strcmp("void", retType->symbol->name) ) {
      returnType = llvm::Type::getVoidTy(info->module->getContext());
    } else {
      returnType = retType->codegen().type;
    }
    llvm::FunctionType* fnType =
      llvm::FunctionType::get(returnType,
                              argumentTypes,
                               false);
    ret.type = fnType;
#endif
  }
  return ret;
}
GenRet FnSymbol :: codegenFunctionType ( bool forHeader ) { GenInfo * info = gGenInfo ; GenRet ret ; ret . chplType = typeInfo ( ) ; INT_ASSERT ( ret . chplType == dtUnknown ) ; if ( info -> cfile ) { std :: string str ; std :: string retString = transformTypeForPointer ( retType ) ; str += retString . c_str ( ) ; if ( forHeader ) { str += " " ; str += cname ; } else str += " " ; str += " " ; if ( numFormals ( ) == 0 ) { str += " " ; } else { int count = 0 ; for_formals ( formal , this ) { if ( formal -> hasFlag ( FLAG_NO_CODEGEN ) ) continue ; if ( count > 0 ) str += " \n " ; str += formal -> codegenType ( ) . c ; if ( forHeader ) { str += " " ; str += formal -> cname ; } if ( fGenIDS ) { str += " " ; str += idCommentTemp ( formal ) ; } count ++ ; } } str += " " ; ret . c = str ; } else { #ifdef HAVE_LLVM llvm :: Type * returnType ; std :: vector < llvm :: Type * > argumentTypes ; int count = 0 ; for_formals ( formal , this ) { if ( formal -> hasFlag ( FLAG_NO_CODEGEN ) ) continue ; argumentTypes . push_back ( formal -> codegenType ( ) . type ) ; count ++ ; } if ( 0 == strcmp ( " " , retType -> symbol -> name ) ) { returnType = llvm :: Type :: getVoidTy ( info -> module -> getContext ( ) ) ; } else { returnType = retType -> codegen ( ) . type ; } llvm :: FunctionType * fnType = llvm :: FunctionType :: get ( returnType , argumentTypes , false ) ; ret . type = fnType ; #endif } return ret ; }
forHeader == true when generating the C header.
forHeader == true when generating the C header .
//just documenting the current state // Cast to right function type. // do not print locale argument, end count, dummy class // do not print locale argument, end count, dummy class //Void type handled here since LLVM complains about a //void type defined in a module // now cast to correct function type /* is var arg */