blob: 2e16933830c67500fbe8be4c23ca86204956716a [file] [log] [blame]
Gabor Greifa99be512007-07-05 17:07:56 +00001//===-- lib/Archive/ArchiveInternals.h -------------------------*- C++ -*-===//
Misha Brukman2b37d7c2005-04-21 21:13:18 +00002//
Reid Spencer362cbf02004-11-06 08:51:45 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman2b37d7c2005-04-21 21:13:18 +00007//
Reid Spencer362cbf02004-11-06 08:51:45 +00008//===----------------------------------------------------------------------===//
9//
10// Internal implementation header for LLVM Archive files.
11//
12//===----------------------------------------------------------------------===//
13
Gabor Greifa99be512007-07-05 17:07:56 +000014#ifndef LIB_ARCHIVE_ARCHIVEINTERNALS_H
15#define LIB_ARCHIVE_ARCHIVEINTERNALS_H
Reid Spencer362cbf02004-11-06 08:51:45 +000016
Chris Lattnerc1d56242007-05-06 09:28:33 +000017#include "llvm/Bitcode/Archive.h"
Reid Spencer362cbf02004-11-06 08:51:45 +000018#include "llvm/System/TimeValue.h"
Reid Spencerbc9fc842004-11-14 21:57:46 +000019#include "llvm/ADT/StringExtras.h"
Reid Spencer362cbf02004-11-06 08:51:45 +000020
Misha Brukman2b37d7c2005-04-21 21:13:18 +000021#define ARFILE_MAGIC "!<arch>\n" ///< magic string
22#define ARFILE_MAGIC_LEN (sizeof(ARFILE_MAGIC)-1) ///< length of magic string
Reid Spencer9a29db42004-11-20 07:29:40 +000023#define ARFILE_SVR4_SYMTAB_NAME "/ " ///< SVR4 symtab entry name
24#define ARFILE_LLVM_SYMTAB_NAME "#_LLVM_SYM_TAB_#" ///< LLVM symtab entry name
25#define ARFILE_BSD4_SYMTAB_NAME "__.SYMDEF SORTED" ///< BSD4 symtab entry name
26#define ARFILE_STRTAB_NAME "// " ///< Name of string table
Reid Spencerbc9fc842004-11-14 21:57:46 +000027#define ARFILE_PAD "\n" ///< inter-file align padding
28#define ARFILE_MEMBER_MAGIC "`\n" ///< fmag field magic #
Reid Spencer362cbf02004-11-06 08:51:45 +000029
30namespace llvm {
31
Gabor Greifa99be512007-07-05 17:07:56 +000032 /// The ArchiveMemberHeader structure is used internally for bitcode
Misha Brukman2b37d7c2005-04-21 21:13:18 +000033 /// archives.
34 /// The header precedes each file member in the archive. This structure is
Reid Spencer362cbf02004-11-06 08:51:45 +000035 /// defined using character arrays for direct and correct interpretation
36 /// regardless of the endianess of the machine that produced it.
37 /// @brief Archive File Member Header
38 class ArchiveMemberHeader {
Reid Spencerbc9fc842004-11-14 21:57:46 +000039 /// @name Data
40 /// @{
41 public:
Misha Brukman2b37d7c2005-04-21 21:13:18 +000042 char name[16]; ///< Name of the file member.
Reid Spencerbc9fc842004-11-14 21:57:46 +000043 char date[12]; ///< File date, decimal seconds since Epoch
44 char uid[6]; ///< user id in ASCII decimal
45 char gid[6]; ///< group id in ASCII decimal
46 char mode[8]; ///< file mode in ASCII octal
47 char size[10]; ///< file size in ASCII decimal
48 char fmag[2]; ///< Always contains ARFILE_MAGIC_TERMINATOR
49
50 /// @}
51 /// @name Methods
52 /// @{
Reid Spencer362cbf02004-11-06 08:51:45 +000053 public:
54 void init() {
55 memset(name,' ',16);
56 memset(date,' ',12);
57 memset(uid,' ',6);
58 memset(gid,' ',6);
59 memset(mode,' ',8);
60 memset(size,' ',10);
61 fmag[0] = '`';
62 fmag[1] = '\n';
63 }
Reid Spencer362cbf02004-11-06 08:51:45 +000064
Reid Spencerbc9fc842004-11-14 21:57:46 +000065 bool checkSignature() {
66 return 0 == memcmp(fmag, ARFILE_MEMBER_MAGIC,2);
Reid Spencer362cbf02004-11-06 08:51:45 +000067 }
Reid Spencer362cbf02004-11-06 08:51:45 +000068 };
Chris Lattnerf36c7b82007-02-07 23:53:17 +000069
Gabor Greifa99be512007-07-05 17:07:56 +000070 // Get just the externally visible defined symbols from the bitcode
71 bool GetBitcodeSymbols(const sys::Path& fName,
Chris Lattnerf36c7b82007-02-07 23:53:17 +000072 std::vector<std::string>& symbols,
Chris Lattnerc1d56242007-05-06 09:28:33 +000073 std::string* ErrMsg);
Chris Lattnerf36c7b82007-02-07 23:53:17 +000074
Gabor Greifa99be512007-07-05 17:07:56 +000075 ModuleProvider* GetBitcodeSymbols(const unsigned char*Buffer,unsigned Length,
76 const std::string& ModuleID,
77 std::vector<std::string>& symbols,
78 std::string* ErrMsg);
Reid Spencer362cbf02004-11-06 08:51:45 +000079}
80
81#endif
82
83// vim: sw=2 ai