Alien-TinyCCx

 view release on metacpan or  search on metacpan

src/arm-gen.c  view on Meta::CPAN

  if(f==10.0)
    return r|7;
  return 0;
}

/* generate a floating point operation 'v = t1 op t2' instruction. The
   two operands are guaranted to have the same floating point type */
void gen_opf(int op)
{
  uint32_t x, r, r2, c1, c2;
  //fputs("gen_opf\n",stderr);
  vswap();
  c1 = is_fconst();
  vswap();
  c2 = is_fconst();
  x=0xEE000100;
#if LDOUBLE_SIZE == 8
  if ((vtop->type.t & VT_BTYPE) != VT_FLOAT)
    x|=0x80;
#else
  if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE)

src/examples/ex4.c  view on Meta::CPAN


/* Yes, TCC can use X11 too ! */

int main(int argc, char **argv)
{
    Display *display;
    Screen *screen;

    display = XOpenDisplay("");
    if (!display) {
        fprintf(stderr, "Could not open X11 display\n");
        exit(1);
    }
    printf("X11 display opened.\n");
    screen = XScreenOfDisplay(display, 0);
    printf("width = %d\nheight = %d\ndepth = %d\n",
           screen->width,
           screen->height,
           screen->root_depth);
    XCloseDisplay(display);
    return 0;

src/lib/bcheck.c  view on Meta::CPAN

    if (e1->is_invalid)
        return __bound_invalid_t2;
    else
        return __bound_empty_t2;
}

/* print a bound error message */
static void bound_error(const char *fmt, ...)
{
    __bound_error_msg = fmt;
    fprintf(stderr,"%s %s: %s\n", __FILE__, __FUNCTION__, fmt);
    *(void **)0 = 0; /* force a runtime error */
}

static void bound_alloc_error(void)
{
    bound_error("not enough memory for bound checking code");
}

/* return '(p + offset)' for pointer arithmetic (a pointer can reach
   the end of a region in this case */
void * FASTCALL __bound_ptr_add(void *p, size_t offset)
{
    size_t addr = (size_t)p;
    BoundEntry *e;

    dprintf(stderr, "%s %s: %p %x\n",
        __FILE__, __FUNCTION__, p, (unsigned)offset);

    __bound_init();

    e = __bound_t1[addr >> (BOUND_T2_BITS + BOUND_T3_BITS)];
    e = (BoundEntry *)((char *)e + 
                       ((addr >> (BOUND_T3_BITS - BOUND_E_BITS)) & 
                        ((BOUND_T2_SIZE - 1) << BOUND_E_BITS)));
    addr -= e->start;
    if (addr > e->size) {
        e = __bound_find_region(e, p);
        addr = (size_t)p - e->start;
    }
    addr += offset;
    if (addr >= e->size) {
	fprintf(stderr,"%s %s: %p is outside of the region\n",
            __FILE__, __FUNCTION__, p + offset);
        return INVALID_POINTER; /* return an invalid pointer */
    }
    return p + offset;
}

/* return '(p + offset)' for pointer indirection (the resulting must
   be strictly inside the region */
#define BOUND_PTR_INDIR(dsize)                                          \
void * FASTCALL __bound_ptr_indir ## dsize (void *p, size_t offset)     \
{                                                                       \
    size_t addr = (size_t)p;                                            \
    BoundEntry *e;                                                      \
                                                                        \
    dprintf(stderr, "%s %s: %p %x start\n",                             \
        __FILE__, __FUNCTION__, p, (unsigned)offset);	                \
									\
    __bound_init();							\
    e = __bound_t1[addr >> (BOUND_T2_BITS + BOUND_T3_BITS)];            \
    e = (BoundEntry *)((char *)e +                                      \
                       ((addr >> (BOUND_T3_BITS - BOUND_E_BITS)) &      \
                        ((BOUND_T2_SIZE - 1) << BOUND_E_BITS)));        \
    addr -= e->start;                                                   \
    if (addr > e->size) {                                               \
        e = __bound_find_region(e, p);                                  \
        addr = (size_t)p - e->start;                                    \
    }                                                                   \
    addr += offset + dsize;                                             \
    if (addr > e->size) {                                               \
	fprintf(stderr,"%s %s: %p is outside of the region\n",          \
            __FILE__, __FUNCTION__, p + offset);                        \
        return INVALID_POINTER; /* return an invalid pointer */         \
    }									\
    dprintf(stderr, "%s %s: return p+offset = %p\n",                    \
        __FILE__, __FUNCTION__, p + offset);                            \
    return p + offset;                                                  \
}

BOUND_PTR_INDIR(1)
BOUND_PTR_INDIR(2)
BOUND_PTR_INDIR(4)
BOUND_PTR_INDIR(8)
BOUND_PTR_INDIR(12)
BOUND_PTR_INDIR(16)

src/lib/bcheck.c  view on Meta::CPAN

#define GET_CALLER_FP(fp)\
{\
    fp = (size_t)__builtin_frame_address(1);\
}

