diff options
Diffstat (limited to 'backend/lib/MIR')
| -rw-r--r-- | backend/lib/MIR/EmbeddedIR.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/backend/lib/MIR/EmbeddedIR.cpp b/backend/lib/MIR/EmbeddedIR.cpp index d936d66..67b91e2 100644 --- a/backend/lib/MIR/EmbeddedIR.cpp +++ b/backend/lib/MIR/EmbeddedIR.cpp @@ -9,6 +9,7 @@ #include <optional> #include <string> #include <string_view> +#include <unordered_set> #include <utility> namespace rcc::mir { @@ -185,6 +186,7 @@ public: return failureResult(); } + resolveFunctionAttributes(); validateLocalReferences(); if (Failed) return failureResult(); @@ -350,6 +352,10 @@ private: parseFunctionHeader(Line, LineOffset, Position, End, false); return; } + if (startsWord(Line, Position, End, "attributes")) { + parseAttributeGroup(Line, LineOffset, Position, End); + return; + } if (Line[Position] == '@') { parseGlobalObject(Line, LineOffset, Position, End); return; @@ -531,6 +537,19 @@ private: } if (InQuote) continue; + if (HeaderParenthesisDepth == 0 && startsWord(Line, Position, End, "minsize")) { + Index.Functions[ActiveFunction.value()].HasMinSize = true; + Position += std::string_view("minsize").size() - 1U; + continue; + } + if (HeaderParenthesisDepth == 0 && Character == '#') { + auto Group = parseIdentifier(Line, LineOffset, Position, End, '#'); + if (!Group || Failed) + return; + Index.Functions[ActiveFunction.value()].AttributeGroup = std::move(Group->Name); + Position = Group->End - 1U; + continue; + } if (Character == '%' && HeaderParenthesisDepth != 0 && ActiveFunction) { const std::size_t IdentifierBegin = Position; auto Name = parseIdentifier(Line, LineOffset, Position, End, '%'); @@ -801,6 +820,25 @@ private: } } + void parseAttributeGroup(std::string_view Line, std::size_t LineOffset, std::size_t Position, + std::size_t End) { + Position += std::string_view("attributes").size(); + Position = skipHorizontalSpace(Line, Position, End); + auto Group = parseIdentifier(Line, LineOffset, Position, End, '#'); + if (!Group || Failed) + return; + if (containsWord(Line, End, "minsize")) + MinSizeAttributeGroups.insert(std::move(Group->Name)); + } + + void resolveFunctionAttributes() { + for (EmbeddedIRFunction &Function : Index.Functions) { + if (Function.AttributeGroup && MinSizeAttributeGroups.contains(*Function.AttributeGroup)) { + Function.HasMinSize = true; + } + } + } + void parseGlobalObject(std::string_view Line, std::size_t LineOffset, std::size_t Position, std::size_t End) { auto Name = parseIdentifier(Line, LineOffset, Position, End, '@'); @@ -893,6 +931,7 @@ private: EmbeddedIRReferenceIndex Index; std::vector<TextDiagnostic> Diagnostics; std::optional<std::size_t> ActiveFunction; + std::unordered_set<std::string> MinSizeAttributeGroups; std::size_t HeaderParenthesisDepth = 0; std::size_t FunctionBraceDepth = 0; bool Failed = false; |
