Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions BeefySysLib/util/MappedFile.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#include "MappedFile.h"

#ifndef BF_PLATFORM_WINDOWS
#include <climits>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#endif

USING_NS_BF;

#ifdef BF_PLATFORM_WINDOWS
Expand Down Expand Up @@ -43,4 +51,41 @@ bool MappedFile::Open(const StringImpl& fileName)
return true;
}

#else

MappedFile::MappedFile()
{
mData = NULL;
mFileSize = 0;
}

MappedFile::~MappedFile()
{
if (mData != NULL)
munmap(mData, mFileSize);
}

bool MappedFile::Open(const StringImpl& fileName)
{
mFileName = fileName;
int fd = open(fileName.c_str(), O_RDONLY);
if (fd == -1)
return false;

struct stat fileStat;
if ((fstat(fd, &fileStat) != 0) || (fileStat.st_size <= 0) || (fileStat.st_size > INT_MAX))
{
close(fd);
return false;
}

mFileSize = (int)fileStat.st_size;
void* data = mmap(NULL, mFileSize, PROT_READ, MAP_PRIVATE, fd, 0);
close(fd);
if (data == MAP_FAILED)
return false;
mData = data;
return true;
}

#endif
19 changes: 18 additions & 1 deletion BeefySysLib/util/MappedFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ class MappedFile
~MappedFile();
};

#endif //BF_PLATFORM_WINDOWS
#else

class MappedFile
{
BF_DISALLOW_COPY(MappedFile);
public:
String mFileName;
void* mData;
int mFileSize;

public:
bool Open(const StringImpl& fileName);

MappedFile();
~MappedFile();
};

#endif

