Ejemplo n.º 1
0
	inline void set_buffers(zstream_handle stream,
	                        const char * in_first, const char * in_last,
	                        char * out_first, char * out_last)
	{
		set_in(stream, in_first, in_last);
		set_out(stream, out_first, out_last);
	}
Ejemplo n.º 2
0
static void reducemult(char* nameres,char* name1,char* name2,set index)
{  int l, n;
   set  index1=index,index2=index;

   emitindex(&index1);
   writeF(" %s:=%s*%s$\n",nameres,name1,name2);
   while (!set_eq0(index1))
   {
      emitindex(&index1);
      writeF(" %s:=%s$\n",nameres,nameres);
   }
   if(!set_eq0(index2))
   {
      writeF(" RemInd  ");
      for(l=1,n=1;!set_eq0(index2);l++)
      {
         if(set_in(l,index2))
         {
            if (n != 1) writeF(",");
            n++;
	    writeF("m%d",l);
         }
         set_del1(&index2,l);
      }
      writeF("$\n");
   }
}
Ejemplo n.º 3
0
	inline void set_buffers(zstream_handle stream,
	                        const char * in_first, std::size_t in_size,
	                        char * out_first, std::size_t out_size)
	{
		set_in(stream, in_first, in_size);
		set_out(stream, out_first, out_size);
	}
