Skip to content

Commit

Permalink
adds basic symbol table test for flatten types
Browse files Browse the repository at this point in the history
  • Loading branch information
rdaly525 committed Mar 5, 2021
1 parent f601002 commit 0e1b09e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/gtest/test_flattentypes.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "gtest/gtest.h"
#include "assert_pass.h"
#include "coreir.h"
#include "coreir/ir/symbol_table_interface.hpp"

using namespace CoreIR;

Expand All @@ -20,6 +21,42 @@ TEST(FlattenTypesTests, TestFlattenTypesPreserveNDArray) {
deleteContext(c);
}


//void check_port(SymbolTableInterface* sym, std::string key, std::string val) {
// assert(sym->getPortName(key)==val);
//}

TEST(FlattenTypesTests, TestSymbolTable) {
Context* c = newContext();
Module* top;

if (!loadFromFile(c, "srcs/flattentypes_preserve_nd_array.json", &top)) { c->die();}
assert(top != nullptr);
c->setTop(top->getRefName());
c->getPassManager()->setDebug(true);
SymbolTableInterface* sym = c->getPassManager()->getSymbolTable();
cout << sym->json() << endl;
c->runPasses({"flattentypes"});
assert(c->getPassManager()->getSymbolTable() == sym);
//Verify the symbol table makes sense
//Check I0 (ND-array)
// ["I0",["Array",12,["Array",16,["Array",8,"BitIn"]]]],
for (int i=0; i<12; ++i) {
for (int j=0; j<16; ++j) {
auto key = "I0." + std::to_string(i) + "." + std::to_string(j);
auto val = "I0_" + std::to_string(i) + "_" + std::to_string(j);
assert(sym->getPortName(top->getName(), key) == val);
}
}
//Check I1 (Record)
// ["I1",["Record",[["_0","BitIn"],["_1",["Array",3,"BitIn"]]]]],
assert(sym->getPortName(top->getName(), "I1._0")== "I1__0");
assert(sym->getPortName(top->getName(), "I1._1")== "I1__1");

deleteContext(c);
}


} // namespace

int main(int argc, char** argv) {
Expand Down

0 comments on commit 0e1b09e

Please sign in to comment.