diff --git a/BUSY b/BUSY index 500e4124f..be7360c15 100644 --- a/BUSY +++ b/BUSY @@ -36,10 +36,68 @@ let config : Config { } } -let orangefront ! : Executable { - .configs += config; +let config2 : Config { .include_dirs += [ . ./src/occopt ./src/util ./src/ocpp ] .defines += [ "ORANGE_NO_MSIL" "ORANGE_NO_INASM" ] +} + +let common : SourceSet { + .configs += [ config config2 ] + .sources += [ + ./src/util/CmdFiles.cpp + ./src/util/CmdSwitch.cpp + ./src/util/crc.cpp + ./src/util/NamedPipe.cpp + ./src/util/Random.cpp + ./src/util/SharedMemory.cpp + ./src/util/ToolChain.cpp + ./src/util/UTF8.cpp + ./src/util/UTF8Table.cpp + ./src/util/UTF8Upper.cpp + ./src/util/Utils.cpp + ./src/util/xml.cpp + ./src/util/winsystem.c + + ./src/util/CmdFiles.h + ./src/util/CmdSwitch.h + ./src/util/FNV_hash.h + ./src/util/LSDateTime.h + ./src/util/SharedMemory.h + ./src/util/ToolChain.h + ./src/util/UTF8.h + ./src/util/Utils.h + ./src/util/xml.h + + ./src/occopt/config.cpp + ./src/occopt/config.h + ./src/occopt/configx86.cpp + ./src/occopt/configx86.h + ./src/occopt/iblock.cpp + ./src/occopt/iblock.h + ./src/occopt/ifloatconv.cpp + ./src/occopt/ifloatconv.h + ./src/occopt/ildata.cpp + ./src/occopt/ildata.h + ./src/occopt/ilstream.cpp + ./src/occopt/ilstream.h + ./src/occopt/iout.cpp + ./src/occopt/iout.h + ./src/occopt/memory.cpp + ./src/occopt/memory.h + ./src/occopt/optmodules.cpp + ./src/occopt/optmodules.h + ./src/occopt/OptUtils.cpp + ./src/occopt/OptUtils.h + ./src/occopt/output.cpp + ./src/occopt/output.h + ./src/occopt/symfuncs.cpp + ./src/occopt/symfuncs.h + ] +} + +let orangefront : Executable { + .configs += [ config config2 ] + .deps += common; .sources += [ ./src/occparse/beinterf.cpp ./src/occparse/browse.cpp @@ -84,19 +142,6 @@ let orangefront ! : Executable { ./src/occparse/types.cpp ./src/occparse/unmangle.cpp ./src/occparse/wseh.cpp - ./src/util/CmdFiles.cpp - ./src/util/CmdSwitch.cpp - ./src/util/crc.cpp - ./src/util/NamedPipe.cpp - ./src/util/Random.cpp - ./src/util/SharedMemory.cpp - ./src/util/ToolChain.cpp - ./src/util/UTF8.cpp - ./src/util/UTF8Table.cpp - ./src/util/UTF8Upper.cpp - ./src/util/Utils.cpp - ./src/util/xml.cpp - ./src/util/winsystem.c ./src/ocpp/Errors.cpp ./src/ocpp/Floating.cpp ./src/ocpp/InputFile.cpp @@ -114,18 +159,6 @@ let orangefront ! : Executable { ./src/ocpp/PreProcessor.cpp ./src/ocpp/SymbolTable.cpp ./src/ocpp/Token.cpp - ./src/occopt/config.cpp - ./src/occopt/ildata.cpp - ./src/occopt/OptUtils.cpp - ./src/occopt/memory.cpp - ./src/occopt/ifloatconv.cpp - ./src/occopt/iblock.cpp - ./src/occopt/configx86.cpp - ./src/occopt/output.cpp - ./src/occopt/symfuncs.cpp - ./src/occopt/optmodules.cpp - ./src/occopt/ilstream.cpp - ./src/occopt/iout.cpp ] .sources += [ # Headers @@ -179,74 +212,89 @@ let orangefront ! : Executable { ./src/occparse/unmangle.h ./src/occparse/winmode.h ./src/occparse/wseh.h + ./src/ocpp/Errors.h + ./src/ocpp/Floating.h + ./src/ocpp/InputFile.h + ./src/ocpp/MakeStubs.h + ./src/ocpp/PipeArbitrator.h + ./src/ocpp/ppCommon.h + ./src/ocpp/ppCond.h + ./src/ocpp/ppCtx.h + ./src/ocpp/ppDefine.h + ./src/ocpp/ppError.h + ./src/ocpp/ppExpr.h + ./src/ocpp/ppFile.h + ./src/ocpp/ppInclude.h + ./src/ocpp/ppkw.h + ./src/ocpp/ppMacro.h + ./src/ocpp/ppMain.h + ./src/ocpp/ppPragma.h + ./src/ocpp/PreProcessor.h + ./src/ocpp/SymbolTable.h + ./src/ocpp/Token.h + ] +} + +let orangeopt : Executable { + .configs += [ config config2 ] + .deps += common; + .sources += [ ./src/occopt/beinterfdefs.h ./src/occopt/browsedefs.h - ./src/occopt/config.h - ./src/occopt/configmsil.h - ./src/occopt/configx86.h ./src/occopt/ctypes.h + ./src/occopt/ialias.cpp ./src/occopt/ialias.h - ./src/occopt/iblock.h + ./src/occopt/iconfl.cpp ./src/occopt/iconfl.h + ./src/occopt/iconst.cpp ./src/occopt/iconst.h - ./src/occopt/ifloatconv.h + ./src/occopt/iflow.cpp ./src/occopt/iflow.h + ./src/occopt/iinvar.cpp ./src/occopt/iinvar.h + ./src/occopt/ilazy.cpp ./src/occopt/ilazy.h - ./src/occopt/ildata.h + ./src/occopt/ilive.cpp ./src/occopt/ilive.h + ./src/occopt/ilocal.cpp ./src/occopt/ilocal.h + ./src/occopt/iloop.cpp ./src/occopt/iloop.h - ./src/occopt/ilstream.h + ./src/occopt/ilunstream.cpp ./src/occopt/ilunstream.h ./src/occopt/iopt.h ./src/occopt/ioptimizer.h + ./src/occopt/ioptutil.cpp ./src/occopt/ioptutil.h - ./src/occopt/iout.h + ./src/occopt/ipeep.cpp ./src/occopt/ipeep.h + ./src/occopt/ipinning.cpp ./src/occopt/ipinning.h + ./src/occopt/irc.cpp ./src/occopt/irc.h + ./src/occopt/ireshape.cpp ./src/occopt/ireshape.h + ./src/occopt/irewrite.cpp ./src/occopt/irewrite.h + ./src/occopt/issa.cpp ./src/occopt/issa.h + ./src/occopt/istren.cpp ./src/occopt/istren.h + ./src/occopt/localprotect.cpp ./src/occopt/localprotect.h - ./src/occopt/memory.h + ./src/occopt/msilprocess.cpp + ./src/occopt/optmain.cpp ./src/occopt/optmain.h - ./src/occopt/optmodules.h - ./src/occopt/OptUtils.h - ./src/occopt/output.h + ./src/occopt/optmodulerun.cpp + ./src/occopt/rewritemsil.cpp ./src/occopt/rewritemsil.h + ./src/occopt/rewritex86.cpp ./src/occopt/rewritex86.h - ./src/occopt/symfuncs.h - ./src/util/CmdFiles.h - ./src/util/CmdSwitch.h - ./src/util/FNV_hash.h - ./src/util/LSDateTime.h - ./src/util/SharedMemory.h - ./src/util/ToolChain.h - ./src/util/UTF8.h - ./src/util/Utils.h - ./src/util/xml.h - ./src/ocpp/Errors.h - ./src/ocpp/Floating.h - ./src/ocpp/InputFile.h - ./src/ocpp/MakeStubs.h - ./src/ocpp/PipeArbitrator.h - ./src/ocpp/ppCommon.h - ./src/ocpp/ppCond.h - ./src/ocpp/ppCtx.h - ./src/ocpp/ppDefine.h - ./src/ocpp/ppError.h - ./src/ocpp/ppExpr.h - ./src/ocpp/ppFile.h - ./src/ocpp/ppInclude.h - ./src/ocpp/ppkw.h - ./src/ocpp/ppMacro.h - ./src/ocpp/ppMain.h - ./src/ocpp/ppPragma.h - ./src/ocpp/PreProcessor.h - ./src/ocpp/SymbolTable.h - ./src/ocpp/Token.h - ] + + ./src/ocpp/Floating.cpp + ] +} + +let all ! : Group { + .deps += [ orangefront orangeopt ] } diff --git a/src/occopt/ilunstream.cpp b/src/occopt/ilunstream.cpp index 2e4f6301d..22ec3a982 100644 --- a/src/occopt/ilunstream.cpp +++ b/src/occopt/ilunstream.cpp @@ -366,6 +366,7 @@ static AMODE* UnstreamAssemblyOperand() static OCODE* UnstreamAssemblyInstruction() { OCODE* rv = Allocate(); +#ifndef ORANGE_NO_INASM rv->opcode = (e_opcode)UnstreamIndex(); rv->diag = UnstreamIndex(); rv->noopt = UnstreamIndex(); @@ -374,6 +375,9 @@ static OCODE* UnstreamAssemblyInstruction() rv->oper1 = UnstreamAssemblyOperand(); rv->oper2 = UnstreamAssemblyOperand(); rv->oper3 = UnstreamAssemblyOperand(); +#else + memset(rv,0,sizeof(OCODE)); +#endif return rv; } static Optimizer::IMODE* UnstreamOperand() @@ -1269,8 +1273,8 @@ void ReadMappingFile(SharedMemory* mem, FILE* fil) fseek(fil, 0, SEEK_END); int end = ftell(fil); fseek(fil, 0, SEEK_SET); - unsigned char* p = mem->GetMapping(); mem->EnsureCommitted(end); + unsigned char* p = mem->GetMapping(); while (end > 0) { @@ -1283,4 +1287,4 @@ void ReadMappingFile(SharedMemory* mem, FILE* fil) p = mem->GetMapping(pos); } } -} // namespace Optimizer \ No newline at end of file +} // namespace Optimizer diff --git a/src/ocpp/ppInclude.cpp b/src/ocpp/ppInclude.cpp index d2a149413..13672ba51 100644 --- a/src/ocpp/ppInclude.cpp +++ b/src/ocpp/ppInclude.cpp @@ -378,7 +378,11 @@ std::string ppInclude::SrchPath(bool system, const std::string& name, const std: } AddName(buf, name); +#ifdef TARGET_OS_WINDOWS while (char* p = (char*)strchr(buf, '/')) +#else + while (char* p = (char*)strchr(buf, '\\')) +#endif { *p = CmdFiles::DIR_SEP[0]; } @@ -489,4 +493,4 @@ bool ppInclude::GetLine(std::string& line, int& lineno) popFile(); } return false; -} \ No newline at end of file +} diff --git a/src/util/CmdFiles.cpp b/src/util/CmdFiles.cpp index 938292b7f..6fb7f5729 100644 --- a/src/util/CmdFiles.cpp +++ b/src/util/CmdFiles.cpp @@ -35,8 +35,13 @@ using namespace std; // borland puts the io stuff in the std namespace... // microsoft does not seem to. +#ifdef TARGET_OS_WINDOWS const char* CmdFiles::DIR_SEP = "\\"; const char* CmdFiles::PATH_SEP = ";"; +#else +const char* CmdFiles::DIR_SEP = "/"; +const char* CmdFiles::PATH_SEP = ":"; +#endif CmdFiles::~CmdFiles() {} bool CmdFiles::Add(char** array, bool recurseDirs) @@ -211,4 +216,4 @@ void CmdFiles::Remove(const std::string& name) break; } } -} \ No newline at end of file +} diff --git a/src/util/CmdSwitch.cpp b/src/util/CmdSwitch.cpp index 66914b959..9c48d4e61 100644 --- a/src/util/CmdSwitch.cpp +++ b/src/util/CmdSwitch.cpp @@ -364,7 +364,11 @@ bool CmdSwitchParser::Parse(int* argc, char* argv[]) memmove(argv, argv + 1, (*argc + 1 - i) * sizeof(char*)); (*argc)--; } - else if ((argv[0][0] == '-' || argv[0][0] == '/' || (argv[0][0] == '+' && argv[0][1] != '-')) && argv[0][1] && + else if ((argv[0][0] == '-' || + #ifdef TARGET_OS_WINDOWS + argv[0][0] == '/' || + #endif + (argv[0][0] == '+' && argv[0][1] != '-')) && argv[0][1] && (argv[0][1] != '-' || argv[0][2])) { const char* swtch = &argv[0][0]; diff --git a/src/util/SharedMemory.cpp b/src/util/SharedMemory.cpp index 476a1b059..548ef232b 100644 --- a/src/util/SharedMemory.cpp +++ b/src/util/SharedMemory.cpp @@ -37,7 +37,7 @@ #define USE_PAGING_FILE SharedMemory::SharedMemory(unsigned max, std::string name, unsigned window) : - max_(max), windowSize_(window), current_(0), regionStart(0), regionHandle(nullptr), fileHandle_(nullptr), regionBase_(0) + max_(max), windowSize_(window), current_(0), regionStart(0), regionHandle(nullptr), fileHandle_(nullptr) { if (!name.empty()) name_ = name; @@ -52,6 +52,9 @@ SharedMemory::~SharedMemory() CloseMapping(); CloseHandle(regionHandle); CloseHandle(fileHandle_); +#else + if( regionHandle ) + free(regionHandle); #endif } @@ -59,6 +62,8 @@ bool SharedMemory::Open() { #ifdef TARGET_OS_WINDOWS regionHandle = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, name_.c_str()); +#else + return true; #endif return !!regionHandle; } @@ -73,6 +78,8 @@ bool SharedMemory::Create() FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, nullptr); # endif regionHandle = CreateFileMapping(fileHandle_, NULL, PAGE_READWRITE | SEC_RESERVE, 0, max_, name_.c_str()); +#else + return true; #endif return !!regionHandle && GetMapping(); } @@ -89,11 +96,13 @@ void SharedMemory::Flush() unsigned char* SharedMemory::GetMapping(unsigned pos) { #ifdef TARGET_OS_WINDOWS - regionBase_ = pos & -4096; + const unsigned int regionBase_ = pos & -4096; CloseMapping(); regionStart = (unsigned char*)MapViewOfFile(regionHandle, FILE_MAP_ALL_ACCESS, 0, regionBase_, ViewWindowSize() * 2); if (regionStart) return regionStart - regionBase_; +#else + return (unsigned char*) regionHandle; #endif return 0; } @@ -129,7 +138,29 @@ bool SharedMemory::EnsureCommitted(int size) } return true; #else - return false; + if( size > max_ ) + return false; + if( size > current_ ) + { + unsigned new_size = current_; + while( size > new_size ) + new_size += windowSize_; + void* old_handle = regionHandle; + void* new_handle = malloc(new_size); + if( new_handle && old_handle ) + { + memcpy(new_handle,old_handle,current_); + free(old_handle); + } + if( new_handle ) + { + current_ = new_size; + regionHandle = new_handle; + return true; + }else + return false; + }else + return true; #endif } void SharedMemory::SetName() @@ -140,4 +171,4 @@ void SharedMemory::SetName() // the lssm: is an attempt to prevent the RNG from choosing someone else's name accidentally... name_ = "lssm:" + std::string(rnd.begin(), rnd.end()); -} \ No newline at end of file +} diff --git a/src/util/SharedMemory.h b/src/util/SharedMemory.h index cb8f7fc6d..512c7336a 100644 --- a/src/util/SharedMemory.h +++ b/src/util/SharedMemory.h @@ -42,11 +42,10 @@ class SharedMemory void SetName(); std::string name_; - unsigned max_; - unsigned windowSize_; + const unsigned max_; + const unsigned windowSize_; unsigned current_; void* fileHandle_; - unsigned regionBase_; - void* regionHandle; - unsigned char* regionStart; + void* regionHandle; // result of OpenFileMapping/CreateFileMapping + unsigned char* regionStart; // result of MapViewOfFile(regionHandle,regionBase_,windowSize_) };