/* called when entering a function to add all the local regions */
void FASTCALL __bound_local_new(void *p1) 
{
    size_t addr, size, fp, *p = p1;

    dprintf(stderr, "%s, %s start p1=%p\n", __FILE__, __FUNCTION__, p);
    GET_CALLER_FP(fp);
    for(;;) {
        addr = p[0];
        if (addr == 0)
            break;
        addr += fp;
        size = p[1];
        p += 2;
        __bound_new_region((void *)addr, size);
    }
    dprintf(stderr, "%s, %s end\n", __FILE__, __FUNCTION__);
}

/* called when leaving a function to delete all the local regions */
void FASTCALL __bound_local_delete(void *p1) 
{
    size_t addr, fp, *p = p1;
    GET_CALLER_FP(fp);
    for(;;) {
        addr = p[0];
        if (addr == 0)

src/lib/bcheck.c  view on Meta::CPAN

    start = addr;
    end = addr + size;

    t2_start = (start + BOUND_T3_SIZE - 1) >> BOUND_T3_BITS;
    if (end != 0)
        t2_end = end >> BOUND_T3_BITS;
    else
        t2_end = 1 << (BOUND_T1_BITS + BOUND_T2_BITS);

#if 0
    dprintf(stderr, "mark_invalid: start = %x %x\n", t2_start, t2_end);
#endif
    
    /* first we handle full pages */
    t1_start = (t2_start + BOUND_T2_SIZE - 1) >> BOUND_T2_BITS;
    t1_end = t2_end >> BOUND_T2_BITS;

    i = t2_start & (BOUND_T2_SIZE - 1);
    j = t2_end & (BOUND_T2_SIZE - 1);
    
    if (t1_start == t1_end) {

src/lib/bcheck.c  view on Meta::CPAN

    BoundEntry *page;
    size_t start, size;
    size_t *p;

    static int inited;
    if (inited)
	return;

    inited = 1;

    dprintf(stderr, "%s, %s() start\n", __FILE__, __FUNCTION__);

    /* save malloc hooks and install bound check hooks */
    install_malloc_hooks();

#ifndef BOUND_STATIC
    __bound_t1 = libc_malloc(BOUND_T1_SIZE * sizeof(BoundEntry *));
    if (!__bound_t1)
        bound_alloc_error();
#endif
    __bound_empty_t2 = __bound_new_page();

src/lib/bcheck.c  view on Meta::CPAN

    mark_invalid(start, size);
#endif

    /* add all static bound check values */
    p = (size_t *)&__bounds_start;
    while (p[0] != 0) {
        __bound_new_region((void *)p[0], p[1]);
        p += 2;
    }

    dprintf(stderr, "%s, %s() end\n\n", __FILE__, __FUNCTION__);
}

void __bound_main_arg(void **p)
{
    void *start = p;
    while (*p++);

    dprintf(stderr, "%s, %s calling __bound_new_region(%p %x)\n",
            __FILE__, __FUNCTION__, start, (unsigned)((void *)p - start));

    __bound_new_region(start, (void *) p - start);
}

void __bound_exit(void)
{
    dprintf(stderr, "%s, %s()\n", __FILE__, __FUNCTION__);
    restore_malloc_hooks();
}

static inline void add_region(BoundEntry *e, 
                              size_t start, size_t size)
{
    BoundEntry *e1;
    if (e->start == 0) {
        /* no region : add it */
        e->start = start;

src/lib/bcheck.c  view on Meta::CPAN

    }
}

/* create a new region. It should not already exist in the region list */
void __bound_new_region(void *p, size_t size)
{
    size_t start, end;
    BoundEntry *page, *e, *e2;
    size_t t1_start, t1_end, i, t2_start, t2_end;

    dprintf(stderr, "%s, %s(%p, %x) start\n",
        __FILE__, __FUNCTION__, p, (unsigned)size);

    __bound_init();

    start = (size_t)p;
    end = start + size;
    t1_start = start >> (BOUND_T2_BITS + BOUND_T3_BITS);
    t1_end = end >> (BOUND_T2_BITS + BOUND_T3_BITS);

    /* start */

src/lib/bcheck.c  view on Meta::CPAN

        /* last page */
        page = get_page(t1_end);
        e2 = (BoundEntry *)((char *)page + t2_end);
        for(e=page;e<e2;e++) {
            e->start = start;
            e->size = size;
        }
        add_region(e, start, size);
    }

    dprintf(stderr, "%s, %s end\n", __FILE__, __FUNCTION__);
}

/* delete a region */
static inline void delete_region(BoundEntry *e, void *p, size_t empty_size)
{
    size_t addr;
    BoundEntry *e1;

    addr = (size_t)p;
    addr -= e->start;

src/lib/bcheck.c  view on Meta::CPAN

}

/* WARNING: 'p' must be the starting point of the region. */
/* return non zero if error */
int __bound_delete_region(void *p)
{
    size_t start, end, addr, size, empty_size;
    BoundEntry *page, *e, *e2;
    size_t t1_start, t1_end, t2_start, t2_end, i;

    dprintf(stderr, "%s %s() start\n", __FILE__, __FUNCTION__);

    __bound_init();

    start = (size_t)p;
    t1_start = start >> (BOUND_T2_BITS + BOUND_T3_BITS);
    t2_start = (start >> (BOUND_T3_BITS - BOUND_E_BITS)) & 
        ((BOUND_T2_SIZE - 1) << BOUND_E_BITS);
    
    /* find region size */
    page = __bound_t1[t1_start];

src/lib/bcheck.c  view on Meta::CPAN

        /* last page */
        page = get_page(t1_end);
        e2 = (BoundEntry *)((char *)page + t2_end);
        for(e=page;e<e2;e++) {
            e->start = 0;
            e->size = empty_size;
        }
        delete_region(e, p, empty_size);
    }

    dprintf(stderr, "%s %s() end\n", __FILE__, __FUNCTION__);

    return 0;
}

