compiler/passes/normalize.cpp
//
// Inserts a temporary for the result if the last statement is a call.
//
// Inserts PRIM_LOGICAL_FOLDER from the local branch result into the argument
// 'result' based on the argument 'cond'. PRIM_LOGICAL_FOLDER will either turn
// into an addr-of during resolution or be replaced by its second actual.
//
// BHARSH INIT TODO: Do we really need PRIM_LOGICAL_FOLDER anymore?
//
Inserts a temporary for the result if the last statement is a call.
Inserts PRIM_LOGICAL_FOLDER from the local branch result into the argument
'result' based on the argument 'cond'. PRIM_LOGICAL_FOLDER will either turn
into an addr-of during resolution or be replaced by its second actual.


Inserts a temporary for the result if the last statement is a call . Inserts PRIM_LOGICAL_FOLDER from the local branch result into the argument ' result ' based on the argument ' cond ' . PRIM_LOGICAL_FOLDER will either turn into an addr - of during resolution or be replaced by its second actual .
static void normalizeIfExprBranch(VarSymbol* cond, VarSymbol* result, BlockStmt* stmt) {
  Expr* last = stmt->body.tail->remove();
  Symbol* localResult = NULL;
  if (isCallExpr(last) || isIfExpr(last) || isUnresolvedSymExpr(last)) {
    localResult = newTemp();
    localResult->addFlag(FLAG_MAYBE_TYPE);
    localResult->addFlag(FLAG_MAYBE_PARAM);
    localResult->addFlag(FLAG_EXPR_TEMP);
    localResult->addFlag(FLAG_NO_AUTO_DESTROY);
    stmt->body.insertAtTail(new DefExpr(localResult));
    stmt->body.insertAtTail(new CallExpr(PRIM_MOVE, localResult, last));
  } else if (SymExpr* se = toSymExpr(last)) {
    localResult = se->symbol();
  } else {
    INT_FATAL("Unexpected AST node at the end of IfExpr branch");
  }
  stmt->body.insertAtTail(new CallExpr(PRIM_MOVE, result, new CallExpr(PRIM_LOGICAL_FOLDER, cond, localResult)));
}
static void normalizeIfExprBranch ( VarSymbol * cond , VarSymbol * result , BlockStmt * stmt ) { Expr * last = stmt -> body . tail -> remove ( ) ; Symbol * localResult = NULL ; if ( isCallExpr ( last ) || isIfExpr ( last ) || isUnresolvedSymExpr ( last ) ) { localResult = newTemp ( ) ; localResult -> addFlag ( FLAG_MAYBE_TYPE ) ; localResult -> addFlag ( FLAG_MAYBE_PARAM ) ; localResult -> addFlag ( FLAG_EXPR_TEMP ) ; localResult -> addFlag ( FLAG_NO_AUTO_DESTROY ) ; stmt -> body . insertAtTail ( new DefExpr ( localResult ) ) ; stmt -> body . insertAtTail ( new CallExpr ( PRIM_MOVE , localResult , last ) ) ; } else if ( SymExpr * se = toSymExpr ( last ) ) { localResult = se -> symbol ( ) ; } else { INT_FATAL ( " " ) ; } stmt -> body . insertAtTail ( new CallExpr ( PRIM_MOVE , result , new CallExpr ( PRIM_LOGICAL_FOLDER , cond , localResult ) ) ) ; }
Inserts a temporary for the result if the last statement is a call.
Inserts a temporary for the result if the last statement is a call .