Commit 29ac720d authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

setup subroutine return stmts to handle expressions

parent 40e8ad40
Loading
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -28,8 +28,9 @@ def generate_random_int() qubit:q -> int {
    }
    // Print the binary string
    print("random binary: ", b);
    int n = int[32](b);
    return n;

    // Cast to int and return
    return int[32](b);
}

// Allocate a single qubit
+10 −3
Original line number Diff line number Diff line
@@ -182,11 +182,18 @@ antlrcpp::Any qasm3_visitor::visitReturnStatement(
      printErrorMessage("We do not return memrefs from subroutines.", context);
    }

  } else {
    if (auto expr_stmt = context->statement()->expressionStatement()) {
      qasm3_expression_generator exp_generator(builder, symbol_table,
                                               file_name);
      exp_generator.visit(expr_stmt);
      value = exp_generator.current_value;
    } else {
      visitChildren(context->statement());

      value = symbol_table.get_last_value_added();
    }
    
  }
  is_return_stmt = false;

  builder.create<mlir::ReturnOp>(