static llvm::raw_ostream& yamlCOFFSymbols(llvm::object::COFFObjectFile &Obj, std::size_t NumSymbols, llvm::raw_ostream &Out) { llvm::error_code ec; Out << "symbols:" << endl; for (llvm::object::symbol_iterator iter = Obj.begin_symbols(); iter != Obj.end_symbols(); iter.increment(ec)) { // Gather all the info that we need llvm::StringRef str; const llvm::object::coff_symbol *symbol = Obj.getCOFFSymbol(iter); Obj.getSymbolName(symbol, str); std::size_t simpleType = symbol->getBaseType(); std::size_t complexType = symbol->getComplexType(); std::size_t storageClass = symbol->StorageClass; Out << " - !Symbol" << endl; Out << " Name: " << str << endl; Out << " Value: " << symbol->Value << endl; Out << " SectionNumber: " << symbol->SectionNumber << endl; Out << " SimpleType: " << nameLookup(SymbolBaseTypePairs, simpleType, "# Unknown_SymbolBaseType") << " # (" << simpleType << ")" << endl; Out << " ComplexType: " << nameLookup(SymbolComplexTypePairs, complexType, "# Unknown_SymbolComplexType") << " # (" << complexType << ")" << endl; Out << " StorageClass: " << nameLookup(SymbolStorageClassPairs, storageClass, "# Unknown_StorageClass") << " # (" << (int) storageClass << ")" << endl; if (symbol->NumberOfAuxSymbols > 0) { llvm::ArrayRef<uint8_t> aux = Obj.getSymbolAuxData(symbol); Out << " NumberOfAuxSymbols: " << (int) symbol->NumberOfAuxSymbols << endl; Out << " AuxillaryData: "; yaml::writeHexStream(Out, aux); } Out << endl; } return Out; }
static llvm::raw_ostream &yamlCOFFHeader( const llvm::object::coff_file_header *Header,llvm::raw_ostream &Out) { Out << "header: !Header" << endl; Out << " Machine: "; Out << nameLookup(MachineTypePairs, Header->Machine, "# Unknown_MachineTypes") << " # ("; return yaml::writeHexNumber(Out, Header->Machine) << ")" << endl << endl; }
static llvm::raw_ostream &yamlCOFFSections(llvm::object::COFFObjectFile &Obj, std::size_t NumSections, llvm::raw_ostream &Out) { llvm::error_code ec; Out << "sections:" << endl; for (llvm::object::section_iterator iter = Obj.begin_sections(); iter != Obj.end_sections(); iter.increment(ec)) { const llvm::object::coff_section *sect = Obj.getCOFFSection(iter); Out << " - !Section" << endl; Out << " Name: "; yaml::writeName(Out, sect->Name, sizeof(sect->Name)) << endl; Out << " Characteristics: ["; yaml::writeBitMask(Out, SectionCharacteristicsPairs1, sect->Characteristics); Out << nameLookup(SectionCharacteristicsPairsAlignment, sect->Characteristics & 0x00F00000, "# Unrecognized_IMAGE_SCN_ALIGN") << ", "; yaml::writeBitMask(Out, SectionCharacteristicsPairs2, sect->Characteristics); Out << "] # "; yaml::writeHexNumber(Out, sect->Characteristics) << endl; llvm::ArrayRef<uint8_t> sectionData; Obj.getSectionContents(sect, sectionData); Out << " SectionData: "; yaml::writeHexStream(Out, sectionData) << endl; if (iter->begin_relocations() != iter->end_relocations()) Out << " Relocations:\n"; for (llvm::object::relocation_iterator rIter = iter->begin_relocations(); rIter != iter->end_relocations(); rIter.increment(ec)) { const llvm::object::coff_relocation *reloc = Obj.getCOFFRelocation(rIter); Out << " - !Relocation" << endl; Out << " VirtualAddress: " ; yaml::writeHexNumber(Out, reloc->VirtualAddress) << endl; Out << " SymbolTableIndex: " << reloc->SymbolTableIndex << endl; Out << " Type: " << nameLookup(RelocationTypeX86Pairs, reloc->Type) << endl; // TODO: Use the correct reloc type for the machine. Out << endl; } } return Out; }
int lookupTypeTick(commod* pcomCommod) { // Looks up the type, tick size and tick value for this commodity. Returns 0 // on success; ERRVAL, if the commodity was not found. int iKey = nameLookup(pcomCommod->szName); if(iKey < 0) { return iKey; } pcomCommod->iType = comDatabase[iKey].iType; pcomCommod->dTickVal = comDatabase[iKey].dTickVal; pcomCommod->dTickSize = comDatabase[iKey].dTickSize; return (0); }
double tradeSystemData(char* szName, double dPercentData, int iEntryWindow, int iTrailStopWindow, int iStopLossWindow, char* szEntryDateMonthDay, char* szNoEntryDateMonthDay, char* szExitDateMonthDay) { commod comCommodity; double dTotalProfit = 0; int iBaseYear; int iTotalYears; int iKey; int iNumYears; int iYear; int i; int iError; int iSize; double* adOpen; double* adClose; double* adLow; double* adHigh; char** aszDates; struct Date { char szYMD[9]; char szMonthDay[5]; char szYear[5]; } dateEntry, dateNoEntry, dateExit, dateCommon; iKey = nameLookup(szName); if(iKey < 0) { FPRINTE(stderr, "Could not find %s\n", szName); return ERRVAL; } iBaseYear = comDatabase[iKey].iYear; iTotalYears = comDatabase[iKey].iNumYears; if(dPercentData == TRAIN_YEARS) { dPercentData = TRAIN_YEARS_PERCENTAGE; } else if(dPercentData == TEST_YEARS) { iBaseYear += iTotalYears*TRAIN_YEARS_PERCENTAGE; dPercentData = TEST_YEARS_PERCENTAGE; } if(dPercentData < 0 || dPercentData > 1) { FPRINTE(stderr, "Invalid data percentage\n"); return ERRVAL; } iNumYears = iTotalYears * dPercentData; comCommodity.szName = szName; //guaranteed to be after any othe date memset(dateCommon.szYMD, ~0, DATE_LEN); for(i = 0; i < iNumYears; i++) { comCommodity.iYear = iBaseYear + i; iError = generateTradeData(comCommodity, &adLow, &adHigh, &adOpen, &adClose, &aszDates, &iSize); if(iError == ERRVAL) { FPRINTE(stderr, "generateTradeData failed\n"); return iError; } else //immediately free the ones we don't need { free(adLow); free(adHigh); free(adOpen); free(adClose); } if(strncmp(aszDates[iSize-1], dateCommon.szYMD, DATE_LEN) < 0) { strncpy(dateCommon.szYMD, aszDates[iSize-1], DATE_LEN); } for (i = 0; i < iSize; i++) { if(aszDates[i] != NULL) free(aszDates[i]); } free(aszDates); } strncpy(dateCommon.szYear, dateCommon.szYMD, 4); strncpy(dateCommon.szMonthDay, dateCommon.szYMD+4, 4); dateCommon.szYear[4] = (char)0; dateCommon.szMonthDay[4] = (char)0; strncpy(dateEntry.szMonthDay, szEntryDateMonthDay, 4+1); strncpy(dateNoEntry.szMonthDay, szNoEntryDateMonthDay, 4+1); strncpy(dateExit.szMonthDay, szExitDateMonthDay, 4+1); for(i = 0; i < iNumYears; i++) { iYear = iBaseYear + i; if (strncmp(dateCommon.szMonthDay, dateExit.szMonthDay, 4) > 0) { snprintf(dateExit.szYear, 4+1, "%d", atoi(dateCommon.szYear) + i); } else { snprintf(dateExit.szYear, 4+1, "%d", atoi(dateCommon.szYear) - 1 + i); } if (strncmp(dateEntry.szMonthDay, dateExit.szMonthDay, 4) < 0) { snprintf(dateEntry.szYear, 4+1, "%s", dateExit.szYear); } else { snprintf(dateEntry.szYear, 4+1, "%d", atoi(dateExit.szYear) - 1); } if (strncmp(dateNoEntry.szMonthDay, dateEntry.szMonthDay, 4) > 0) { snprintf(dateNoEntry.szYear, 4+1, "%s", dateEntry.szYear); } else { snprintf(dateNoEntry.szYear, 4+1, "%d", atoi(dateEntry.szYear) + 1); } snprintf(dateEntry.szYMD, 8+1, "%s%s", dateEntry.szYear, dateEntry.szMonthDay); snprintf(dateNoEntry.szYMD, 8+1, "%s%s", dateNoEntry.szYear, dateNoEntry.szMonthDay); snprintf(dateExit.szYMD, 8+1, "%s%s", dateExit.szYear, dateExit.szMonthDay); dTotalProfit += tradeSystem(szName, iYear, iEntryWindow, iTrailStopWindow, iStopLossWindow, dateEntry.szYMD, dateNoEntry.szYMD, dateExit.szYMD); } return dTotalProfit; }