-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathConstantEmitter.h
66 lines (54 loc) · 2.1 KB
/
ConstantEmitter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2018 The Clspv Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CLSPV_LIB_CONSTANT_EMITTER_H
#define CLSPV_LIB_CONSTANT_EMITTER_H
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/Support/raw_ostream.h"
namespace clspv {
// A Constant value emitter. Emit the bytes of a constant as if it were
// laid out in memory, converted to hexadecimal.
class ConstantEmitter {
public:
ConstantEmitter(const llvm::DataLayout &DL, llvm::raw_ostream &out)
: Layout(DL), Out(out), Offset(0) {}
void Emit(llvm::Constant *c);
private:
// Emit |n| zeroes.
void EmitZeroes(size_t n);
// Emit just enough zeros to align to the given alignment.
void AlignTo(size_t alignment);
void EmitStruct(llvm::ConstantStruct *c);
// ConstantDataSequential is an LLVM optimization for smallish numeric
// arrays and vectors.
void EmitDataSequential(llvm::ConstantDataSequential *c);
// Aggregate covers both Array and (general) Vector
void EmitAggregate(llvm::ConstantAggregate *c);
void EmitAggregateZero(llvm::ConstantAggregateZero *c);
void EmitInt(llvm::ConstantInt *c);
void EmitFP(llvm::ConstantFP *c);
// Emit bytes representing the first num_bits bits from the
// array at |data|.
void EmitRaw(unsigned num_bits, const uint64_t *data);
// Emit a byte as a hex number to the output stream.
void EmitByte(size_t byte);
const llvm::DataLayout &Layout;
// The output stream.
llvm::raw_ostream &Out;
// Offset into the memory layout in memory.
size_t Offset;
};
} // namespace clspv
#endif