/* return the size of the region starting at p, or EMPTY_SIZE if non
   existent region. */
static size_t get_region_size(void *p)
{
    size_t addr = (size_t)p;
    BoundEntry *e;

src/lib/bcheck.c  view on Meta::CPAN

    void *ptr;
    
    /* we allocate one more byte to ensure the regions will be
       separated by at least one byte. With the glibc malloc, it may
       be in fact not necessary */
    ptr = libc_malloc(size + 1);
    
    if (!ptr)
        return NULL;

    dprintf(stderr, "%s, %s calling __bound_new_region(%p, %x)\n",
           __FILE__, __FUNCTION__, ptr, (unsigned)size);

    __bound_new_region(ptr, size);
    return ptr;
}

void *__bound_memalign(size_t size, size_t align, const void *caller)
{
    void *ptr;

src/lib/bcheck.c  view on Meta::CPAN

       separated by at least one byte. With the glibc malloc, it may
       be in fact not necessary */
    ptr = memalign(size + 1, align);
#endif
    
    install_malloc_hooks();
    
    if (!ptr)
        return NULL;

    dprintf(stderr, "%s, %s calling __bound_new_region(%p, %x)\n",
           __FILE__, __FUNCTION__, ptr, (unsigned)size);

    __bound_new_region(ptr, size);
    return ptr;
}

void __bound_free(void *ptr, const void *caller)
{
    if (ptr == NULL)
        return;

src/lib/bcheck.c  view on Meta::CPAN

    return ptr;
}
#endif

#if 0
static void bound_dump(void)
{
    BoundEntry *page, *e;
    size_t i, j;

    fprintf(stderr, "region dump:\n");
    for(i=0;i<BOUND_T1_SIZE;i++) {
        page = __bound_t1[i];
        for(j=0;j<BOUND_T2_SIZE;j++) {
            e = page + j;
            /* do not print invalid or empty entries */
            if (e->size != EMPTY_SIZE && e->start != 0) {
                fprintf(stderr, "%08x:", 
                       (i << (BOUND_T2_BITS + BOUND_T3_BITS)) + 
                       (j << BOUND_T3_BITS));
                do {
                    fprintf(stderr, " %08lx:%08lx", e->start, e->start + e->size);
                    e = e->next;
                } while (e != NULL);
                fprintf(stderr, "\n");
            }
        }
    }
}
#endif

/* some useful checked functions */

/* check that (p ... p + size - 1) lies inside 'p' region, if any */
static void __bound_check(const void *p, size_t size)

src/lib/bcheck.c  view on Meta::CPAN

        return;
    p = __bound_ptr_add((void *)p, size - 1);
    if (p == INVALID_POINTER)
        bound_error("invalid pointer");
}

void *__bound_memcpy(void *dst, const void *src, size_t size)
{
    void* p;

    dprintf(stderr, "%s %s: start, dst=%p src=%p size=%x\n",
            __FILE__, __FUNCTION__, dst, src, (unsigned)size);

    __bound_check(dst, size);
    __bound_check(src, size);
    /* check also region overlap */
    if (src >= dst && src < dst + size)
        bound_error("overlapping regions in memcpy()");

    p = memcpy(dst, src, size);

    dprintf(stderr, "%s %s: end, p=%p\n", __FILE__, __FUNCTION__, p);
    return p;
}

void *__bound_memmove(void *dst, const void *src, size_t size)
{
    __bound_check(dst, size);
    __bound_check(src, size);
    return memmove(dst, src, size);
}

src/lib/bcheck.c  view on Meta::CPAN

        len++;
    }
    return len;
}

char *__bound_strcpy(char *dst, const char *src)
{
    size_t len;
    void *p;

    dprintf(stderr, "%s %s: strcpy start, dst=%p src=%p\n",
            __FILE__, __FUNCTION__, dst, src);
    len = __bound_strlen(src);
    p = __bound_memcpy(dst, src, len + 1);
    dprintf(stderr, "%s %s: strcpy end, p = %p\n",
            __FILE__, __FUNCTION__, p);
    return p;
}

