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/MC/MCContext.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/MC/MCContext.h')
| -rw-r--r-- | backend/include/rcc/MC/MCContext.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/backend/include/rcc/MC/MCContext.h b/backend/include/rcc/MC/MCContext.h new file mode 100644 index 0000000..e9b2d90 --- /dev/null +++ b/backend/include/rcc/MC/MCContext.h @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef RCC_MC_MCCONTEXT_H +#define RCC_MC_MCCONTEXT_H + +#include "rcc/MC/MCSection.h" +#include "rcc/MC/MCSymbol.h" +#include "rcc/Support/Error.h" + +#include <cstdint> +#include <functional> +#include <string> +#include <string_view> +#include <unordered_map> + +namespace rcc::mc { + +class MCContext final { +public: + [[nodiscard]] Expected<MCSymbolRef> getOrCreateSymbol(std::string Name, MCSymbolKind Kind); + [[nodiscard]] Expected<MCSymbolRef> createTemporarySymbol(std::string_view Prefix); + [[nodiscard]] MCSymbolRef symbol(std::string_view Name) const noexcept; + + [[nodiscard]] Expected<MCSectionRef> getOrCreateSection(MCSectionDesc Description); + [[nodiscard]] MCSectionRef section(std::string_view Name) const noexcept; + +private: + struct StringHash final { + using is_transparent = void; // NOLINT(readability-identifier-naming) + + [[nodiscard]] std::size_t operator()(std::string_view Value) const noexcept { + return std::hash<std::string_view>{}(Value); + } + }; + + std::unordered_map<std::string, MCSymbolRef, StringHash, std::equal_to<>> Symbols; + std::unordered_map<std::string, MCSectionRef, StringHash, std::equal_to<>> Sections; + std::uint64_t NextTemporarySymbol = 0; +}; + +} // namespace rcc::mc + +#endif // RCC_MC_MCCONTEXT_H |
