Branch: Tag:

1997-03-09

1997-03-09 09:11:13 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

peephole optimizer and code generator bugfixed and improved

Rev: bin/mkpeep.pike:1.3
Rev: src/docode.c:1.13
Rev: src/interpret.c:1.30
Rev: src/language.yacc:1.29
Rev: src/lex.c:1.17
Rev: src/operators.h:1.2
Rev: src/peep.c:1.7
Rev: src/peep.in:1.5
Rev: src/testsuite.in:1.34

81:    return insert_opcode(f,0,current_line, current_file);   }    +    void update_arg(int instr,INT32 arg)   {    p_instr *p;
153:    case F_DEC_NEQ_LOOP: \    case F_LAND: \    case F_LOR: \ +  case F_EQ_OR: \    case F_CATCH: \    case F_FOREACH   
191:       for(e=0;e<length;e++)    { -  int tmp; +     switch(c[e].opcode)    {    case BRANCH_CASES:    case F_POINTER:    while(1)    { -  +  int tmp,tmp2;    tmp=labels[c[e].arg];       while(c[tmp].opcode == F_LABEL ||    c[tmp].opcode == F_NOP) tmp++;    -  if(c[tmp].opcode!=F_BRANCH) break; +  if(c[tmp].opcode==F_BRANCH) +  {    c[e].arg=c[tmp].arg; -  +  continue;    } -  +  + #define TWOO(X,Y) (((X)<<8)+(Y)) +  +  switch(TWOO(c[e].opcode,c[tmp].opcode)) +  { +  case TWOO(F_LOR,F_BRANCH_WHEN_NON_ZERO): +  c[e].opcode=F_BRANCH_WHEN_NON_ZERO; +  case TWOO(F_LOR,F_LOR): +  c[e].arg=c[tmp].arg; +  continue; +  +  case TWOO(F_LAND,F_BRANCH_WHEN_ZERO): +  c[e].opcode=F_BRANCH_WHEN_ZERO; +  case TWOO(F_LAND,F_LAND): +  c[e].arg=c[tmp].arg; +  continue; +  } +  break; +  }    uses[c[e].arg]++;    }    }
311:   static int fifo_len, eye,len;   static p_instr *instructions;    + int insopt(int f, INT32 b, int cl, struct pike_string *cf) + { +  p_instr *p; +  + #ifdef DEBUG +  if(!hasarg(f) && b) +  fatal("hasarg() is wrong!\n"); + #endif +  +  p=(p_instr *)low_make_buf_space(sizeof(p_instr), &instrbuf); +  +  if(fifo_len) +  { +  MEMMOVE(p-fifo_len+1,p-fifo_len,fifo_len*sizeof(p_instr)); +  p-=fifo_len; +  fifo_len++; +  } +  + #ifdef DEBUG +  if(!instrbuf.s.len) +  fatal("Low make buf space failed!!!!!!\n"); + #endif +  +  p->opcode=f; +  p->line=current_line; +  copy_shared_string(p->file, current_file); +  p->arg=b; +  +  return p - (p_instr *)instrbuf.s.str; + } +  + int insopt2(int f, int cl, struct pike_string *cf) + { + #ifdef DEBUG +  if(hasarg(f)) +  fatal("hasarg() is wrong!\n"); + #endif +  return insert_opcode(f,0,cl, cf); + } +  +    static void debug()   {    if(fifo_len > (long)instrbuf.s.len / (long)sizeof(p_instr))
336:       debug();    -  if(offset >= 0) -  { +     if(offset < fifo_len)    {    p=(p_instr *)low_make_buf_space(0, &instrbuf);    p-=fifo_len;    p+=offset; -  +  if(((char *)p)<instrbuf.s.str) return 0;    return p;    }else{    offset-=fifo_len;
350:    if(offset >= len) return 0;    return instructions+offset;    } -  }else{ -  fatal("Can't handle negative offsets in peephole optimizer!\n"); -  return 0; /* Make GCC happy */ +    } - } +       static int opcode(int offset)   {
393:    {    p_instr *p;    -  d=fifo_len; -  if(d>n) d=n; +  d=n; +  if(d>fifo_len) d=fifo_len;   #ifdef DEBUG    if((long)d > (long)instrbuf.s.len / (long)sizeof(p_instr))    fatal("Popping out of instructions.\n");   #endif    -  low_make_buf_space(-((INT32)sizeof(p_instr))*fifo_len, &instrbuf); +     p=(p_instr *)low_make_buf_space(0, &instrbuf); -  +  p-=fifo_len;    for(e=0;e<d;e++) free_string(p[e].file);    fifo_len-=d;    if(fifo_len) MEMMOVE(p,p+d,fifo_len*sizeof(p_instr));    n-=d; -  +  low_make_buf_space(-((INT32)sizeof(p_instr))*d, &instrbuf);    }    eye+=n;   }    - static void dofix() - { -  p_instr *p,tmp; -  int e; +     -  if(fifo_len) -  { -  p=(p_instr *)low_make_buf_space(0, &instrbuf); -  tmp=p[-1]; -  for(e=0;e<fifo_len;e++) -  p[-1-e]=p[-2-e]; -  p[-1-e]=tmp; -  } - } -  +    static void asm_opt(void)   {   #ifdef DEBUG