[Object] Replace TimeValue with std::chrono

Summary:
Most of the changes are very straight-forward. The only choice I had to make was
to use second-precision time points in the Archive classes. I did this because
the archive files use that precision in the on-disk representation anyway.

Reviewers: rafael, zturner

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D25773

llvm-svn: 284974
This commit is contained in:
Pavel Labath
2016-10-24 13:38:27 +00:00
parent 504bf334b0
commit bff47b51b6
5 changed files with 32 additions and 30 deletions

View File

@@ -47,7 +47,7 @@ NewArchiveMember::getOldMember(const object::Archive::Child &OldMember,
NewArchiveMember M;
M.Buf = MemoryBuffer::getMemBuffer(*BufOrErr, false);
if (!Deterministic) {
Expected<sys::TimeValue> ModTimeOrErr = OldMember.getLastModified();
auto ModTimeOrErr = OldMember.getLastModified();
if (!ModTimeOrErr)
return ModTimeOrErr.takeError();
M.ModTime = ModTimeOrErr.get();
@@ -95,7 +95,8 @@ Expected<NewArchiveMember> NewArchiveMember::getFile(StringRef FileName,
NewArchiveMember M;
M.Buf = std::move(*MemberBufferOrErr);
if (!Deterministic) {
M.ModTime = Status.getLastModificationTime();
M.ModTime = std::chrono::time_point_cast<std::chrono::seconds>(
Status.getLastModificationTime());
M.UID = Status.getUser();
M.GID = Status.getGroup();
M.Perms = Status.permissions();
@@ -127,11 +128,10 @@ static void print32(raw_ostream &Out, object::Archive::Kind Kind,
support::endian::Writer<support::little>(Out).write(Val);
}
static void printRestOfMemberHeader(raw_fd_ostream &Out,
const sys::TimeValue &ModTime, unsigned UID,
unsigned GID, unsigned Perms,
unsigned Size) {
printWithSpacePadding(Out, ModTime.toEpochTime(), 12);
static void printRestOfMemberHeader(
raw_fd_ostream &Out, const sys::TimePoint<std::chrono::seconds> &ModTime,
unsigned UID, unsigned GID, unsigned Perms, unsigned Size) {
printWithSpacePadding(Out, sys::toTimeT(ModTime), 12);
printWithSpacePadding(Out, UID, 6, true);
printWithSpacePadding(Out, GID, 6, true);
printWithSpacePadding(Out, format("%o", Perms), 8);
@@ -139,17 +139,20 @@ static void printRestOfMemberHeader(raw_fd_ostream &Out,
Out << "`\n";
}
static void printGNUSmallMemberHeader(raw_fd_ostream &Out, StringRef Name,
const sys::TimeValue &ModTime,
unsigned UID, unsigned GID,
unsigned Perms, unsigned Size) {
static void
printGNUSmallMemberHeader(raw_fd_ostream &Out, StringRef Name,
const sys::TimePoint<std::chrono::seconds> &ModTime,
unsigned UID, unsigned GID, unsigned Perms,
unsigned Size) {
printWithSpacePadding(Out, Twine(Name) + "/", 16);
printRestOfMemberHeader(Out, ModTime, UID, GID, Perms, Size);
}
static void printBSDMemberHeader(raw_fd_ostream &Out, StringRef Name,
const sys::TimeValue &ModTime, unsigned UID,
unsigned GID, unsigned Perms, unsigned Size) {
static void
printBSDMemberHeader(raw_fd_ostream &Out, StringRef Name,
const sys::TimePoint<std::chrono::seconds> &ModTime,
unsigned UID, unsigned GID, unsigned Perms,
unsigned Size) {
uint64_t PosAfterHeader = Out.tell() + 60 + Name.size();
// Pad so that even 64 bit object files are aligned.
unsigned Pad = OffsetToAlignment(PosAfterHeader, 8);
@@ -171,8 +174,8 @@ static void
printMemberHeader(raw_fd_ostream &Out, object::Archive::Kind Kind, bool Thin,
StringRef Name,
std::vector<unsigned>::iterator &StringMapIndexIter,
const sys::TimeValue &ModTime, unsigned UID, unsigned GID,
unsigned Perms, unsigned Size) {
const sys::TimePoint<std::chrono::seconds> &ModTime,
unsigned UID, unsigned GID, unsigned Perms, unsigned Size) {
if (Kind == object::Archive::K_BSD)
return printBSDMemberHeader(Out, Name, ModTime, UID, GID, Perms, Size);
if (!useStringTable(Thin, Name))
@@ -239,12 +242,12 @@ static void writeStringTable(raw_fd_ostream &Out, StringRef ArcName,
Out.seek(Pos);
}
static sys::TimeValue now(bool Deterministic) {
static sys::TimePoint<std::chrono::seconds> now(bool Deterministic) {
using namespace std::chrono;
if (!Deterministic)
return sys::TimeValue::now();
sys::TimeValue TV;
TV.fromEpochTime(0);
return TV;
return time_point_cast<seconds>(system_clock::now());
return sys::TimePoint<seconds>();
}
// Returns the offset of the first reference to a member offset.