1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

Implementation declarations for Archive

llvm-svn: 17766
This commit is contained in:
Reid Spencer 2004-11-14 21:57:46 +00:00
parent 131f129398
commit 0a3e3a41c3

View File

@ -16,21 +16,39 @@
#include "llvm/Bytecode/Archive.h"
#include "llvm/System/TimeValue.h"
#include "llvm/ADT/StringExtras.h"
#define ARFILE_MAGIC "!<arch>\n" ///< magic string
#define ARFILE_MAGIC_LEN (sizeof(ARFILE_MAGIC)-1) ///< length of magic string
#define ARFILE_SYMTAB_NAME "/" ///< name of symtab entry
#define ARFILE_STRTAB_NAME "//" ///< name of strtab entry
#define ARFILE_PAD '\n' ///< inter-file align padding
#define ARFILE_SYMTAB_NAME "/ " ///< regular symtab entry
#define ARFILE_STRTAB_NAME "// " ///< Name of string table
#define ARFILE_LLVM_SYMTAB_NAME "#_LLVM_SYM_TAB_#" ///< LLVM's symtab entry
#define ARFILE_PAD "\n" ///< inter-file align padding
#define ARFILE_MEMBER_MAGIC "`\n" ///< fmag field magic #
namespace llvm {
/// The ArchiveMemberHeader structure is used internally for bytecode archives.
/// The ArchiveMemberHeader structure is used internally for bytecode
/// archives.
/// The header precedes each file member in the archive. This structure is
/// defined using character arrays for direct and correct interpretation
/// regardless of the endianess of the machine that produced it.
/// @brief Archive File Member Header
class ArchiveMemberHeader {
/// @name Data
/// @{
public:
char name[16];///< Name of the file member.
char date[12]; ///< File date, decimal seconds since Epoch
char uid[6]; ///< user id in ASCII decimal
char gid[6]; ///< group id in ASCII decimal
char mode[8]; ///< file mode in ASCII octal
char size[10]; ///< file size in ASCII decimal
char fmag[2]; ///< Always contains ARFILE_MAGIC_TERMINATOR
/// @}
/// @name Methods
/// @{
public:
void init() {
memset(name,' ',16);
@ -42,115 +60,13 @@ namespace llvm {
fmag[0] = '`';
fmag[1] = '\n';
}
void setDate( int secondsSinceEpoch = 0 ) {
if (secondsSinceEpoch == 0) {
sys::TimeValue tv = sys::TimeValue::now();
uint64_t secs; uint32_t nanos;
tv.GetTimespecTime(secs,nanos);
secondsSinceEpoch = (int) secs;
}
char buffer[20];
sprintf(buffer,"%d", secondsSinceEpoch);
memcpy(date,buffer,strlen(buffer));
}
void setSize(size_t sz) {
char buffer[20];
sprintf(buffer, "%u", (unsigned)sz);
memcpy(size,buffer,strlen(buffer));
bool checkSignature() {
return 0 == memcmp(fmag, ARFILE_MEMBER_MAGIC,2);
}
void setMode(int m) {
char buffer[20];
sprintf(buffer, "%o", m);
memcpy(mode,buffer,strlen(buffer));
}
void setUid(unsigned u) {
char buffer[20];
sprintf(buffer, "%u", u);
memcpy(uid,buffer,strlen(buffer));
}
void setGid(unsigned g) {
char buffer[20];
sprintf(buffer, "%u", g);
memcpy(gid,buffer,strlen(buffer));
}
bool setName(const std::string& nm) {
if (nm.length() > 0 && nm.length() <= 16) {
memcpy(name,nm.c_str(),nm.length());
for (int i = nm.length()+1; i < 16; i++ ) name[i] = ' ';
return true;
}
return false;
}
private:
char name[16]; ///< Name of the file member. The filename is terminated with '/'
///< and blanks. The empty name (/ and 15 blanks) is for the
///< symbol table. The special name "//" and 15 blanks is for
///< the string table, used for long file names. It must be
///< first in the archive.
char date[12]; ///< File date, decimal seconds since Epoch
char uid[6]; ///< user id in ASCII decimal
char gid[6]; ///< group id in ASCII decimal
char mode[8]; ///< file mode in ASCII octal
char size[10]; ///< file size in ASCII decimal
char fmag[2]; ///< Always contains ARFILE_MAGIC_TERMINATOR
};
/// The ArchiveInternals class is used to hold the content of the archive
/// while it is in memory. It also provides the bulk of the implementation for
/// the llvm:Archive class's interface.
class Archive::ArchiveInternals {
/// @name Types
/// @{
public:
typedef std::vector<std::string> StrTab;
/// This structure holds information for one member in the archive. It is
/// used temporarily while the contents of the archive are being
/// determined.
struct MemberInfo {
MemberInfo() {}
sys::Path path;
std::string name;
sys::Path::StatusInfo status;
StrTab symbols;
unsigned offset;
};
/// @}
/// @name Methods
/// @{
public:
/// @brief Add a file member to the archive.
void addFileMember(
const sys::Path& path, ///< The path to the file to be added
const std::string& name, ///< The name for the member
const StrTab* syms = 0 ///< The symbol table of the member
);
/// @brief Write the accumulated archive information to an archive file
void writeArchive();
void writeMember(const MemberInfo& member,std::ofstream& ARFile);
void writeSymbolTable(std::ofstream& ARFile);
void writeInteger(int num, std::ofstream& ARFile);
/// @}
/// @name Data
/// @{
private:
friend class Archive; ///< Parent class is a friend
sys::Path fname; ///< Path to the archive file
std::vector<MemberInfo> members; ///< Info about member files
Archive::SymTab* symtab; ///< User's symbol table
/// @}
};
}
#endif