blob: 7ba30244a2138084fcdeb360810ec6d9bd7f3aa3 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- lib/Archive/ArchiveInternals.h -------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// Internal implementation header for LLVM Archive files.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LIB_ARCHIVE_ARCHIVEINTERNALS_H
15#define LIB_ARCHIVE_ARCHIVEINTERNALS_H
16
17#include "llvm/Bitcode/Archive.h"
18#include "llvm/System/TimeValue.h"
19#include "llvm/ADT/StringExtras.h"
20
Anton Korobeynikov357a27d2008-02-20 11:08:44 +000021#include <cstring>
22
Dan Gohmanf17a25c2007-07-18 16:29:46 +000023#define ARFILE_MAGIC "!<arch>\n" ///< magic string
24#define ARFILE_MAGIC_LEN (sizeof(ARFILE_MAGIC)-1) ///< length of magic string
25#define ARFILE_SVR4_SYMTAB_NAME "/ " ///< SVR4 symtab entry name
26#define ARFILE_LLVM_SYMTAB_NAME "#_LLVM_SYM_TAB_#" ///< LLVM symtab entry name
27#define ARFILE_BSD4_SYMTAB_NAME "__.SYMDEF SORTED" ///< BSD4 symtab entry name
28#define ARFILE_STRTAB_NAME "// " ///< Name of string table
29#define ARFILE_PAD "\n" ///< inter-file align padding
30#define ARFILE_MEMBER_MAGIC "`\n" ///< fmag field magic #
31
32namespace llvm {
33
34 /// The ArchiveMemberHeader structure is used internally for bitcode
35 /// archives.
36 /// The header precedes each file member in the archive. This structure is
37 /// defined using character arrays for direct and correct interpretation
38 /// regardless of the endianess of the machine that produced it.
39 /// @brief Archive File Member Header
40 class ArchiveMemberHeader {
41 /// @name Data
42 /// @{
43 public:
44 char name[16]; ///< Name of the file member.
45 char date[12]; ///< File date, decimal seconds since Epoch
46 char uid[6]; ///< user id in ASCII decimal
47 char gid[6]; ///< group id in ASCII decimal
48 char mode[8]; ///< file mode in ASCII octal
49 char size[10]; ///< file size in ASCII decimal
50 char fmag[2]; ///< Always contains ARFILE_MAGIC_TERMINATOR
51
52 /// @}
53 /// @name Methods
54 /// @{
55 public:
56 void init() {
57 memset(name,' ',16);
58 memset(date,' ',12);
59 memset(uid,' ',6);
60 memset(gid,' ',6);
61 memset(mode,' ',8);
62 memset(size,' ',10);
63 fmag[0] = '`';
64 fmag[1] = '\n';
65 }
66
67 bool checkSignature() {
68 return 0 == memcmp(fmag, ARFILE_MEMBER_MAGIC,2);
69 }
70 };
71
72 // Get just the externally visible defined symbols from the bitcode
73 bool GetBitcodeSymbols(const sys::Path& fName,
74 std::vector<std::string>& symbols,
75 std::string* ErrMsg);
76
77 ModuleProvider* GetBitcodeSymbols(const unsigned char*Buffer,unsigned Length,
78 const std::string& ModuleID,
79 std::vector<std::string>& symbols,
80 std::string* ErrMsg);
81}
82
83#endif
84
85// vim: sw=2 ai