Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 609 → Rev 608

/programs/develop/metcc/trunk/source/start.asm
File deleted
\ No newline at end of file
/programs/develop/metcc/trunk/source/Makefile
File deleted
/programs/develop/metcc/trunk/source/console.asm
File deleted
/programs/develop/metcc/trunk/source/tccmeos.c
96,11 → 96,12
Elf32_Sym* esym = ((Elf32_Sym *)symtab_section->data)+sym;
int sect=esym->st_shndx;
ss=findsection(me,sect);
if (ss==0) continue;
if (ss==0)
ss=me->bss_sections;
if (rel->r_offset>s->data_size)
continue;
if (type==R_386_PC32)
*(int*)(rel->r_offset+s->data)+=ss->sh_addr+esym->st_value-rel->r_offset-s->sh_addr;
*(int*)(rel->r_offset+s->data)=ss->sh_addr+esym->st_value-rel->r_offset-s->sh_addr-4;
else if (type==R_386_32)
*(int*)(rel->r_offset+s->data)+=ss->sh_addr+esym->st_value;
}
226,6 → 227,7
me.s1=s1;
relocate_common_syms();
assign_addresses(&me);
me.header.version=1;
me.header.entry_point=tcc_find_symbol_me(&me,"start");
me.header.params= tcc_find_symbol_me(&me,"__argv"); // <--
me.header.argv= tcc_find_symbol_me(&me,"__path"); // <--
/programs/develop/metcc/trunk/source/tcc.c
31,10 → 31,10
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
//#include <errno.h>
#include <errno.h>
#include <math.h>
#include <unistd.h>
//#include <signal.h>
#include <signal.h>
#include <fcntl.h>
#include <setjmp.h>
#include <time.h>
41,11 → 41,10
#ifdef WIN32
#include <sys/timeb.h>
#endif
//#ifndef WIN32
 
#ifndef WIN32
#include <sys/time.h>
//#include <sys/ucontext.h>
//#endif
#include <sys/ucontext.h>
#endif
 
#endif /* !CONFIG_TCCBOOT */
 
74,8 → 73,6
//#define TCC_TARGET_I386 /* i386 code generator */
//#define TCC_TARGET_ARM /* ARMv4 code generator */
//#define TCC_TARGET_C67 /* TMS320C67xx code generator */
//----------------------------------------------------------------
#define TCC_TARGET_MEOS
 
/* default target is I386 */
#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
721,7 → 718,7
#define strtoll (long long)strtol
#endif
#elif defined(TCC_UCLIBC) || defined(__FreeBSD__)
 
/* currently incorrect */
long double strtold(const char *nptr, char **endptr)
{
return (long double)strtod(nptr, endptr);
730,20 → 727,12
{
return (float)strtod(nptr, endptr);
}
 
#else
 
/* XXX: need to define this to use them in non ISOC99 context */
extern float strtof (const char *__nptr, char **__endptr);
extern long double strtold (const char *__nptr, char **__endptr);
//extern long long strtoll(const char *__nptr, char **__endptr, int __base)
#endif
 
#define strtold (long double)strtod
#define strtof (float)strtod
#define strtoll (long long)strtol
 
 
static char *pstrcpy(char *buf, int buf_size, const char *s);
static char *pstrcat(char *buf, int buf_size, const char *s);
static const char *tcc_basename(const char *name);
935,7 → 924,7
static TCCSyms tcc_syms[] = {
#if !defined(CONFIG_TCCBOOT)
TCCSYM(printf)
TCCSYM(printf)
TCCSYM(fprintf)
TCCSYM(fopen)
TCCSYM(fclose)
#endif
955,15 → 944,14
}
 
#elif !defined(WIN32)
//-------------------------------------------------------------------------
//#include <dlfcn.h>
 
#include <dlfcn.h>
 
void *resolve_sym(TCCState *s1, const char *sym, int type)
{
return(0);
//return dlsym(RTLD_DEFAULT, sym);
return dlsym(RTLD_DEFAULT, sym);
}
//-------------------------------------------------------------------------
 
#endif
 
/********************************************************/
1385,7 → 1373,7
 
if (!s1->error_func) {
/* default case: stderr */
printf("%s\n", buf);
fprintf(stderr, "%s\n", buf);
} else {
s1->error_func(s1->error_opaque, buf);
}
1899,7 → 1887,7
}
 
