Ejemplo n.º 1
0
      @Override
      public Boolean caseProcedure(Procedure procedure) {
        this.procedure = procedure;

        // Test if The procedure contains a BlockWhile before size - 1
        int blockSize = procedure.getBlocks().size();
        if (blockSize > 1) {
          Block block = procedure.getBlocks().get(blockSize - 2);
          if (block.isBlockWhile()) {
            // If it is check if an additional loop should be added
            doSwitch(block);
          } else {
            return true;
          }
        }

        return false;
      }
Ejemplo n.º 2
0
  protected void createBroadcast(String id, Port port, List<? extends Edge> outList) {

    // Add broadcast vertex
    Actor bcast = dfFactory.createActor();
    bcast.setName(id + "_" + port.getName());

    Instance instance = dfFactory.createInstance(id + "_" + port.getName() + "_bcast", bcast);
    network.add(instance);

    Type portVarType = irFactory.createTypeList(1, port.getType());

    Pattern inputPattern = dfFactory.createPattern();
    Pattern outputPattern = dfFactory.createPattern();

    Port input = dfFactory.createPort(EcoreUtil.copy(port.getType()), "input");
    bcast.getInputs().add(input);

    // Creates a connection between the vertex and the broadcast
    Connection conn = (Connection) outList.get(0);
    Connection incoming =
        dfFactory.createConnection(
            conn.getSource(),
            conn.getSourcePort(),
            instance,
            input,
            EcoreUtil.copyAll(conn.getAttributes()));
    incoming.getAttributes().addAll(EcoreUtil.copyAll(conn.getAttributes()));
    network.getConnections().add(incoming);

    inputPattern.setNumTokens(input, 1);
    inputPattern.setVariable(input, irFactory.createVar(portVarType, "input", true, 0));

    // Change the source of the other connections
    int i = 0;
    for (Edge edge : outList) {
      Port output = dfFactory.createPort(EcoreUtil.copy(port.getType()), "output_" + i);
      bcast.getOutputs().add(output);

      Connection connection = (Connection) edge;
      connection.setSourcePort(output);
      connection.setSource(instance);

      outputPattern.setNumTokens(output, 1);
      outputPattern.setVariable(output, irFactory.createVar(portVarType, "output_" + i, true, 0));

      i++;
    }

    // Create body of the broadcast
    Procedure body = irFactory.createProcedure("copy", 0, irFactory.createTypeVoid());
    Var tmpVar = body.newTempLocalVariable(IrUtil.copy(port.getType()), "tmp");
    BlockBasic block = IrUtil.getLast(body.getBlocks());

    block.add(irFactory.createInstLoad(tmpVar, inputPattern.getVariable(input), 0));
    for (Port output : bcast.getOutputs()) {
      block.add(irFactory.createInstStore(outputPattern.getVariable(output), 0, tmpVar));
    }

    // Create the scheduler
    Procedure scheduler =
        irFactory.createProcedure("isSchedulable_copy", 0, irFactory.createTypeBool());
    BlockBasic block2 = IrUtil.getLast(scheduler.getBlocks());
    block2.add(irFactory.createInstReturn(irFactory.createExprBool(true)));

    Action copy =
        dfFactory.createAction(
            "copy", inputPattern, outputPattern, dfFactory.createPattern(), scheduler, body);

    bcast.getActions().add(copy);
    bcast.getActionsOutsideFsm().add(copy);
  }