예제 #1
0
void
addCache(SymbolMapCache& cache, FnSymbol* oldFn, FnSymbol* fn, SymbolMap* map) {
  Vec<SymbolMapCacheEntry*>* entries = cache.get(oldFn);
  SymbolMapCacheEntry* entry = new SymbolMapCacheEntry(fn, map);
  if (entries) {
    entries->add(entry);
  } else {
    entries = new Vec<SymbolMapCacheEntry*>();
    entries->add(entry);
    cache.put(oldFn, entries);
  }
}
예제 #2
0
파일: parser.cpp 프로젝트: benharsh/chapel
void addModuleToParseList(const char* name, UseStmt* useExpr) {
  const char* modName = astr(name);

  if (sModDoneSet.set_in(modName) == NULL &&
      sModNameSet.set_in(modName) == NULL) {
    if (currentModuleType           == MOD_INTERNAL ||
        sHandlingInternalModulesNow == true) {
      sModReqdByInt.add(useExpr);
    }

    sModNameSet.set_add(modName);
    sModNameList.add(modName);
  }
}
예제 #3
0
//
// Do a breadth first search starting from functions generated for local blocks
// for all function calls in each level of the search, if they directly cause
// communication, add a local temp that isn't wide. If it is a resolved call,
// meaning that it isn't a primitive or external function, clone it and add it
// to the queue of functions to handle at the next iteration of the BFS.
//
static void handleLocalBlocks() {
  Map<FnSymbol*,FnSymbol*> cache; // cache of localized functions
  Vec<BlockStmt*> queue; // queue of blocks to localize

  forv_Vec(BlockStmt, block, gBlockStmts) {
    if (block->parentSymbol) {
      // NOAKES 2014/11/25 Transitional.  Avoid calling blockInfoGet()
      if (block->isLoopStmt() == true) {

      } else if (block->blockInfoGet()) {
        if (block->blockInfoGet()->isPrimitive(PRIM_BLOCK_LOCAL)) {
          queue.add(block);
        }
      }
    }
  }

  forv_Vec(BlockStmt, block, queue) {
    std::vector<CallExpr*> calls;
    collectCallExprs(block, calls);
    for_vector(CallExpr, call, calls) {
      localizeCall(call);
      if (FnSymbol* fn = call->isResolved()) {
        SET_LINENO(fn);
        if (FnSymbol* alreadyLocal = cache.get(fn)) {
          call->baseExpr->replace(new SymExpr(alreadyLocal));
        } else {
          if (!fn->hasFlag(FLAG_EXTERN)) {
            FnSymbol* local = fn->copy();
            local->addFlag(FLAG_LOCAL_FN);
            local->name = astr("_local_", fn->name);
            local->cname = astr("_local_", fn->cname);
            fn->defPoint->insertBefore(new DefExpr(local));
            call->baseExpr->replace(new SymExpr(local));
            queue.add(local->body);
            cache.put(fn, local);
            cache.put(local, local); // to handle recursion
            if (local->retType->symbol->hasFlag(FLAG_WIDE_REF)) {
              CallExpr* ret = toCallExpr(local->body->body.tail);
              INT_ASSERT(ret && ret->isPrimitive(PRIM_RETURN));
              // Capture the return expression in a local temp.
              insertLocalTemp(ret->get(1));
              local->retType = ret->get(1)->typeInfo();
            }
          }
        }
      }
    }
예제 #4
0
//alg for calculating shading. Calls diffuseShade and SpecularShade
Color RT_lights(Figure* obj, const Ray& ray, const Vec& thePoint, const Vec& normal)
{
    Color c = Color();
    for (list<Light*>::iterator iterator = lightList.begin(), end = lightList.end(); iterator != end; ++iterator) {
        Light* theLight = *iterator;

        pair<double, Figure*> inter = nearestIntersection(Ray(Vec(thePoint), theLight->getPos()), MIN_T / SHAD_RES, 1.0, EPSILON, false);
        if (inter.first <= 0) {
            Vec* toLight = thePoint.normalize(theLight->getPos());
            double dotProduct = toLight->dot(normal);
            Vec* subt = (thePoint.sub(theLight->getPos()));
            double dist = abs(subt->getMag());
            Color dif = diffuseShade(obj, theLight, max(dotProduct, 0.0), dist);
            Vec* Q = normal.scale(normal.dot(*toLight));
            Vec* S = Q->sub(*toLight);
            Vec* S2 = S->scale(2.0);
            Vec* R = toLight->add(*S2);
            Vec* norm = ray.getNorm();
            Vec* scaledNorm = norm->scale(-1.0);
            dotProduct = max(0.0, R->dot(*scaledNorm));
            Color spec = specularShade(obj, normal, theLight, *toLight, pow(dotProduct, obj->getShininess()), ray, dist);
            c = c.add(dif.add(spec));
            delete(toLight);
            delete(Q);
            delete(S);
            delete(R);
            delete(S2);
            delete(subt);
            delete(norm);
            delete(scaledNorm);
        }
    }
    return c;
}
예제 #5
0
void collectMyCallExprs(BaseAST* ast, Vec<CallExpr*>& callExprs,
                        FnSymbol* parent_fn) {
  AST_CHILDREN_CALL(ast, collectMyCallExprs, callExprs, parent_fn);
  if (CallExpr* callExpr = toCallExpr(ast))
    if (callExpr->parentSymbol == parent_fn)
      callExprs.add(callExpr);
}
예제 #6
0
void collect_stmts(BaseAST* ast, Vec<Expr*>& stmts) {
  if (Expr* expr = toExpr(ast)) {
    stmts.add(expr);
    if (isBlockStmt(expr) || isCondStmt(expr)) {
      AST_CHILDREN_CALL(ast, collect_stmts, stmts);
    }
  }
}
예제 #7
0
void flattenNestedFunction(FnSymbol* nestedFunction) {
  if (isFnSymbol(nestedFunction->defPoint->parentSymbol)) {
    Vec<FnSymbol*> nestedFunctions;

    nestedFunctions.add(nestedFunction);

    flattenNestedFunctions(nestedFunctions);
  }
}
예제 #8
0
void flattenFunctions() {
  Vec<FnSymbol*> nestedFunctions;

  forv_Vec(FnSymbol, fn, gFnSymbols) {
    if (isFnSymbol(fn->defPoint->parentSymbol)) {
      nestedFunctions.add(fn);
    }
  }

  markTaskFunctionsInIterators(nestedFunctions);
  flattenNestedFunctions(nestedFunctions);
}
예제 #9
0
//calculates reflections. Recursively calls RT_Trace
Color RT_reflect(Figure* obj, const Ray& ray, const Vec& i, const Vec& normal, double depth)
{
    if (obj->isR()) {
        Vec* V = ray.getV2().normalize(ray.getV1());
        Vec* Q = normal.scale(normal.dot(*V));
        Vec* S = Q->sub(*V);
        Vec* S2 = S->scale(2.0);
        Vec* R = V->add(*S2);
        Vec* inter = new Vec(i);
        Vec* dest = R->add(*inter);
        Ray* theRay = new Ray(*inter, *dest);
        Color newColor = RT_Trace(*theRay, depth + 1).mult(obj->getRef());
        delete(V);
        delete(Q);
        delete(S);
        delete(S2);
        delete(R);
        delete(inter);
        delete(dest);
        delete(theRay);
        return newColor;
    }
    else return Color(0, 0, 0);
}
예제 #10
0
//calctulates refractions. Recursively calls RT_Trace
Color RT_transmit(Figure* obj, const Ray& ray, const Vec& i, const Vec& normal,
                  bool inside, double depth)
{
    Color returnColor = Color(0, 0, 0);
    if (obj->isT()) {
        double ratio = 0;
        Ray transmittedRay = Ray();
        double dir = 1.0;
        if (!inside) {
            ratio = SPACE_INDEX / obj->getIOR();
        }
        else {
            ratio = obj->getIOR() / SPACE_INDEX;
            dir = -1.0;
        }
        Vec* norm = normal.scale(dir);
        Vec* V = ray.getV2().normalize(ray.getV1());
        double dp = norm->dot(*V);
        double rsqrd = pow(ratio, 2.0);
        double coeff = (ratio * dp) - pow(((1 - rsqrd) + (rsqrd * pow(dp, 2.0))), 0.5);
        Vec* scaledN = norm->scale(coeff);
        Vec* rV = V->scale(ratio);
        Vec* T = scaledN->sub(*rV);
        Vec* dest = i.add(*T);
        Vec* iCopy = new Vec(i);
        Ray* tranRay = new Ray(*iCopy, *dest);
        if (inside) {
            tranRay->setInside(nullptr);
        }
        else tranRay->setInside(obj);
        returnColor = RT_Trace(*tranRay, depth + 1);
        delete(scaledN);
        delete(rV);
        delete(V);
        delete(T);
        delete(dest);
        delete(iCopy);
        delete(tranRay);
        delete(norm);
    }
    return returnColor;
}
예제 #11
0
void flattenClasses(void) {
  //
  // collect nested classes
  //
  Vec<AggregateType*> nestedClasses;
  forv_Vec(TypeSymbol, ts, gTypeSymbols) {
    if (AggregateType* ct = toAggregateType(ts->type))
      if (toAggregateType(ct->symbol->defPoint->parentSymbol->type))
        nestedClasses.add(ct);
  }

  //
  // move nested classes to module level
  //
  forv_Vec(AggregateType, ct, nestedClasses) {
    ModuleSymbol* mod = ct->getModule();
    DefExpr *def = ct->symbol->defPoint;
    def->remove();
    mod->block->insertAtTail(def);
  }
예제 #12
0
void
get_lines(char *b, Vec<Line *> &lines) {
  int index = 0;
  while (1) {
    Line *l = new Line;
    l->index = index++;
    do {
      while (*b && isspace(*b)) b++;
      if (*b != '/') 
        break;
      while (*b && *b != '\n') b++;
    } while (*b);
    if ((l->name = get(b)) == EOF_TOK) return;
    if ((l->string = get(b)) == EOF_TOK) return;
    if ((l->nargs = get(b)) == EOF_TOK) return;
    if ((l->pos = get(b)) == EOF_TOK) return;
    if ((l->nres = get(b, 1)) == EOF_TOK) return;
    if ((l->argtypes = get(b)) == EOF_TOK) return;
    if ((l->rettypes = get(b)) == EOF_TOK) return;
    if ((l->options = get(b)) == EOF_TOK) return;
    lines.add(l);
  }
}
예제 #13
0
void collectCallExprs(BaseAST* ast, Vec<CallExpr*>& callExprs) {
  AST_CHILDREN_CALL(ast, collectCallExprs, callExprs);
  if (CallExpr* callExpr = toCallExpr(ast))
    callExprs.add(callExpr);
}
예제 #14
0
void collectDefExprs(BaseAST* ast, Vec<DefExpr*>& defExprs) {
  AST_CHILDREN_CALL(ast, collectDefExprs, defExprs);
  if (DefExpr* defExpr = toDefExpr(ast))
    defExprs.add(defExpr);
}
예제 #15
0
void collectFnCalls(BaseAST* ast, Vec<CallExpr*>& calls) {
  AST_CHILDREN_CALL(ast, collectFnCalls, calls);
  if (CallExpr* call = toCallExpr(ast))
    if (call->isResolved())
      calls.add(call);
}
예제 #16
0
void collect_asts(BaseAST* ast, Vec<BaseAST*>& asts) {
  asts.add(ast);
  AST_CHILDREN_CALL(ast, collect_asts, asts);
}
예제 #17
0
void collectSymExprs(BaseAST* ast, Vec<SymExpr*>& symExprs) {
  AST_CHILDREN_CALL(ast, collectSymExprs, symExprs);
  if (SymExpr* symExpr = toSymExpr(ast))
    symExprs.add(symExpr);
}
예제 #18
0
static void collectMySymExprsHelp(BaseAST* ast, Vec<SymExpr*>& symExprs) {
  if (isSymbol(ast)) return; // do not descend into nested symbols
  AST_CHILDREN_CALL(ast, collectMySymExprsHelp, symExprs);
  if (SymExpr* se = toSymExpr(ast))
    symExprs.add(se);
}
예제 #19
0
static void collect_top_asts_internal(BaseAST* ast, Vec<BaseAST*>& asts) {
  if (!isSymbol(ast) || isArgSymbol(ast)) {
    AST_CHILDREN_CALL(ast, collect_top_asts_internal, asts);
    asts.add(ast);
  }
}
예제 #20
0
void collectGotoStmts(BaseAST* ast, Vec<GotoStmt*>& gotoStmts) {
  AST_CHILDREN_CALL(ast, collectGotoStmts, gotoStmts);
  if (GotoStmt* gotoStmt = toGotoStmt(ast))
    gotoStmts.add(gotoStmt);
}
예제 #21
0
void addIncInfo(const char* incDir) {
  incDirs.add(astr(incDir));
}
예제 #22
0
void collectSymbols(BaseAST* ast, Vec<Symbol*>& symbols) {
  AST_CHILDREN_CALL(ast, collectSymbols, symbols);
  if (Symbol* symbol = toSymbol(ast))
    symbols.add(symbol);
}
예제 #23
0
파일: parser.cpp 프로젝트: benharsh/chapel
void setupModulePaths() {
  const char* modulesRoot = NULL;

  if (fMinimalModules == true) {
    modulesRoot = "modules/minimal";

  } else if (fUseIPE == true) {
    modulesRoot = "modules/ipe";

  } else {
    modulesRoot = "modules";
  }

  //
  // Set up the search path for modulesRoot/internal
  //

  sIntModPath.add(astr(CHPL_HOME,
                      "/",
                      modulesRoot,
                      "/internal/localeModels/",
                      CHPL_LOCALE_MODEL));

  sIntModPath.add(astr(CHPL_HOME,
                      "/",
                      modulesRoot,
                      "/internal/tasktable/",
                      fEnableTaskTracking ? "on" : "off"));

  sIntModPath.add(astr(CHPL_HOME,
                      "/",
                      modulesRoot,
                      "/internal/tasks/",
                      CHPL_TASKS));

  sIntModPath.add(astr(CHPL_HOME,
                      "/",
                      modulesRoot,
                      "/internal/comm/",
                      CHPL_COMM));

  sIntModPath.add(astr(CHPL_HOME, "/", modulesRoot, "/internal"));

  //
  // Set up the search path for modulesRoot/standard
  //
  sStdModPath.add(astr(CHPL_HOME,
                      "/",
                      modulesRoot,
                      "/standard/gen/",
                      CHPL_TARGET_PLATFORM,
                      "-",
                      CHPL_TARGET_COMPILER));

  sStdModPath.add(astr(CHPL_HOME, "/", modulesRoot, "/standard"));

  sStdModPath.add(astr(CHPL_HOME, "/", modulesRoot, "/packages"));

  sStdModPath.add(astr(CHPL_HOME, "/", modulesRoot, "/layouts"));

  sStdModPath.add(astr(CHPL_HOME, "/", modulesRoot, "/dists"));

  sStdModPath.add(astr(CHPL_HOME, "/", modulesRoot, "/dists/dims"));

  if (const char* envvarpath  = getenv("CHPL_MODULE_PATH")) {
    char  path[FILENAME_MAX + 1];
    char* colon = NULL;

    strncpy(path, envvarpath, FILENAME_MAX);

    do {
      char* start = colon ? colon+1 : path;

      colon = strchr(start, ':');

      if (colon != NULL) {
        *colon = '\0';
      }

      addFlagModulePath(start);
    } while (colon);
  }
}
예제 #24
0
void collect_asts_postorder(BaseAST* ast, Vec<BaseAST*>& asts) {
  AST_CHILDREN_CALL(ast, collect_asts_postorder, asts);
  asts.add(ast);
}
예제 #25
0
파일: parser.cpp 프로젝트: benharsh/chapel
// track directories specified via -M and CHPL_MODULE_PATH.
void addFlagModulePath(const char* newPath) {
  sFlagModPath.add(astr(newPath));
}
예제 #26
0
void collect_top_asts(BaseAST* ast, Vec<BaseAST*>& asts) {
  AST_CHILDREN_CALL(ast, collect_top_asts_internal, asts);
  asts.add(ast);
}
예제 #27
0
파일: beautify.cpp 프로젝트: rlugojr/chapel
static void update_state(char *line) {
  int oldstuff; /* characters up to the last open paren */
  int stuff;            /* characters since last open paren */
  char *cp;
  int oldoldstuff;

  oldstuff = justify;
  stuff = 0;
  cp = line;
  escaped = FALSE;

  while (cp[0] != '\0') {
    switch (*cp) {
    case '\\': 
      escaped = !escaped;
      stuff++;
      break;
    case '\'':
      stuff++;
      if (!escaped && !inquote) {
        intick = !intick;
      }
      escaped = FALSE;
      break;
    case '\"':
      stuff++;
      if (!escaped) {
        inquote = !inquote;
      }
      escaped = FALSE;
      break;
    case '{':
      if (!inquote && !intick) {
        if (oldstuff == -1) {
          INT_FATAL("Unbalanced curly braces:\n\t%s",line);
        }
        oldstuff = 0;   /* assume all parens have been closed */
        stuff = 0;
        depth++;
      } else {
        stuff++;
      }
      escaped = FALSE;
      break;
    case '}':
      if (!inquote && !intick) {
        if (oldstuff == -1) {
          INT_FATAL("Unbalanced curly braces:\n\t%s",line);
        }
        oldstuff = 0;   /* assume all parens have been closed */
        stuff = 0;
        depth--;
      } else {
        stuff++;
      }
      escaped = FALSE;
      break;
    case '(':
      if (!inquote && !intick) {
        justification.add(oldstuff);
        if (oldstuff == -1) {
          INT_FATAL("Unbalanced parentheses:\n\t%s",line);
        }
        oldoldstuff = oldstuff;
        oldstuff = oldoldstuff + stuff + 1;
        stuff = 0;
        parens++;
      } else {
        stuff++;
      }
      escaped = FALSE;
      break;
    case ')':
      if (!inquote && !intick) {
        oldstuff = justification.pop();
        stuff = 0;
        parens--;
      } else {
        stuff++;
      }
      escaped = FALSE;
      break;
    default:
      stuff++;
      escaped = FALSE;
      break;
    }
    cp++;
  }

  if ((parens == 0) || (oldstuff == -1)) {
    justify = 0;
  } else {
    justify = oldstuff;
  }

}