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