src/lib/libtcc1.c  view on Meta::CPAN

        goto use_overflow_area;

    case __va_stack:
    use_overflow_area:
        ap->overflow_arg_area += size;
        ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align);
        return ap->overflow_arg_area - size;

    default: /* should never happen */
#ifndef __TINYC__
        fprintf(stderr, "unknown ABI type for __va_arg\n");
#endif
        abort();
    }
}
#endif /* __x86_64__ */

#ifdef TCC_TARGET_ARM
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>

src/libtcc.c  view on Meta::CPAN

    ptr = tcc_malloc_debug(strlen(str) + 1, file, line);
    strcpy(ptr, str);
    return ptr;
}

PUB_FUNC void tcc_memstats(int bench)
{
    if (mem_cur_size) {
        mem_debug_header_t *header = mem_debug_chain;

        fprintf(stderr, "MEM_DEBUG: mem_leak= %d bytes, mem_max_size= %d bytes\n",
            mem_cur_size, mem_max_size);

        while (header) {
            fprintf(stderr, "%s:%u: error: %u bytes leaked\n",
                header->file_name, header->line_num, header->size);
            header = header->next;
        }
    }
    else if (bench)
        fprintf(stderr, "mem_max_size= %d bytes\n", mem_max_size);
}

#undef MEM_DEBUG_MAGIC1
#undef MEM_DEBUG_MAGIC2
#undef MEM_DEBUG_FILE_LEN

#endif

#define free(p) use_tcc_free(p)
#define malloc(s) use_tcc_malloc(s)

src/libtcc.c  view on Meta::CPAN

    } else {
        strcat_printf(buf, sizeof(buf), "tcc: ");
    }
    if (is_warning)
        strcat_printf(buf, sizeof(buf), "warning: ");
    else
        strcat_printf(buf, sizeof(buf), "error: ");
    strcat_vprintf(buf, sizeof(buf), fmt, ap);

    if (!s1->error_func) {
        /* default case: stderr */
        if (s1->ppfp) /* print a newline during tcc -E */
            fprintf(s1->ppfp, "\n"), fflush(s1->ppfp);
        fprintf(stderr, "%s\n", buf);
        fflush(stderr); /* print error/warning now (win32) */
    } else {
        s1->error_func(s1->error_opaque, buf);
    }
    if (!is_warning || s1->warn_error)
        s1->nb_errors++;
}

LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
                        void (*error_func)(void *opaque, const char *msg))
{

src/libtcc.c  view on Meta::CPAN

    dynarray_reset(&argv, &argc);
    return ret;
}

PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time)
{
    if (total_time < 1)
        total_time = 1;
    if (total_bytes < 1)
        total_bytes = 1;
    fprintf(stderr, "%d idents, %d lines, %d bytes, %0.3f s, %u lines/s, %0.1f MB/s\n",
           tok_ident - TOK_IDENT, total_lines, total_bytes,
           (double)total_time/1000,
           (unsigned)total_lines*1000/total_time,
           (double)total_bytes/1000/total_time);
}

PUB_FUNC void tcc_set_environment(TCCState *s)
{
    char * path;

src/tccelf.c  view on Meta::CPAN

            break;
#endif
        case R_386_COPY:
            /* This reloction must copy initialized data from the library
            to the program .bss segment. Currently made like for ARM
            (to remove noise of defaukt case). Is this true? 
            */
            break;

        default:
            fprintf(stderr,"FIXME: handle reloc type %d at %x [%p] to %x\n",
                type, (unsigned)addr, ptr, (unsigned)val);
            break;
#elif defined(TCC_TARGET_ARM)
        case R_ARM_PC24:
        case R_ARM_CALL:
        case R_ARM_JUMP24:
        case R_ARM_PLT32:
            {
                int x, is_thumb, is_call, h, blx_avail, is_bl, th_ko;
                x = (*(int *) ptr) & 0xffffff;

src/tccelf.c  view on Meta::CPAN

            break;
        case R_ARM_NONE:
            /* Nothing to do.  Normally used to indicate a dependency
               on a certain symbol (like for exception handling under EABI).  */
            break;
#ifdef TCC_TARGET_PE
	case R_ARM_RELATIVE: /* handled in pe_relocate_rva() */
	    break;
#endif
        default:
            fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n",
                type, (unsigned)addr, ptr, (unsigned)val);
            break;
#elif defined(TCC_TARGET_ARM64)
        case R_AARCH64_ABS64:
            write64le(ptr, val);
            break;
        case R_AARCH64_ABS32:
            write32le(ptr, val);
            break;
	case R_AARCH64_PREL32:

src/tccelf.c  view on Meta::CPAN

        case R_AARCH64_JUMP_SLOT:
            /* They don't need addend */
#ifdef DEBUG_RELOC
	    printf ("reloc %d @ 0x%lx: val=0x%lx name=%s\n", type, addr,
		    val - rel->r_addend,
		    (char *) symtab_section->link->data + sym->st_name);
#endif
            write64le(ptr, val - rel->r_addend);
            break;
        default:
            fprintf(stderr, "FIXME: handle reloc type %x at %x [%p] to %x\n",
                    type, (unsigned)addr, ptr, (unsigned)val);
            break;
#elif defined(TCC_TARGET_C67)
        case R_C60_32:
            *(int *)ptr += val;
            break;
        case R_C60LO16:
            {
                uint32_t orig;

src/tccelf.c  view on Meta::CPAN


                /* patch both at once - assumes always in pairs Low - High */

                *(int *) ptr    = (*(int *) ptr    & (~(0xffff << 7)) ) |  (((val+orig)      & 0xffff) << 7);
                *(int *)(ptr+4) = (*(int *)(ptr+4) & (~(0xffff << 7)) ) | ((((val+orig)>>16) & 0xffff) << 7);
            }
            break;
        case R_C60HI16:
            break;
        default:
            fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n",
                type, (unsigned)addr, ptr, (unsigned)val);
            break;
