tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] tinycc 0.9.26


From: Archidemon
Subject: [Tinycc-devel] tinycc 0.9.26
Date: Wed, 02 Mar 2011 04:56:27 +0300

Hello, programmar :)

Tinycc - is my favorit compiler :) but I have something to say.

At first, some operating variables, like inc, loc, text_section, etc., declared as static to speed up compilation. But becouse of this nested or parallel compilation brokes.
If we move this static global variables to non-static TCCState members we may enabling nested or parallel compilation.
I wrote a patch. Lets see.

$tar -zxf tinycc.tar.bz2
$mv ./tinycc ./tinycc_org
$tar -zxf tinycc.tar.bz2
$mv ./tinycc ./tinycc_new
$cd ./tinycc_new && patch -N -p1 ../nestpatch1.diff

$cat > nest.c << "EOF"
#define TCC_TARGET_X86_64 1
#include "tinycc_org/libtcc.c"
#include <stdio.h>

void err(void *d, const char *s)
{
  printf("error n%ld (%s)", d, s);
}

void comp_n_exec(const char *s)
{
  TCCState *st = tcc_new();
  int n;
  tcc_set_error_func(st, &n, err);
  tcc_compile_string(st, s);
  tcc_add_symbol(st, "printf", (void*)printf);
  tcc_add_symbol(st, "comp_n_exec", (void*)comp_n_exec);
  int rc = tcc_relocate(st);
  if (rc) printf("reloc error");
  int (*cmain)();
  cmain = (int(*)())tcc_get_symbol(st, "main");
  cmain();
  tcc_free(st);
 
}

int main()
{
  comp_n_exec("int main()\n"
              "{\n"
              "  printf(\"msg first\");\n"
              "  comp_n_exec(\"int main() {printf(\\\"msg center\\\");}\");\n"
              "  printf(\"msg last\");\n"
              "}");
  return 0;
}
EOF
$gcc ./nest.c -lm -ldl -o nest.out

now if we $./nest.out
we'll se an error: :1: error: missing #endif

but when
$cat > nest.c << "EOF"
#define TCC_TARGET_X86_64 1
#include "tinycc_new/libtcc.c"
#include <stdio.h>

void err(void *d, const char *s)
{
  printf("error n%ld (%s)", d, s);
}

void comp_n_exec(const char *s)
{
  TCCState *st = tcc_new();
  int n;
  tcc_set_error_func(st, &n, err);
  tcc_compile_string(st, s, NULL);
  tcc_add_symbol(st, "printf", (void*)printf);
  tcc_add_symbol(st, "comp_n_exec", (void*)comp_n_exec);
  int rc = tcc_relocate(st);
  if (rc) printf("reloc error");
  int (*cmain)();
  cmain = (int(*)())tcc_get_symbol(st, "main");
  cmain();
  tcc_free(st,st);
 
}

int main()
{
  comp_n_exec("int main()\n"
              "{\n"
              "  printf(\"msg first\");\n"
              "  comp_n_exec(\"int main() {printf(\\\"msg center\\\");}\");\n"
              "  printf(\"msg last\");\n"
              "}");
  return 0;
}
EOF
$gcc ./nest.c -lm -ldl -o nest.out
We'll see that al allright!!
But excluding static variables makes new problem - how to transfer TCCState pointer to glibc baser sig_error function? Thats the problem.
Mb someone wah ideas?

p.s. Many tcc type convertion a raw! at example:
$cat > mchar.c <<"EOF"
#define TCC_TARGET_X86_64 1
#include "tinycc_new/libtcc.c"
#include <stdio.h>

void err(void *d, const char *s)
{
  printf("error n%ld (%s)", d, s);
}

int main()
{
  TCCState *st = tcc_new();
  int n;
  tcc_set_error_func(st, &n, err);
  tcc_compile_string(st, "int main() {long n=49; if (n>128) printf(\"sux\"); else printf(\"gut\");}", NULL);
  tcc_add_symbol(st, "printf", (void*)printf);
  int rc = tcc_relocate(st);
  if (rc) printf("reloc error");
  int (*cmain)();
  cmain = (int(*)())tcc_get_symbol(st, "main");
  cmain();
  tcc_free(st,st);
  return 0;
}
EOF
If we $gcc ./mchar.c -lm -ldl -o mchar.out
that we'll be all gut. Program prints gut, and that's Ok
but If we $gcc ./mchar.c -lm -ldl -o mchar.out -funsigned-char
The program prints sux, and it's not good not gut. It's SUXX :(

Where are a great more to do...

Best Regards, Archidemon
mailto:address@hidden

----------------------------------------------------------------------
Zimbabwe CMS - best c script(tcc) based CMS ever!

Attachment: nestpatch1.diff.bz2
Description: Binary data


reply via email to

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