/* read next char from current input file and handle end of input buffer */
static inline void input(void)
static inline void inp(void)
{
ch = *(++(file->buf_ptr));
/* end of buffer/file handling */
1911,16 → 1899,16
static void handle_stray(void)
{
while (ch == '\\') {
input();
inp();
if (ch == '\n') {
file->line_num++;
input();
inp();
} else if (ch == '\r') {
input();
inp();
if (ch != '\n')
goto fail;
file->line_num++;
input();
inp();
} else {
fail:
error("stray '\\' in program");
1979,7 → 1967,7
strings or comments */
static void minp(void)
{
input();
inp();
if (ch == '\\')
handle_stray();
}
2851,7 → 2839,7
/* eat all spaces and comments after include */
/* XXX: slightly incorrect */
while (ch1 != '\n' && ch1 != CH_EOF)
input();
inp();
#endif
} else {
/* computed #include : either we have only strings or
3375,7 → 3363,7
}
*q = '\0';
t = toup(ch);
//errno = 0;
errno = 0;
if (t == 'F') {
ch = *p++;
tok = TOK_CFLOAT;
5919,7 → 5907,6
{
Sym *s;
int bt;
int size;
 
bt = type->t & VT_BTYPE;
if (bt == VT_STRUCT) {
5926,14 → 5913,11
/* struct/union */
s = type->ref;
*a = s->r;
 
return s->c;
} else if (bt == VT_PTR) {
 
if (type->t & VT_ARRAY) {
s = type->ref;
size=type_size(&s->type, a) * s->c;
return size;//type_size(&s->type, a) * s->c;
return type_size(&s->type, a) * s->c;
} else {
*a = PTR_SIZE;
return PTR_SIZE;
6597,13 → 6581,9
bit field */
if (lbit_pos == 0) {
if (a == TOK_STRUCT) {
//17.09.2007
//c = (c + align - 1) & -align;
c = (c + align - 1) & -align;
offset = c;
//c += size;
if (size<=4) {c=c+size;}
else
{c=c+align;}
c += size;
} else {
offset = 0;
if (size > c)
9369,7 → 9349,7
int incl_index, len, last_line_num, i;
const char *str, *p;
 
printf("0x%08lx:", wanted_pc);
fprintf(stderr, "0x%08lx:", wanted_pc);
 
func_name[0] = '\0';
func_addr = 0;
9464,20 → 9444,20
}
}
/* did not find any info: */
printf(" ???\n");
fprintf(stderr, " ???\n");
return;
found:
if (last_func_name[0] != '\0') {
printf(" %s()", last_func_name);
fprintf(stderr, " %s()", last_func_name);
}
if (incl_index > 0) {
printf(" (%s:%d",
fprintf(stderr, " (%s:%d",
incl_files[incl_index - 1], last_line_num);
for(i = incl_index - 2; i >= 0; i--)
printf(", included from %s", incl_files[i]);
printf(")");
fprintf(stderr, ", included from %s", incl_files[i]);
fprintf(stderr, ")");
}
printf("\n");
fprintf(stderr, "\n");
}
 
#if !defined(WIN32) && !defined(CONFIG_TCCBOOT)
9491,7 → 9471,6
#endif
 
/* return the PC at frame level 'level'. Return non zero if not found */
/*
static int rt_get_caller_pc(unsigned long *paddr,
ucontext_t *uc, int level)
{
9516,7 → 9495,7
fp = uc->uc_mcontext.gregs[REG_EBP];
#endif
for(i=1;i<level;i++) {
// XXX: check address validity with program info
/* XXX: check address validity with program info */
if (fp <= 0x1000 || fp >= 0xc0000000)
return -1;
fp = ((unsigned long *)fp)[0];
9525,21 → 9504,18
return 0;
}
}
*/
#else
 
#warning add arch specific rt_get_caller_pc()
/*
 
static int rt_get_caller_pc(unsigned long *paddr,
ucontext_t *uc, int level)
{
return -1;
}
*/
#endif
 
/* emit a run time error at position 'pc' */
/*
void rt_error(ucontext_t *uc, const char *fmt, ...)
{
va_list ap;
9547,16 → 9523,16
int i;
 
va_start(ap, fmt);
printf("Runtime error: ");
//vfprintf(stderr, fmt, ap);
printf("\n");
fprintf(stderr, "Runtime error: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
for(i=0;i<num_callers;i++) {
if (rt_get_caller_pc(&pc, uc, i) < 0)
break;
if (i == 0)
printf("at ");
fprintf(stderr, "at ");
else
printf("by ");
fprintf(stderr, "by ");
rt_printline(pc);
}
exit(255);
9563,9 → 9539,7
va_end(ap);
}
 
*/
/* signal handler for fatal errors */
/*
static void sig_error(int signum, siginfo_t *siginf, void *puc)
{
ucontext_t *uc = puc;
9601,10 → 9575,8
}
exit(255);
}
*/
#endif
 
 
/* do all relocations (needed before using tcc_get_symbol()) */
int tcc_relocate(TCCState *s1)
{
9664,17 → 9636,17
#if defined(WIN32) || defined(CONFIG_TCCBOOT)
error("debug mode currently not available for Windows");
#else
//struct sigaction sigact;
struct sigaction sigact;
/* install TCC signal handlers to print debug info on fatal
runtime errors */
//sigact.sa_flags = SA_SIGINFO | SA_RESETHAND;
//sigact.sa_sigaction = sig_error;
//sigemptyset(&sigact.sa_mask);
//sigaction(SIGFPE, &sigact, NULL);
//sigaction(SIGILL, &sigact, NULL);
//sigaction(SIGSEGV, &sigact, NULL);
//sigaction(SIGBUS, &sigact, NULL);
//sigaction(SIGABRT, &sigact, NULL);
sigact.sa_flags = SA_SIGINFO | SA_RESETHAND;
sigact.sa_sigaction = sig_error;
sigemptyset(&sigact.sa_mask);
sigaction(SIGFPE, &sigact, NULL);
sigaction(SIGILL, &sigact, NULL);
sigaction(SIGSEGV, &sigact, NULL);
sigaction(SIGBUS, &sigact, NULL);
sigaction(SIGABRT, &sigact, NULL);
#endif
}
 
9771,7 → 9743,6
}
#else
#ifdef TCC_TARGET_MEOS
tcc_add_library_path(s, ".//lib");
#else
tcc_add_library_path(s, "/usr/local/lib");
tcc_add_library_path(s, "/usr/lib");
10070,10 → 10041,6
tcc_add_sysinclude_path(s, "/usr/local/include");
tcc_add_sysinclude_path(s, "/usr/include");
#endif
 
#if defined(TCC_TARGET_MEOS)
tcc_add_sysinclude_path(s, ".//include");
#endif
snprintf(buf, sizeof(buf), "%s/include", tcc_lib_path);
tcc_add_sysinclude_path(s, buf);
#ifdef TCC_TARGET_PE
10122,7 → 10089,7
#endif
#if defined(TCC_TARGET_MEOS)
if (s->output_type != TCC_OUTPUT_OBJ)
tcc_add_file(s,".//start.o");
tcc_add_file(s,".\\start.o");
#endif
return 0;
}
10262,6 → 10229,9
" -r relocatable output\n"
"Debugger options:\n"
" -g generate runtime debug info\n"
#ifdef CONFIG_TCC_BCHECK
" -b compile with built-in memory and bounds checker (implies -g)\n"
#endif
" -bt N show N callers in stack traces\n"
);
}
10381,19 → 10351,10
int parse_args(TCCState *s, int argc, char **argv)
{
int optind;
int i;
const TCCOption *popt;
const char *optarg, *p1, *r1;
char *r;
/*
printf("\n%d\n",argc);
 
for(i=0;i<argc;i++)
{
printf("\n parameter %d = %s",i+1,argv[i]);
}
printf("\n");
*/
optind = 0;
while (1) {
if (optind >= argc) {
10404,7 → 10365,6
}
r = argv[optind++];
if (r[0] != '-') {
/* add a new file */
dynarray_add((void ***)&files, &nb_files, r);
if (!multiple_files) {
10418,7 → 10378,7
for(;;) {
p1 = popt->name;
if (p1 == NULL)
printf("\n invalid option -- '%s'", r);
error("invalid option -- '%s'", r);
r1 = r + 1;
for(;;) {
if (*p1 == '\0')
10436,7 → 10396,7
optarg = r1;
} else {
if (optind >= argc)
printf("\n argument to '%s' is missing", r);
error("argument to '%s' is missing", r);
optarg = argv[optind++];
}
} else {
10452,7 → 10412,7
exit(1);
case TCC_OPTION_I:
if (tcc_add_include_path(s, optarg) < 0)
printf("\n too many include paths");
error("too many include paths");
break;
case TCC_OPTION_D:
{
10571,10 → 10531,10
} else
#endif
{
printf("\n target %s not found", p);
error("target %s not found", p);
}
} else {
printf("\n unsupported linker option '%s'", optarg);
error("unsupported linker option '%s'", optarg);
}
}
break;
10582,7 → 10542,6
if (s->warn_unsupported) {
unsupported_option:
warning("unsupported option '%s'", r);
printf("\n unsupported option '%s'", r);
}
break;
}
10591,7 → 10550,7
return optind;
}
 
int app_main(int argc, char **argv)
int main(int argc, char **argv)
{
int i;
TCCState *s;
10598,9 → 10557,7
int nb_objfiles, ret, optind;
char objfilename[1024];
int64_t start_time = 0;
int bug;
 
printf("\nTinyC compiler started.\n ");
#ifdef WIN32
/* on win32, we suppose the lib and includes are at the location
of 'tcc.exe' */
10629,12 → 10586,9
nb_libraries = 0;
reloc_output = 0;
print_search_dirs = 0;
printf("TinyC initializated.\n");
bug=argc;
if (bug==0) {bug==1;}
optind = parse_args(s, bug - 1, argv + 1) + 1;
printf("\n Arguments parsed.\n");
 
optind = parse_args(s, argc - 1, argv + 1) + 1;
 
if (print_search_dirs) {
/* enough for Linux kernel */
printf("install: %s/\n", tcc_lib_path);
10648,14 → 10602,13
if (outfile && output_type == TCC_OUTPUT_MEMORY)
output_type = TCC_OUTPUT_EXE;
 
/* check -c
consistency : only single file handled. XXX: checks file type */
/* check -c consistency : only single file handled. XXX: checks file type */
if (output_type == TCC_OUTPUT_OBJ && !reloc_output) {
/* accepts only a single input file */
if (nb_objfiles != 1)
printf("\n cannot specify multiple files with -c");
error("cannot specify multiple files with -c");
if (nb_libraries != 0)
printf("\n cannot specify libraries with -c");
error("cannot specify libraries with -c");
}
if (output_type != TCC_OUTPUT_MEMORY) {
10749,7 → 10702,6
printf("memory: %d bytes, max = %d bytes\n", mem_cur_size, mem_max_size);
}
#endif
printf("\n TinyC finished work\n");
return ret;
}
 
/programs/develop/metcc/trunk/source/tccelf.c
2224,7 → 2224,7
case '\v':
case '\r':
case '\n':
input();
inp();
goto redo;
case '/':
minp();
2266,7 → 2266,7
break;
default:
c = ch;
input();
inp();
break;
}
#if 0
/programs/develop/metcc/trunk/source/tccpe.c
1083,7 → 1083,7
int f = 0, sym_index;
char *p, line[120], dllname[40];
while (fgets(line, sizeof line, fp)) {
//p = strchr(line, 0);
p = strchr(line, 0);
while (p > line && p[-1] <= ' ')
--p;
*p = 0;
1136,7 → 1136,7
{
char *ext = strrchr(objfilename, '.');
if (NULL == ext)
//ext = strchr(objfilename, 0);
ext = strchr(objfilename, 0);
if (output_type == TCC_OUTPUT_DLL)
strcpy(ext, ".dll");
else