diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-09 18:31:49 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-09 18:31:49 +0800 |
| commit | 379ff50dcc7ccf977379aee68fa9d10f69065d23 (patch) | |
| tree | e0fac3952d46d0bbcaea32bcfc6087c95fff2992 /backend/include/rcc/CodeGen/MachineMCContext.h | |
| parent | 495c675771f43cfa12ab7a426a538be72fec1805 (diff) | |
| download | rcc-project-379ff50dcc7ccf977379aee68fa9d10f69065d23.tar.gz rcc-project-379ff50dcc7ccf977379aee68fa9d10f69065d23.tar.xz | |
[MC] Implement RV64GC assembly emission
Diffstat (limited to 'backend/include/rcc/CodeGen/MachineMCContext.h')
| -rw-r--r-- | backend/include/rcc/CodeGen/MachineMCContext.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/backend/include/rcc/CodeGen/MachineMCContext.h b/backend/include/rcc/CodeGen/MachineMCContext.h new file mode 100644 index 0000000..2464dc5 --- /dev/null +++ b/backend/include/rcc/CodeGen/MachineMCContext.h @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef RCC_CODEGEN_MACHINEMCCONTEXT_H +#define RCC_CODEGEN_MACHINEMCCONTEXT_H + +#include "rcc/CodeGen/MachineIRTypes.h" +#include "rcc/MC/MCContext.h" +#include "rcc/MC/MCSymbol.h" +#include "rcc/Support/Error.h" + +#include <string> +#include <string_view> +#include <unordered_map> + +namespace rcc { + +class CompilationUnit; +struct GlobalObjectDesc; +class MachineBasicBlock; +class MachineFunction; + +class MachineMCContext final { +public: + explicit MachineMCContext(mc::MCContext &Context) noexcept : Context(&Context) {} + + [[nodiscard]] Expected<void> initialize(const CompilationUnit &Unit); + [[nodiscard]] Expected<void> initializeFunction(const MachineFunction &Function); + + [[nodiscard]] mc::MCSymbolRef functionSymbol(const MachineFunction &Function) const noexcept; + [[nodiscard]] mc::MCSymbolRef globalSymbol(const GlobalObjectDesc &Object) const noexcept; + [[nodiscard]] mc::MCSymbolRef blockSymbol(const MachineBasicBlock &Block) const noexcept; + [[nodiscard]] mc::MCSymbolRef constantPoolSymbol(const MachineFunction &Function, + ConstantPoolIndex Index) const noexcept; + [[nodiscard]] mc::MCSymbolRef jumpTableSymbol(const MachineFunction &Function, + JumpTableIndex Index) const noexcept; + + [[nodiscard]] Expected<mc::MCSymbolRef> symbol(std::string Name, + mc::MCSymbolKind Kind = mc::MCSymbolKind::Generic); + [[nodiscard]] Expected<mc::MCSymbolRef> blockAddressSymbol(std::string_view FunctionName, + std::string_view BlockName) const; + + [[nodiscard]] mc::MCContext &context() const noexcept { + return *Context; + } + +private: + struct FunctionIndexKey final { + const MachineFunction *Function = nullptr; + std::uint32_t Index = 0; + + friend bool operator==(FunctionIndexKey Left, FunctionIndexKey Right) noexcept = default; + }; + + struct FunctionIndexHash final { + [[nodiscard]] std::size_t operator()(FunctionIndexKey Key) const noexcept; + }; + + mc::MCContext *Context; + std::unordered_map<const MachineFunction *, mc::MCSymbolRef> FunctionSymbols; + std::unordered_map<const GlobalObjectDesc *, mc::MCSymbolRef> GlobalSymbols; + std::unordered_map<const MachineBasicBlock *, mc::MCSymbolRef> BlockSymbols; + std::unordered_map<FunctionIndexKey, mc::MCSymbolRef, FunctionIndexHash> ConstantPoolSymbols; + std::unordered_map<FunctionIndexKey, mc::MCSymbolRef, FunctionIndexHash> JumpTableSymbols; +}; + +} // namespace rcc + +#endif // RCC_CODEGEN_MACHINEMCCONTEXT_H |