NS_BF_END
36 changes: 18 additions & 18 deletions BeefySysLib/util/MultiDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ class MultiDictionary : public TFuncs
{
while (true)
{
MoveToNextHashMatch();
if (*this == mDict->end())
this->MoveToNextHashMatch();
if (*this == this->mDict->end())
break;
if (mKey == GetKey())
if (mKey == this->GetKey())
break;
}
return *this;
Expand Down Expand Up @@ -212,7 +212,7 @@ class MultiDictionary : public TFuncs
void ResizeEntries(int newSize)
{
BF_ASSERT(newSize >= mAllocSize);
Entry* newEntries = TFuncs::allocate<Entry>(newSize);
Entry* newEntries = TFuncs::template allocate<Entry>(newSize);

for (int i = 0; i < mCount; i++)
{
Expand Down Expand Up @@ -309,7 +309,7 @@ class MultiDictionary : public TFuncs
{
if (this->mHashHeads == NULL)
{
this->mHashHeads = TFuncs::allocate<int>(mHashSize);
this->mHashHeads = TFuncs::template allocate<int>(mHashSize);
memset(this->mHashHeads, -1, sizeof(int) * mHashSize);
}

Expand All @@ -318,7 +318,7 @@ class MultiDictionary : public TFuncs
int headEntry = this->mHashHeads[hashIdx];

Entry* newEntry = &mEntries[index];
newEntry->mValue = T();
newEntry->mValue = TValue();
newEntry->mNext = headEntry;
newEntry->mHashCode = hash;

Expand All @@ -331,7 +331,7 @@ class MultiDictionary : public TFuncs
{
if (this->mHashHeads == NULL)
{
this->mHashHeads = TFuncs::allocate<int>(mHashSize);
this->mHashHeads = TFuncs::template allocate<int>(mHashSize);
memset(this->mHashHeads, -1, sizeof(int) * mHashSize);
}

Expand Down Expand Up @@ -367,7 +367,7 @@ class MultiDictionary : public TFuncs

void Rehash(int newHashSize)
{
auto newHashHeads = TFuncs::allocate<int>(newHashSize);
auto newHashHeads = TFuncs::template allocate<int>(newHashSize);
memset(newHashHeads, -1, sizeof(int) * newHashSize);

if (mHashHeads != NULL)
Expand Down Expand Up @@ -414,8 +414,8 @@ class MultiDictionary : public TFuncs
}
}

template <typename TKey>
bool TryGet(const TKey& key, TKey* outKey, TValue* outValue)
template <typename TAltKey>
bool TryGet(const TAltKey& key, TAltKey* outKey, TValue* outValue)
{
if (mHashHeads == NULL)
return false;
Expand All @@ -441,8 +441,8 @@ class MultiDictionary : public TFuncs
return false;
}

template <typename TKey>
MatchIterator TryGet(const TKey& key)
template <typename TAltKey>
MatchIterator TryGet(const TAltKey& key)
{
if (mHashHeads == NULL)
return end();
Expand All @@ -468,23 +468,23 @@ class MultiDictionary : public TFuncs
return end();
}

template <typename TKey>
bool Contains(const TKey& key)
template <typename TAltKey>
bool Contains(const TAltKey& key)
{
return TryGet(key) != end();
}

template <typename TKey>
int GetCount(const TKey& key)
template <typename TAltKey>
int GetCount(const TAltKey& key)
{
int count = 0;
for (auto itr = TryGet(key); itr != end(); ++itr)
count++;
return count;
}

template <typename TKey>
bool Remove(const TKey& key)
template <typename TAltKey>
bool Remove(const TAltKey& key)
{
if (mHashHeads == NULL)
return false;
Expand Down
2 changes: 2 additions & 0 deletions Debugger32/Debugger32.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<ClInclude Include="..\IDEHelper\CPU.h" />
<ClInclude Include="..\IDEHelper\DbgEvalPool.h" />
<ClInclude Include="..\IDEHelper\DbgExprEvaluator.h" />
<ClInclude Include="..\IDEHelper\DbgTargetHost.h" />
<ClInclude Include="..\IDEHelper\DbgModule.h" />
<ClInclude Include="..\IDEHelper\DbgSymSrv.h" />
<ClInclude Include="..\IDEHelper\DbgTypeMap.h" />
Expand All @@ -42,6 +43,7 @@
<ItemGroup>
<ClCompile Include="..\IDEHelper\COFF.cpp" />
<ClCompile Include="..\IDEHelper\DbgEvalPool.cpp" />
<ClCompile Include="..\IDEHelper\DbgEvalSupport.cpp" />
<ClCompile Include="..\IDEHelper\DbgExprEvaluator.cpp" />
<ClCompile Include="..\IDEHelper\DbgModule.cpp" />
<ClCompile Include="..\IDEHelper\DbgSymSrv.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions Debugger32/Debugger32.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<ClInclude Include="..\IDEHelper\DbgEvalPool.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\IDEHelper\DbgTargetHost.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\IDEHelper\DbgTypeMap.h">
<Filter>Source Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -96,6 +99,9 @@
<ClCompile Include="..\IDEHelper\DbgEvalPool.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\IDEHelper\DbgEvalSupport.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\IDEHelper\DbgTypeMap.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
2 changes: 2 additions & 0 deletions Debugger64/Debugger64.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<ClInclude Include="..\IDEHelper\CPU.h" />
<ClInclude Include="..\IDEHelper\DbgEvalPool.h" />
<ClInclude Include="..\IDEHelper\DbgExprEvaluator.h" />
<ClInclude Include="..\IDEHelper\DbgTargetHost.h" />
<ClInclude Include="..\IDEHelper\DbgSymSrv.h" />
<ClInclude Include="..\IDEHelper\DbgTypeMap.h" />
<ClInclude Include="..\IDEHelper\DebugCommon.h" />
Expand All @@ -44,6 +45,7 @@
<ItemGroup>
<ClCompile Include="..\IDEHelper\COFF.cpp" />
<ClCompile Include="..\IDEHelper\DbgEvalPool.cpp" />
<ClCompile Include="..\IDEHelper\DbgEvalSupport.cpp" />
<ClCompile Include="..\IDEHelper\DbgExprEvaluator.cpp" />
<ClCompile Include="..\IDEHelper\DbgSymSrv.cpp" />
<ClCompile Include="..\IDEHelper\DbgTypeMap.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions Debugger64/Debugger64.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<ClInclude Include="..\IDEHelper\DbgEvalPool.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\IDEHelper\DbgTargetHost.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\IDEHelper\DbgTypeMap.h">
<Filter>Source Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -101,6 +104,9 @@
<ClCompile Include="..\IDEHelper\DbgEvalPool.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\IDEHelper\DbgEvalSupport.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\IDEHelper\DbgTypeMap.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
16 changes: 16 additions & 0 deletions IDEHelper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,22 @@ if(UNIX AND NOT APPLE)

endif()

option(BF_DBG_HOST "Build the Beef debug info and expression evaluation layer" OFF)

if (BF_DBG_HOST AND NOT MSVC)
set(DBG_HOST_FILES
DbgModule.cpp
DebugTarget.cpp
DbgTypeMap.cpp
DbgExprEvaluator.cpp
DbgEvalSupport.cpp
DbgEvalPool.cpp
HotHeap.cpp
)
set_source_files_properties(${DBG_HOST_FILES} PROPERTIES COMPILE_DEFINITIONS BF_DBG_64)
list(APPEND SRC_FILES ${DBG_HOST_FILES})
endif()

# Add library to build.
add_library(${PROJECT_NAME} STATIC
${SRC_FILES}
Expand Down
Loading
Loading