tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Added virtual io to tinycc


From: Domingo Alvarez Duarte
Subject: Re: [Tinycc-devel] Added virtual io to tinycc
Date: Fri, 11 Jan 2013 12:39:17 +0000

The idea is the same, but I think that I did it in a more general adding the virtual io to tinycc with any source can be easily used like databases, compressed files,

Main code of vio:

/* virtual io */

LIBTCCAPI void tcc_set_vio_module(TCCState *s, vio_module_t *vio_module){
    s->vio_module = vio_module;
    vio_module->tcc_state = s;
}

void vio_initialize(vio_fd *fd) {
    fd->fd = -1;
    fd->vio_udata = NULL;
    fd->vio_module = NULL;
}

int vio_open(struct TCCState *s, vio_fd *fd, const char *fn, int oflag) {
    int rc;
    vio_initialize(fd);
    fd->vio_module = s->vio_module;
    if(s->vio_module && (s->vio_module->call_vio_open_flags & CALL_VIO_OPEN_FIRST)) {
    rc =  s->vio_module->vio_open(fd, fn, oflag);
    if(rc >= 0) return rc;
    }
   
    fd->fd = open(fn, oflag);
   
    if(fd->fd < 0 && s->vio_module && (s->vio_module->call_vio_open_flags & CALL_VIO_OPEN_LAST)) {
    rc =  s->vio_module->vio_open(fd, fn, oflag);
    if(rc >= 0) return rc;
    }
    //printf("vio_open = %d %s\n", fd->fd, fn);
    return fd->fd;
}

off_t vio_lseek(vio_fd fd, off_t offset, int whence) {
    if(fd.vio_udata) {
        return fd.vio_module->vio_lseek(fd, offset, whence);
    }
    return lseek(fd.fd, offset, whence);
}

size_t vio_read(vio_fd fd, void *buf, size_t bytes) {
    if(fd.vio_udata) {
    return fd.vio_module->vio_read(fd, buf, bytes);
    }
    return read(fd.fd, buf, bytes);
}

int vio_close(vio_fd *fd) {
    int rc = 0;
    if(fd->vio_udata){
    fd->vio_module->vio_close(fd);
    } else rc = close(fd->fd);
    vio_initialize(fd);
    return rc;
}



On Fri, Jan 11, 2013 at 7:28 AM, <address@hidden> wrote:
Hello Domingo,

On Fri, Jan 11, 2013 at 12:23:35AM +0000, Domingo Alvarez Duarte wrote:
> Added what I call virtual io to tinycc this way we can make a monolitic
> executable or library that contains all needed to compile programs, truly
> tinycc portable.
>     Tested under linux exec the "mk-it" shell script and you'll end up with
> a portable tinycc executable that doesn't depend on anything else.

Is it like
 http://ptspts.blogspot.se/2009/11/tiny-self-contained-c-compiler-using.html
?

Hope you did it in a more general fashion. (I have no time slices now
to look at/test you code, sorry).

I always felt that such a thing should belong to tcc upstream, thanks for
doing this.

> The idea is inspired by what http://www.evolane.com/software/etcl/ did,
> make a no dependency tinycc library that can be added to a project and work
> without need extra files or paths for basic c compilation.

I am not a fan of "including everything" in an application package, I
prefer global file systems when you always have at hand those parts
which you _need_ but not have to keep with you all the parts you _might_ need.

Anyway, having a single executable which does all the job is sometimes
very handy and tcc looks like a very suitable target.

Cheers,
Rl


_______________________________________________
Tinycc-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


reply via email to

[Prev in Thread] Current Thread [Next in Thread]