Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/coreclr/tools/superpmi/mcs/commandline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ bool CommandLine::Parse(int argc, char* argv[], /* OUT */ Options* o)
i++;
processMCL2:

bool isValidList = MCList::processArgAsMCL(argv[i], &o->indexCount, &o->indexes);
bool isValidList = MCList::processArgAsMCL(argv[i], o->indexes);
o->indexCount = (int)o->indexes.size();
if (!isValidList)
i--;
}
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/tools/superpmi/mcs/commandline.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class CommandLine
, nameOfFile2(nullptr)
, nameOfFile3(nullptr)
, indexCount(-1)
, indexes(nullptr)
{
}

Expand Down Expand Up @@ -68,7 +67,7 @@ class CommandLine
char* nameOfFile2;
char* nameOfFile3;
int indexCount;
int* indexes;
std::vector<int> indexes;
};

static bool Parse(int argc, char* argv[], /* OUT */ Options* o);
Expand Down
14 changes: 7 additions & 7 deletions src/coreclr/tools/superpmi/mcs/mcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int __cdecl main(int argc, char* argv[])
int exitCode = 0;
if (o.actionASMDump)
{
exitCode = verbASMDump::DoWork(o.nameOfFile1, o.nameOfFile2, o.indexCount, o.indexes);
exitCode = verbASMDump::DoWork(o.nameOfFile1, o.nameOfFile2, o.indexCount, o.indexes.data());
}
if (o.actionConcat)
{
Expand All @@ -55,15 +55,15 @@ int __cdecl main(int argc, char* argv[])
}
if (o.actionCopy)
{
exitCode = verbStrip::DoWork(o.nameOfFile1, o.nameOfFile2, o.indexCount, o.indexes, false, o.stripCR);
exitCode = verbStrip::DoWork(o.nameOfFile1, o.nameOfFile2, o.indexCount, o.indexes.data(), false, o.stripCR);
}
if (o.actionDump)
{
exitCode = verbDump::DoWork(o.nameOfFile1, o.indexCount, o.indexes, o.simple);
exitCode = verbDump::DoWork(o.nameOfFile1, o.indexCount, o.indexes.data(), o.simple);
}
if (o.actionFracture)
{
exitCode = verbFracture::DoWork(o.nameOfFile1, o.nameOfFile2, o.indexCount, o.indexes, o.stripCR);
exitCode = verbFracture::DoWork(o.nameOfFile1, o.nameOfFile2, o.indexCount, o.indexes.data(), o.stripCR);
}
if (o.actionDumpMap)
{
Expand All @@ -75,7 +75,7 @@ int __cdecl main(int argc, char* argv[])
}
if (o.actionILDump)
{
exitCode = verbILDump::DoWork(o.nameOfFile1, o.indexCount, o.indexes);
exitCode = verbILDump::DoWork(o.nameOfFile1, o.indexCount, o.indexes.data());
}
if (o.actionInteg)
{
Expand All @@ -87,11 +87,11 @@ int __cdecl main(int argc, char* argv[])
}
if (o.actionStat)
{
exitCode = verbStat::DoWork(o.nameOfFile1, o.nameOfFile2, o.indexCount, o.indexes);
exitCode = verbStat::DoWork(o.nameOfFile1, o.nameOfFile2, o.indexCount, o.indexes.data());
}
if (o.actionStrip)
{
exitCode = verbStrip::DoWork(o.nameOfFile1, o.nameOfFile2, o.indexCount, o.indexes, true, o.stripCR);
exitCode = verbStrip::DoWork(o.nameOfFile1, o.nameOfFile2, o.indexCount, o.indexes.data(), true, o.stripCR);
}
if (o.actionTOC)
{
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/tools/superpmi/mcs/removedup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ bool RemoveDup::uniqueLegacy(MethodContext* mc)
return true;
}

