#ifndef COURGETTE_INSTRUCTION_UTILS_H_
#define COURGETTE_INSTRUCTION_UTILS_H_
#include <stdint.h>
#include "base/functional/callback.h"
#include "courgette/image_utils.h"
#include "courgette/memory_allocator.h"
namespace courgette {
class InstructionReceptor {
public:
InstructionReceptor() = default;
InstructionReceptor(const InstructionReceptor&) = delete;
InstructionReceptor& operator=(const InstructionReceptor&) = delete;
virtual ~InstructionReceptor() = default;
virtual CheckBool EmitPeRelocs() = 0;
virtual CheckBool EmitElfRelocation() = 0;
virtual CheckBool EmitOrigin(RVA rva) = 0;
virtual CheckBool EmitSingleByte(uint8_t byte) = 0;
virtual CheckBool EmitMultipleBytes(const uint8_t* bytes, size_t len) = 0;
virtual CheckBool EmitRel32(Label* label) = 0;
virtual CheckBool EmitAbs32(Label* label) = 0;
virtual CheckBool EmitAbs64(Label* label) = 0;
};
using InstructionGenerator =
base::RepeatingCallback<CheckBool(InstructionReceptor*)>;
template <typename T>
class CountingVector {
public:
CountingVector() {}
void push_back(const T& ) { ++size_; }
size_t size() const { return size_; }
private:
size_t size_ = 0;
};
}
#endif