Exemplo n.º 1
0
Arquivo: mcc.c Projeto: JamesLinus/mcc
// 'program' runs in a separate process
static int program(void *context)
{
    struct vector *v = (struct vector *)context;
    const char *ifile = (const char *)vec_at(v, 0);
    const char *ofile = (const char *)vec_at_safe(v, 1);
    return cc_main(ifile, ofile);
}
Exemplo n.º 2
0
int64_t decode(void *buffer, size_t size, int64_t sum)
{
    unsigned int i;
    C(table_t) foobarcontainer;
    FooBar(vec_t) list;
    FooBar(table_t) foobar;
    Bar(struct_t) bar;
    Foo(struct_t) foo;

    foobarcontainer = C(as_root(buffer));
    sum += C(initialized(foobarcontainer));
    sum += StringLen(C(location(foobarcontainer)));
    sum += C(fruit(foobarcontainer));
    list = C(list(foobarcontainer));
    for (i = 0; i < FooBar(vec_len(list)); ++i) {
        foobar = FooBar(vec_at(list, i));
        sum += StringLen(FooBar(name(foobar)));
        sum += FooBar(postfix(foobar));
        sum += (int64_t)FooBar(rating(foobar));
        bar = FooBar(sibling(foobar));
        sum += (int64_t)Bar(ratio(bar));
        sum += Bar(size(bar));
        sum += Bar(time(bar));
        foo = Bar(parent(bar));
        sum += Foo(count(foo));
        sum += Foo(id(foo));
        sum += Foo(length(foo));
        sum += Foo(prefix(foo));
    }
    return sum + 2 * sum;
}
Exemplo n.º 3
0
static void fields(node_t * sym)
{
    int follow[] = {INT, CONST, '}', IF, 0};
    node_t *sty = SYM_TYPE(sym);

    if (!first_decl(token)) {
        error("expect type name or qualifiers");
        return;
    }

    struct vector *v = vec_new();
    do {
        node_t *basety = specifiers(NULL, NULL);

        for (;;) {
            node_t *field = new_field();
            if (token->id == ':') {
                bitfield(field);
                FIELD_TYPE(field) = basety;
            } else {
                node_t *ty = NULL;
                struct token *id = NULL;
                declarator(&ty, &id, NULL);
                attach_type(&ty, basety);
                if (token->id == ':')
                    bitfield(field);
                FIELD_TYPE(field) = ty;
                if (id) {
                    for (int i = 0; i < vec_len(v); i++) {
                        node_t *f = vec_at(v, i);
                        if (FIELD_NAME(f) &&
                                !strcmp(FIELD_NAME(f), id->name)) {
                            errorf(id->src,
                                   "redefinition of '%s'",
                                   id->name);
                            break;
                        }
                    }
                    FIELD_NAME(field) = id->name;
                    AST_SRC(field) = id->src;
                }
            }

            vec_push(v, field);
            if (token->id != ',')
                break;
            expect(',');
            ensure_field(field, vec_len(v), false);
        }

        match(';', follow);
        ensure_field(vec_tail(v), vec_len(v),
                     isstruct(sty) && !first_decl(token));
    } while (first_decl(token));

    TYPE_FIELDS(sty) = (node_t **) vtoa(v);
    set_typesize(sty);
}
Exemplo n.º 4
0
void* vec_back(vec_t* vec) {
  assert(vec->size);
  return vec_at(vec, vec->size - 1);
}
Exemplo n.º 5
0
Arquivo: mcc.c Projeto: JamesLinus/mcc
int main(int argc, char **argv)
{
    int ret = EXIT_SUCCESS;
    const char *tmpdir;
    size_t fails = 0;

    progname = argv[0];
    setup_sys();
    init_env();
    parse_opts(argc, argv);

    bool partial = opts.E || opts.ast_dump || opts.ir_dump || opts.S || opts.c;

    if (argc == 1) {
        usage();
        return EXIT_SUCCESS;
    } else if (vec_len(inputs) == 0) {
        fprintf(stderr, "no input file.\n");
        return EXIT_FAILURE;
    } else if (output && vec_len(inputs) > 1 && partial) {
        fprintf(stderr,
                "mcc: cannot specify -o when generating multiple output files\n");
        return EXIT_FAILURE;
    }

    if (!(tmpdir = mktmpdir()))
        die("Can't make temporary directory.");

    struct vector *objects = vec_new();

    for (int i = 0; i < vec_len(inputs); i++) {
        const char *ifile = vec_at(inputs, i);
        const char *iname = basename(xstrdup(ifile));
        const char *ofile = NULL;
        int ret;
        if (opts.E || opts.ast_dump || opts.ir_dump) {
            if (output)
                ofile = output;
            ret = translate(ifile, ofile);
        } else if (opts.S) {
            if (output)
                ofile = output;
            else
                ofile = replace_suffix(iname, "s");
            ret = translate(ifile, ofile);
        } else if (opts.c) {
            if (output)
                ofile = output;
            else
                ofile = replace_suffix(iname, "o");
            const char *sfile =
                tempname(tmpdir, replace_suffix(ifile, "s"));
            ret = translate(ifile, sfile);
            if (ret == 0)
                ret = assemble(sfile, ofile);
        } else {
            const char *sfile =
                tempname(tmpdir, replace_suffix(ifile, "s"));
            ret = translate(ifile, sfile);
            if (ret == 0) {
                ofile =
                    tempname(tmpdir,
                             replace_suffix(ifile, "o"));
                ret = assemble(sfile, ofile);
                vec_push(objects, (char *)ofile);
            }
        }
        if (ret == EXIT_FAILURE)
            fails++;
    }

    if (fails) {
        ret = EXIT_FAILURE;
        fprintf(stderr, "%lu succeed, %lu failed.\n",
                vec_len(inputs) - fails, fails);
    } else if (!partial) {
        // link
        ret = link(objects, output, opts.ld_options);
    }

    if (tmpdir)
        rmdir(tmpdir);
    return ret;
}
Exemplo n.º 6
0
GLRenderTexture* GLRenderTexture::getBound(int idx)
{
    return vec_at(s_bound, -idx - 1);
}