Commit 76cd4343 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Added debug asserts to weed out invalid ConstantOp create calls during QASM3 syntax handler



Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 5cfd2553
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -505,8 +505,12 @@ antlrcpp::Any qasm3_expression_generator::visitXOrExpression(
      auto mem_type = mlir::MemRefType::get(shaperef, lhs_element_type);

      auto integer_attr2 = mlir::IntegerAttr::get(lhs_element_type, 0);
      
      assert(integer_attr2.getType().cast<mlir::IntegerType>().isSignless());
      auto ret2 = builder.create<mlir::ConstantOp>(location, integer_attr2);
      
      auto integer_attr3 = mlir::IntegerAttr::get(lhs_element_type, 1);
      assert(integer_attr3.getType().cast<mlir::IntegerType>().isSignless());
      auto ret3 = builder.create<mlir::ConstantOp>(location, integer_attr3);

      mlir::Value loop_var_memref = builder.create<mlir::AllocaOp>(
@@ -774,6 +778,7 @@ antlrcpp::Any qasm3_expression_generator::visitExpressionTerminator(
               ? internal_value_type.cast<mlir::IntegerType>()
               : builder.getI64Type()),
          idx);
      assert(integer_attr.getType().cast<mlir::IntegerType>().isSignless());
      current_value = builder.create<mlir::ConstantOp>(location, integer_attr);
    }
    return 0;
+1 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ mlir::Value get_or_create_constant_integer_value(
    return symbol_table.get_constant_integer(idx, width);
  } else {
    auto integer_attr = mlir::IntegerAttr::get(type, idx);
    assert(integer_attr.getType().cast<mlir::IntegerType>().isSignless());
    auto ret = builder.create<mlir::ConstantOp>(location, integer_attr);
    symbol_table.add_constant_integer(idx, ret, width);
    return ret;
+1 −0
Original line number Diff line number Diff line
@@ -232,6 +232,7 @@ antlrcpp::Any qasm3_visitor::visitNoDesignatorDeclaration(
    if (auto id_list = context->identifierList()) {
      for (auto id : id_list->Identifier()) {
        variable_names.push_back(id->getText());
        assert(init_attr.getType().cast<mlir::IntegerType>().isSignless());
        initial_values.push_back(
            builder.create<mlir::ConstantOp>(location, init_attr));
      }