From befde76cfa46c766e81f74eb5ac65d3dae2dde87 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 19 Apr 2025 17:33:26 +0200 Subject: dev, LibCompiler, tooling: refactor and separate components into modules (cppdrv, cxxdrv) Signed-off-by: Amlal El Mahrouss --- dev/LibCompiler/NFC/AE.h | 142 ----------------------------------------------- 1 file changed, 142 deletions(-) delete mode 100644 dev/LibCompiler/NFC/AE.h (limited to 'dev/LibCompiler/NFC/AE.h') diff --git a/dev/LibCompiler/NFC/AE.h b/dev/LibCompiler/NFC/AE.h deleted file mode 100644 index fdf42a5..0000000 --- a/dev/LibCompiler/NFC/AE.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - * ======================================================== - * - * LibCompiler - * Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved. - * - * ======================================================== - */ - -#pragma once - -#include - -#define kAEMag0 'A' -#define kAEMag1 'E' - -#define kAESymbolLen (255) -#define kAEPad (8) -#define kAEMagLen (2) -#define kAENullType (0x00) - -// Advanced Executable File Format for ld64. -// Reloctable by offset is the default strategy. -// You can also relocate at runtime but that's up to the operating system loader. - -namespace LibCompiler -{ - // @brief Advanced Executable Header - // One thing to keep in mind. - // This object format, is reloctable. - typedef struct AEHeader final - { - CharType fMagic[kAEMagLen]; - CharType fArch; - CharType fSubArch; - SizeType fCount; - CharType fSize; - SizeType fStartCode; - SizeType fCodeSize; - CharType fPad[kAEPad]; - } PACKED AEHeader, *AEHeaderPtr; - - // @brief Advanced Executable Record. - // Could be data, code or bss. - // fKind must be filled with PEF fields. - - typedef struct AERecordHeader final - { - CharType fName[kAESymbolLen]; - SizeType fKind; - SizeType fSize; - SizeType fFlags; - UIntPtr fOffset; - CharType fPad[kAEPad]; - } PACKED AERecordHeader, *AERecordHeaderPtr; - - enum - { - kKindRelocationByOffset = 0x23f, - kKindRelocationAtRuntime = 0x34f, - }; -} // namespace LibCompiler - -// provide operator<< for AE - -inline std::ofstream& operator<<(std::ofstream& fp, LibCompiler::AEHeader& container) -{ - fp.write((char*)&container, sizeof(LibCompiler::AEHeader)); - - return fp; -} - -inline std::ofstream& operator<<(std::ofstream& fp, - LibCompiler::AERecordHeader& container) -{ - fp.write((char*)&container, sizeof(LibCompiler::AERecordHeader)); - - return fp; -} - -inline std::ifstream& operator>>(std::ifstream& fp, LibCompiler::AEHeader& container) -{ - fp.read((char*)&container, sizeof(LibCompiler::AEHeader)); - return fp; -} - -inline std::ifstream& operator>>(std::ifstream& fp, - LibCompiler::AERecordHeader& container) -{ - fp.read((char*)&container, sizeof(LibCompiler::AERecordHeader)); - return fp; -} - -namespace LibCompiler::Utils -{ - /** - * @brief AE Reader protocol - * - */ - class AEReadableProtocol final - { - public: - std::ifstream FP; - - public: - explicit AEReadableProtocol() = default; - ~AEReadableProtocol() = default; - - LIBCOMPILER_COPY_DELETE(AEReadableProtocol); - - /** - * @brief Read AE Record headers. - * - * @param raw the containing buffer - * @param sz it's size (1 = one AERecordHeader, 2 two AERecordHeader(s)) - * @return AERecordHeaderPtr - */ - AERecordHeaderPtr Read(char* raw, std::size_t sz) - { - if (!raw) - return nullptr; - - return this->_Read(raw, sz * sizeof(AERecordHeader)); - } - - private: - /** - * @brief Implementation of Read for raw classes. - * - * @tparam TypeClass The class to read. - * @param raw the buffer - * @param sz the size - * @return TypeClass* the returning class. - */ - template - TypeClass* _Read(char* raw, std::size_t sz) - { - FP.read(raw, std::streamsize(sz)); - return reinterpret_cast(raw); - } - }; -} // namespace LibCompiler::Utils -- cgit v1.2.3