grischka wrote:
> tcc -c doesn't load libraries ...
Sure. In fact, I found the opportunity by trying just tcc -c first. :)
but this code also runs @tcc link time as well as the -run e.g. I gave.
One of the original sales points of tcc was #!/bin/tcc -run and such
"scripts" can easily be run 1000s of times on 1000s of files/something.
>Everything very good, except what is the scenario where the difference
>of 0.00025 seconds would matter?
Linker scripts could be much larger (and more numerous) than the tiny
253 byte ones on my test system, e.g. some few thousand byte comment.
I agree that I could have "sold" the idea better. One can easily
construct an example with some multi-kB LICENSE comment. Then my 1.3x
faster would probably become 5X faster. Perhaps a small absolute scale,
but some people might link thousands of binaries. (I routinely link
on the order of a hundred.)
So those are 3 scenarios for you: 1) #!/ scripts, 2) many linkings,
and 3) giant linker scripts. Anyway, mostly it seemed needlessly
wasteful and buffered IO seems like a "done deal" & easy enough. :)
>allocate the buffer & variables on the stack and just have a pointer
Thanks! Great suggestion! Done in the attached new patch. I did
not put an fd in the struct io since that would mean more invasive
logic changes to the parser code, but I agree doing all that would
be nicer. I also just called the struct "io" with the idea this
could maybe be done someday and maybe another application may arise
as people sure like to use files for a lot of things. But the field
ld_io since it's just for that.
diff --git a/tcc.h b/tcc.h
index 687fb607..c4f68074 100644
--- a/tcc.h
+++ b/tcc.h
@@ -725,6 +725,12 @@ struct sym_attr {
#endif
};
+struct io {
+ int n; /* number of bytes of buf[] used */
+ char *p; /* pointer to next byte of buf[] to use */
+ char buf[1024];
+};
+
struct TCCState {
unsigned char verbose; /* if true, display some information during compilation */
unsigned char nostdinc; /* if true, no standard headers are added */
@@ -989,6 +995,7 @@ struct TCCState {
/* used by tcc_load_ldscript */
int fd, cc;
+ struct io *ld_io;
/* for warnings/errors for object files */
const char *current_filename;
diff --git a/tccelf.c b/tccelf.c
index 8e11c1bf..3406e55d 100644
--- a/tccelf.c
+++ b/tccelf.c
@@ -3799,17 +3799,24 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level)
#define LD_TOK_NAME 256
#define LD_TOK_EOF (-1)
+static char ld_ioFill(TCCState *s1) {
+ int m = read(s1->fd, s1->ld_io->buf, sizeof s1->ld_io->buf);
+ if (m > 0) {
+ s1->ld_io->p = &s1->ld_io->buf[1];
+ s1->ld_io->n = m - 1;
+ return s1->ld_io->buf[0];
+ }
+ return CH_EOF;
+}
+
static int ld_inp(TCCState *s1)
{
- char b;
if (s1->cc != -1) {
int c = s1->cc;
s1->cc = -1;
return c;
}
- if (1 == read(s1->fd, &b, 1))
- return b;
- return CH_EOF;
+ return s1->ld_io->n-- > 0 ? *s1->ld_io->p++ : ld_ioFill(s1);
}
/* return next ld script token */
@@ -4021,6 +4028,8 @@ ST_FUNC int tcc_load_ldscript(TCCState *s1, int fd)
{
char cmd[64];
char filename[1024];
+ struct io io = { 0, 0, {0} };
+ s1->ld_io = &io;
int t, ret;
s1->fd = fd;
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel