Пример #1
0
/* Instruction Stream type setup */
gc_type_def register_stream_type(gc_type *gc) {
  gc_type_def type = 0;

  type = gc_register_type(gc, sizeof(ins_stream_type));
  /* we only need to register the head */
  gc_register_pointer(gc, type, offsetof(ins_stream_type, head));

  return type;
}
Пример #2
0
/* Compiler core type  */
gc_type_def register_compiler_type(gc_type *gc) {
  gc_type_def type = 0;

  type = gc_register_type(gc, sizeof(compiler_core_type));
  gc_register_pointer(gc, type, offsetof(compiler_core_type, stream));
  gc_register_pointer(gc, type, offsetof(compiler_core_type, include_stack));

  return type;
}
Пример #3
0
/* setup an single instruction stream node */
gc_type_def register_node_single_type(gc_type *gc) {
  gc_type_def type = 0;

  type = gc_register_type(gc, sizeof(ins_node_type));
  gc_register_pointer(gc, type, offsetof(ins_node_type, next));
  gc_register_pointer(gc, type, offsetof(ins_node_type, value) +
    offsetof(node_value_type, stream));

  return type;
}
Пример #4
0
/* Setup a literal node */
gc_type_def register_node_literal_type(gc_type *gc) {
  gc_type_def type = 0;

  type = gc_register_type(gc, sizeof(ins_node_type));
  gc_register_pointer(gc, type, offsetof(ins_node_type, next));
  gc_register_pointer(gc, type, offsetof(ins_node_type, value) +
    offsetof(node_value_type, literal));

  /* Add other fields here */

  return type;
}
Пример #5
0
/* setup an two instruction stream node */ 
gc_type_def register_node_double_type(gc_type *gc) {
  gc_type_def type = 0;

  type = gc_register_type(gc, sizeof(ins_node_type));
  gc_register_pointer(gc, type, offsetof(ins_node_type, next));

  gc_register_pointer(gc, type, offsetof(ins_node_type, value) +
    offsetof(node_value_type, two) + offsetof(two_stream_type, stream1));
  gc_register_pointer(gc, type, offsetof(ins_node_type, value) +
    offsetof(node_value_type, two) + offsetof(two_stream_type, stream2));

  return type;
}
Пример #6
0
void asm_jump(gc_type *gc, buffer_type *buf,
              yyscan_t *scanner, jump_type **jump_list) {

    static int init = 0;
    static gc_type_def jump_def = 0;
    jump_type *jump = 0;
    char *label = 0;

    /* TODO: This is a hack */
    if(!init) {
        init = 1;
        jump_def = gc_register_type(gc, sizeof(jump_type));
        
        gc_register_pointer(gc, jump_def, offsetof(jump_type, label));
        
        gc_register_pointer(gc, jump_def, offsetof(jump_type, next)); 
    }

    gc_register_root(gc, (void **)&jump);

    /* allocate a new jump */
    gc_alloc_type(gc, 0, jump_def, (void **)&jump);

    /* save location of jump addr field */
    jump->addr = buffer_size(buf);

    /* save the line number for this jump */
    jump->lineno = yyget_lineno(scanner);

    /* make sure we have a label */
    if(yylex(scanner) != LABEL_TOKEN) {
        assert(0);
    }

    /* save a copy of the label */
    label = get_text(scanner);
    gc_alloc(gc, 0, strlen(label)+1, (void **)&(jump->label));
    strcpy(jump->label, label);
    
    /* put this jump at the head of the
       list */
    jump->next = *jump_list;
    *jump_list = jump;
    
    gc_unregister_root(gc, (void **)&jump);

    /* Make sure we have space to write target */
    EMIT(buf, INT_64(0),8);

}