compiler/passes/normalize.cpp
// Expected to run after we make the wrapper, since the wrapper is generated
// prior to any normalization occurring on the function, and this gets called
// during normalize called on a specific AST node.
Expected to run after we make the wrapper, since the wrapper is generated
prior to any normalization occurring on the function, and this gets called
during normalize called on a specific AST node.
Expected to run after we make the wrapper since the wrapper is generated prior to any normalization occurring on the function and this gets called during normalize called on a specific AST node .
static void fixupExportedArrayReturns(FnSymbol* fn) {
  if (fn->hasFlag(FLAG_EXPORT) &&
      fn->hasFlag(FLAG_COMPILER_GENERATED) &&
      returnsArray(fn)) {
    CallExpr* call = toCallExpr(fn->retExprType->body.tail);
    int nArgs = call->numActuals();
    Expr* eltExpr = nArgs == 2 ? call->get(2) : NULL;
    if (SymExpr* eltSym = toSymExpr(eltExpr)) {
      if (TypeSymbol* eltType = toTypeSymbol(eltSym->symbol())) {
        exportedArrayElementType[fn] = eltType;
      }
    }
    if (exportedArrayElementType[fn] == NULL && fLibraryPython) {
      USR_FATAL_CONT(fn,
                     "Array return types must include an explicit element type"
                     " for Python compilation");
    }
    fn->retExprType->replace(new BlockStmt(new SymExpr(dtExternalArray->symbol)));
    CallExpr* retCall = toCallExpr(fn->body->body.tail);
    INT_ASSERT(retCall && retCall->isPrimitive(PRIM_RETURN));
    CallExpr* transformRet = new CallExpr("convertToExternalArray",
                                          retCall->get(1)->remove());
    retCall->insertAtTail(transformRet);
  }
}
static void fixupExportedArrayReturns ( FnSymbol * fn ) { if ( fn -> hasFlag ( FLAG_EXPORT ) && fn -> hasFlag ( FLAG_COMPILER_GENERATED ) && returnsArray ( fn ) ) { CallExpr * call = toCallExpr ( fn -> retExprType -> body . tail ) ; int nArgs = call -> numActuals ( ) ; Expr * eltExpr = nArgs == 2 ? call -> get ( 2 ) : NULL ; if ( SymExpr * eltSym = toSymExpr ( eltExpr ) ) { if ( TypeSymbol * eltType = toTypeSymbol ( eltSym -> symbol ( ) ) ) { exportedArrayElementType [ fn ] = eltType ; } } if ( exportedArrayElementType [ fn ] == NULL && fLibraryPython ) { USR_FATAL_CONT ( fn , " " " " ) ; } fn -> retExprType -> replace ( new BlockStmt ( new SymExpr ( dtExternalArray -> symbol ) ) ) ; CallExpr * retCall = toCallExpr ( fn -> body -> body . tail ) ; INT_ASSERT ( retCall && retCall -> isPrimitive ( PRIM_RETURN ) ) ; CallExpr * transformRet = new CallExpr ( " " , retCall -> get ( 1 ) -> remove ( ) ) ; retCall -> insertAtTail ( transformRet ) ; } }
Expected to run after we make the wrapper, since the wrapper is generated
prior to any normalization occurring on the function, and this gets called
during normalize called on a specific AST node.
Expected to run after we make the wrapper since the wrapper is generated prior to any normalization occurring on the function and this gets called during normalize called on a specific AST node .
// Save the element type for use at code generation, specifically for Python // modules.  Eventually, these operations will probably want to be moved // after type resolution in order to handle more complicated types. // This appears to be prior to any insertion of call temps, etc, so it seems // okay for now to just insert the conversion call around the function call.