Commit 09c51bf3 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Refactor common MLIR generation subroutines to a common helper



Generate MLIR from a file name or (kenel name + source string): the first one will delegate to the latter after reading the file.

Refactor MLIR API: let the code to detect the language from the source string.

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent e8d46002
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -215,10 +215,10 @@ QCOR_EXPECT_TRUE(m10[3] == 0);
QCOR_EXPECT_TRUE(m10[4] == 0);
QCOR_EXPECT_TRUE(m10[5] == 1);
)#";
  auto mlir = qcor::mlir_compile("qasm3", alias_by_indicies, "test",
  auto mlir = qcor::mlir_compile(alias_by_indicies, "test",
                                 qcor::OutputType::MLIR, true);
  std::cout << "MLIR:\n" << mlir << "\n";
  EXPECT_FALSE(qcor::execute("qasm3", alias_by_indicies, "test"));
  EXPECT_FALSE(qcor::execute(alias_by_indicies, "test"));
}

int main(int argc, char **argv) {
+2 −2
Original line number Diff line number Diff line
@@ -70,9 +70,9 @@ QCOR_EXPECT_TRUE(ff == 3.14);

)#";
  auto mlir =
      qcor::mlir_compile("qasm3", src, "test", qcor::OutputType::MLIR, true);
      qcor::mlir_compile(src, "test", qcor::OutputType::MLIR, true);
  std::cout << "MLIR:\n" << mlir << "\n";
  EXPECT_FALSE(qcor::execute("qasm3", src, "test"));
  EXPECT_FALSE(qcor::execute(src, "test"));
}

int main(int argc, char **argv) {
+2 −2
Original line number Diff line number Diff line
@@ -21,12 +21,12 @@ for i in [0:100] {
print(count);
QCOR_EXPECT_TRUE(count > 30);
)#";
  auto mlir = qcor::mlir_compile("qasm3", check_pow, "check_pow",
  auto mlir = qcor::mlir_compile(check_pow, "check_pow",
                                 qcor::OutputType::MLIR, false);
  std::cout << mlir << "\n";

 
  EXPECT_FALSE(qcor::execute("qasm3", check_pow, "check_pow"));
  EXPECT_FALSE(qcor::execute(check_pow, "check_pow"));
}

int main(int argc, char **argv) {
+4 −4
Original line number Diff line number Diff line
@@ -19,10 +19,10 @@ QCOR_EXPECT_TRUE(b3 == 1);
QCOR_EXPECT_TRUE(b4 == 1);

)#";
  auto mlir = qcor::mlir_compile("qasm3", uint_index, "uint_index",
  auto mlir = qcor::mlir_compile(uint_index, "uint_index",
                                 qcor::OutputType::MLIR, false);
  std::cout << mlir << "\n";
  EXPECT_FALSE(qcor::execute("qasm3", uint_index, "uint_index"));
  EXPECT_FALSE(qcor::execute(uint_index, "uint_index"));
}

TEST(qasm3VisitorTester, checkCastBitToInt) {
@@ -34,12 +34,12 @@ int[4] t = int[4](c);
print(t);
QCOR_EXPECT_TRUE(t == 15);
)#";
  auto mlir = qcor::mlir_compile("qasm3", cast_int, "cast_int",
  auto mlir = qcor::mlir_compile(cast_int, "cast_int",
                                 qcor::OutputType::MLIR, false);

  std::cout << "cast_int MLIR:\n" << mlir << "\n";

  EXPECT_FALSE(qcor::execute("qasm3", cast_int, "cast_int"));
  EXPECT_FALSE(qcor::execute(cast_int, "cast_int"));
}

int main(int argc, char **argv) {
+2 −2
Original line number Diff line number Diff line
@@ -12,10 +12,10 @@ result = (shots - num_parity_ones) / shots - num_parity_ones / shots;
test = result - .007812;
QCOR_EXPECT_TRUE(test < .01);
)#";
  auto mlir = qcor::mlir_compile("qasm3", global_const, "global_const",
  auto mlir = qcor::mlir_compile(global_const, "global_const",
                                 qcor::OutputType::MLIR, false);
  std::cout << mlir << "\n";
  EXPECT_FALSE(qcor::execute("qasm3", global_const, "global_const"));
  EXPECT_FALSE(qcor::execute(global_const, "global_const"));
}

int main(int argc, char **argv) {
Loading