Branch: Tag:

2003-11-19

2003-11-19 17:19:29 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Various assemble()-related cleanups:
Moved the global variable store_linenumbers to an argument of assemble().
assemble() and docode() now return the entrypoint of the generated code.
Support for ALIGN_PIKE_FUNCTION_BEGINNINGS has moved to assemble().
Some lowlevel opcode stuff has been moved from eval_low() to docode().
Moved call of ADD_COMPILED() from the individual files in code/ to assemble().
Added pseudo opcodes F_FILENAME and F_LINE for the benefit of PIKE_PORTABLE_BYTECODE.
assemble() now has some support for PIKE_PORTABLE_BYTECODE.

Rev: src/code/bytecode.c:1.7
Rev: src/code/computedgoto.c:1.4
Rev: src/code/ia32.c:1.36
Rev: src/code/ppc32.c:1.33
Rev: src/code/sparc.c:1.38
Rev: src/docode.c:1.173
Rev: src/docode.h:1.19
Rev: src/las.c:1.343
Rev: src/opcodes.c:1.161
Rev: src/opcodes.h:1.38
Rev: src/peep.c:1.93
Rev: src/peep.h:1.14

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: peep.c,v 1.92 2003/10/17 03:49:26 nilsson Exp $ + || $Id: peep.c,v 1.93 2003/11/19 17:19:29 grubba Exp $   */      #include "global.h"
26:   #include "interpret.h"   #include "pikecode.h"    - RCSID("$Id: peep.c,v 1.92 2003/10/17 03:49:26 nilsson Exp $"); + RCSID("$Id: peep.c,v 1.93 2003/11/19 17:19:29 grubba Exp $");      static void asm_opt(void);   
147:      /**** Bytecode Generator *****/    - void assemble(void) + INT32 assemble(int store_linenumbers)   { -  +  INT32 entry_point;    INT32 max_label=-1,tmp;    INT32 *labels, *jumps, *uses;    ptrdiff_t e, length;    p_instr *c;    int reoptimize=!(debug_options & NO_PEEP_OPTIMIZING); -  + #ifdef PIKE_PORTABLE_BYTECODE +  struct pike_tripple *tripples = NULL; + #endif /* PIKE_PORTABLE_BYTECODE */   #ifdef PIKE_DEBUG    INT32 max_pointer=-1;    int synch_depth = 0;
180:    }   #endif    + #ifdef PIKE_PORTABLE_BYTECODE +  /* No need to do this for constant evaluations. */ +  if (store_linenumbers) { +  struct pike_tripple *current_tripple; +  struct pike_string *previous_file = NULL; +  int previous_line = 0; +  ptrdiff_t num_linedirectives = 0; +  +  /* Count the number of F_FILE/F_LINE pseudo-ops we need to add. */ +  for (e=0; e < length; e++) { +  if (c[e].file != previous_file) { +  previous_file = c[e].file; +  num_linedirectives++; +  } +  if (c[e].line != previous_line) { +  previous_line = c[e].line; +  num_linedirectives++; +  } +  } +  +  fprintf(stderr, "length:%d directives:%d\n", length, num_linedirectives); +  +  if (!(tripples = malloc(sizeof(struct pike_tripple) * +  (length+num_linedirectives)))) { +  Pike_fatal("Failed to allocate %d tripples (%d + %d).\n", +  length+num_linedirectives, length, num_linedirectives); +  } +  previous_file = NULL; +  previous_line = 0; +  current_tripple = tripples; +  for (e = 0; e < length; e++) { +  if (c[e].file != previous_file) { +  current_tripple->opcode = F_FILENAME; +  current_tripple->arg = store_prog_string(c[e].file); +  current_tripple->arg2 = 0; +  current_tripple++; +  previous_file = c[e].file; +  } +  if (c[e].line != previous_line) { +  current_tripple->opcode = F_LINE; +  current_tripple->arg = c[e].line; +  current_tripple->arg2 = 0; +  current_tripple++; +  previous_line = c[e].line; +  } +  current_tripple->opcode = c[e].opcode; +  current_tripple->arg = c[e].arg; +  current_tripple->arg2 = c[e].arg2; +  current_tripple++; +  } + #ifdef PIKE_DEBUG +  if (current_tripple != tripples + length + num_linedirectives) { +  Pike_fatal("Tripple length mismatch %d != %d (%d + %d)\n", +  current_tripple - tripples, +  length + num_linedirectives, +  length, num_linedirectives); +  } + #endif /* PIKE_DEBUG */ +  } +  + #endif /* PIKE_PORTABLE_BYTECODE */ +     for(e=0;e<length;e++,c++) {    if(c->opcode == F_LABEL) {    if(c->arg > max_label)
321:   #endif /* 1 */    }    +  /* Time to create the actual bytecode. */ +     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;    -  + #ifdef ALIGN_PIKE_FUNCTION_BEGINNINGS +  while( ( (((INT32) PIKE_PC)+2) & (ALIGN_PIKE_JUMPS-1))) +  ins_byte(0); + #endif +  + #ifdef PIKE_PORTABLE_BYTECODE +  if (store_linenumbers) { +  ins_pointer(tripples); +  } else { +  ins_pointer(NULL); +  } + #endif /* PIKE_PORTABLE_BYTECODE */ +  +  entry_point = PIKE_PC; +    #ifdef PIKE_DEBUG    synch_depth = 0;   #endif
348:    }   #endif    -  if(store_linenumbers) +  if(store_linenumbers) {    store_linenumber(c->line, c->file); -  + #ifdef PIKE_DEBUG +  if (c->opcode < F_MAX_OPCODE) +  ADD_COMPILED(c->opcode); + #endif /* PIKE_DEBUG */ +  }       switch(c->opcode)    {
618:   #endif /* PIKE_DEBUG */       exit_bytecode(); +  +  return entry_point;   }      /**** Peephole optimizer ****/