File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @name Wrong metrics group in tile
3+ * @description Metrics accessed in a tile should belong to that tile
4+ * @kind problem
5+ * @problem.severity warning
6+ * @precision medium
7+ * @id asymmetric-research/metrics-wrong-group
8+ */
9+
10+ import cpp
11+
12+
13+ class Tile extends File {
14+ Tile ( ) { this .getBaseName ( ) .matches ( "%_tile.%" ) }
15+
16+ string getName ( ) {
17+ exists ( GlobalVariable v | v .getType ( ) .getName ( ) = "fd_topo_run_tile_t" |
18+ v .getLocation ( ) .getFile ( ) = this .getFile ( ) and
19+ exists ( Field f | f .hasName ( "name" ) |
20+ v .getInitializer ( )
21+ .getExpr ( )
22+ .( ClassAggregateLiteral )
23+ .getAFieldExpr ( f )
24+ .( StringLiteral )
25+ .getValue ( ) = result
26+ )
27+ )
28+ }
29+
30+ string metricsName ( ) {
31+ /* Account for renames in topology.c */
32+ if this .getLocation ( ) .getFile ( ) .getRelativePath ( ) = "src/discof/resolv/fd_resolv_tile.c"
33+ then result = "resolf"
34+ else
35+ if this .getLocation ( ) .getFile ( ) .getRelativePath ( ) = "src/discof/bank/fd_bank_tile.c"
36+ then result = "bankf"
37+ else result = this .getName ( )
38+ }
39+ }
40+
41+ from ArrayExpr arrayAccess , MacroAccess ma , Tile t , string metricsGroup
42+ where
43+ arrayAccess .getArrayBase ( ) .toString ( ) = "fd_metrics_tl" and
44+ inmacroexpansion ( arrayAccess .getArrayOffset ( ) , ma ) and
45+ ma .getMacroName ( ) .matches ( "FD_METRICS_%" ) and
46+ arrayAccess .getFile ( ) = t .getLocation ( ) .getFile ( ) and
47+ metricsGroup = ma .getMacroName ( ) .splitAt ( "_" , 3 ) and
48+ metricsGroup .toLowerCase ( ) != t .metricsName ( )
49+ select arrayAccess , "Metrics group " + metricsGroup + " unexpected for tile " + t .getName ( )
You can’t perform that action at this time.
0 commit comments