#elif defined(TCC_TARGET_X86_64)
        case R_X86_64_64:
            if (s1->output_type == TCC_OUTPUT_DLL) {
                esym_index = s1->symtab_to_dynsym[sym_index];
                qrel->r_offset = rel->r_offset;
                if (esym_index) {
                    qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_64);
		    qrel->r_addend = rel->r_addend;

src/tccgen.c  view on Meta::CPAN

            gen_op('*');
#if 0
/* #ifdef CONFIG_TCC_BCHECK
    The main reason to removing this code:
	#include <stdio.h>
	int main ()
	{
	    int v[10];
	    int i = 10;
	    int j = 9;
	    fprintf(stderr, "v+i-j  = %p\n", v+i-j);
	    fprintf(stderr, "v+(i-j)  = %p\n", v+(i-j));
	}
    When this code is on. then the output looks like 
	v+i-j = 0xfffffffe
	v+(i-j) = 0xbff84000
    */
            /* if evaluating constant expression, no code should be
               generated, so no bound check */
            if (tcc_state->do_bounds_check && !const_wanted) {
                /* if bounded pointers, we generate a special code to
                   test bounds */

src/tcclib.h  view on Meta::CPAN

int atoi(const char *nptr);
long int strtol(const char *nptr, char **endptr, int base);
unsigned long int strtoul(const char *nptr, char **endptr, int base);
void exit(int);

/* stdio.h */
typedef struct __FILE FILE;
#define EOF (-1)
extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;
FILE *fopen(const char *path, const char *mode);
FILE *fdopen(int fildes, const char *mode);
FILE *freopen(const  char *path, const char *mode, FILE *stream);
int fclose(FILE *stream);
size_t  fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t  fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream);
int fgetc(FILE *stream);
char *fgets(char *s, int size, FILE *stream);
int getc(FILE *stream);
int getchar(void);

src/tccpp.c  view on Meta::CPAN

}

ST_FUNC void tal_delete(TinyAlloc *al)
{
    TinyAlloc *next;

tail_call:
    if (!al)
        return;
#ifdef TAL_INFO
    fprintf(stderr, "limit=%5d, size=%5g MB, nb_peak=%6d, nb_total=%8d, nb_missed=%6d, usage=%5.1f%%\n",
            al->limit, al->size / 1024.0 / 1024.0, al->nb_peak, al->nb_total, al->nb_missed,
            (al->peak_p - al->buffer) * 100.0 / al->size);
#endif
#ifdef TAL_DEBUG
    if (al->nb_allocs > 0) {
        uint8_t *p;
        fprintf(stderr, "TAL_DEBUG: mem leak %d chunks (limit= %d)\n",
                al->nb_allocs, al->limit);
        p = al->buffer;
        while (p < al->p) {
            tal_header_t *header = (tal_header_t *)p;
            if (header->line_num > 0) {
                fprintf(stderr, "  file %s, line %u: %u bytes\n",
                        header->file_name, header->line_num, header->size);
            }
            p += header->size + sizeof(tal_header_t);
        }
    }
#endif
    next = al->next;
    tcc_free(al->buffer);
    tcc_free(al);
    al = next;

src/tccpp.c  view on Meta::CPAN


ST_FUNC void tal_free_impl(TinyAlloc *al, void *p TAL_DEBUG_PARAMS)
{
    if (!p)
        return;
tail_call:
    if (al->buffer <= (uint8_t *)p && (uint8_t *)p < al->buffer + al->size) {
#ifdef TAL_DEBUG
        tal_header_t *header = (((tal_header_t *)p) - 1);
        if (header->line_num < 0) {
            fprintf(stderr, "TAL_DEBUG: file %s, line %u double frees chunk from\n",
                    file, line);
            fprintf(stderr, "  file %s, line %u: %u bytes\n",
                    header->file_name, -header->line_num, header->size);
        } else
            header->line_num = -header->line_num;
#endif
        al->nb_allocs--;
        if (!al->nb_allocs)
            al->p = al->buffer;
    } else if (al->next) {
        al = al->next;
        goto tail_call;

src/tccrun.c  view on Meta::CPAN

                    wanted_pc < sym->st_value + sym->st_size) {
                    pstrcpy(last_func_name, sizeof(last_func_name),
                            (char *) strtab_section->data + sym->st_name);
                    func_addr = sym->st_value;
                    goto found;
                }
            }
        }
    }
    /* did not find any info: */
    fprintf(stderr, "%s %p ???\n", msg, (void*)wanted_pc);
    fflush(stderr);
    return 0;
 found:
    i = incl_index;
    if (i > 0)
        fprintf(stderr, "%s:%d: ", incl_files[--i], last_line_num);
    fprintf(stderr, "%s %p", msg, (void*)wanted_pc);
    if (last_func_name[0] != '\0')
        fprintf(stderr, " %s()", last_func_name);
    if (--i >= 0) {
        fprintf(stderr, " (included from ");
        for (;;) {
            fprintf(stderr, "%s", incl_files[i]);
            if (--i < 0)
                break;
            fprintf(stderr, ", ");
        }
        fprintf(stderr, ")");
    }
    fprintf(stderr, "\n");
    fflush(stderr);
    return func_addr;
}

