static void traverse_loop(loop_t *loop,int postorder,void (*f) (statement_t *), void (*e) (expr_t *),void (*d) (symboltable_t *)) { DB1(80,"traverse_loop(,%d,,,);\n",postorder); if (loop == NULL) { INT_FATAL(NULL,"Null loop in traverse_loop()"); } switch (T_TYPE(loop)) { case L_DO: if (e != NULL) { (*e)(T_IVAR(loop)); (*e)(T_START(loop)); (*e)(T_STOP(loop)); if (T_STEP(loop) != NULL) { (*e)(T_STEP(loop)); } } traverse_stmtls(T_BODY(loop),postorder,f,e,d); break; case L_WHILE_DO: case L_REPEAT_UNTIL: if (e != NULL) { (*e)(T_LOOPCOND(loop)); } traverse_stmtls(T_BODY(loop),postorder,f,e,d); break; default: INT_FATAL(NULL, "Bad looptype (%d) in traverse_loop()",T_TYPE(loop)); } #ifdef DEBUG fflush(stdout); #endif }
forv_Vec(AggregateType, at, gAggregateTypes) { if (! at->defaultInitializer) INT_FATAL(at, "aggregate type has no initializer"); if (! at->defaultTypeConstructor) INT_FATAL(at, "aggregate type has no default type constructor"); }
void Expr::verify() { if (prev || next) if (!list) INT_FATAL(this, "Expr is in list but does not point at it"); if (prev && prev->next != this) INT_FATAL(this, "Bad Expr->prev->next"); if (next && next->prev != this) INT_FATAL(this, "Bad Expr->next->prev"); if (!parentSymbol) INT_FATAL(this, "Expr::parentSymbol is NULL"); if (parentExpr && parentExpr->parentSymbol != parentSymbol) INT_FATAL(this, "Bad Expr::parentSymbol"); if (list && parentExpr && list->parent != parentExpr) INT_FATAL(this, "Bad Expr::list::parent"); if (list && !parentExpr) { if (Symbol* lps = toSymbol(list->parent)) if (lps != parentSymbol) INT_FATAL(this, "Bad symbol Expr::list::parent"); if (Type* lpt = toType(list->parent)) if (lpt->symbol != parentSymbol) INT_FATAL(this, "Bad type Expr::list::parent"); if (isExpr(list->parent)) INT_FATAL(this, "Expr::list::parent is an Expr unexpectedly"); } }
void CatchStmt::verify() { Stmt::verify(); if (astTag != E_CatchStmt) { INT_FATAL(this, "CatchStmt::verify. Bad astTag"); } if (!_body) { INT_FATAL(this, "CatchStmt::verify. _body is missing"); } if (!body()) { INT_FATAL(this, "CatchStmt::verify. Invalid catch body"); } }
void BlockStmt::verify() { Expr::verify(); if (astTag != E_BlockStmt) { INT_FATAL(this, "Bad BlockStmt::astTag"); } if (body.parent != this) INT_FATAL(this, "Bad AList::parent in BlockStmt"); for_alist(expr, body) { if (expr->parentExpr != this) INT_FATAL(this, "Bad BlockStmt::body::parentExpr"); } if (blockInfo && blockInfo->parentExpr != this) INT_FATAL(this, "Bad BlockStmt::blockInfo::parentExpr"); if (modUses && modUses->parentExpr != this) INT_FATAL(this, "Bad BlockStmt::blockInfo::parentExpr"); }
// Same except uses TFITag. It is encoded as int to deal with header ordering. // Do not invoke on TFI_REDUCE. ArgSymbol* tiMarkForTFIntent(int tfIntent) { ArgSymbol* retval = NULL; switch ((TFITag) tfIntent) { case TFI_DEFAULT: retval = tiMarkBlank; break; case TFI_CONST: retval = tiMarkConstDflt; break; case TFI_IN: retval = tiMarkIn; break; case TFI_CONST_IN: retval = tiMarkConstIn; break; case TFI_REF: retval = tiMarkRef; break; case TFI_CONST_REF: retval = tiMarkConstRef; break; case TFI_REDUCE: INT_FATAL("unexpected intent in tiMarkForTFIntent()"); break; } return retval; }
const char* istr(int i) { char s[64]; if (sprintf(s, "%d", i) > 63) INT_FATAL("istr buffer overflow"); return astr(s); }
void CallInfo::haltNotWellFormed() const { for (int i = 1; i <= call->numActuals(); i++) { Expr* actual = call->get(i); if (NamedExpr* named = toNamedExpr(actual)) { actual = named->actual; } SymExpr* se = toSymExpr(actual); INT_ASSERT(se); Symbol* sym = se->symbol(); Type* t = sym->type; if (t == dtUnknown && sym->hasFlag(FLAG_TYPE_VARIABLE) == false) { USR_FATAL(call, "use of '%s' before encountering its definition, " "type unknown", sym->name); } else if (t->symbol->hasFlag(FLAG_GENERIC) == true) { INT_FATAL(call, "the type of the actual argument '%s' is generic", sym->name); } } }
GenRet ExternBlockStmt::codegen() { GenRet ret; // Needs to be handled specially by creating a C // file per module.. INT_FATAL(this, "ExternBlockStmt codegen called"); return ret; }
int RankOfCover(function_t* fn) { expr_t* reg; int numdims = 0; int newnumdims; callsite_t *callinfo; callinfo = T_CALLINFO(fn); if (callinfo != NULL) { reg = COV_REG(CALL_COVER(callinfo)); if (reg != NULL) { numdims = D_REG_NUM(T_TYPEINFO(reg)); } callinfo = CALL_NEXT(callinfo); } while (callinfo != NULL) { reg = COV_REG(CALL_COVER(callinfo)); if (reg != NULL) { newnumdims = D_REG_NUM(T_TYPEINFO(reg)); if (newnumdims != numdims) { INT_FATAL(NULL, "Function is covered by regions of differing ranks!"); } } callinfo = CALL_NEXT(callinfo); } return numdims; }
// // Determine the index type for a ParamForLoop. // // This implementation creates a range with low/high values and then // asks for its type. // Type* ParamForLoop::indexType() { SymExpr* lse = lowExprGet(); SymExpr* hse = highExprGet(); CallExpr* range = new CallExpr("chpl_build_bounded_range", lse->copy(), hse->copy()); Type* idxType = 0; insertBefore(range); resolveCall(range); if (FnSymbol* sym = range->isResolved()) { resolveFormals(sym); DefExpr* formal = toDefExpr(sym->formals.get(1)); if (toArgSymbol(formal->sym)->typeExpr) idxType = toArgSymbol(formal->sym)->typeExpr->body.tail->typeInfo(); else idxType = formal->sym->type; range->remove(); } else { INT_FATAL("unresolved range"); } return idxType; }
void ParamForLoop::verify() { BlockStmt::verify(); if (mResolveInfo == 0) INT_FATAL(this, "ParamForLoop::verify. mResolveInfo is NULL"); if (BlockStmt::blockInfoGet() != 0) INT_FATAL(this, "ParamForLoop::verify. blockInfo is not NULL"); if (modUses != 0) INT_FATAL(this, "ParamForLoop::verify. modUses is not NULL"); if (byrefVars != 0) INT_FATAL(this, "ParamForLoop::verify. byrefVars is not NULL"); }
CallInfo::CallInfo(CallExpr* icall) : call(icall), scope(NULL) { if (SymExpr* se = toSymExpr(call->baseExpr)) name = se->var->name; else if (UnresolvedSymExpr* use = toUnresolvedSymExpr(call->baseExpr)) name = use->unresolved; if (call->numActuals() >= 2) { if (SymExpr* se = toSymExpr(call->get(1))) { if (se->var == gModuleToken) { se->remove(); se = toSymExpr(call->get(1)); INT_ASSERT(se); ModuleSymbol* mod = toModuleSymbol(se->var); INT_ASSERT(mod); se->remove(); scope = mod->block; } } } for_actuals(actual, call) { if (NamedExpr* named = toNamedExpr(actual)) { actualNames.add(named->name); actual = named->actual; } else { actualNames.add(NULL); } SymExpr* se = toSymExpr(actual); INT_ASSERT(se); Type* t = se->var->type; if (t == dtUnknown) USR_FATAL(call, "use of '%s' before encountering its definition, type unknown", se->var->name); if (t->symbol->hasFlag(FLAG_GENERIC)) INT_FATAL(call, "the type of the actual argument '%s' is generic", se->var->name); actuals.add(se->var); } }
const char* createDebuggerFile(const char* debugger, int argc, char* argv[]) { const char* dbgfilename = genIntermediateFilename(astr(debugger, ".commands")); FILE* dbgfile = openfile(dbgfilename); int i; if (strcmp(debugger, "gdb") == 0) { fprintf(dbgfile, "set args"); } else if (strcmp(debugger, "lldb") == 0) { fprintf(dbgfile, "settings set -- target.run-args"); } else { INT_FATAL(astr("createDebuggerFile doesn't know how to handle the given " "debugger: '", debugger, "'")); } for (i=1; i<argc; i++) { if (strcmp(argv[i], astr("--", debugger)) != 0) { fprintf(dbgfile, " %s", argv[i]); } } fprintf(dbgfile, "\n"); closefile(dbgfile); mysystem(astr("cat ", CHPL_HOME, "/compiler/etc/", debugger, ".commands >> ", dbgfilename), astr("appending ", debugger, " commands"), false); return dbgfilename; }
void deleteTmpDir() { static int inDeleteTmpDir = 0; // break infinite recursion if (inDeleteTmpDir) { return; } inDeleteTmpDir = 1; #ifndef DEBUGTMPDIR if (tmpdirname != NULL) { if (strlen(tmpdirname) < 1 || strchr(tmpdirname, '*') != NULL || strcmp(tmpdirname, "//") == 0) { INT_FATAL("tmp directory name looks fishy"); } const char* rmdircommand = "rm -r "; const char* command = astr(rmdircommand, tmpdirname); mysystem(command, "removing temporary directory"); tmpdirname = NULL; } #endif inDeleteTmpDir = 0; }
// BHARSH TODO: merge this with returnInfoAsRef and fix the WIDE_REF case... static QualifiedType returnInfoRef(CallExpr* call) { Type* t = call->get(1)->getValType(); if (!t->refType) INT_FATAL(call, "invalid attempt to get reference type"); return QualifiedType(t->refType, QUAL_REF); }
static QualifiedType returnInfoVal(CallExpr* call) { AggregateType* ct = toAggregateType(call->get(1)->typeInfo()); if (ct) { if (call->get(1)->isRef()) { if(ct->symbol->hasFlag(FLAG_REF)) { return QualifiedType(ct->getField(1)->type, QUAL_VAL); } else { return QualifiedType(ct, QUAL_VAL); } } else if (call->get(1)->isWideRef()) { if(ct->symbol->hasFlag(FLAG_WIDE_REF)) { return QualifiedType(ct->getField(2)->type, QUAL_VAL); } else { return QualifiedType(ct, QUAL_VAL); } } else if (ct->symbol->hasFlag(FLAG_WIDE_CLASS)) { // insertWideReferences will sometimes insert a PRIM_DEREF to a // wide class. There should probably be a better way of expressing the // desired pattern... return QualifiedType(ct, QUAL_VAL); } } INT_FATAL(call, "attempt to get value type of non-reference type"); return QualifiedType(NULL); }
IntentTag blankIntentForType(Type* t) { if (isSyncType(t) || isAtomicType(t) || t->symbol->hasFlag(FLAG_ARRAY)) { return INTENT_REF; } else if (is_bool_type(t) || is_int_type(t) || is_uint_type(t) || is_real_type(t) || is_imag_type(t) || is_complex_type(t) || is_enum_type(t) || is_string_type(t) || t == dtStringC || t == dtStringCopy || isClass(t) || isRecord(t) || isUnion(t) || t == dtTaskID || t == dtFile || t == dtTaskList || t == dtNil || t == dtOpaque || t->symbol->hasFlag(FLAG_DOMAIN) || t->symbol->hasFlag(FLAG_DISTRIBUTION) || t->symbol->hasFlag(FLAG_EXTERN)) { return constIntentForType(t); } INT_FATAL(t, "Unhandled type in blankIntentForType()"); return INTENT_BLANK; }
UseStmt::UseStmt(BaseAST* source, std::vector<const char*>* args, bool exclude, std::map<const char*, const char*>* renames) : Stmt(E_UseStmt), src(NULL), named(), renamed(), except(exclude), relatedNames() { if (Symbol* b = toSymbol(source)) { src = new SymExpr(b); } else if (Expr* b = toExpr(source)) { src = b; } else { INT_FATAL(this, "Bad mod in UseStmt constructor"); } if (args->size() > 0) { // Symbols to search when going through this module's scope from an outside // scope for_vector(const char, str, *args) { named.push_back(str); } }
static IntentTag constIntentForType(Type* t) { if (isSyncType(t) || isRecordWrappedType(t) || // domain, array, or distribution isRecord(t) || // may eventually want to decide based on size is_string_type(t)) { return INTENT_CONST_REF; } else if (is_bool_type(t) || is_int_type(t) || is_uint_type(t) || is_real_type(t) || is_imag_type(t) || is_complex_type(t) || is_enum_type(t) || isClass(t) || isUnion(t) || isAtomicType(t) || t == dtOpaque || t == dtTaskID || t == dtFile || t == dtTaskList || t == dtNil || t == dtStringC || t == dtStringCopy || t->symbol->hasFlag(FLAG_EXTERN)) { return INTENT_CONST_IN; } INT_FATAL(t, "Unhandled type in constIntentForType()"); return INTENT_CONST; }
static void buildWideClass(Type* type) { SET_LINENO(type->symbol); AggregateType* wide = new AggregateType(AGGREGATE_RECORD); TypeSymbol* wts = new TypeSymbol(astr("__wide_", type->symbol->cname), wide); wts->addFlag(FLAG_WIDE_CLASS); theProgram->block->insertAtTail(new DefExpr(wts)); wide->fields.insertAtTail(new DefExpr(new VarSymbol("locale", dtLocaleID))); wide->fields.insertAtTail(new DefExpr(new VarSymbol("addr", type))); // // Strings need an extra field in their wide class to hold their length // if (type == dtString) { wide->fields.insertAtTail(new DefExpr(new VarSymbol("size", dtInt[INT_SIZE_DEFAULT]))); if (wideStringType) { INT_FATAL("Created two wide string types"); } wideStringType = wide; } // // set reference type of wide class to reference type of class since // it will be widened // if (type->refType) wide->refType = type->refType; wideClassMap.put(type, wide); }
void TypeSymbol::codegenDef() { GenInfo *info = gGenInfo; if( id == breakOnCodegenID || (breakOnCodegenCname[0] && 0 == strcmp(cname, breakOnCodegenCname)) ) { gdbShouldBreakHere(); } if (!hasFlag(FLAG_EXTERN)) { type->codegenDef(); } this->addFlag(FLAG_CODEGENNED); if( info->cfile ) { // no action required. } else { #ifdef HAVE_LLVM llvm::Type *type = info->lvt->getType(cname); if(type == NULL) { printf("No type '%s'/'%s' found\n", cname, name); INT_FATAL(this, "No type found"); } llvmType = type; if(debug_info) debug_info->get_type(this->type); #endif } }
static Type* returnInfoRef(CallExpr* call) { Type* t = call->get(1)->typeInfo(); if (!t->refType) INT_FATAL(call, "invalid attempt to get reference type"); return t->refType; }
static Type* returnInfoVal(CallExpr* call) { AggregateType* ct = toAggregateType(call->get(1)->typeInfo()); if (!ct || !ct->symbol->hasFlag(FLAG_REF)) INT_FATAL(call, "attempt to get value type of non-reference type"); return ct->getField(1)->type; }
GenRet ForLoop::codegen() { GenRet ret; INT_FATAL(this, "ForLoop::codegen This should be unreachable"); return ret; }
void BlockStmt::replaceChild(Expr* old_ast, Expr* new_ast) { if (old_ast == blockInfo) blockInfo = toCallExpr(new_ast); else if (old_ast == modUses) modUses = toCallExpr(new_ast); else INT_FATAL(this, "Unexpected case in BlockStmt::replaceChild"); }
void Timer::stop() { if (mRunning == true) { mAccumUsec = elapsedUsecs(); mRunning = false; } else { INT_FATAL("stop called on a timer that has not been started"); } }
void Timer::start() { if (mRunning == false) { gettimeofday(&mRefTime, 0); mRunning = true; } else { INT_FATAL("start called on a timer that has not been stopped"); } }
datatype_t* ensure_good_scanred_type(datatype_t* pdt) { datatype_t* basetype; datatype_t* newtype; switch (D_CLASS(pdt)) { case DT_CHAR: case DT_BOOLEAN: case DT_SIGNED_BYTE: case DT_INTEGER: case DT_SHORT: return pdtINT; break; case DT_UNSIGNED_BYTE: case DT_UNSIGNED_SHORT: case DT_UNSIGNED_INT: return pdtUNSIGNED_INT; break; case DT_LONG: return pdtLONG; break; case DT_UNSIGNED_LONG: return pdtUNSIGNED_LONG; break; case DT_REAL: return pdtFLOAT; break; case DT_DOUBLE: return pdtDOUBLE; break; case DT_QUAD: return pdtQUAD; break; case DT_COMPLEX: return pdtCOMPLEX; break; case DT_DCOMPLEX: return pdtDCOMPLEX; break; case DT_QCOMPLEX: return pdtQCOMPLEX; break; case DT_ARRAY: basetype = D_ARR_TYPE(pdt); newtype = ensure_good_scanred_type(basetype); if (newtype == basetype) { return pdt; } else { /* sharing dimension list */ return build_array_type(D_ARR_DIM(pdt),newtype); } break; default: INT_FATAL(NULL, "Unexpected datatype in ensure_good_scanred_type(): %d", D_CLASS(pdt)); } return NULL; }
void ForLoop::verify() { BlockStmt::verify(); if (BlockStmt::blockInfoGet() != 0) INT_FATAL(this, "ForLoop::verify. blockInfo is not NULL"); if (mIndex == 0) INT_FATAL(this, "ForLoop::verify. index is NULL"); if (mIterator == 0) INT_FATAL(this, "ForLoop::verify. iterator is NULL"); if (modUses != 0) INT_FATAL(this, "ForLoop::verify. modUses is not NULL"); if (byrefVars != 0) INT_FATAL(this, "ForLoop::verify. byrefVars is not NULL"); }