Ejemplo n.º 1
0
Archivo: Gro.cpp Proyecto: fmenol/gro
Value * map_to_cells (  std::list<Value *> * args, Scope * s ) {

  World * world = current_gro_program->get_world();

  std::list<Value *>::iterator i = args->begin();
  Expr * expression = (*i)->func_body();

  while ( expression->get_type() == Expr::CONSTANT ) {
    expression = expression->get_val()->func_body();
  }

  return world->map_to_cells ( expression );

}
Ejemplo n.º 2
0
BoolOpSeq::BoolOpSeq( Expr expr, bool pos ) {
    if ( expr->get_val( val_if_not_or_seq ) )
        val_if_not_or_seq ^= not pos;
    else
        or_seq.push_back()->push_back( Item{ expr, pos } );
}
Ejemplo n.º 3
0
Expr phi( Expr cond, Expr ok, Expr ko ) {
    // known value ?
    bool v;
    if ( cond.get_val( v ) )
        return v ? ok : ko;

    // the same value in all the cases ?
    if ( ok == ko )
        return ok;

    // if ok or ko are undefined
    // if ( ok.inst->undefined() ) return ko;
    // if ( ko.inst->undefined() ) return ok;


    // phi( not c, a, b ) -> phi( c, b, a )
    if ( cond.inst->inst_id() == Inst::Id_Op_not )
        return phi( cond.inst->inp_expr( 0 ), ko, ok );

    // phi( c, true, false ) -> c
    // phi( c, false, true ) -> not c
    if ( ok.size_in_bits() == 1 and ko.size_in_bits() == 1 ) {
        bool va, vb;
        if ( ok.get_val( va ) and ko.get_val( vb ) ) {
            if ( va and not vb )
                return cond;
            if ( vb and not va )
                return op_not( bt_Bool, cond );
        }
    }

    // phi( c, b, c )
    if ( cond == ko )
        return phi( cond, ok, cst( false ) );

    // phi( c, c, b )
    if ( cond == ok )
        return phi( cond, cst( true ), ko );


    // if ok is a phi node tree which contain cond in the conditions
    if ( Expr nok = phi_with_cond( cond, 1, ok ) )
        return phi( cond, nok, ko );

    // if ko is a phi node tree which contain cond in the conditions
    if ( Expr nko = phi_with_cond( cond, 0, ko ) )
        return phi( cond, ok, nko );

    // phi( cond, a, phi( cond,  ) )

    // cond = bool( ... )
    //if ( cond.inst->inst_id() == Inst::Id_Conv and cond.inst->out_bt( 0 ) == bt_Bool )
    //    cond = cond.inst->inp_expr( 0 );

    // else, create a new inst
    Phi *res = new Phi;
    res->inp_repl( 0, cond );
    res->inp_repl( 1, ok );
    res->inp_repl( 2, ko );
    return Expr( Inst::factorized( res ), 0 );
}