/* emit a run time error at position 'pc' */
static void rt_error(ucontext_t *uc, const char *fmt, ...)
{
    va_list ap;
    addr_t pc;
    int i;

    fprintf(stderr, "Runtime error: ");
    va_start(ap, fmt);
    vfprintf(stderr, fmt, ap);
    va_end(ap);
    fprintf(stderr, "\n");

    for(i=0;i<rt_num_callers;i++) {
        if (rt_get_caller_pc(&pc, uc, i) < 0)
            break;
        pc = rt_printline(pc, i ? "by" : "at");
        if (pc == (addr_t)rt_prog_main && pc)
            break;
    }
}

src/tests/boundtest.c  view on Meta::CPAN

    }
    return sum;
}

/* ok */
int test4(void)
{
    int i, sum = 0;
    int *tab4;

    fprintf(stderr, "%s start\n", __FUNCTION__);

    tab4 = malloc(20 * sizeof(int));
    for(i=0;i<20;i++) {
        sum += tab4[i];
    }
    free(tab4);

    fprintf(stderr, "%s end\n", __FUNCTION__);
    return sum;
}

/* error */
int test5(void)
{
    int i, sum = 0;
    int *tab4;

    fprintf(stderr, "%s start\n", __FUNCTION__);

    tab4 = malloc(20 * sizeof(int));
    for(i=0;i<21;i++) {
        sum += tab4[i];
    }
    free(tab4);

    fprintf(stderr, "%s end\n", __FUNCTION__);
    return sum;
}

/* error */
/* XXX: currently: bug */
int test6(void)
{
    int i, sum = 0;
    int *tab4;
    

src/tests/boundtest.c  view on Meta::CPAN

    p[TAB_SIZE-1] = 0;
    return strlen(p);
}

/* ok */
int test16()
{
    char *demo = "This is only a test.";
    char *p;

    fprintf(stderr, "%s start\n", __FUNCTION__);

    p = alloca(16);
    strcpy(p,"12345678901234");
    printf("alloca: p is %s\n", p);

    /* Test alloca embedded in a larger expression */
    printf("alloca: %s\n", strcpy(alloca(strlen(demo)+1),demo) );

    fprintf(stderr, "%s end\n", __FUNCTION__);
}

/* error */
int test17()
{
    char *demo = "This is only a test.";
    char *p;

    fprintf(stderr, "%s start\n", __FUNCTION__);

    p = alloca(16);
    strcpy(p,"12345678901234");
    printf("alloca: p is %s\n", p);

    /* Test alloca embedded in a larger expression */
    printf("alloca: %s\n", strcpy(alloca(strlen(demo)),demo) );

    fprintf(stderr, "%s end\n", __FUNCTION__);
}

int (*table_test[])(void) = {
    test1,
    test2,
    test3,
    test4,
    test5,
    test6,
    test7,

src/tests/exsymtab/01-test-symtab-copy.c  view on Meta::CPAN

    HAS_STRUCT,
    HAS_IDENTIFIER
};

