Ejemplo n.º 1
0
void free_algo(struct algo *algo)
{
  free_instructions(algo->instructions);
  free_decls(algo->declarations);
  free(algo->ident);
  if (algo->return_type)
    free(algo->return_type);
  free(algo);
}
Ejemplo n.º 2
0
void free_prog(struct prog *prog)
{
  free_var_decl(prog->entry_point->var_decl);
  free_const_decl(prog->entry_point->const_decls);
  free_type_decls(prog->entry_point->type_decls);
  free_instructions(prog->entry_point->instructions);
  free(prog->entry_point);
  for (unsigned i = 0; i < prog->algos.size; ++i)
    free_algo(prog->algos.data[i]);
  list_free(prog->algos);
  free(prog);
}
Ejemplo n.º 3
0
/* Run yyparse and return a pointer to the first instruction if no
   errors occur, otherwise return NULL */
Instruction* parse()
{
    opcode_init();
    yyparse();
    if (error_found)
    {
	free_instructions(first_instruction);
	return NULL;
    }
    else
    {
      return first_instruction;
    }
}
Ejemplo n.º 4
0
void free_instruction(struct instruction *i)
{
  switch (i->kind)
  {
    case assignment:
      free_expression(i->instr.assignment->e1);
      free_expression(i->instr.assignment->e2);
      free(i->instr.assignment);
      break;
    case switchcase:
      free_caseblocklist(i->instr.switchcase->caseblocklist);
      free_instructions(i->instr.switchcase->otherwiseblock);
      free_expression(i->instr.switchcase->cond);
      free(i->instr.switchcase);
      break;
    case dowhile:
      free_expression(i->instr.dowhile->cond);
      free_instructions(i->instr.dowhile->instructions);
      free(i->instr.dowhile);
      break;
    case whiledo:
      free_expression(i->instr.whiledo->cond);
      free_instructions(i->instr.whiledo->instructions);
      free(i->instr.whiledo);
      break;
    case forloop:
      free_expression(i->instr.forloop->assignment->e1);
      free_expression(i->instr.forloop->assignment->e2);
      free(i->instr.forloop->assignment);
      free_instructions(i->instr.forloop->instructions);
      free_expression(i->instr.forloop->upto);
      free(i->instr.forloop);
      break;
    case funcall:
      free_args(i->instr.funcall->args);
      free(i->instr.funcall->fun_ident);
      free(i->instr.funcall);
      break;
    case ifthenelse:
      free_expression(i->instr.ifthenelse->cond);
      free_instructions(i->instr.ifthenelse->instructions);
      free_instructions(i->instr.ifthenelse->elseblock);
      free(i->instr.ifthenelse);
      break;
    case returnstmt:
      free_expression(i->instr.returnstmt->expr);
      free(i->instr.returnstmt);
      break;
  }
  free(i);
}
Ejemplo n.º 5
0
void
make_memory (int text_size, int data_size, int data_limit,
	     int stack_size, int stack_limit, int k_text_size,
	     int k_data_size, int k_data_limit)
{
  if (data_size <= 65536)
    data_size = 65536;
  data_size = ROUND_UP(data_size, BYTES_PER_WORD); /* Keep word aligned */

  if (text_seg == NULL)
    text_seg = (instruction **) xmalloc (BYTES_TO_INST(text_size));
  else
    {
      free_instructions (text_seg, (text_top - TEXT_BOT) / BYTES_PER_WORD);
      text_seg = (instruction **) realloc (text_seg, BYTES_TO_INST(text_size));
    }
  memclr (text_seg, BYTES_TO_INST(text_size));
  text_top = TEXT_BOT + text_size;

  data_size = ROUND_UP(data_size, BYTES_PER_WORD); /* Keep word aligned */
  if (data_seg == NULL)
    data_seg = (mem_word *) xmalloc (data_size);
  else
    data_seg = (mem_word *) realloc (data_seg, data_size);
  memclr (data_seg, data_size);
  data_seg_b = (BYTE_TYPE *) data_seg;
  data_seg_h = (short *) data_seg;
  data_top = DATA_BOT + data_size;
  data_size_limit = data_limit;

  stack_size = ROUND_UP(stack_size, BYTES_PER_WORD); /* Keep word aligned */
  if (stack_seg == NULL)
    stack_seg = (mem_word *) xmalloc (stack_size);
  else
    stack_seg = (mem_word *) realloc (stack_seg, stack_size);
  memclr (stack_seg, stack_size);
  stack_seg_b = (BYTE_TYPE *) stack_seg;
  stack_seg_h = (short *) stack_seg;
  stack_bot = STACK_TOP - stack_size;
  stack_size_limit = stack_limit;

  if (k_text_seg == NULL)
    k_text_seg = (instruction **) xmalloc (BYTES_TO_INST(k_text_size));
  else
    {
      free_instructions (k_text_seg,
			 (k_text_top - K_TEXT_BOT) / BYTES_PER_WORD);
      k_text_seg = (instruction **) realloc(k_text_seg,
					    BYTES_TO_INST(k_text_size));
    }
  memclr (k_text_seg, BYTES_TO_INST(k_text_size));
  k_text_top = K_TEXT_BOT + k_text_size;

  k_data_size = ROUND_UP(k_data_size, BYTES_PER_WORD); /* Keep word aligned */
  if (k_data_seg == NULL)
    k_data_seg = (mem_word *) xmalloc (k_data_size);
  else
    k_data_seg = (mem_word *) realloc (k_data_seg, k_data_size);
  memclr (k_data_seg, k_data_size);
  k_data_seg_b = (BYTE_TYPE *) k_data_seg;
  k_data_seg_h = (short *) k_data_seg;
  k_data_top = K_DATA_BOT + k_data_size;
  k_data_size_limit = k_data_limit;

  text_modified = 1;
  data_modified = 1;
}
Ejemplo n.º 6
0
void free_caseblock(struct caseblock *caseblock)
{
  free_expressions(caseblock->exprlist);
  free_instructions(caseblock->instructions);
  free(caseblock);
}