src/objectemitter/AbstractObjectEmitter.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include <filesystem> | ||
| 6 | #include <string> | ||
| 7 | |||
| 8 | // Forward declarations | ||
| 9 | namespace llvm { | ||
| 10 | class Module; | ||
| 11 | } // namespace llvm | ||
| 12 | |||
| 13 | namespace spice::compiler { | ||
| 14 | |||
| 15 | /** | ||
| 16 | * Abstract interface implemented by every concrete object emitter (LLVM CodeGen, TPDE, ...). | ||
| 17 | * | ||
| 18 | * Kept intentionally free of Spice-internal headers so it can be inherited by TUs that are compiled | ||
| 19 | * with -fno-rtti (in particular the TPDE emitter, which has to match TPDE's compile-option ABI). | ||
| 20 | */ | ||
| 21 | class AbstractObjectEmitter { | ||
| 22 | public: | ||
| 23 | // Destructor | ||
| 24 | 2127 | virtual ~AbstractObjectEmitter() = default; | |
| 25 | |||
| 26 | // Delete copies — object emitters own compile-time state and are always used as short-lived | ||
| 27 | // stack objects at their construction site. | ||
| 28 | AbstractObjectEmitter(const AbstractObjectEmitter &) = delete; | ||
| 29 | AbstractObjectEmitter &operator=(const AbstractObjectEmitter &) = delete; | ||
| 30 | |||
| 31 | /** | ||
| 32 | * Emit an object file for the module associated with this emitter. | ||
| 33 | * | ||
| 34 | * @param objectPath Filesystem path where the object file should be written. | ||
| 35 | */ | ||
| 36 | virtual void emit(const std::filesystem::path &objectPath) const = 0; | ||
| 37 | |||
| 38 | /** | ||
| 39 | * Write a textual representation of the emitter's output into @p output. LLVM CodeGen emits | ||
| 40 | * a real assembly listing here; TPDE (which produces object bytes directly) returns a | ||
| 41 | * placeholder note. | ||
| 42 | * | ||
| 43 | * @param output Destination string, cleared/filled by the emitter. | ||
| 44 | */ | ||
| 45 | virtual void getASMString(std::string &output) const = 0; | ||
| 46 | |||
| 47 | protected: | ||
| 48 | 2127 | AbstractObjectEmitter() = default; | |
| 49 | }; | ||
| 50 | |||
| 51 | } // namespace spice::compiler | ||
| 52 |