int main(int argc, char **argv)
{
    TCCState *s;

    s = tcc_new();
    if (!s) {
        fprintf(stderr, "Could not create tcc state\n");
        exit(1);
    }

    pass("Allocated tcc state");

    /* if tcclib.h and libtcc1.a are not installed, where can we find them */
    if (argc == 2 && !memcmp(argv[1], "lib_path=",9))
        tcc_set_lib_path(s, argv[1]+9);

    /* MUST BE CALLED before any compilation */

src/tests/exsymtab/10-symtab-compare-func-decl-and-def.c  view on Meta::CPAN

    /* Get symtab */
    extended_symtab_p decl_symtab = tcc_get_extended_symbol_table(s_decl);

    /* All done with that compiler, clean up */
    tcc_free(s_decl);

    pass("Built declaration compiler state's symbol table");

    TCCState *s_def = tcc_new();
    if (!s_def) {
        fprintf(stderr, "Could not create tcc state\n");
        exit(1);
    }

    /* if tcclib.h and libtcc1.a are not installed, where can we find them */
    if (argc == 2 && !memcmp(argv[1], "lib_path=",9))
        tcc_set_lib_path(s_def, argv[1]+9);

    /* MUST BE CALLED before any compilation */
    tcc_set_output_type(s_def, TCC_OUTPUT_MEMORY);

src/tests/libtcc_test.c  view on Meta::CPAN

"}\n";

int main(int argc, char **argv)
{
    TCCState *s;
    int i;
    int (*func)(int);

    s = tcc_new();
    if (!s) {
        fprintf(stderr, "Could not create tcc state\n");
        exit(1);
    }

    /* if tcclib.h and libtcc1.a are not installed, where can we find them */
    for (i = 1; i < argc; ++i) {
        char *a = argv[i];
        if (a[0] == '-') {
            if (a[1] == 'B')
                tcc_set_lib_path(s, a+2);
            else if (a[1] == 'I')

src/tests/tests2/32_led.c  view on Meta::CPAN

#ifndef NO_MAIN
int main(int argc, char **argv)
{

   int i=0,n;
   long x;
   static int d[MAX_DIGITS];
   char buf[5*MAX_DIGITS];

   if(argc != 2){
      fprintf(stderr,"led: usage: led integer\n");
      return 1;
   }

   /* fetch argument from command line */

   x = atol(argv[1]);

   /* sanity check */

   if(x<0){
      fprintf(stderr,"led: %d must be non-negative\n",x);
      return 1;
   }

   print_led(x,buf);
   printf("%s\n",buf);

   return 0;

}
#endif

src/tests/tests2/46_grep.c  view on Meta::CPAN


/*** Display a file name *******************************/
void file(char *s)
{
   printf("File %s:\n", s);
}

/*** Report unopenable file ****************************/
void cant(char *s)
{
   fprintf(stderr, "%s: cannot open\n", s);
}

/*** Give good help ************************************/
void help(char **hp)
{
   char   **dp;

   for (dp = hp; *dp; ++dp)
      printf("%s\n", *dp);
}

/*** Display usage summary *****************************/
void usage(char *s)
{
   fprintf(stderr, "?GREP-E-%s\n", s);
   fprintf(stderr,
         "Usage: grep [-cfnv] pattern [file ...].  grep ? for help\n");
   exit(1);
}

/*** Compile the pattern into global pbuf[] ************/
void compile(char *source)
{
   char  *s;         /* Source string pointer     */
   char  *lp;        /* Last pattern pointer      */
   int   c;          /* Current character         */

src/tests/tests2/46_grep.c  view on Meta::CPAN

      error("Pattern too complex\n");
   *pp++ = op;
}

/*** Report a bad pattern specification ****************/
void badpat(char *message, char *source, char *stop)
   /* char  *message;       // Error message */
   /* char  *source;        // Pattern start */
   /* char  *stop;          // Pattern end   */
{
   fprintf(stderr, "-GREP-E-%s, pattern is\"%s\"\n", message, source);
   fprintf(stderr, "-GREP-E-Stopped at byte %ld, '%c'\n",
         stop-source, stop[-1]);
   error("?GREP-E-Bad pattern\n");
}

/*** Scan the file for the pattern in pbuf[] ***********/
void grep(FILE *fp, char *fn)
   /* FILE       *fp;       // File to process            */
   /* char       *fn;       // File name (for -f option)  */
{
   int lno, count, m;

src/tests/tests2/46_grep.c  view on Meta::CPAN

            printf("Bad op code %d\n", op);
            error("Cannot happen -- match\n");
      }
   }
   return(l);
}

/*** Report an error ***********************************/
void error(char *s)
{
   fprintf(stderr, "%s", s);
   exit(1);
}

/*** Main program - parse arguments & grep *************/
int main(int argc, char **argv)
{
   char   *p;
   int    c, i;
   int             gotpattern;

src/win32/include/stdio.h  view on Meta::CPAN

#define _FPOSOFF(fp) ((long)(fp))
#endif

#endif

#ifndef _STDSTREAM_DEFINED
#define _STDSTREAM_DEFINED

#define stdin (&__iob_func()[0])
#define stdout (&__iob_func()[1])
#define stderr (&__iob_func()[2])
#endif

#define _IOREAD 0x0001
#define _IOWRT 0x0002

#define _IOFBF 0x0000
#define _IOLBF 0x0040
#define _IONBF 0x0004

#define _IOMYBUF 0x0008

src/win32/include/wchar.h  view on Meta::CPAN

#define _iob __iob_func()
#endif
#endif

#define _iob __iob_func()
#endif

#ifndef _STDSTREAM_DEFINED
#define stdin (&__iob_func()[0])
#define stdout (&__iob_func()[1])
#define stderr (&__iob_func()[2])
#define _STDSTREAM_DEFINED
#endif

#ifndef _FSIZE_T_DEFINED
  typedef unsigned long _fsize_t;
#define _FSIZE_T_DEFINED
#endif

#ifndef _WFINDDATA_T_DEFINED
  struct _wfinddata32_t {

src/win32/tools/tiny_impdef.c  view on Meta::CPAN

            } else
                goto usage;
        } else if (0 == infile[0])
            strcpy(infile, a);
        else
            goto usage;
    }

    if (0 == infile[0]) {
usage:
        fprintf(stderr,
            "tiny_impdef: create export definition file (.def) from a dll\n"
            "Usage: tiny_impdef library.dll [-o outputfile]\n"
            );
        goto the_end;
    }

    if (0 == outfile[0])
    {
        strcpy(outfile, file_basename(infile));
        q = strrchr(outfile, '.');

src/win32/tools/tiny_impdef.c  view on Meta::CPAN

#ifdef _WIN32
    pp = ext;
    do if (SearchPath(NULL, file, *pp, sizeof path, path, NULL)) {
       file = path;
       break;
    } while (*pp++);
#endif

    fp = fopen(file, "rb");
    if (NULL == fp) {
        fprintf(stderr, "tiny_impdef: no such file: %s\n", infile);
        goto the_end;
    }
    if (v)
        printf("--> %s\n", file);

    p = get_export_names(fileno(fp));
    if (NULL == p) {
        fprintf(stderr, "tiny_impdef: could not get exported function names.\n");
        goto the_end;
    }

    op = fopen(outfile, "w");
    if (NULL == op) {
        fprintf(stderr, "tiny_impdef: could not create output file: %s\n", outfile);
        goto the_end;
    }

    fprintf(op, "LIBRARY %s\n\nEXPORTS\n", file_basename(file));
    for (q = p, i = 0; *q; ++i) {
        fprintf(op, "%s\n", q);
        q += strlen(q) + 1;
    }

    if (v) {

src/win32/tools/tiny_libmaker.c  view on Meta::CPAN

  for (; *s; s++) {
      for (l = list; *l; l++) {
          if (*s == *l)
              return 1;
      }
  }
  return 0;
}

int usage(int ret) {
    fprintf(stderr, "usage: tiny_libmaker [rcsv] lib file...\n");
    fprintf(stderr, "Always creates a new lib. [abdioptxN] are explicitly rejected.\n");
    return ret;
}

int main(int argc, char **argv)
{
    FILE *fi, *fh = NULL, *fo = NULL;
    ElfW(Ehdr) *ehdr;
    ElfW(Shdr) *shdr;
    ElfW(Sym) *sym;
    int i, fsize, i_lib, i_obj;

src/win32/tools/tiny_libmaker.c  view on Meta::CPAN

                i_lib = i;
            else if (!i_obj)  // second file is the first obj
                i_obj = i;
        }
    }
    if (!i_obj)  // i_obj implies also i_lib. we require both.
        return usage(1);

    if ((fh = fopen(argv[i_lib], "wb")) == NULL)
    {
        fprintf(stderr, "Can't open file %s \n", argv[i_lib]);
        goto the_end;
    }

    sprintf(tfile, "%s.tmp", argv[i_lib]);
    if ((fo = fopen(tfile, "wb+")) == NULL)
    {
        fprintf(stderr, "Can't create temporary file %s\n", tfile);
        goto the_end;
    }

    funcmax = 250;
    afpos = realloc(NULL, funcmax * sizeof *afpos); // 250 func
    memcpy(&arhdro.ar_mode, "100666", 6);

    // i_obj = first input object file
    while (i_obj < argc)
    {
        if (*argv[i_obj] == '-') {  // by now, all options start with '-'
            i_obj++;
            continue;
        }
        if (verbose)
            printf("a - %s\n", argv[i_obj]);

        if ((fi = fopen(argv[i_obj], "rb")) == NULL)
        {
            fprintf(stderr, "Can't open file %s \n", argv[i_obj]);
            goto the_end;
        }
        fseek(fi, 0, SEEK_END);
        fsize = ftell(fi);
        fseek(fi, 0, SEEK_SET);
        buf = malloc(fsize + 1);
        fread(buf, fsize, 1, fi);
        fclose(fi);

        // elf header
        ehdr = (ElfW(Ehdr) *)buf;
        if (ehdr->e_ident[4] != ELFCLASSW)
        {
            fprintf(stderr, "Unsupported Elf Class: %s\n", argv[i_obj]);
            goto the_end;
        }

        shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + ehdr->e_shstrndx * ehdr->e_shentsize);
        shstr = (char *)(buf + shdr->sh_offset);
        for (i = 0; i < ehdr->e_shnum; i++)
        {
            shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + i * ehdr->e_shentsize);
            if (!shdr->sh_offset)
                continue;



( run in 1.737 second using v1.01-cache-2.11-cpan-49f99fa48dc )