//-------------------------------------------------------------------------------------
int static secure_cmd_burn_in_raw(char *pSRC, int nDataLen, char *pOUT,int *pOUTLen)
{
	int ret = -1;
	if((nDataLen!= 24) || (NULL == pSRC))
		return ret;				
	if(pin->status == 0)
		return ret;
	
	char out[128];
	int outlen = 128;
	memset(out, 0, 128);
	memcpy(out, pSRC, 24);	
	ret = set_in(out, FROM_KERNEL);
	
	if(ret == 0){
		pin->status = 0;
		memcpy(&(pin->factory_id[0]), out, CONFIG_EFUSE_IN_DATA_SIZE);
	}
	
#ifdef SECURE_EFUSE_DEBUG
	efuse_debug_get(177, 26, pOUT);
#endif	
		
		return ret;	
}
Ejemplo n.º 5
0
static void  r_mult(int arg1,int arg2,set index1)
{  char      name0[8],name1[8],name2[8];
   set       mind;
   unsigned  m,mm,maxmm;
   int       pstn[15];
   int       n,l;
   set       index;

   index=index1;
   sprintf(name1,"Vrt_%d",arg1);
   sprintf(name2,"Vrt_%d",arg2);
   if(arg1 < arg2) strcpy(name0,name1); else strcpy(name0,name2);
   mind=set_and(index,setmassindex);
   if(set_eq0(mind)) reducemult(name0,name1,name2,index); else
   {
      reducemult("Vrt_0",name1,name2,index);
      l = 1; n = 0;
      while (!set_eq0(mind))
      {
         if (set_in(l,mind)) pstn[n++] = l;
         set_del1(&mind,l++);
      }
      maxmm =  (1 << n) - 1 ;
      for (mm = 1;mm <= maxmm ; mm++)
      {
         writeF(" Vrt_L:=%s$   Vrt_R:=%s$\n",name1,name2);
         mind=set_constr(_E);
         m = mm; n = 1;
         while (m != 0)
         {
            if ((m & 1) != 0 && (l = pstn[n-1]) != 0)
            {
               writeF(" Vrt_L:=(Vrt_L where %s)$\n",subst(l,arg1));
               writeF(" Vrt_R:=(Vrt_R where %s)$\n",subst(l,arg2));
               set_add1(&mind,l);
            }
            ++(n);
            m >>= 1;
         }
         reducemult("Vrt_0","Vrt_0 + Vrt_L","Vrt_R",set_aun(index,mind));
         writeF(" Clear Vrt_L $    Clear Vrt_R $\n");
      }
      writeF(" %s:=Vrt_0 $    Clear Vrt_0 $\n",name0);
   }
   if (arg1 < arg2)
   {
      writeF(" Clear %s$\n",name2);
      for (n = 1; n <= vcs.sizet; n++)
         if (vertmap[n-1] == arg2) vertmap[n-1] = arg1;
   }
   if (arg2 < arg1)
   {
      writeF(" Clear %s$\n",name1);
      for (n = 1; n <= vcs.sizet; n++)
      if (vertmap[n-1] == arg1) vertmap[n-1] = arg2;
   }
}  /*  R_mult  */
//-------------------------------------------------------------------------------------
static int secure_cmd_rsa_proc_dec_in(char *pSRC, int nDataLen,char *pOUT,int *pOUTLen,int procedure)
{
	int nret = -1;
/*		
	if((nDataLen!= 128) || (*pOUTLen < 127))
		return nret;
	if ( NULL == pSRC || NULL == pOUT )
		return nret;
*/
	if((nDataLen!= 128) || (NULL == pSRC))
		return nret;					
	if(pin->status == 0)
		return nret;
		
	//prepare key
	fp_int key[3];
	memset(&key[0],0,sizeof(key));		
	if(get_auth_ra_key(&key[0],&key[1],&key[2]))
		return nret;
	
	char out[128];
	int outlen = 128;
	memset(out, 0, 128);
	nret = 	do_rsa_proc(pSRC, nDataLen, out, &outlen, &(key[0]), procedure);		
	if(nret == 0)
		nret = set_in(out, FROM_KERNEL);
		
	if(nret == 0){
		pin->status = 0;
		memcpy(&(pin->factory_id[0]), out, CONFIG_EFUSE_IN_DATA_SIZE);
	}

#ifdef SECURE_DEBUG
	memcpy(pOUT, &(pin->factory_id[0]), CONFIG_EFUSE_IN_DATA_SIZE);
#ifdef SECURE_EFUSE_DEBUG
	char *pbch = (char*)(&(pOUT[CONFIG_EFUSE_IN_DATA_SIZE]));
	efuse_debug_get(177, 26, pbch);
#endif		
#endif	
	return nret;
}
Ejemplo n.º 7
0
static void  formblocks(int* vrtsize)
{  int   v, l, lori, v1, vv, v2, count;

   for (v = 0; v < 2 * maxvert; v++)  vertmap[v] = fermmap[v]; 
   for (count = 1; count <= nloop; count++) /*  ferm loop vertex  */
   {
      writeF(" Vrt_%d:=Fl%d$",count,count);
      writeF(" Clear Fl%d$\n",count);
   }

   count = nloop;
   for (v = 0; v < vcs.sizet; v++) if(!vertmap[v])
   {  vertmap[v] = ++count;
      writeF(" Vrt_%d:=%s$\n",count,parsedverts[v]);
   } 

   for (v = 0; v < count; v++)
   {  vertinfo[v].vlnc = 0;
      vertinfo[v].weight = 1;
      vertinfo[v].ind=set_constr(_E);
      vertinfo[v].g5 = 0;
   }

   for(v=0; v<vcs.sizet; v++)
   {
      v1 = vertmap[v]-1;
      if(v1 < nloop)
      {
         vertinfo[v1].weight += 2;
         if(fermloops[v1].g5) vertinfo[v1].g5 = 1;  
      }
      for(l=0; l<vcs.valence[v]; l++)
      {  int np=vcs.vertlist[v][l].partcl;
         vv=vcs.vertlist[v][l].link.vno;
         v2=vertmap[vv]-1;
         lori=vcs.vertlist[v][l].lorentz;
         if(lori && (prtclbase1[np].spin!=4 || prtclbase1[np].hlp=='t'))
         { 
            if(v1!=v2)
            {  
               vertinfo[v1].link[vertinfo[v1].vlnc++]=v2+1;
               set_add1(&(vertinfo[v1].ind),lori);
               if(prtclbase1[np].hlp=='t') set_add1(&(vertinfo[v1].ind),lori-1);
            }
            vertinfo[v1].weight += 2;
            if(set_in(lori,setmassindex))  ++(vertinfo[v1].weight);
         }
      }
   }
   
   for(v=0; v<vcs.sizet; v++) for(l=0; l<vcs.valence[v]; l++)
   {  int np=vcs.vertlist[v][l].partcl;
      if(prtclbase1[np].spin==4 && prtclbase1[np].hlp!='t')   
      { vv=vcs.vertlist[v][l].link.vno;
        if(v<vv && vertmap[v]!=vertmap[vv] )  
        {  int ll=vcs.vertlist[v][l].link.edno;
           int m2=vcs.vertlist[v][l].lorentz,   m1=m2-1;
           int n2=vcs.vertlist[vv][ll].lorentz, n1=n2-1;

           v1 = vertmap[v]-1;
           v2 = vertmap[vv]-1;

           vertinfo[count].vlnc = 1;
           vertinfo[count].link[0]=v1+1;
           vertinfo[v1].link[vertinfo[v1].vlnc++]=count+1;
           if(v1!=v2)
           {
              vertinfo[count].vlnc = 2;
              vertinfo[count].link[1]=v2+1;
              vertinfo[v2].link[vertinfo[v2].vlnc++]=count+1;
           }
           vertinfo[count].weight = 2;
           vertinfo[count].ind=set_constr(m1,m2,n1,n2,_E);
           vertinfo[v1].ind=set_or(vertinfo[v1].ind,set_constr(m1,m2,_E));
           vertinfo[v2].ind=set_or(vertinfo[v2].ind,set_constr(n1,n2,_E));
           vertinfo[count].g5 = 0;
           count++;
           { 
             int P=abs(vcs.vertlist[v][l].moment);
             char *mass=prtclbase1[np].massidnt;
              
             writeF(" Vrt_%d:=(m%d.m%d*m%d.m%d+m%d.m%d*m%d.m%d-m%d.m%d*m%d.m%d)/2",
             count, m1,n1, m2,n2,  m1,n2,m2,n1,  m1,m2,n1,n2);
             writeF("-(m%d.m%d*P%d.m%d*P%d.m%d+m%d.m%d*P%d.m%d*P%d.m%d+"
              "m%d.m%d*P%d.m%d*P%d.m%d+m%d.m%d*P%d.m%d*P%d.m%d )/(2*%s^2)",
             m1,n1,P,m2,P,n2, m2,n2,P,m1,P,n1, m1,n2,P,m2,P,n1, m2,n1,P,m1,P,n2,mass);
             
             writeF("+(m%d.m%d+2*P%d.m%d*P%d.m%d/%s^2)*(m%d.m%d+2*P%d.m%d*P%d.m%d/%s^2)/6$\n",
             m1,m2, P,m1,P,m2,mass, n1,n2, P,n1,P,n2,mass);
           }
        }
      }

      else if(prtclbase1[np].spin==2 && PLR_PRTCL&vcs.vertlist[v][l].prop )   
      { int  P=vcs.vertlist[v][l].moment;
        vv=vcs.vertlist[v][l].link.vno;
        if(P>0 /*&& vertmap[v]!=vertmap[vv]*/ )  
        {  int ll=vcs.vertlist[v][l].link.edno;
           int m1=vcs.vertlist[v][l].lorentz;  
           int m2=vcs.vertlist[vv][ll].lorentz;
           
           v1 = vertmap[v]-1;
           v2 = vertmap[vv]-1;

           vertinfo[count].vlnc = 1;
           vertinfo[count].link[0]=v1+1;
           vertinfo[v1].link[vertinfo[v1].vlnc++]=count+1;
           if(v1!=v2)
           {
              vertinfo[count].vlnc = 2;
              vertinfo[count].link[1]=v2+1;
              vertinfo[v2].link[vertinfo[v2].vlnc++]=count+1;
           }
           vertinfo[count].weight = 1;
           vertinfo[count].ind=set_constr(m1,m2,_E);
           vertinfo[v1].ind=set_or(vertinfo[v1].ind,set_constr(m1,_E));
           vertinfo[v2].ind=set_or(vertinfo[v2].ind,set_constr(m2,_E));
           vertinfo[count].g5 = 1;
           count++;
           { int Paux;
             if(P==1) Paux=2; else Paux=1;
             writeF(" Vrt_%d:=m%d.m%d*p%d.p%d - p%d.m%d*p%d.m%d - p%d.m%d*p%d.m%d"
                             " -i*lPolar%d*eps(p%d,p%d,m%d,m%d)$",
             count, m1,m2, P,Paux,  P,m1,Paux,m2,  P,m2,Paux,m1,P,P,Paux,m1,m2);
           }
        }
      }  
   }  
   *vrtsize = count;
} 
Ejemplo n.º 8
0
void exec_stream_t::start( std::string const & program, std::string const & arguments )
{
    if( !close() ) {
        throw exec_stream_t::error_t( "exec_stream_t::start: previous child process has not yet terminated" );
    }

    pipe_t in;
    pipe_t out;
    pipe_t err;
    set_stdhandle_t set_in( STD_INPUT_HANDLE, in.r() );
    set_stdhandle_t set_out( STD_OUTPUT_HANDLE, out.w() );
    set_stdhandle_t set_err( STD_ERROR_HANDLE, err.w() );
    HANDLE cp=GetCurrentProcess();
    if( !DuplicateHandle( cp, in.w(), cp, &m_impl->m_in_pipe, 0, FALSE, DUPLICATE_SAME_ACCESS ) ) {
        throw os_error_t( "exec_stream_t::start: unable to duplicate in handle" );
    }
    in.close_w();
    if( !DuplicateHandle( cp, out.r(), cp, &m_impl->m_out_pipe, 0, FALSE, DUPLICATE_SAME_ACCESS ) ) {
        throw os_error_t( "exec_stream_t::start: unable to duplicate out handle" );
    }
    out.close_r();
    if( !DuplicateHandle( cp, err.r(), cp, &m_impl->m_err_pipe, 0, FALSE, DUPLICATE_SAME_ACCESS ) ) {
        throw os_error_t( "exec_stream_t::start: unable to duplicate err handle" );
    }
    err.close_r();

    std::string command;
    command.reserve( program.size()+arguments.size()+3 );
    if( program.find_first_of( " \t" )!=std::string::npos ) {
        command+='"';
        command+=program;
        command+='"';
    }else
        command=program;
    if( arguments.size()!=0 ) {
        command+=' ';
        command+=arguments;
    }
    STARTUPINFOA si;
    ZeroMemory( &si, sizeof( si ) );
    si.cb=sizeof( si );
    PROCESS_INFORMATION pi;
    ZeroMemory( &pi, sizeof( pi ) );
    if( !CreateProcessA( 0, const_cast< char * >( command.c_str() ), 0, 0, TRUE, 0, 0, 0, &si, &pi ) ) {
        throw os_error_t( "exec_stream_t::start: CreateProcess failed.\n command line was: "+command );
    }

    m_impl->m_child_process=pi.hProcess;
    
    m_impl->m_in_buffer.clear();
    m_impl->m_out_buffer.clear();
    m_impl->m_err_buffer.clear();

    m_impl->m_in.clear();
    m_impl->m_out.clear();
    m_impl->m_err.clear();

    m_impl->m_out_thread.set_read_buffer_size( STREAM_BUFFER_SIZE );
    m_impl->m_out_thread.start_reader_thread( m_impl->m_out_pipe );

    m_impl->m_err_thread.set_read_buffer_size( STREAM_BUFFER_SIZE );
    m_impl->m_err_thread.start_reader_thread( m_impl->m_err_pipe );

    m_impl->m_in_thread.start_writer_thread( m_impl->m_in_pipe );
}
Ejemplo n.º 9
0
/*
** Perform a reduce action and the shift that must immediately
** follow the reduce.
*/
static void yy_reduce(
  yyParser *yypParser,         /* The parser */
  int yyruleno                 /* Number of the rule by which to reduce */
){
  int yygoto;                     /* The next state */
  int yyact;                      /* The next action */
  YYMINORTYPE yygotominor;        /* The LHS of the rule reduced */
  yyStackEntry *yymsp;            /* The top of the parser's stack */
  int yysize;                     /* Amount to pop the stack */
  ParseARG_FETCH;
  yymsp = &yypParser->yystack[yypParser->yyidx];
#ifndef NDEBUG
  if( yyTraceFILE && yyruleno>=0 
        && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
    fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
      yyRuleName[yyruleno]);
  }
