@@ -23,11 +23,13 @@ import scala.collection.mutable.ListBuffer
2323
2424object Query {
2525 private val tables = ListBuffer .empty[QueryTable ]
26+ private var batchTable : Option [BatchQueryTable ] = None
2627 def register (gen : DifftestBundle , locPrefix : String , dutZone : String ) = {
2728 tables += new QueryTable (gen, locPrefix, dutZone)
2829 }
29- def register (gens : Seq [DifftestBundle ], locPrefix : String , dutZone : String ) = {
30+ def registerBatch (gens : Seq [DifftestBundle ], locPrefix : String , dutZone : String ) = {
3031 gens.foreach { gen => tables += new QueryTable (gen, locPrefix, dutZone) }
32+ batchTable = Some (new BatchQueryTable (gens))
3133 }
3234 def writeInvoke (gen : DifftestBundle ): String = {
3335 tables.find(_.gen == gen).get.writeInvoke
@@ -51,11 +53,15 @@ object Query {
5153 |class QueryStats: public QueryStatsBase {
5254 |public:
5355 | ${tables.map { t => s " Query* ${t.instName}; " }.mkString(" \n " )}
56+ | ${batchTable.map(_.members).getOrElse(" " )}
5457 | QueryStats(char *path): QueryStatsBase(path) {
5558 | ${tables.map(_.initInvoke).mkString(" \n " )}
59+ | ${batchTable.map(_.initInvoke).getOrElse(" " )}
5660 | }
5761 | ${tables.map(_.initDecl).mkString(" " )}
5862 | ${tables.map(_.writeDecl).mkString(" " )}
63+ | ${batchTable.map(_.initDecl).getOrElse(" " )}
64+ | ${batchTable.map(_.writeDecl).getOrElse(" " )}
5965 |};
6066 |#endif // CONFIG_DIFFTEST_QUERY
6167 |#endif // __DIFFTEST_QUERY_H__
@@ -121,3 +127,61 @@ class QueryTable(val gen: DifftestBundle, locPrefix: String, dutZone: String) {
121127 }
122128 val writeInvoke = s " qStats-> ${tableName}_write( $dutZone, ${locArgs.map(locPrefix + _._2).mkString(" , " )}, packet); "
123129}
130+
131+ class BatchQueryTable (template : Seq [DifftestBundle ]) {
132+ private val bundleNames : Seq [String ] =
133+ template.map(_.desiredModuleName.replace(" Difftest" , " " )) ++ Seq (" BatchStep" , " BatchFinish" )
134+
135+ val members : String =
136+ s """ Query* query_BatchInfo;
137+ | Query* query_BatchStep; """ .stripMargin
138+
139+ val initInvoke : String = " BatchTable_init();"
140+
141+ val initDecl : String = {
142+ val bundleNameInserts = bundleNames.zipWithIndex.map { case (name, id) =>
143+ s " INSERT INTO BundleNames VALUES( $id, ' $name'); "
144+ }.mkString(" " )
145+
146+ s """
147+ | void BatchTable_init() {
148+ | const char* createBatchInfoSql = "CREATE TABLE BatchInfo("
149+ | "ID INTEGER PRIMARY KEY AUTOINCREMENT,"
150+ | "STEP INTEGER NOT NULL,"
151+ | "BUNDLE_ID INTEGER NOT NULL,"
152+ | "NUM INTEGER NOT NULL);";
153+ | const char* insertBatchInfoSql = "INSERT INTO BatchInfo (STEP,BUNDLE_ID,NUM)"
154+ | " VALUES (?,?,?);";
155+ | query_BatchInfo = new Query(mem_db, createBatchInfoSql, insertBatchInfoSql);
156+ |
157+ | const char* createBundleNamesSql = "CREATE TABLE BundleNames("
158+ | "BUNDLE_ID INTEGER PRIMARY KEY,"
159+ | "NAME TEXT NOT NULL);";
160+ | char* errMsg;
161+ | sqlite3_exec(mem_db, createBundleNamesSql, 0, 0, &errMsg);
162+ | sqlite3_exec(mem_db, " $bundleNameInserts", 0, 0, &errMsg);
163+ |
164+ | const char* createBatchStepSql = "CREATE TABLE BatchStep("
165+ | "ID INTEGER PRIMARY KEY AUTOINCREMENT,"
166+ | "STEP INTEGER NOT NULL,"
167+ | " ${bundleNames.map(n => s " $n INTEGER NOT NULL " ).mkString(" ," )});";
168+ | const char* insertBatchStepSql = "INSERT INTO BatchStep (STEP, ${bundleNames.mkString(" ," )}) "
169+ | "VALUES ( ${Seq .fill(bundleNames.length + 1 )(" ?" ).mkString(" ," )});";
170+ | query_BatchStep = new Query(mem_db, createBatchStepSql, insertBatchStepSql);
171+ | }
172+ | """ .stripMargin
173+ }
174+
175+ val writeDecl : String = {
176+ val numArgs = bundleNames.indices.map(i => s " nums[ $i] " ).mkString(" , " )
177+ val writeArgCount = bundleNames.length + 1 // STEP + bundleNames
178+ s """
179+ | void BatchInfo_write(int bundle_id, int num) {
180+ | query_BatchInfo->write(3, (int)query_step, bundle_id, num);
181+ | }
182+ | void BatchStep_write(int* nums) {
183+ | query_BatchStep->write( $writeArgCount, (int)query_step, $numArgs);
184+ | }
185+ | """ .stripMargin
186+ }
187+ }
0 commit comments