action.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "decl.h"
  2. #include <alloc.h>
  3. /* This file contains some routines needed in "pars.g" to handle the action-
  4. * grammarrule. The assembler-instructions are handeld in blocks rather than
  5. * one at a time. So these routines provide saving and removing of assembler-
  6. * instructions.
  7. */
  8. char **as_instructions; /* The buffer(?) where the instructions are saved */
  9. int quantum = 0, /* Max. nr. of instructions in as_instructions[] */
  10. nr_instr, /* Number of saved instructions */
  11. first_action, /* Is this block of assembler-instr. the first after
  12. * a '==>'?
  13. */
  14. last_action; /* Is this block followed by a '.' ? */
  15. init_as_block()
  16. {
  17. nr_instr = 0;
  18. if ( quantum == 0) {
  19. quantum = 16;
  20. as_instructions = (char **)Malloc( quantum*sizeof( char *));
  21. }
  22. }
  23. save_as( instr)
  24. char *instr;
  25. /* Save a copy of 'instr'
  26. */
  27. {
  28. if ( nr_instr == quantum) {
  29. quantum *= 2;
  30. as_instructions = (char **) Realloc( (char *) as_instructions,
  31. quantum*sizeof( char *));
  32. }
  33. as_instructions[nr_instr++] = Salloc( instr, strlen( instr) + 1);
  34. }
  35. do_block_assemble()
  36. {
  37. int i;
  38. if ( nr_instr > 0) {
  39. block_assemble( as_instructions, nr_instr,
  40. first_action, last_action);
  41. for ( i=0; i<nr_instr; i++)
  42. free( as_instructions[i]);
  43. }
  44. }