#endif /* NDEBUG */

  /* Silence complaints from purify about yygotominor being uninitialized
  ** in some cases when it is copied into the stack after the following
  ** switch.  yygotominor is uninitialized when a rule reduces that does
  ** not set the value of its left-hand side nonterminal.  Leaving the
  ** value of the nonterminal uninitialized is utterly harmless as long
  ** as the value is never used.  So really the only thing this code
  ** accomplishes is to quieten purify.  
  **
  ** 2007-01-16:  The wireshark project (www.wireshark.org) reports that
  ** without this code, their parser segfaults.  I'm not sure what there
  ** parser is doing to make this happen.  This is the second bug report
  ** from wireshark this week.  Clearly they are stressing Lemon in ways
  ** that it has not been previously stressed...  (SQLite ticket #2172)
  */
  /*memset(&yygotominor, 0, sizeof(yygotominor));*/
  yygotominor = yyzerominor;


  switch( yyruleno ){
  /* Beginning here are the reduction cases.  A typical example
  ** follows:
  **   case 0:
  **  #line <lineno> <grammarfile>
  **     { ... }           // User supplied code
  **  #line <lineno> <thisfile>
  **     break;
  */
      case 4: /* decl ::= REPORT TO STR */
#line 22 "cfg.y"
{set_report(ps,yymsp[0].minor.yy0);}
#line 739 "cfg.c"
        break;
      case 5: /* decl ::= LISTEN ON STR */
#line 23 "cfg.y"
{set_listen(ps,yymsp[0].minor.yy0);}
#line 744 "cfg.c"
        break;
      case 6: /* job ::= JOB LCURLY sbody RCURLY */
#line 24 "cfg.y"
{push_job(ps);}
#line 749 "cfg.c"
        break;
      case 9: /* kv ::= NAME STR */
#line 27 "cfg.y"
{set_name(ps,yymsp[0].minor.yy0);}
#line 754 "cfg.c"
        break;
      case 11: /* kv ::= DIR path */
#line 29 "cfg.y"
{set_dir(ps,yymsp[0].minor.yy0);}
#line 759 "cfg.c"
        break;
      case 12: /* kv ::= OUT path */
#line 30 "cfg.y"
{set_out(ps,yymsp[0].minor.yy0);}
#line 764 "cfg.c"
        break;
      case 13: /* kv ::= IN path */
#line 31 "cfg.y"
{set_in(ps,yymsp[0].minor.yy0);}
#line 769 "cfg.c"
        break;
      case 14: /* kv ::= ERR path */
#line 32 "cfg.y"
{set_err(ps,yymsp[0].minor.yy0);}
#line 774 "cfg.c"
        break;
      case 15: /* kv ::= USER STR */
#line 33 "cfg.y"
{set_user(ps,yymsp[0].minor.yy0);}
#line 779 "cfg.c"
        break;
      case 16: /* kv ::= ORDER STR */
#line 34 "cfg.y"
{set_ord(ps,yymsp[0].minor.yy0);}
#line 784 "cfg.c"
        break;
      case 17: /* kv ::= ENV STR */
#line 35 "cfg.y"
{set_env(ps,yymsp[0].minor.yy0);}
#line 789 "cfg.c"
        break;
      case 18: /* kv ::= ULIMIT STR STR */
      case 34: /* pairs ::= pairs STR STR */ yytestcase(yyruleno==34);
#line 36 "cfg.y"
{set_ulimit(ps,yymsp[-1].minor.yy0,yymsp[0].minor.yy0);}
#line 795 "cfg.c"
        break;
      case 20: /* kv ::= DISABLED */
#line 38 "cfg.y"
{set_dis(ps);  }
#line 800 "cfg.c"
        break;
      case 21: /* kv ::= WAIT */
#line 39 "cfg.y"
{set_wait(ps); }
#line 805 "cfg.c"
        break;
      case 22: /* kv ::= ONCE */
#line 40 "cfg.y"
{set_once(ps); }
#line 810 "cfg.c"
        break;
      case 23: /* kv ::= BOUNCE EVERY STR */
#line 41 "cfg.y"
{set_bounce(ps,yymsp[0].minor.yy0);}
#line 815 "cfg.c"
        break;
      case 25: /* cmd ::= path */
#line 43 "cfg.y"
{set_cmd(ps,yymsp[0].minor.yy0);}
#line 820 "cfg.c"
        break;
      case 26: /* cmd ::= path args */
#line 44 "cfg.y"
{set_cmd(ps,yymsp[-1].minor.yy0);}
#line 825 "cfg.c"
        break;
      case 27: /* path ::= STR */
      case 30: /* arg ::= STR */ yytestcase(yyruleno==30);
#line 45 "cfg.y"
{yygotominor.yy0=yymsp[0].minor.yy0;}
#line 831 "cfg.c"
        break;
      case 28: /* args ::= args arg */
      case 29: /* args ::= arg */ yytestcase(yyruleno==29);
#line 46 "cfg.y"
{utarray_push_back(&ps->job->cmdv,&yymsp[0].minor.yy0);}
#line 837 "cfg.c"
        break;
      case 31: /* arg ::= QUOTEDSTR */
#line 49 "cfg.y"
{yygotominor.yy0=unquote(yymsp[0].minor.yy0);}
#line 842 "cfg.c"
        break;
      case 32: /* paths ::= paths path */
      case 33: /* paths ::= path */ yytestcase(yyruleno==33);
#line 50 "cfg.y"
{utarray_push_back(&ps->job->depv,&yymsp[0].minor.yy0);}
#line 848 "cfg.c"
        break;
      default:
      /* (0) file ::= decls */ yytestcase(yyruleno==0);
      /* (1) decls ::= decls job */ yytestcase(yyruleno==1);
      /* (2) decls ::= decls decl */ yytestcase(yyruleno==2);
      /* (3) decls ::= */ yytestcase(yyruleno==3);
      /* (7) sbody ::= sbody kv */ yytestcase(yyruleno==7);
      /* (8) sbody ::= kv */ yytestcase(yyruleno==8);
      /* (10) kv ::= CMD cmd */ yytestcase(yyruleno==10);
      /* (19) kv ::= ULIMIT LCURLY pairs RCURLY */ yytestcase(yyruleno==19);
      /* (24) kv ::= DEPENDS LCURLY paths RCURLY */ yytestcase(yyruleno==24);
      /* (35) pairs ::= */ yytestcase(yyruleno==35);
        break;
  };
  yygoto = yyRuleInfo[yyruleno].lhs;
  yysize = yyRuleInfo[yyruleno].nrhs;
  yypParser->yyidx -= yysize;
  yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
  if( yyact < YYNSTATE ){
#ifdef NDEBUG
    /* If we are not debugging and the reduce action popped at least
    ** one element off the stack, then we can push the new element back
    ** onto the stack here, and skip the stack overflow test in yy_shift().
    ** That gives a significant speed improvement. */
    if( yysize ){
      yypParser->yyidx++;
      yymsp -= yysize-1;
      yymsp->stateno = (YYACTIONTYPE)yyact;
      yymsp->major = (YYCODETYPE)yygoto;
      yymsp->minor = yygotominor;
    }else
#endif
    {
      yy_shift(yypParser,yyact,yygoto,&yygotominor);
    }
  }else{
    assert( yyact == YYNSTATE + YYNRULE + 1 );
    yy_accept(yypParser);
  }
}
Ejemplo n.º 10
0
#include "dryad_circular_list.h"

