mescc: Tinycc support: compile tcc with TCC_IS_NATIVE.

* mlibc/include/string.h (strcat): Declare.
* mlibc/libc-mes+tcc.c (dlclose, dlopen, mprotect, sigaction,
  sigemptyset, strcat, vfprintf): Move from libc-gcc+tcc.c.
* mlibc/libc-gcc+tcc.c: Remove them.
* module/language/c99/compiler.mes (c99-input->full-ast): Define __i386__=1.
  (i386:type-alist): Parse `long long int', `unsigned short int',
  `unsigned long long int'.
  (struct-field): Support void**.
  (init-declr->name):
  (init-declr->pointer): Support function declaration.
This commit is contained in:
Jan Nieuwenhuizen 2017-07-28 08:07:41 +02:00
parent 397d7a6c43
commit ce980c8239
4 changed files with 80 additions and 65 deletions

View File

@ -44,10 +44,11 @@ void *memmove (void *dest, void const *src, size_t n);
void *memset (void *s, int c, size_t n);
int memcmp (void const *s1, void const *s2, size_t n);
size_t strlen (char const*);
char *strcat (char *dest, char const *src);
char *strchr (char const *s, int c);
int strcmp (char const*, char const*);
char *strcpy (char *dest, char const *src);
size_t strlen (char const*);
int strncmp (char const*, char const*, size_t);
char *strrchr (char const *s, int c);
char *strstr (char const *haystack, char const *needle);

View File

@ -109,67 +109,6 @@ getcwd (char *buf, size_t size)
return r;
}
int dlclose (void *handle)
{
return 0;
}
void *
dlopen (char const *filename, int flags)
{
return 0;
}
int
mprotect (void *addr, size_t len, int prot)
{
return 0;
}
int
sigaction (int signum, struct sigaction const *act, struct sigaction *oldact)
{
return 0;
}
int
sigemptyset (sigset_t *set)
{
return 0;
}
char *
strcat (char *dest, char const *src)
{
return 0;
}
int
vfprintf (FILE* f, char const* format, va_list ap)
{
int fd = (int)f;
char const *p = format;
while (*p)
if (*p != '%')
putchar (*p++);
else
{
p++;
char c = *p;
switch (c)
{
case '%': {fputc (*p, fd); break;}
case 'c': {char c; c = va_arg (ap, char); fputc (c, fd); break;}
case 'd': {int d; d = va_arg (ap, int); fputs (itoa (d), fd); break;}
case 's': {char *s; s = va_arg (ap, char *); fputs (s, fd); break;}
default: {fputc (*p, fd); break;}
}
p++;
}
va_end (ap);
return 0;
}
int
__udivdi3 (int a, int b)
{

View File

@ -24,6 +24,8 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <unistd.h>
@ -31,6 +33,8 @@
#define FULL_MALLOC 1
#include <libc-mes.c>
int errno;
int
close (int fd)
{
@ -72,6 +76,18 @@ getcwd (char *buf, size_t size)
#endif // !__GNUC__
int
dlclose (void *handle)
{
return 0;
}
void *
dlopen (char const *filename, int flags)
{
return 0;
}
int
execvp (char const *file, char *const argv[])
{
@ -183,6 +199,12 @@ memcmp (void const *s1, void const *s2, size_t n)
return 0;
}
int
mprotect (void *addr, size_t len, int prot)
{
return 0;
}
void
qsort (void *base, size_t nmemb, size_t size, int (*compar)(void const *, void const *))
{
@ -200,6 +222,18 @@ setjmp (jmp_buf env)
return 0;
}
int
sigaction (int signum, struct sigaction const *act, struct sigaction *oldact)
{
return 0;
}
int
sigemptyset (sigset_t *set)
{
return 0;
}
int
snprintf(char *str, size_t size, char const *format, ...)
{
@ -212,6 +246,13 @@ sscanf (char const *str, const char *format, ...)
return 0;
}
char *
strcat (char *dest, char const *src)
{
eputs ("strcat stub\n");
return 0;
}
char *
strchr (char const *s, int c)
{
@ -285,3 +326,29 @@ realloc (void *ptr, size_t size)
}
return new;
}
int
vfprintf (FILE* f, char const* format, va_list ap)
{
int fd = (int)f;
char const *p = format;
while (*p)
if (*p != '%')
putchar (*p++);
else
{
p++;
char c = *p;
switch (c)
{
case '%': {fputc (*p, fd); break;}
case 'c': {char c; c = va_arg (ap, char); fputc (c, fd); break;}
case 'd': {int d; d = va_arg (ap, int); fputs (itoa (d), fd); break;}
case 's': {char *s; s = va_arg (ap, char *); fputs (s, fd); break;}
default: {fputc (*p, fd); break;}
}
p++;
}
va_end (ap);
return 0;
}

View File

@ -57,6 +57,7 @@
(parse-c99
#:inc-dirs (append includes (cons* include "mlibc/include" "mlibc" (or (and=> (getenv "C_INCLUDE_PATH") (cut string-split <> #\:)) '())))
#:cpp-defs `(
"__i386__=1"
"POSIX=0"
"_POSIX_SOURCE=0"
"__MESC__=1"
@ -1117,14 +1118,17 @@
("int" . ,(make-type 'builtin 4 0 #f))
("long" . ,(make-type 'builtin 4 0 #f))
("long long" . ,(make-type 'builtin 8 0 #f))
("long long int" . ,(make-type 'builtin 8 0 #f))
("void" . ,(make-type 'builtin 4 0 #f))
;; FIXME sign
("unsigned char" . ,(make-type 'builtin 1 0 #f))
("unsigned short" . ,(make-type 'builtin 2 0 #f))
("unsigned short int" . ,(make-type 'builtin 2 0 #f))
("unsigned" . ,(make-type 'builtin 4 0 #f))
("unsigned int" . ,(make-type 'builtin 4 0 #f))
("unsigned long" . ,(make-type 'builtin 4 0 #f))
("unsigned long long" . ,(make-type 'builtin 8 0 #f))))
("unsigned long long" . ,(make-type 'builtin 8 0 #f))
("unsigned long long int" . ,(make-type 'builtin 8 0 #f))))
(define (field:name o)
(pmatch o
@ -1442,10 +1446,12 @@
(list name type 4 1))
((comp-decl (decl-spec-list (type-spec (fixed-type ,type))) (comp-declr-list (comp-declr (ptr-declr (pointer (pointer)) (ident ,name)))))
(list name type 4 2))
((comp-decl (decl-spec-list (type-spec (void))) (comp-declr-list (comp-declr (ptr-declr (pointer (pointer)) (ident ,name)))))
(list name "void" 4 2))
((comp-decl (decl-spec-list (type-spec (void))) (comp-declr-list (comp-declr (ptr-declr (pointer) (ident ,name)))))
(list name '(void) 4 1))
(list name "void" 4 1))
((comp-decl (decl-spec-list (type-spec (void))) (comp-declr-list (comp-declr (ftn-declr (scope (ptr-declr (pointer) (ident ,name))) (param-list . ,param-list)))))
(list name '(void) 4 1))
(list name "void" 4 1))
((comp-decl (decl-spec-list (type-spec (typename ,type))) (comp-declr-list (comp-declr (ptr-declr (pointer) (ident ,name)))))
(list name type 4 1))
((comp-decl (decl-spec-list (type-spec (typename ,type))) (comp-declr-list (comp-declr (ptr-declr (pointer) (array-of (ident ,name) ,count)))))
@ -1539,6 +1545,7 @@
((ptr-declr ,pointer (ident ,name)) name)
((array-of (ident ,name)) name)
((array-of (ident ,name) ,index) name)
((ftn-declr (scope (ptr-declr (pointer) (ident ,name))) (param-list . ,params)) name)
((ptr-declr (pointer) (array-of (ident ,name))) name)
((ptr-declr (pointer) (array-of (ident ,name) (p-expr ,size))) name)
(_ (error "init-declr->name unsupported: " o))))
@ -1549,6 +1556,7 @@
((ptr-declr ,pointer (ident ,name)) (ptr-declr->pointer pointer))
((array-of (ident ,name) ,index) -1)
((array-of (ident ,name)) -1)
((ftn-declr (scope (ptr-declr ,pointer (ident ,name))) (param-list . ,params)) (ptr-declr->pointer pointer))
((ptr-declr (pointer) (array-of (ident ,name))) -2)
((ptr-declr (pointer) (array-of (ident ,name) (p-expr ,size))) -2)
(_ (error "init-declr->pointer unsupported: " o))))