Пример #1
0
void jsa_serialisert::operator()(irept &sdu,
    const jsa_genetic_solutiont &entity) const
{
  sdu.set(FITNESS, entity.fitness);
  irept invariant;
  irept::subt &invariant_instructions=invariant.get_sub();
  for (const jsa_genetic_solutiont::invariantt::value_type &instr : entity.invariant)
  {
    irept instruction;
    instruction.set(OPCODE, instr.opcode);
    invariant_instructions.push_back(instruction);
  }
  sdu.set(INVARIANT, invariant);
  irept predicates;
  irept::subt &predicates_list=predicates.get_sub();
  for (const jsa_genetic_solutiont::predicatet &predicate : entity.predicates)
  {
    irept pred;
    irept::subt &predicate_instructions=pred.get_sub();
    for (const jsa_genetic_solutiont::predicatet::value_type &instr : predicate)
    {
      irept instruction;
      instruction.set(OPCODE, instr.opcode);
      instruction.set(OP0, instr.op0);
      instruction.set(OP1, instr.op1);
      instruction.set(RESULT_OP, instr.result_op);
      predicate_instructions.push_back(instruction);
    }
    predicates_list.push_back(pred);
  }
  sdu.set(PREDICATES, predicates);
  irept query;
  irept::subt &query_instructions=query.get_sub();
  for (const jsa_genetic_solutiont::queryt::value_type &instr : entity.query)
  {
    irept instruction;
    instruction.set(OPCODE, instr.opcode);
    instruction.set(OP0, instr.op0);
    instruction.set(OP1, instr.op1);
    query_instructions.push_back(instruction);
  }
  sdu.set(QUERY, query);
}
Пример #2
0
void convert(const goto_programt::instructiont &instruction, irept &irep)
{
  irep.set(ID_code, instruction.code);

  if(instruction.function!="")
    irep.set(ID_function, instruction.function);

  if(instruction.source_location.is_not_nil())
    irep.set(ID_location, instruction.source_location);

  irep.set(ID_type, (long) instruction.type);

  irep.set(ID_guard, instruction.guard);

  if(!instruction.targets.empty())
  {
    irept &tgts=irep.add(ID_targets);
    for(goto_programt::targetst::const_iterator it=
          instruction.targets.begin();
        it!=instruction.targets.end();
        it++)
    {
      irept t(i2string((*it)->location_number));
      tgts.move_to_sub(t);
    }
  }

  if(!instruction.labels.empty())
  {
    irept &lbls = irep.add(ID_labels);
    irept::subt &subs = lbls.get_sub();
    subs.reserve(instruction.labels.size());
    for(goto_programt::instructiont::labelst::const_iterator it=
          instruction.labels.begin();
        it!=instruction.labels.end();
        it++)
    {
      subs.push_back(irept(*it));
    }
  }
}