LLVM  15.0.0git
WasmWriter.h
Go to the documentation of this file.
1 //===- WasmWriter.h ---------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_LIB_OBJCOPY_WASM_WASMWRITER_H
10 #define LLVM_LIB_OBJCOPY_WASM_WASMWRITER_H
11 
12 #include "WasmObject.h"
13 #include <cstdint>
14 #include <vector>
15 
16 namespace llvm {
17 namespace objcopy {
18 namespace wasm {
19 
20 class Writer {
21 public:
22  Writer(Object &Obj, raw_ostream &Out) : Obj(Obj), Out(Out) {}
23  Error write();
24 
25 private:
26  using SectionHeader = SmallVector<char, 8>;
27  Object &Obj;
28  raw_ostream &Out;
29  std::vector<SectionHeader> SectionHeaders;
30 
31  /// Generate a wasm section section header for S.
32  /// The header consists of
33  /// * A one-byte section ID (aka the section type).
34  /// * The size of the section contents, encoded as ULEB128.
35  /// * If the section is a custom section (type 0) it also has a name, which is
36  /// encoded as a length-prefixed string. The encoded section size *includes*
37  /// this string.
38  /// See https://webassembly.github.io/spec/core/binary/modules.html#sections
39  /// Return the header and store the total size in SectionSize.
40  static SectionHeader createSectionHeader(const Section &S,
41  size_t &SectionSize);
42  size_t finalize();
43 };
44 
45 } // end namespace wasm
46 } // end namespace objcopy
47 } // end namespace llvm
48 
49 #endif // LLVM_LIB_OBJCOPY_WASM_WASMWRITER_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::objcopy::wasm::Writer::Writer
Writer(Object &Obj, raw_ostream &Out)
Definition: WasmWriter.h:22
llvm::objcopy::wasm::Section
Definition: WasmObject.h:22
llvm::COFF::SectionSize
@ SectionSize
Definition: COFF.h:60
llvm::objcopy::wasm::Object
Definition: WasmObject.h:30
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::objcopy::wasm::Writer
Definition: WasmWriter.h:20
llvm::objcopy::wasm::Writer::write
Error write()
Definition: WasmWriter.cpp:57
WasmObject.h