Branch: Tag:

2016-12-31

2016-12-31 17:12:22 by Arne Goedeke <el@laramies.com>

dynamic_buffer: use new buffer internally

The API of dynamic_buffer is now a slim swapper around the new buffer
API. This changes many places where the dynamic_buffer internals were
directly used.

59:      void init_bytecode(void)   { -  initialize_buf(&instrbuf); +  buffer_init(&instrbuf); +  buffer_ensure_space(&instrbuf, 512);    num_instrs = 0;   }   
68:    ptrdiff_t e, length;    p_instr *c;    -  c=(p_instr *)instrbuf.s.str; -  length=instrbuf.s.len / sizeof(p_instr); +  c=(p_instr *)buffer_ptr(&instrbuf); +  length=buffer_content_length(&instrbuf) / sizeof(p_instr);       for(e=0;e<length;e++) {    free_string(dmalloc_touch_named(struct pike_string *, c[e].file,
91:    if (!p) Pike_fatal("Out of memory in peep.\n");    *p = *opcode;    num_instrs++; -  return p - (p_instr *)instrbuf.s.str; +  return p - (p_instr *)buffer_ptr(&instrbuf);   }      ptrdiff_t insert_opcode2(unsigned int f,
111:         #ifdef PIKE_DEBUG -  if(!instrbuf.s.len) +  if(!buffer_content_length(&instrbuf))    Pike_fatal("Low make buf space failed!!!!!!\n");   #endif   
123:    p->arg=b;    p->arg2=c;    -  return p - (p_instr *)instrbuf.s.str; +  return p - (p_instr *)buffer_ptr(&instrbuf);   }      ptrdiff_t insert_opcode1(unsigned int f,
154:   {    p_instr *p;   #ifdef PIKE_DEBUG -  if(instr > (long)instrbuf.s.len / (long)sizeof(p_instr) || instr < 0) +  if(instr > (long)buffer_content_length(&instrbuf) / (long)sizeof(p_instr) || instr < 0)    Pike_fatal("update_arg outside known space.\n");   #endif -  p=(p_instr *)instrbuf.s.str; +  p=(p_instr *)buffer_ptr(&instrbuf);    p[instr].arg=arg;   }   
186:    CHECK_COMPILER();    lex = &THIS_COMPILATION->lex;    -  c=(p_instr *)instrbuf.s.str; -  length=instrbuf.s.len / sizeof(p_instr); +  c=(p_instr *)buffer_ptr(&instrbuf); +  length=buffer_content_length(&instrbuf) / sizeof(p_instr);      #ifdef PIKE_DEBUG    if((a_flag > 1 && store_linenumbers) || a_flag > 2)
296: Inside #if defined(PIKE_DEBUG)
   "Reference to undefined label %d > %d\n"    "Bad instructions are marked with '***':\n",    max_pointer, max_label); -  c=(p_instr *)instrbuf.s.str; +  c=(p_instr *)buffer_ptr(&instrbuf);    for(e=0;e<length;e++,c++) {    if (c->opcode == F_POP_SYNCH_MARK) synch_depth--;    fprintf(stderr, " * %4ld %4lx ",
318: Inside #if undefined(INS_ENTRY)
     #ifndef INS_ENTRY    /* Replace F_ENTRY with F_NOP if we have no entry prologue. */ -  for (c = (p_instr *) instrbuf.s.str, e = 0; e < length; e++, c++) +  for (c = (p_instr *) buffer_ptr(&instrbuf), e = 0; e < length; e++, c++)    if (c->opcode == F_ENTRY) c->opcode = F_NOP;   #endif   
333:    memset(labels, 0xff, ((max_label + 2) * 3) * sizeof(INT32));    memset(uses, 0x00, (max_label + 2) * sizeof(INT32));    -  c=(p_instr *)instrbuf.s.str; -  length=instrbuf.s.len / sizeof(p_instr); +  c=(p_instr *)buffer_ptr(&instrbuf); +  length=buffer_content_length(&instrbuf) / sizeof(p_instr);    for(e=0;e<length;e++)    if(c[e].opcode == F_LABEL && c[e].arg>=0) {    INT32 l = c[e].arg;
461:    }       /* Time to create the actual bytecode. */ -  c=(p_instr *)instrbuf.s.str; -  length=instrbuf.s.len / sizeof(p_instr); +  c=(p_instr *)buffer_ptr(&instrbuf); +  length=buffer_content_length(&instrbuf) / sizeof(p_instr);       for(e=0;e<=max_label;e++) labels[e]=jumps[e]=-1;   
496: Inside #if defined(PIKE_DEBUG)
   size_t opcode_start = PIKE_PC;   # endif    -  if (c != (((p_instr *)instrbuf.s.str)+e)) { +  if (c != (((p_instr *)buffer_ptr(&instrbuf))+e)) {    Pike_fatal("Instruction loop deviates. "    "0x%04"PRINTPTRDIFFT"x != 0x%04"PRINTPTRDIFFT"x\n", -  e, c - ((p_instr *)instrbuf.s.str)); +  e, c - ((p_instr *)buffer_ptr(&instrbuf)));    }    if(((a_flag > 2) && store_linenumbers) ||    (a_flag > 3) ||
876: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG   static void debug(void)   { -  if (num_instrs != (long)instrbuf.s.len / (long)sizeof(p_instr)) { +  if (num_instrs != (long)buffer_content_length(&instrbuf) / (long)sizeof(p_instr)) {    Pike_fatal("PEEP: instrbuf lost count (%d != %d)\n", -  num_instrs, (long)instrbuf.s.len / (long)sizeof(p_instr)); +  num_instrs, (long)buffer_content_length(&instrbuf) / (long)sizeof(p_instr));    } -  if(instrbuf.s.len) +  if(buffer_content_length(&instrbuf))    {    p_instr *p; -  p=(p_instr *)low_make_buf_space(0, &instrbuf); +  p=(p_instr *)buffer_dst(&instrbuf);    if(!p[-1].file)    Pike_fatal("No file name on last instruction!\n");    }
897:   static inline p_instr *instr(int offset)   {    if (offset >= num_instrs) return NULL; -  return ((p_instr *)low_make_buf_space(0, &instrbuf)) - (offset + 1); +  return ((p_instr *)buffer_dst(&instrbuf)) - (offset + 1);   }      static inline int opcode(int offset)
951:    Pike_fatal("Popping out of instructions.\n");   #endif    -  p = ((p_instr *)low_make_buf_space(0, &instrbuf)) - n; +  p = ((p_instr *)buffer_dst(&instrbuf)) - n;    for (e = 0; e < n; e++) {    free_string(dmalloc_touch_named(struct pike_string *, p[e].file,    "pop_n_opcodes"));
1080: Inside #if defined(PIKE_DEBUG)
   ptrdiff_t e, length;    int synch_depth = 0;    -  c=(p_instr *)instrbuf.s.str; -  length=instrbuf.s.len / sizeof(p_instr); +  c=(p_instr *)buffer_ptr(&instrbuf); +  length=buffer_content_length(&instrbuf) / sizeof(p_instr);       fprintf(stderr,"Before peep optimization:\n");    for(e=0;e<length;e++,c++)
1095:    }   #endif    -  len=instrbuf.s.len/sizeof(p_instr); -  instructions=(p_instr *)instrbuf.s.str; -  instrbuf.s.str=0; +  len=buffer_content_length(&instrbuf)/sizeof(p_instr); +  instructions=(p_instr *)buffer_ptr(&instrbuf);    init_bytecode();       for(eye = 0; advance();)
1127: Inside #if defined(PIKE_DEBUG)
   ptrdiff_t e, length;    int synch_depth = 0;    -  c=(p_instr *)instrbuf.s.str; -  length=instrbuf.s.len / sizeof(p_instr); +  c=(p_instr *)buffer_ptr(&instrbuf); +  length=buffer_content_length(&instrbuf) / sizeof(p_instr);       fprintf(stderr,"After peep optimization:\n");    for(e=0;e<length;e++,c++)