80
80
#include < iostream>
81
81
#include < memory>
82
82
#include < queue>
83
+ #include < regex>
83
84
#include < set>
84
85
#include < vector>
85
86
@@ -1584,30 +1585,32 @@ std::vector<std::pair<Decoration, std::string>>
1584
1585
tryParseIntelFPGAAnnotationString (StringRef AnnotatedCode) {
1585
1586
std::vector<std::pair<Decoration, std::string>> Decorates;
1586
1587
1587
- size_t OpenBracketNum = AnnotatedCode.count (' {' );
1588
- size_t CloseBracketNum = AnnotatedCode.count (' }' );
1589
- if (OpenBracketNum != CloseBracketNum)
1590
- return {};
1591
-
1592
- for (size_t I = 0 ; I < OpenBracketNum; ++I) {
1593
- size_t From = AnnotatedCode.find (' {' );
1594
- size_t To = AnnotatedCode.find (' }' , From);
1595
- StringRef AnnotatedDecoration = AnnotatedCode.substr (From + 1 , To - 1 );
1596
- std::pair<StringRef, StringRef> D = AnnotatedDecoration.split (' :' );
1597
-
1598
- StringRef F = D.first , S = D.second ;
1599
- StringRef Value;
1588
+ // Intel FPGA decorations are separated into
1589
+ // {word} OR {word:value,value,...} blocks
1590
+ std::regex DecorationRegex (" \\ {[\\ w:,]+\\ }" );
1591
+ using RegexIterT = std::regex_iterator<StringRef::const_iterator>;
1592
+ RegexIterT DecorationsIt (AnnotatedCode.begin (), AnnotatedCode.end (),
1593
+ DecorationRegex);
1594
+ RegexIterT DecorationsEnd;
1595
+ for (; DecorationsIt != DecorationsEnd; ++DecorationsIt) {
1596
+ // Drop the braces surrounding the actual decoration
1597
+ const StringRef AnnotatedDecoration = AnnotatedCode.substr (
1598
+ DecorationsIt->position () + 1 , DecorationsIt->length () - 2 );
1599
+ std::pair<StringRef, StringRef> Split = AnnotatedDecoration.split (' :' );
1600
+ StringRef Name = Split.first , ValueStr = Split.second ;
1601
+
1602
+ StringRef Annotation;
1600
1603
Decoration Dec;
1601
- if (F == " pump" ) {
1602
- Dec = llvm::StringSwitch<Decoration>(S )
1604
+ if (Name == " pump" ) {
1605
+ Dec = llvm::StringSwitch<Decoration>(ValueStr )
1603
1606
.Case (" 1" , DecorationSinglepumpINTEL)
1604
1607
.Case (" 2" , DecorationDoublepumpINTEL);
1605
- } else if (F == " register" ) {
1608
+ } else if (Name == " register" ) {
1606
1609
Dec = DecorationRegisterINTEL;
1607
- } else if (F == " simple_dual_port" ) {
1610
+ } else if (Name == " simple_dual_port" ) {
1608
1611
Dec = DecorationSimpleDualPortINTEL;
1609
1612
} else {
1610
- Dec = llvm::StringSwitch<Decoration>(F )
1613
+ Dec = llvm::StringSwitch<Decoration>(Name )
1611
1614
.Case (" memory" , DecorationMemoryINTEL)
1612
1615
.Case (" numbanks" , DecorationNumbanksINTEL)
1613
1616
.Case (" bankwidth" , DecorationBankwidthINTEL)
@@ -1618,13 +1621,12 @@ tryParseIntelFPGAAnnotationString(StringRef AnnotatedCode) {
1618
1621
.Case (" force_pow2_depth" , DecorationForcePow2DepthINTEL)
1619
1622
.Default (DecorationUserSemantic);
1620
1623
if (Dec == DecorationUserSemantic)
1621
- Value = AnnotatedCode. substr (From, To + 1 ) ;
1624
+ Annotation = AnnotatedDecoration ;
1622
1625
else
1623
- Value = S ;
1626
+ Annotation = ValueStr ;
1624
1627
}
1625
1628
1626
- Decorates.emplace_back (Dec, Value.str ());
1627
- AnnotatedCode = AnnotatedCode.drop_front (To + 1 );
1629
+ Decorates.emplace_back (Dec, Annotation.str ());
1628
1630
}
1629
1631
return Decorates;
1630
1632
}
0 commit comments