Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: src/IceELFStreamer.h

Issue 678533005: Subzero: Add basic ELFObjectWriter (text section, symtab, strtab, headers) (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: minor cleanup Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceELFSection.cpp ('k') | src/IceGlobalContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 //===- subzero/src/IceELFStreamer.h - Low level ELF writing -----*- C++ -*-===//
2 //
3 // The Subzero Code Generator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Interface for serializing bits for common ELF types (words, extended words,
11 // etc.), based on the ELF Class.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef SUBZERO_SRC_ICEELFSTREAMER_H
16 #define SUBZERO_SRC_ICEELFSTREAMER_H
17
18 #include "IceDefs.h"
19
20 namespace Ice {
21
22 // Low level writer that can that can handle ELFCLASS32/64.
23 // Little endian only for now.
24 class ELFStreamer {
25 public:
26 explicit ELFStreamer(Fdstream &Out) : Out(Out) {}
27
28 void write8(uint8_t Value) { Out << char(Value); }
29
30 void writeLE16(uint16_t Value) {
31 write8(uint8_t(Value));
32 write8(uint8_t(Value >> 8));
33 }
34
35 void writeLE32(uint32_t Value) {
36 writeLE16(uint16_t(Value));
37 writeLE16(uint16_t(Value >> 16));
38 }
39
40 void writeLE64(uint64_t Value) {
41 writeLE32(uint32_t(Value));
42 writeLE32(uint32_t(Value >> 32));
43 }
44
45 template <bool IsELF64, typename T> void writeAddrOrOffset(T Value) {
46 if (IsELF64)
47 writeLE64(Value);
48 else
49 writeLE32(Value);
50 }
51
52 template <bool IsELF64, typename T> void writeELFWord(T Value) {
53 writeLE32(Value);
54 }
55
56 template <bool IsELF64, typename T> void writeELFXword(T Value) {
57 if (IsELF64)
58 writeLE64(Value);
59 else
60 writeLE32(Value);
61 }
62
63 void writeBytes(llvm::StringRef Bytes) { Out << Bytes; }
64
65 void writeZeroPadding(SizeT N) {
66 static const char Zeros[16] = {0};
67
68 for (SizeT i = 0, e = N / 16; i != e; ++i)
69 Out << llvm::StringRef(Zeros, 16);
70
71 Out << llvm::StringRef(Zeros, N % 16);
72 }
73
74 uint64_t tell() const { return Out.tell(); }
75
76 void seek(uint64_t Off) { Out.seek(Off); }
77
78 private:
79 Fdstream &Out;
80 };
81
82 } // end of namespace Ice
83
84 #endif // SUBZERO_SRC_ICEELFSTREAMER_H
OLDNEW
« no previous file with comments | « src/IceELFSection.cpp ('k') | src/IceGlobalContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698