bool RemoveDup::CopyAndRemoveDups(const char* nameOfInput, HANDLE hFileOut)
bool RemoveDup::CopyAndRemoveDups(const char* nameOfInput, FILE* fpOut)
{
MethodContextIterator mci(/* progressReport */ true);
if (!mci.Initialize(nameOfInput))
Expand All @@ -138,7 +138,7 @@ bool RemoveDup::CopyAndRemoveDups(const char* nameOfInput, HANDLE hFileOut)
{
if (uniqueLegacy(mc))
{
mc->saveToFile(hFileOut);
mc->saveToFile(fpOut);
savedCount++;

// In this case, for the legacy comparer, it has placed the 'mc' in the 'm_inFileLegacy' table, so we
Expand All @@ -153,7 +153,7 @@ bool RemoveDup::CopyAndRemoveDups(const char* nameOfInput, HANDLE hFileOut)
{
if (unique(mc))
{
mc->saveToFile(hFileOut);
mc->saveToFile(fpOut);
savedCount++;
}
delete mc; // we no longer need this
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/superpmi/mcs/removedup.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RemoveDup

~RemoveDup();

bool CopyAndRemoveDups(const char* nameOfInput, HANDLE hFileOut);
bool CopyAndRemoveDups(const char* nameOfInput, FILE* fpOut);

private:

Expand Down
20 changes: 7 additions & 13 deletions src/coreclr/tools/superpmi/mcs/verbasmdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,25 @@ int verbASMDump::DoWork(const char* nameOfInput, const char* nameOfOutput, int i
char buff[500];
sprintf_s(buff, 500, "%s-%d.asm", nameOfOutput, mci.MethodContextNumber());

HANDLE hFileOut = CreateFileA(buff, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hFileOut == INVALID_HANDLE_VALUE)
FILE* fpOut = fopen(buff, "w");
if (fpOut == NULL)
{
LogError("Failed to open output '%s'. GetLastError()=%u", buff, GetLastError());
LogError("Failed to open output '%s'. errno=%d", buff, errno);
return -1;
}

if (mc->cr->IsEmpty())
{
const size_t bufflen = 4096;
DWORD bytesWritten;
char buff[bufflen];
ZeroMemory(buff, bufflen * sizeof(char));
int buff_offset = sprintf_s(buff, bufflen, ";;Method context has no compile result");
WriteFile(hFileOut, buff, buff_offset * sizeof(char), &bytesWritten, nullptr);
fprintf(fpOut, ";;Method context has no compile result");
}
else
{
ASMDumper::DumpToFile(hFileOut, mc, mc->cr);
ASMDumper::DumpToFile(fpOut, mc, mc->cr);
}

if (!CloseHandle(hFileOut))
if (fclose(fpOut) != 0)
{
LogError("CloseHandle failed. GetLastError()=%u", GetLastError());
LogError("fclose failed. errno=%d", errno);
return -1;
}
savedCount++;
Expand Down
65 changes: 21 additions & 44 deletions src/coreclr/tools/superpmi/mcs/verbconcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,61 +14,37 @@ int verbConcat::DoWork(const char* nameOfFile1, const char* nameOfFile2)

LogVerbose("Concatenating '%s'+'%s' into %s", nameOfFile1, nameOfFile2, nameOfFile1);

LARGE_INTEGER DataTemp1;
LARGE_INTEGER DataTemp2;

HANDLE hFileIn1 = CreateFileA(nameOfFile1, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hFileIn1 == INVALID_HANDLE_VALUE)
{
LogError("Failed to open input 1 '%s'. GetLastError()=%u", nameOfFile1, GetLastError());
return -1;
}
if (GetFileSizeEx(hFileIn1, &DataTemp1) == 0)
FILE* fp1 = fopen(nameOfFile1, "ab+");
if (fp1 == NULL)
{
LogError("GetFileSizeEx failed. GetLastError()=%u", GetLastError());
LogError("Failed to open input 1 '%s'. errno=%d", nameOfFile1, errno);
return -1;
}

LONG highDWORD = 0;
DWORD dwPtr = SetFilePointer(hFileIn1, 0, &highDWORD, FILE_END);
if (dwPtr == INVALID_SET_FILE_POINTER)
{
LogError("Failed to SetFilePointer on input 1 '%s'. GetLastError()=%u", nameOfFile1, GetLastError());
return -1;
}

HANDLE hFileIn2 = CreateFileA(nameOfFile2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hFileIn2 == INVALID_HANDLE_VALUE)
{
LogError("Failed to open input 2 '%s'. GetLastError()=%u", nameOfFile2, GetLastError());
return -1;
}
if (GetFileSizeEx(hFileIn2, &DataTemp2) == 0)
FILE* fp2 = fopen(nameOfFile2, "rb");
if (fp2 == NULL)
{
LogError("2nd GetFileSizeEx failed. GetLastError()=%u", GetLastError());
LogError("Failed to open input 2 '%s'. errno=%d", nameOfFile2, errno);
return -1;
}

unsigned char* buffer = new unsigned char[BUFFER_SIZE];
int64_t offset = 0;

st1.Start();
for (LONGLONG offset = 0; offset < DataTemp2.QuadPart; offset += BUFFER_SIZE)
while (!feof(fp2))
{
DWORD bytesRead = -1;
BOOL res = ReadFile(hFileIn2, buffer, BUFFER_SIZE, &bytesRead, nullptr);
if (res == 0)
size_t bytesRead = fread(buffer, 1, BUFFER_SIZE, fp2);
if (bytesRead <= 0)
{
LogError("Failed to read '%s' from offset %lld. GetLastError()=%u", nameOfFile2, offset, GetLastError());
LogError("Failed to read '%s' from offset %lld. errno=%d", nameOfFile2, offset, errno);
delete[] buffer;
return -1;
}
DWORD bytesWritten = -1;
BOOL res2 = WriteFile(hFileIn1, buffer, bytesRead, &bytesWritten, nullptr);
if (res2 == 0)
size_t bytesWritten = fwrite(buffer, 1, bytesRead, fp1);
if (bytesWritten <= 0)
{
LogError("Failed to write '%s' at offset %lld. GetLastError()=%u", nameOfFile1, offset, GetLastError());
LogError("Failed to write '%s' at offset %lld. errno=%d", nameOfFile1, offset, errno);
delete[] buffer;
return -1;
}
Expand All @@ -78,24 +54,25 @@ int verbConcat::DoWork(const char* nameOfFile1, const char* nameOfFile2)
delete[] buffer;
return -1;
}
offset += bytesRead;
}
st1.Stop();

delete[] buffer;

if (CloseHandle(hFileIn1) == 0)
if (fclose(fp1) != 0)
{
LogError("CloseHandle failed. GetLastError()=%u", GetLastError());
LogError("CloseHandle failed. errno=%d", errno);
return -1;
}
if (CloseHandle(hFileIn2) == 0)
if (fclose(fp2) != 0)
{
LogError("2nd CloseHandle failed. GetLastError()=%u", GetLastError());
LogError("2nd CloseHandle failed. errno=%d", errno);
return -1;
}

LogInfo("Read/Wrote %lld MB @ %4.2f MB/s.\n", DataTemp2.QuadPart / (1000 * 1000),
(((double)DataTemp2.QuadPart) / (1000 * 1000)) /
LogInfo("Read/Wrote %lld MB @ %4.2f MB/s.\n", offset / (1000 * 1000),
(((double)offset) / (1000 * 1000)) /
st1.GetSeconds()); // yes yes.. http://en.wikipedia.org/wiki/Megabyte_per_second#Megabyte_per_second

return 0;
Expand Down
27 changes: 13 additions & 14 deletions src/coreclr/tools/superpmi/mcs/verbfracture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,27 @@ int verbFracture::DoWork(
int fileCount = 0;
char fileName[512];

HANDLE hFileOut = INVALID_HANDLE_VALUE;
FILE* fpOut = NULL;
while (mci.MoveNext())
{
MethodContext* mc = mci.Current();

if ((hFileOut == INVALID_HANDLE_VALUE) || (((mci.MethodContextNumber() - 1) % rangeSize) == 0))
if ((fpOut == NULL) || (((mci.MethodContextNumber() - 1) % rangeSize) == 0))
{
if (hFileOut != INVALID_HANDLE_VALUE)
if (fpOut != NULL)
{
if (!CloseHandle(hFileOut))
if (fclose(fpOut) != 0)
{
LogError("1st CloseHandle failed. GetLastError()=%u", GetLastError());
LogError("1st CloseHandle failed. errno=%d", errno);
return -1;
}
hFileOut = INVALID_HANDLE_VALUE;
fpOut = NULL;
}
sprintf_s(fileName, 512, "%s-%0*d.mch", nameOfOutput, 5, fileCount++);
hFileOut = CreateFileA(fileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hFileOut == INVALID_HANDLE_VALUE)
fpOut = fopen(fileName, "wb");
if (fpOut == NULL)
{
LogError("Failed to open output file '%s'. GetLastError()=%u", fileName, GetLastError());
LogError("Failed to open output file '%s'. errno=%d", fileName, errno);
return -1;
}
}
Expand All @@ -54,14 +53,14 @@ int verbFracture::DoWork(
delete mc->cr;
mc->cr = new CompileResult();
}
mc->saveToFile(hFileOut);
mc->saveToFile(fpOut);
}

if (hFileOut != INVALID_HANDLE_VALUE)
if (fpOut != NULL)
{
if (!CloseHandle(hFileOut))
if (fclose(fpOut) != 0)
{
LogError("2nd CloseHandle failed. GetLastError()=%u", GetLastError());
LogError("2nd CloseHandle failed. errno=%d", errno);
return -1;
}
}
Expand Down
Loading