Beispiel #1
0
static void libdef_set(BuildCtx *ctx, char *p, int arg)
{
    UNUSED(arg);
    if (ctx->mode == BUILD_libdef) {
        if (p[0] == '!' && p[1] == '\0') p[0] = '\0';  /* Set env. */
        libdef_name(p, LIBINIT_STRING);
        *optr++ = LIBINIT_SET;
        obuf[2]++;  /* Bump hash table size. */
    }
}
Beispiel #2
0
static void libdef_func(BuildCtx *ctx, char *p, int arg)
{
    if (arg != LIBINIT_CF)
        ffasmfunc++;
    if (ctx->mode == BUILD_libdef) {
        if (modstate == 0) {
            fprintf(stderr, "Error: no module for function definition %s\n", p);
            exit(1);
        }
        if (regfunc == REGFUNC_NOREG) {
            if (optr + 1 > obuf + sizeof(obuf)) {
                fprintf(stderr, "Error: output buffer overflow\n");
                exit(1);
            }
            *optr++ = LIBINIT_FFID;
        }
        else {
            if (arg != LIBINIT_ASM_) {
                if (modstate != 1) fprintf(ctx->fp, ",\n");
                modstate = 2;
                fprintf(ctx->fp, "  %s%s", arg ? LABEL_PREFIX_FFH : LABEL_PREFIX_CF, p);
            }
            if (regfunc != REGFUNC_NOREGUV) obuf[2]++;  /* Bump hash table size. */
            libdef_name(regfunc == REGFUNC_NOREGUV ? "" : p, arg);
        }
    }
    else if (ctx->mode == BUILD_ffdef) {
        fprintf(ctx->fp, "FFDEF(%s)\n", p);
    }
    else if (ctx->mode == BUILD_recdef) {
        if (strlen(p) > sizeof(funcname) - 1) {
            fprintf(stderr, "Error: function name too long: '%s'\n", p);
            exit(1);
        }
        strcpy(funcname, p);
    }
    else if (ctx->mode == BUILD_vmdef) {
        int i;
        for (i = 1; p[i] && modname[i - 1]; i++)
            if (p[i] == '_') p[i] = '.';
        fprintf(ctx->fp, "\"%s\",\n", p);
    }
    else if (ctx->mode == BUILD_bcdef) {
        if (arg != LIBINIT_CF)
            fprintf(ctx->fp, ",\n%d", find_ffofs(ctx, p));
    }
    ffid++;
    regfunc = REGFUNC_OK;
}
Beispiel #3
0
static void libdef_push(BuildCtx *ctx, char *p, int arg)
{
    UNUSED(arg);
    if (ctx->mode == BUILD_libdef) {
        int len = (int)strlen(p);
        if (*p == '"') {
            if (len > 1 && p[len - 1] == '"') {
                p[len - 1] = '\0';
                libdef_name(p + 1, LIBINIT_STRING);
                return;
            }
        }
        else if (*p >= '0' && *p <= '9') {
            char *ep;
            double d = strtod(p, &ep);
            if (*ep == '\0') {
                if (optr + 1 + sizeof(double) > obuf + sizeof(obuf)) {
                    fprintf(stderr, "Error: output buffer overflow\n");
                    exit(1);
                }
                *optr++ = LIBINIT_NUMBER;
                memcpy_endian(optr, &d, sizeof(double));
                optr += sizeof(double);
                return;
            }
        }
        else if (!strcmp(p, "lastcl")) {
            if (optr + 1 > obuf + sizeof(obuf)) {
                fprintf(stderr, "Error: output buffer overflow\n");
                exit(1);
            }
            *optr++ = LIBINIT_LASTCL;
            return;
        }
        else if (len > 4 && !strncmp(p, "top-", 4)) {
            if (optr + 2 > obuf + sizeof(obuf)) {
                fprintf(stderr, "Error: output buffer overflow\n");
                exit(1);
            }
            *optr++ = LIBINIT_COPY;
            *optr++ = (uint8_t)atoi(p + 4);
            return;
        }
        fprintf(stderr, "Error: bad value for %sPUSH(%s)\n", LIBDEF_PREFIX, p);
        exit(1);
    }
}
Beispiel #4
0
static void libdef_lua(BuildCtx *ctx, char *p, int arg)
{
    UNUSED(arg);
    if (ctx->mode == BUILD_libdef) {
        int i;
        for (i = 0; libbc_map[i].name != NULL; i++) {
            if (!strcmp(libbc_map[i].name, p)) {
                int ofs = libbc_map[i].ofs;
                int len = libbc_map[i+1].ofs - ofs;
                obuf[2]++;  /* Bump hash table size. */
                *optr++ = LIBINIT_LUA;
                libdef_name(p, 0);
                memcpy(optr, libbc_code + ofs, len);
                libdef_fixupbc(optr);
                optr += len;
                return;
            }
        }
        fprintf(stderr, "Error: missing libbc definition for %s\n", p);
        exit(1);
    }
}