pike.git / src / peep.c

version» Context lines:

pike.git/src/peep.c:6:   #include "las.h"   #include "docode.h"   #include "main.h"   #include "error.h"   #include "lex.h"   #include "pike_memory.h"   #include "peep.h"   #include "dmalloc.h"   #include "stuff.h"    - RCSID("$Id: peep.c,v 1.24 1998/05/12 23:51:26 hubbe Exp $"); + RCSID("$Id: peep.c,v 1.25 1998/11/22 11:03:07 hubbe Exp $");      struct p_instr_s   {    short opcode;    short line;    struct pike_string *file;    INT32 arg;   };      typedef struct p_instr_s p_instr;
pike.git/src/peep.c:51:    toss_buffer(&instrbuf);   }      int insert_opcode(unsigned int f,    INT32 b,    INT32 current_line,    struct pike_string *current_file)   {    p_instr *p;    - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(!hasarg(f) && b)    fatal("hasarg(%d) is wrong!\n",f);   #endif       p=(p_instr *)low_make_buf_space(sizeof(p_instr), &instrbuf);       - #ifdef DEBUG + #ifdef PIKE_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 insert_opcode2(int f,int current_line, struct pike_string *current_file)   { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(hasarg(f))    fatal("hasarg(%d) is wrong!\n",f);   #endif    return insert_opcode(f,0,current_line, current_file);   }         void update_arg(int instr,INT32 arg)   {    p_instr *p; - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(instr > (long)instrbuf.s.len / (long)sizeof(p_instr) || instr < 0)    fatal("update_arg outside known space.\n");   #endif    p=(p_instr *)instrbuf.s.str;    p[instr].arg=arg;   }         /**** Bytecode Generator *****/      void ins_f_byte(unsigned int b)   { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(store_linenumbers && b<F_MAX_OPCODE)    ADD_COMPILED(b); - #endif /* DEBUG */ + #endif /* PIKE_DEBUG */       b-=F_OFFSET; - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(b>255)    error("Instruction too big %d\n",b);   #endif    add_to_program((unsigned char)b);   }      static void ins_f_byte_with_arg(unsigned int a,unsigned INT32 b)   {    switch(b >> 8)    {
pike.git/src/peep.c:228:    asm_opt();       c=(p_instr *)instrbuf.s.str;    length=instrbuf.s.len / sizeof(p_instr);       for(e=0;e<=max_label;e++) labels[e]=jumps[e]=-1;       c=(p_instr *)instrbuf.s.str;    for(e=0;e<length;e++)    { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(a_flag > 2 && store_linenumbers)    {    if(hasarg(c->opcode))    fprintf(stderr,"===%3d %4x %s(%d)\n",c->line,PC,get_token_name(c->opcode),c->arg);    else    fprintf(stderr,"===%3d %4x %s\n",c->line,PC,get_token_name(c->opcode));    }   #endif       if(store_linenumbers)
pike.git/src/peep.c:257:       case F_BYTE:    add_to_program(c->arg);    break;       case F_DATA:    ins_int(c->arg, (void(*)(char))add_to_program);    break;       case F_LABEL: - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(c->arg > max_label || c->arg < 0)    fatal("max_label calculation failed!\n");       if(labels[c->arg] != -1)    fatal("Duplicate label!\n");   #endif    labels[c->arg]=PC;    break;       default:    switch(instrs[c->opcode - F_OFFSET].flags)    {    case I_ISJUMP:    ins_f_byte(c->opcode);    case I_ISPOINTER: - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(c->arg > max_label || c->arg < 0) fatal("Jump to unknown label?\n");   #endif    tmp=PC;    ins_int(jumps[c->arg], (void(*)(char))add_to_program);    jumps[c->arg]=tmp;    break;       case I_HASARG:    ins_f_byte_with_arg(c->opcode, c->arg);    break;       case 0:    ins_f_byte(c->opcode);    break;    - #ifdef DEBUG + #ifdef PIKE_DEBUG    default:    fatal("Unknown instruction type.\n");   #endif    }    }       c++;    }       for(e=0;e<=max_label;e++)    {    int tmp2=labels[e];       while(jumps[e]!=-1)    { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(labels[e]==-1)    fatal("Hyperspace error: unknown jump point.\n");   #endif    tmp=read_int(jumps[e]);    upd_int(jumps[e], tmp2 - jumps[e]);    jumps[e]=tmp;    }    }       free((char *)labels);
pike.git/src/peep.c:333:   /**** Peephole optimizer ****/      int remove_clear_locals=0x7fffffff;   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 + #ifdef PIKE_DEBUG    if(!hasarg(f) && b)    fatal("hasarg(%d) is wrong!\n",f);   #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;    }    - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(!instrbuf.s.len)    fatal("Low make buf space failed!!!!!!\n");   #endif       p->opcode=f;    p->line=cl;    copy_shared_string(p->file, lex.current_file);    p->arg=b;       return p - (p_instr *)instrbuf.s.str;   }      int insopt2(int f, int cl, struct pike_string *cf)   { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(hasarg(f))    fatal("hasarg(%d) is wrong!\n",f);   #endif    return insopt(f,0,cl, cf);   }      static void debug(void)   {    if(fifo_len > (long)instrbuf.s.len / (long)sizeof(p_instr))    fifo_len=(long)instrbuf.s.len / (long)sizeof(p_instr); - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(eye < 0)    fatal("Popped beyond start of code.\n");       if(instrbuf.s.len)    {    p_instr *p;    p=(p_instr *)low_make_buf_space(0, &instrbuf);    if(!p[-1].file)    fatal("No file name on last instruction!\n");    }
pike.git/src/peep.c:447:      static void pop_n_opcodes(int n)   {    int e,d;    if(fifo_len)    {    p_instr *p;       d=n;    if(d>fifo_len) d=fifo_len; - #ifdef DEBUG + #ifdef PIKE_DEBUG    if((long)d > (long)instrbuf.s.len / (long)sizeof(p_instr))    fatal("Popping out of instructions.\n");   #endif       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;
pike.git/src/peep.c:507:    va_end(arglist);    fifo_len+=q;    free_string(cf);    debug();    fifo_len+=q + 3;   }         static void asm_opt(void)   { - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(a_flag > 3)    {    p_instr *c;    INT32 e,length;    c=(p_instr *)instrbuf.s.str;    length=instrbuf.s.len / sizeof(p_instr);       fprintf(stderr,"Optimization begins: \n");    for(e=0;e<length;e++,c++)    {
pike.git/src/peep.c:529: Inside #if defined(DEBUG)
   fprintf(stderr,"---%3d: %s(%d)\n",c->line,get_token_name(c->opcode),c->arg);    else    fprintf(stderr,"---%3d: %s\n",c->line,get_token_name(c->opcode));    }    }   #endif      #include "peep_engine.c"       - #ifdef DEBUG + #ifdef PIKE_DEBUG    if(a_flag > 4)    {    p_instr *c;    INT32 e,length;    c=(p_instr *)instrbuf.s.str;    length=instrbuf.s.len / sizeof(p_instr);       fprintf(stderr,"Optimization begins: \n");    for(e=0;e<length;e++,c++)    {    if(hasarg(c->opcode))    fprintf(stderr,">>>%3d: %s(%d)\n",c->line,get_token_name(c->opcode),c->arg);    else    fprintf(stderr,">>>%3d: %s\n",c->line,get_token_name(c->opcode));    }    }   #endif   }