コード例 #1
0
ファイル: stmt.c プロジェクト: beretta42/FUZIX
/**
 * dump switch table
 */
void dumpsw(WHILE *ws) {
        int     i,j;

        data_segment_gdata ();
        generate_label (ws->body_tab);
        if (ws->case_test != swstp) {
                j = ws->case_test;
                while (j < swstp) {
                        gen_def_word ();
                        i = 4;
                        while (i--) {
                                output_number (swstcase[j]);
                                output_byte (',');
                                print_label (swstlab[j++]);
                                if ((i == 0) | (j >= swstp)) {
                                        newline ();
                                        break;
                                }
                                output_byte (',');
                        }
                }
        }
        gen_def_word ();
        print_label (ws->incr_def);
        output_string (",0");
        newline ();
        code_segment_gtext ();
}
コード例 #2
0
ファイル: stmt.c プロジェクト: AtomSoftTech/retrobsd
/**
 * dump switch table
 */
dumpsw(loop_t *loop) {
        int     i,j;

        data_segment_gdata ();
        generate_label (loop->body_label);
        if (loop->test_label != swstp) {
                j = loop->test_label;
                while (j < swstp) {
                        gen_def_word ();
                        i = 4;
                        while (i--) {
                                output_number (swstcase[j]);
                                output_byte (',');
                                print_label (swstlab[j++]);
                                if ((i == 0) | (j >= swstp)) {
                                        newline ();
                                        break;
                                }
                                output_byte (',');
                        }
                }
        }
        gen_def_word ();
        print_label (loop->cont_label);
        output_string (",0");
        newline ();
        code_segment_gtext ();
}
コード例 #3
0
ファイル: sym.c プロジェクト: EtchedPixels/FUZIX
/**
 * add new symbol to local table
 * @param sname
 * @param identity
 * @param type
 * @param offset size in bytes
 * @param storage_class
 * @return 
 */
int add_local (char *sname, int identity, int type, int offset, int storage_class) {
    int k;
    SYMBOL *symbol;
    char *buffer_ptr;

    if ((current_symbol_table_idx = find_locale (sname)) > -1) {
        return (current_symbol_table_idx);
    }
    if (local_table_index >= NUMBER_OF_GLOBALS + NUMBER_OF_LOCALS) {
        error ("local symbol table overflow");
        return (0);
    }
    current_symbol_table_idx = local_table_index;
    symbol = &symbol_table[current_symbol_table_idx];
    buffer_ptr = symbol->name;
    /* FIXME: only copy so many bytes */
    while (alphanumeric(*buffer_ptr++ = *sname++));
    symbol->identity = identity;
    symbol->type = type;
    symbol->storage = storage_class;
    if (storage_class == LSTATIC) {
        data_segment_gdata();
        print_label(k = getlabel());
        output_label_terminator();
        gen_def_storage();
        output_number(offset);
        newline();
        code_segment_gtext();
        offset = k;
    }
    symbol->offset = offset;
    local_table_index++;
    return (current_symbol_table_idx);
}
コード例 #4
0
ファイル: main.c プロジェクト: JamesLinus/FUZIX
/**
 * compile one file if filename is NULL redirect do to stdin/stdout
 * @param file filename
 * @return 
 */
void compile(char *file) {
    if (file == NULL || filename_typeof(file) == 'c') {
        global_table_index = 0;
        local_table_index = NUMBER_OF_GLOBALS;
        while_table_index = 0;
        tag_table_index = 0;
        inclsp =
        iflevel =
        skiplevel =
        swstp =
        litptr =
        stkp =
        errcnt =
        ncmp =
        lastst =
        //quote[1] =
        0;
        input2 = -1;
        //quote[0] = '"';
        cmode = 1;
        glbflag = 1;
        nxtlab = 0;
        litlab = getlabel();
        defmac("end\tmemory");
        //add_global("memory", ARRAY, CCHAR, 0, EXTERN);
        //add_global("stack", ARRAY, CCHAR, 0, EXTERN);
        rglobal_table_index = global_table_index; //rglbptr = glbptr;
        //add_global("etext", ARRAY, CCHAR, 0, EXTERN);
        //add_global("edata", ARRAY, CCHAR, 0, EXTERN);
        defmac("short\tint");
        initmac();
        // compiler body
        if (file == NULL) {
            input = 0;
        } else if (!openin(file))
            return;
        if (file == NULL) {
            output = 1;
        } else if (!openout())
            return;
        header();
        code_segment_gtext();
        parse();
        close(input);
        data_segment_gdata();
        dumplits();
        dumpglbs();
        errorsummary();
        trailer();
        oflush();
        close(output);
        pl("");
        errs = errs || errfile;
    } else {
        writee("Don't understand file ");
        writee(file);
        errs = 1;
    }
}
コード例 #5
0
ファイル: sym.c プロジェクト: EtchedPixels/FUZIX
/**
 * initialize global objects
 * @param symbol_name
 * @param type char or integer or struct
 * @param identity
 * @param dim
 * @return 1 if variable is initialized
 */
int initials(char *symbol_name, int type, int identity, int dim, int otag) {
    int dim_unknown = 0;
    int n;

    if(dim == 0) { // allow for xx[] = {..}; declaration
        dim_unknown = 1;
    }
    if (!(type & CCHAR) && !(type & CINT) && !(type == STRUCT)) {
        error("unsupported storage size");
    }
    data_segment_gdata();
    glabel(symbol_name);
    if(match("=")) {
        // an array or struct
        if(match("{")) {
            // aggregate initialiser
            if ((identity == POINTER || identity == VARIABLE) && type == STRUCT) {
                // aggregate is structure or pointer to structure
                dim = 0;
                struct_init(&tag_table[otag], symbol_name);
            }
            else {
                while((dim > 0) || (dim_unknown)) {
                    if (identity == ARRAY && type == STRUCT) {
                        // array of struct
                        needbrack("{");
                        struct_init(&tag_table[otag], symbol_name);
                        --dim;
                        needbrack("}");
                    }
                    else {
                        if (init(symbol_name, type, identity, &dim, 0)) {
                            dim_unknown++;
                        }
                    }
                    if(match(",") == 0) {
                        break;
                    }
                }
                if(--dim_unknown == 0)
                    identity = POINTER;
                else {
                    /* Pad any missing objects */
                    n = dim;
                    gen_def_storage();
                    if (identity != ARRAY && type != STRUCT) {
                        if (!(type & CCHAR))
                           n *= 2;
                    } else
                        n = tag_table[otag].size;

                    output_number(n);
                    newline();
                }
            }
            needbrack("}");
        // single constant
        } else {
            init(symbol_name, type, identity, &dim, 0);
        }
    }
    code_segment_gtext();
    return identity;
}