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 } }
void clean_exit(int status) { if (status != 0) { gdbShouldBreakHere(); } cleanup_for_exit(); deleteStrings(); exit(status); }
static void chpl_exit_common(int status, int all) { fflush(stdout); fflush(stderr); if (status != 0) { gdbShouldBreakHere(); } chpl_comm_pre_task_exit(all); if (all) { chpl_task_exit(); chpl_reportMemInfo(); } chpl_mem_exit(); chpl_comm_exit(all, status); exit(status); }
// for debugging purposes only void trace_remove(BaseAST* ast, char flag) { // crash if deletedIdHandle is not initialized but deletedIdFilename is if (deletedIdON() == true) { fprintf(deletedIdHandle, "%d %c %p %d\n", currentPassNo, flag, ast, ast->id); } if (ast->id == breakOnDeleteID) { if (deletedIdON() == true) fflush(deletedIdHandle); gdbShouldBreakHere(); } // There should never be an attempt to delete a global type. if (flag != 'z' && // At least, not before compiler shutdown. isPrimitiveType(ast) && toPrimitiveType(ast)->symbol->hasFlag(FLAG_GLOBAL_TYPE_SYMBOL)) INT_FATAL(ast, "Unexpected attempt to eviscerate a global type symbol."); }
void VarSymbol::codegenDef() { GenInfo* info = gGenInfo; if (id == breakOnCodegenID) gdbShouldBreakHere(); // Local variable symbols should never be // generated for extern or void types if (this->hasFlag(FLAG_EXTERN)) return; if (type == dtVoid) return; if( info->cfile ) { codegenDefC(); } else { #ifdef HAVE_LLVM if(isImmediate()) { llvm::GlobalVariable *globalValue = llvm::cast<llvm::GlobalVariable>( info->module->getOrInsertGlobal(cname, type->codegen().type)); globalValue->setConstant(true); if(immediate->const_kind == CONST_KIND_STRING) { if(llvm::Value *constString = codegenImmediateLLVM(immediate)) { llvm::GlobalVariable *globalString = llvm::cast<llvm::GlobalVariable>(constString); globalValue->setInitializer(llvm::cast<llvm::Constant>( info->builder->CreateConstInBoundsGEP2_32( #if HAVE_LLVM_VER >= 37 NULL, #endif globalString, 0, 0))); } else { llvm::GlobalVariable *globalString = new llvm::GlobalVariable( *info->module, llvm::IntegerType::getInt8Ty(info->module->getContext()), true, llvm::GlobalVariable::PrivateLinkage, NULL, "string"); globalString->setInitializer(llvm::Constant::getNullValue( llvm::IntegerType::getInt8Ty(info->module->getContext()))); globalValue->setInitializer(llvm::cast<llvm::Constant>( info->builder->CreateConstInBoundsGEP1_32( #if HAVE_LLVM_VER >= 37 NULL, #endif globalString, 0))); } } else { globalValue->setInitializer(llvm::cast<llvm::Constant>( codegenImmediateLLVM(immediate))); } info->lvt->addGlobalValue(cname, globalValue, GEN_VAL, ! is_signed(type)); } llvm::Type *varType = type->codegen().type; llvm::Value *varAlloca = createTempVarLLVM(varType, cname); info->lvt->addValue(cname, varAlloca, GEN_PTR, ! is_signed(type)); if(AggregateType *ctype = toAggregateType(type)) { if(ctype->isClass() || ctype->symbol->hasFlag(FLAG_WIDE_REF) || ctype->symbol->hasFlag(FLAG_WIDE_CLASS)) { if(isFnSymbol(defPoint->parentSymbol)) { info->builder->CreateStore( llvm::Constant::getNullValue(varType), varAlloca); } } } if(debug_info){ debug_info->get_variable(this); } #endif } }
void VarSymbol::codegenGlobalDef(bool isHeader) { GenInfo* info = gGenInfo; if( id == breakOnCodegenID || (breakOnCodegenCname[0] && 0 == strcmp(cname, breakOnCodegenCname)) ) { gdbShouldBreakHere(); } if( info->cfile ) { codegenDefC(/*global=*/true, isHeader); } else { #ifdef HAVE_LLVM if(type == dtVoid || !isHeader) { return; } if( this->hasFlag(FLAG_EXTERN) ) { // Make sure that it already exists in the layered value table. if( isType() ) { llvm::Type* t = info->lvt->getType(cname); if( ! t ) { // TODO should be USR_FATAL USR_WARN(this, "Could not find extern def of type %s", cname); } } else { GenRet v = info->lvt->getValue(cname); if( ! v.val ) { // TODO should be USR_FATAL // Commenting out to prevent problems with S_IRWXU and friends // USR_WARN(this, "Could not find extern def of %s", cname); } } } else { bool existing; existing = (info->module->getNamedValue(cname) != NULL); if( existing ) INT_FATAL(this, "Redefinition of a global variable %s", cname); // Now, create a global variable with appropriate linkage. llvm::Type* llTy = type->codegen().type; INT_ASSERT(llTy); llvm::GlobalVariable *gVar = new llvm::GlobalVariable( *info->module, llTy, false, /* is constant */ hasFlag(FLAG_EXPORT) ? llvm::GlobalVariable::ExternalLinkage : llvm::GlobalVariable::InternalLinkage, llvm::Constant::getNullValue(llTy), /* initializer, */ cname); info->lvt->addGlobalValue(cname, gVar, GEN_PTR, ! is_signed(type) ); if(debug_info){ debug_info->get_global_variable(this); } } #endif } }