_(logic \bool mutable_list(CNode * x) = x != NULL ==> \mutable(x) && \writable(x))

CNode * lseg_insert_back(CNode * hd, CNode * tl)
	_(requires hd != NULL && tl != NULL)
	_(requires lseg(hd, tl))
	_(requires !\oset_in(tl, lseg_reach(hd, tl)))

	_(ensures \result != tl)
	_(ensures lseg(\result, tl))
	_(ensures !\oset_in(tl, lseg_reach(\result, tl)))
;

_(dryad)
CNode * circular_list_insert_back(CNode * x)
	_(requires x != NULL)
	_(requires x->next != NULL)
	_(requires lseg(x->next, x))
	_(requires !\oset_in(x, lseg_reach(x->next, x)))

	_(ensures \result != x)
	_(ensures \result == x->next)
	_(ensures lseg(\result, x))
	_(ensures !\oset_in(x, lseg_reach(\result, x)))
{
	_(assume mutable_list(x))
	CNode * next = x->next;

	if (next == x) {
		CNode * tl = (CNode *) malloc(sizeof(CNode));
Ejemplo n.º 11
0
Archivo: set.c Proyecto: simon582/dm
/* -----------------------------------
 * brief  : add pdata to set
 * return : success 0, failed -1
 * ----------------------------------- */
int set_add(Set *st, void *pdata) {
    if (set_in(st, pdata) == 1) return -1;
    if (rb_insert(st->rb, pdata) == -1) return -1;
    st->size += 1;
    return 0;
}
Ejemplo n.º 12
0
Archivo: chess.c Proyecto: Omer80/wimps
static void split(set s,set *ss1,set *ss2)
{  int  nsub;
   set   s1_, s2_,s1,s2;
   int  w, w_;
   int  i, j, l, cross, cross_,dim;
   int *nextelem;

   dim=1<<(setpower(s)-1);
   
   nextelem=m_alloc(dim*sizeof(int));

   for(l=set_first(&s,1),w=0,nsub=0;l; )
   {  int l1;
      w += vertinfo[l-1].weight;
      l1=set_first(&s,l+1);
      if(l1) 
      {
         nextelem[nsub]=l;
         for(i=1; i<=nsub; i++)  nextelem[nsub+i]=-nextelem[nsub-i]; 
         nsub = 2 * nsub + 1; 
      } 
      l=l1;
   } 
   
   
   l = nextelem[0]-1; 
   w -= 2 * vertinfo[l].weight; 
   s2=set_constr(l+1,_E);
   
   s1=set_aun(s,s2); 
   cross = 0; 
   for(j=0; j<vertinfo[l].vlnc; j++) if(set_in(vertinfo[l].link[j],s1))cross++; 
   s1_=s1; 
   s2_=s2; 
   w_ = w; cross_ = cross; 
   for (i = 1; i < nsub; i++)
   { 
      l = abs(nextelem[i])-1; 
      if (nextelem[i] > 0) 
      { 
         set_del1(&s1_,l+1);
         for (j = 0; j < vertinfo[l].vlnc; j++) 
         { int ll=vertinfo[l].link[j];
           if(set_in(ll,s1_)) (cross_)++; else if(set_in(ll,s2_)) (cross_)--; 
         }   
         set_add1(&s2_,l+1); 
         w_ -= 2 * vertinfo[l].weight;
      } 
      else 
      { 
         set_del1(&s2_,l+1); 
         for (j = 0; j < vertinfo[l].vlnc; j++) 
         { int ll=vertinfo[l].link[j];
           if(set_in(ll,s2_)) (cross_)++; else if(set_in(ll,s1_)) (cross_)--; 
         }
         set_add1(&s1_,l+1); 
         w_ += 2 * vertinfo[l].weight; 
      } 

      if (MEMORY_OPTIM) 
      { 
         if(abs(w_) < abs(w) || (abs(w_) == abs(w) && cross_ < cross)) 
         {  s1=s1_; s2=s2_; w = w_;  cross = cross_; } 
      } 
      else 
      { 
         if(cross_ < cross || (cross_ == cross && abs(w_) < abs(w)))
         {  s1=s1_; s2=s2_;  w = w_;  cross = cross_; } 
      } 
   }
   free(nextelem);
   *ss1=s1;
   *ss2=s2;
}
Ejemplo n.º 13
0
#include "dryad_gslist.h"

Node * g_slist_last(Node * list)
_(requires sll(list))
_(ensures  sll(list) == \old(sll(list))
  && sll_reach(list) == \old(sll_reach(list))
  && sll_keys(list) == \old(sll_keys(list)))
_(ensures sll(\result))
_(ensures sll_keys(list) == \old(sll_keys(list)))
_(ensures list != NULL ==> \result != NULL)
_(ensures !\oset_in(\result, sll_lseg_reach(list, \result)))
_(ensures sll_lseg(list, \result) && \oset_disjoint(sll_lseg_reach(list, \result), sll_reach(\result)))//\lsegStar(list, \result))
_(ensures \oset_subset(sll_lseg_reach(list, \result), sll_reach(list)))
_(ensures \result != NULL ==> sll_keys(\result) == \intset_singleton(\result->key))
;

_(dryad)
Node * g_slist_append(Node * list, int data)
_(requires sll(list))
_(ensures sll(\result))
_(ensures sll_keys(\result) == \intset_union(\old(sll_keys(list)), \intset_singleton(data)))
{
    _(assume mutable_list(list))

    Node * new_list = (Node *) malloc(sizeof(Node));
    _(assume new_list != NULL)

    new_list->key = data;
    new_list->next = NULL;
    if (list != NULL) {
        Node * last = g_slist_last(list);
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
int callrun;

#ifdef MTRACE_DEBUG
mtrace();
#endif
   /* Start initialisation:*/
   /* Pick out the number from the string "$Revision: 2.37 $":*/
   {/*Block begin*/
        char *tmp=currentrevision;
        for( tmp=currentrevision;(*tmp!=' ')&&(*tmp!='\0');tmp++);
        if(*tmp == ' ') tmp++;
        for( currentRevisionNumber=tmp;(*tmp!=' ')&&(*tmp!='\0');tmp++);
        *tmp='\0';
   }/*Block end*/

   /* Check here is there the request for the version information.
    * If so, output the revision number and quit, if there are no any
    * other option:
    */
   for(i=1; i<argc; i++)
      if( (s_cmp(argv[i],"-V")==0)||(s_cmp(argv[i],"-version")==0)){
        printf("%s\n",currentRevisionNumber);
        if(argc == 2) exit(0);
      }

   first_init();/*module init.c*/
   read_command_line(argc, argv);/*module cmd_line.c*/
   message(INITIALIZATION,NULL);
   /*End initialisation*/
   message(READINGCONFIG,config_name);
   scaner_init(config_name,cnf_comment);/*module init.c*/
   read_config_file_before_truns();/*module cnf_read.c*/
   if( is_bit_set(&mode,bitCHECKMOMENTABALANCE)&&
       (!is_bit_set(&mode,bitONLYINTERPRET))
    ){

       check_momenta_balance_on_each_topology();
   }
   message(DONE,NULL);

   /*Translation of the TM program:*/
   {char tmp[MAX_STR_LEN];

       if (
             (is_bit_set(&mode,bitONLYINTERPRET))||
             (!is_bit_set(&mode,bitBROWS))||
             (is_bit_set(&mode,bitVERIFY))||
             (is_bit_set(&mode,bitFORCEDTRUNSLATION))
          ){
             command_init();/*module truns.c*/
             if(!is_bit_set(&mode,bitONLYINTERPRET)){
                if (set_table==NULL)set_table=create_hash_table(
                      set_hash_size,str_hash,str_cmp,c_destructor);
                if(is_bit_set(&mode,bitBROWS))
                  install(new_str("_specmode"),new_str("browser"),set_table);
                else
                  install(new_str("_specmode"),new_str("common"),set_table);
             }
             message(BEGINTRUNS,NULL);
             do{
               if(truns(&current_number_of_trunslated_lines,
                           &current_array_of_trunslated_lines)){
                  number_of_trunslated_lines=
                                        current_number_of_trunslated_lines;
                  current_number_of_trunslated_lines=0;
                  array_of_trunslated_lines=
                                         current_array_of_trunslated_lines;
                  current_array_of_trunslated_lines=NULL;
               }
             }while(number_of_trunslated_lines==0);
             message(ENDTRUNS,NULL);
             mem_esc_char=esc_char;
             macro_done();/*module macro.c*/
             reject_proc();/*module truns.c*/
             command_done();/*module truns.c*/
             clear_defs();/*module truns.c*/
             clear_label_stack();/*module truns.c*/
             for_done();/*module truns.c*/
             IF_done();/*module truns.c*/
             if(s_scmp(sc_get_token(tmp),"translate"))
                halt(UNEXPECTED ,tmp);
       }
   }
   sc_done();/*module tools.c*/
   /*TM program is translated. The resulting code is in array_of_trunslated_lines*/

/*Keep the table up to the end of the program!:*/
#ifdef SKIP
   if (vectors_table!=NULL){
      hash_table_done(vectors_table);/*module hash.c*/
      vectors_table=NULL;
   }
#endif

   message(DONEINIT,NULL);

   if (is_bit_set(&mode,bitVERIFY)){
     message(ONLYVERIFY,NULL);
     errorlevel=0;halt(NOERROR,NULL);
   }

   if (g_ttnames != NULL){/*Topology tables were defined in the config file*/
      HASH_TABLE wrktrans;
      message(LOADINGTABLES,NULL);
      read_topology_tables();/*module utils.c*/
      free_mem(&g_ttnames);
      /*Create the working table:*/
      g_tt_wrk=tt_createNewTable(g_defaultTokenDictSize,g_defaultHashTableSize);

      /*Check success, if not, halt the system:*/
      checkTT(g_tt_wrk,FAILCREATINGWRKTABLE);

      /*Collect translations from all tables:*/
      wrktrans=tt_table[g_tt_wrk-1]->htrans;
      /*Full toplogies:*/
      for(i=0;i<g_tt_top_full;i++){
         HASH_TABLE  ttrans=tt_table[g_tt_full[i]-1]->htrans;
         if( ttrans!=NULL )
              binary_operations_under_hash_table(
                 ttrans,/*"from"*/
                 wrktrans,/*"to"*/
                 -1);/*see "hash.c"; op>0 -> add enties to "to" from "from", only if they
                 are absent in "to", op<0 -> rewrite entries in "to" by the corresponding
                 "from", op==0 -> remove all entries in "to" matching "from"*/
      }/*for(i=0;i<g_tt_top_full;i++)*/
      /*Internal topologies:*/
      for(i=0;i<g_tt_top_int;i++){
         HASH_TABLE  ttrans=tt_table[g_tt_int[i]-1]->htrans;
         if( ttrans!=NULL )
              binary_operations_under_hash_table(
                 ttrans,/*"from"*/
                 wrktrans,/*"to"*/
                 -1);/*see "hash.c"; op>0 -> add enties to "to" from "from", only if they
                 are absent in "to", op<0 -> rewrite entries in "to" by the corresponding
                 "from", op==0 -> remove all entries in "to" matching "from"*/
      }/*for(i=0;i<g_tt_top_int;i++)*/

      /*Override translations, if present, in wrk table; in loaded tables
        translations remain to be untranslated!:*/
      if( g_ttTokens_table!=NULL )
              binary_operations_under_hash_table(
                 g_ttTokens_table,/*"from"*/
                 wrktrans,/*"to"*/
                 -1);/*see "hash.c"; op>0 -> add enties to "to" from "from", only if they
                 are absent in "to", op<0 -> rewrite entries in "to" by the corresponding
                 "from", op==0 -> remove all entries in "to" matching "from"*/

      /*Now wrk table is ready*/
      /*Override translations, if present, in full toplogies:*/
      if( g_ttTokens_table!=NULL )for(i=0;i<g_tt_top_full;i++){
         HASH_TABLE  ttrans=tt_table[g_tt_full[i]-1]->htrans;
         if( ttrans!=NULL )/*BTW, it CANNOT be a NULL! See, how tt_createNewTableis invoked
                             in the beginning of tt_loadTable, file tt_load.c*/
              binary_operations_under_hash_table(
                 g_ttTokens_table,/*"from"*/
                 ttrans,/*"to"*/
                 -1);/*see "hash.c"; op>0 -> add enties to "to" from "from", only if they
                 are absent in "to", op<0 -> rewrite entries in "to" by the corresponding
                 "from", op==0 -> remove all entries in "to" matching "from"*/
      }/*for(i=0;i<g_tt_top_full;i++)*/
      message(DONE,NULL);
   }/*if (g_ttnames != NULL)*/

   /*If only interpret, we need not analyse diagrams:*/
   if(is_bit_set(&mode,bitONLYINTERPRET)){
    int exitcode;
      run_init(1);/*module init.c*/
      esc_char=mem_esc_char;
      islast=1;
      g_nocurrenttopology=1;/*Similar to islast, but specially for topologies.*/
      message(CALLTOINTERPRETER,NULL);
      exitcode=run(number_of_trunslated_lines,array_of_trunslated_lines);
      message(DONE,NULL);
      {char endmessage[MAX_STR_LEN];
         sprintf(endmessage,EXITCODEFROMINTERPRETER,exitcode);
         errorlevel=exitcode;
         halt(endmessage,NULL);
      }
      /*Stop running...*/
   }/*if(is_bit_set(&mode,bitONLYINTERPRET)*/

   /*ok, if we are here then we have to read diagrams...*/
   detect_last_diagram_number();/*module last_num.c*/
   message(LOOKINGFORFIRRSTDIAGRAM,NULL);
   scaner_init(input_name,0);/*module init.c*/
   skip_until_first_actual_diagram();/*module read_inp.c*/
   create_table(&dbuf,&dtable,MAX_VERTEX,MAX_I_LINE,ext_lines);/*module utils.c*/
   create_table(&wrkbuf,&wrktable,MAX_VERTEX,MAX_I_LINE,ext_lines);
   message(DONE,NULL);
   message(READDIAGRAMS,NULL);

   for(i=start_diagram;!(i>finish_diagram);i++){/*begin main loop*/
      skip_to_new_diagram();/* module read_inp.c Reads until '['*/

      if(i % STEP_INDICATOR == 0){
        char mes[MAX_STR_LEN];
          sprintf(mes,INDICATE_MESSAGE,i,finish_diagram);
          message(mes,NULL);
      }/*if(i % STEP_INDICATOR == 0)*/

      /* Check should we process this diagram:*/
      if (set_in(i % 250,dmask[i / 250])) continue;

      new_diagram();/*module read_inp.c. Some initializations
                                                       before each diagram.*/

      detect_number_and_coefficient();/*module read_inp.c
                                        This function must receive from
                                        scaner exactly 'd###'*/
      if(i!=diagram_count)
         halt(CURRUPTEDINPUT,input_name);
      create_primary_diagram_table();/*module read_inp.c*/

      if ( skiptadpoles && thisistadpole )
         continue;
      define_topology();/*module read_inp.c*/
      /*compare_topology() returns 1 if topology is not actual.
      If topology is undefined, this procedure will call
      'out_undefined_topology();' (if bitBROWS is not set) and set bitTERROR.
      */
      if(compare_topology())/*module read_inp.c*/
         continue;

      create_diagram_table();/*module read_inp.c*/

      define_prototype();/*module read_inp.c*/
      if(!is_bit_set(&mode,bitFORCEDTRUNSLATION))
          if(skip_prototype())/*module utils.c*/
            continue;
      create_indices_table();/*module read_inp.c*/
      if(must_diagram_be_skipped())/*module utils.c*/
         continue;
      if (is_bit_set(&mode,bitBROWS))
         fill_up_diagram_array(count);/*module read_inp.c*/
      count++;
      if(is_bit_set(&mode,bitFORCEDTRUNSLATION)){
         if(g_tt_try_loaded>0)/*Automatic momenta distribution mechanism*/
            callrun=1;
         else if(   ( is_bit_set(&mode,bitTERROR) )&&(!is_bit_set(&mode,bitBROWS)))
           callrun=0;
         else
           callrun=1;
      }else{
         callrun=(
              (!is_bit_set(&mode,bitTERROR) )&&
              (!is_bit_set(&mode,bitBROWS) )
         );
      }
      /*Run the interpreter:*/
      if(callrun){
         build_form_input();/*module read_inp.c*/
         run_init(0);/*module init.c*/
         esc_char=mem_esc_char;
         if(run(number_of_trunslated_lines,array_of_trunslated_lines)==HALT)
             set_bit(&mode,bitRUNSIGNAL);
         run_clear();/*module init.c*/
         if(is_bit_set(&mode, bitSKIP)){
            unset_bit(&mode,bitSKIP);
            count--;
         }else if((is_bit_set(&mode,bitFORCEDTRUNSLATION))&&
                            (skip_prototype()/*module utils.c*/)){
            count--;
         }else{
            if(g_topologyLabel!=NULL){/*First occurence, otherwise will be NULL*/
               /*Mark topology as occurred*/
               set_bit(g_topologyLabel,0);
               if(g_tt_try_loaded>0){/*Table were loaded*/

                  if( topologies[cn_topol].orig==NULL )/*Undefined topology*/
                     process_topol_tables(0);/*try to find momenta, read_inp.c*/

                  if(topologies[cn_topol].coordinates_ok==0)/*No coords*/
                     process_topol_tables(1);/*try to find coordinates, read_inp.c*/
                  /*Now current topology is marked, and wrk toable is built.*/
               }else{
                  if( topologies[cn_topol].orig==NULL ){/*Undefined topology*/
                     if( automatic_momenta_group(NULL,cn_topol)==1)
                        /*Now momenta are distributed automatically:*/
                        set_bit(g_topologyLabel,2);
                        /*Bit 0: 0, if topology not occures, or 1;
                          bit 1: 1, if topology was produced form generic, or 0.
                          bit 2: 1, automatic momenta is implemented, or 0
                        */
                  }/*if( topologies[cn_topol].orig==NULL )*/
               }/*if(g_tt_try_loaded>0)...else...*/
            }/*if(g_topologyLabel!=NULL)*/
            output_common_protocol(count);/*module read_inp.c*/
         }/*if(is_bit_set(&mode, bitSKIP)) ... else ... else*/
         if(is_bit_set(&mode,bitRUNSIGNAL)){
            sc_done();
            errorlevel=0;
            halt(RUNSIGNAL,NULL);
         }/*if(is_bit_set(&mode,bitRUNSIGNAL))*/
      }/*if(callrun)*/
   }/*end main loop*/

   sc_done();
   message(DONEDIAGRAMS,NULL);

   /*Check should we run the interpreter once more:*/
   if(is_bit_set(&mode,bitEND)){
      /*To use some of specmode operators during "extra call":*/
      new_diagram();

      run_init(1);
      esc_char=mem_esc_char;
      islast=1;

      g_nocurrenttopology=1;/*Similar to islast, but specially for topologies.*/
      cn_topol=top_topol;/*Indicate that there is no special topology */
      message(EXTRACALL,NULL);
      if(run(number_of_trunslated_lines,array_of_trunslated_lines)==HALT){
         errorlevel=0;
         halt(RUNSIGNAL,NULL);
      }
      message(DONE,NULL);
   }/*if(is_bit_set(&mode,bitEND))*/

   if (is_bit_set(&mode,bitBROWS)){
      message(BROWSERMODEDETECT,NULL);
      out_browse_head(count);/*module browser.c*/
      message(SORTINGDIAGRAMS,NULL);
      sort_diargams(count);/*module browser.c*/
      message(DONE,NULL);
      message(PRINTINGDIAGRAMS,NULL);
      print_diagrams(count);/*module browser.c*/
      message(DONE,NULL);
      sort_prototypes();/*module browser.c*/
      print_prototypes();/*module browser.c*/
      print_all_found_topologies();/*module browser.c*/
      print_not_found_topologies();/*module browser.c*/
      print_undefined_topologies();/*module browser.c*/
   }/*if (is_bit_set(&mode,bitBROWS))*/
   errorlevel=0;
   halt(NOERROR,NULL);
   return(0);/*Actually, the control can't reach this point*/
}/*main*/
Ejemplo n.º 15
0
#include "dryad_sls.h"

_(dryad)
Node * sls_insert(Node * lst, Node * elt)
  _(requires srtl(lst))
  _(requires elt != NULL)
  _(requires elt->next == NULL)
  _(requires !\oset_in(elt, srtl_reach(lst)))
  _(ensures srtl(\result))
{
  _(assume mutable_list(lst))
  if (lst == NULL || lst->key > elt->key) {
    elt->next = lst;
    return elt;
  } else {
    Node * curr = lst;
    while(curr->next != NULL && curr->next->key <= elt->key)
      _(invariant curr != NULL)
      _(invariant srtl(lst))
      _(invariant srtl(curr))
      _(invariant srtl_lseg(lst, curr))
      _(invariant \oset_disjoint(srtl_lseg_reach(lst, curr), sll_reach(curr)))
      _(invariant !\oset_in(elt, srtl_reach(lst)))
      _(invariant !\oset_in(elt, srtl_reach(curr)))
      _(invariant !\oset_in(elt, srtl_lseg_reach(lst, curr)))
      _(invariant curr->key <= elt->key)
      _(invariant mutable_list(curr))
    {
      curr = curr->next;
      _(assume mutable_list(curr))
    }