Subversion Repositories Kolibri OS

Rev

Rev 145 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 145 Rev 609
Line 29... Line 29...
29
 
29
 
30
#include 
30
#include 
31
#include 
31
#include 
32
#include 
32
#include 
33
#include 
33
#include 
34
#include 
34
//#include 
35
#include 
35
#include 
36
#include 
36
#include 
37
#include 
37
//#include 
38
#include 
38
#include 
39
#include 
39
#include 
40
#include 
40
#include 
41
#ifdef WIN32
41
#ifdef WIN32
42
#include 
42
#include 
43
#endif
43
#endif
-
 
44
//#ifndef WIN32
44
#ifndef WIN32
45
 
45
#include 
46
#include 
46
#include 
47
//#include 
Line 47... Line 48...
47
#endif
48
//#endif
Line 48... Line 49...
48
 
49
 
49
#endif /* !CONFIG_TCCBOOT */
50
#endif /* !CONFIG_TCCBOOT */
Line 71... Line 72...
71
 
72
 
72
/* target selection */
73
/* target selection */
73
//#define TCC_TARGET_I386   /* i386 code generator */
74
//#define TCC_TARGET_I386   /* i386 code generator */
74
//#define TCC_TARGET_ARM    /* ARMv4 code generator */
75
//#define TCC_TARGET_ARM    /* ARMv4 code generator */
-
 
76
//#define TCC_TARGET_C67    /* TMS320C67xx code generator */
-
 
77
//----------------------------------------------------------------
Line 75... Line 78...
75
//#define TCC_TARGET_C67    /* TMS320C67xx code generator */
78
#define TCC_TARGET_MEOS
76
 
79
 
77
/* default target is I386 */
80
/* default target is I386 */
78
#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
81
#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
Line 716... Line 719...
716
  #define strtold (long double)strtod
719
  #define strtold (long double)strtod
717
  #define strtof (float)strtod
720
  #define strtof (float)strtod
718
  #define strtoll (long long)strtol
721
  #define strtoll (long long)strtol
719
#endif
722
#endif
720
#elif defined(TCC_UCLIBC) || defined(__FreeBSD__)
723
#elif defined(TCC_UCLIBC) || defined(__FreeBSD__)
721
/* currently incorrect */
-
 
-
 
724
 
722
long double strtold(const char *nptr, char **endptr)
725
long double strtold(const char *nptr, char **endptr)
723
{
726
{
724
    return (long double)strtod(nptr, endptr);
727
    return (long double)strtod(nptr, endptr);
725
}
728
}
726
float strtof(const char *nptr, char **endptr)
729
float strtof(const char *nptr, char **endptr)
727
{
730
{
728
    return (float)strtod(nptr, endptr);
731
    return (float)strtod(nptr, endptr);
729
}
732
}
-
 
733
 
730
#else
734
#else
-
 
735
 
731
/* XXX: need to define this to use them in non ISOC99 context */
736
/* XXX: need to define this to use them in non ISOC99 context */
732
extern float strtof (const char *__nptr, char **__endptr);
737
extern float strtof (const char *__nptr, char **__endptr);
733
extern long double strtold (const char *__nptr, char **__endptr);
738
extern long double strtold (const char *__nptr, char **__endptr);
-
 
739
//extern long long strtoll(const char *__nptr, char **__endptr, int __base)
734
#endif
740
#endif
Line -... Line 741...
-
 
741
 
-
 
742
#define strtold (long double)strtod
-
 
743
#define strtof (float)strtod
-
 
744
#define strtoll (long long)strtol
-
 
745
 
735
 
746
 
736
static char *pstrcpy(char *buf, int buf_size, const char *s);
747
static char *pstrcpy(char *buf, int buf_size, const char *s);
737
static char *pstrcat(char *buf, int buf_size, const char *s);
748
static char *pstrcat(char *buf, int buf_size, const char *s);
Line 738... Line 749...
738
static const char *tcc_basename(const char *name);
749
static const char *tcc_basename(const char *name);
Line 922... Line 933...
922
 
933
 
923
/* add the symbol you want here if no dynamic linking is done */
934
/* add the symbol you want here if no dynamic linking is done */
924
static TCCSyms tcc_syms[] = {
935
static TCCSyms tcc_syms[] = {
925
#if !defined(CONFIG_TCCBOOT)
936
#if !defined(CONFIG_TCCBOOT)
926
    TCCSYM(printf)
937
    TCCSYM(printf)
927
    TCCSYM(fprintf)
938
    TCCSYM(printf)
928
    TCCSYM(fopen)
939
    TCCSYM(fopen)
929
    TCCSYM(fclose)
940
    TCCSYM(fclose)
930
#endif
941
#endif
931
    { NULL, NULL },
942
    { NULL, NULL },
Line 942... Line 953...
942
    }
953
    }
943
    return NULL;
954
    return NULL;
944
}
955
}
Line 945... Line 956...
945
 
956
 
946
#elif !defined(WIN32)
-
 
-
 
957
#elif !defined(WIN32)
947
 
958
//-------------------------------------------------------------------------
Line 948... Line 959...
948
#include 
959
//#include 
949
 
960
 
-
 
961
void *resolve_sym(TCCState *s1, const char *sym, int type)
950
void *resolve_sym(TCCState *s1, const char *sym, int type)
962
{
951
{
963
    return(0);
952
    return dlsym(RTLD_DEFAULT, sym);
-
 
-
 
964
    //return dlsym(RTLD_DEFAULT, sym);
953
}
965
}
Line 954... Line 966...
954
 
966
//-------------------------------------------------------------------------
Line 955... Line 967...
955
#endif
967
#endif
Line 1371... Line 1383...
1371
        strcat_printf(buf, sizeof(buf), "warning: ");
1383
        strcat_printf(buf, sizeof(buf), "warning: ");
1372
    strcat_vprintf(buf, sizeof(buf), fmt, ap);
1384
    strcat_vprintf(buf, sizeof(buf), fmt, ap);
Line 1373... Line 1385...
1373
 
1385
 
1374
    if (!s1->error_func) {
1386
    if (!s1->error_func) {
1375
        /* default case: stderr */
1387
        /* default case: stderr */
1376
        fprintf(stderr, "%s\n", buf);
1388
        printf("%s\n", buf);
1377
    } else {
1389
    } else {
1378
        s1->error_func(s1->error_opaque, buf);
1390
        s1->error_func(s1->error_opaque, buf);
1379
    }
1391
    }
1380
    if (!is_warning || s1->warn_error)
1392
    if (!is_warning || s1->warn_error)
Line 1885... Line 1897...
1885
{
1897
{
1886
    return tcc_peekc_slow(file);
1898
    return tcc_peekc_slow(file);
1887
}
1899
}
Line 1888... Line 1900...
1888
 
1900
 
1889
/* read next char from current input file and handle end of input buffer */
1901
/* read next char from current input file and handle end of input buffer */
1890
static inline void inp(void)
1902
static inline void input(void)
1891
{
1903
{
1892
    ch = *(++(file->buf_ptr));
1904
    ch = *(++(file->buf_ptr));
1893
    /* end of buffer/file handling */
1905
    /* end of buffer/file handling */
1894
    if (ch == CH_EOB)
1906
    if (ch == CH_EOB)
Line 1897... Line 1909...
1897
 
1909
 
1898
/* handle '\[\r]\n' */
1910
/* handle '\[\r]\n' */
1899
static void handle_stray(void)
1911
static void handle_stray(void)
1900
{
1912
{
1901
    while (ch == '\\') {
1913
    while (ch == '\\') {
1902
        inp();
1914
        input();
1903
        if (ch == '\n') {
1915
        if (ch == '\n') {
1904
            file->line_num++;
1916
            file->line_num++;
1905
            inp();
1917
            input();
1906
        } else if (ch == '\r') {
1918
        } else if (ch == '\r') {
1907
            inp();
1919
            input();
1908
            if (ch != '\n')
1920
            if (ch != '\n')
1909
                goto fail;
1921
                goto fail;
1910
            file->line_num++;
1922
            file->line_num++;
1911
            inp();
1923
            input();
1912
        } else {
1924
        } else {
1913
        fail:
1925
        fail:
1914
            error("stray '\\' in program");
1926
            error("stray '\\' in program");
1915
        }
1927
        }
Line 1965... Line 1977...
1965
/* input with '\[\r]\n' handling. Note that this function cannot
1977
/* input with '\[\r]\n' handling. Note that this function cannot
1966
   handle other characters after '\', so you cannot call it inside
1978
   handle other characters after '\', so you cannot call it inside
1967
   strings or comments */
1979
   strings or comments */
1968
static void minp(void)
1980
static void minp(void)
1969
{
1981
{
1970
    inp();
1982
    input();
1971
    if (ch == '\\') 
1983
    if (ch == '\\') 
1972
        handle_stray();
1984
        handle_stray();
1973
}
1985
}
Line 2837... Line 2849...
2837
            minp();
2849
            minp();
2838
#if 0
2850
#if 0
2839
            /* eat all spaces and comments after include */
2851
            /* eat all spaces and comments after include */
2840
            /* XXX: slightly incorrect */
2852
            /* XXX: slightly incorrect */
2841
            while (ch1 != '\n' && ch1 != CH_EOF)
2853
            while (ch1 != '\n' && ch1 != CH_EOF)
2842
                inp();
2854
                input();
2843
#endif
2855
#endif
2844
        } else {
2856
        } else {
2845
            /* computed #include : either we have only strings or
2857
            /* computed #include : either we have only strings or
2846
               we have anything enclosed in '<>' */
2858
               we have anything enclosed in '<>' */
2847
            next();
2859
            next();
Line 3361... Line 3373...
3361
                    ch = *p++;
3373
                    ch = *p++;
3362
                }
3374
                }
3363
            }
3375
            }
3364
            *q = '\0';
3376
            *q = '\0';
3365
            t = toup(ch);
3377
            t = toup(ch);
3366
            errno = 0;
3378
            //errno = 0;
3367
            if (t == 'F') {
3379
            if (t == 'F') {
3368
                ch = *p++;
3380
                ch = *p++;
3369
                tok = TOK_CFLOAT;
3381
                tok = TOK_CFLOAT;
3370
                tokc.f = strtof(token_buf, NULL);
3382
                tokc.f = strtof(token_buf, NULL);
3371
            } else if (t == 'L') {
3383
            } else if (t == 'L') {
Line 5905... Line 5917...
5905
/* return type size. Put alignment at 'a' */
5917
/* return type size. Put alignment at 'a' */
5906
static int type_size(CType *type, int *a)
5918
static int type_size(CType *type, int *a)
5907
{
5919
{
5908
    Sym *s;
5920
    Sym *s;
5909
    int bt;
5921
    int bt;
-
 
5922
    int size;
Line 5910... Line 5923...
5910
 
5923
 
5911
    bt = type->t & VT_BTYPE;
5924
    bt = type->t & VT_BTYPE;
5912
    if (bt == VT_STRUCT) {
5925
    if (bt == VT_STRUCT) {
5913
        /* struct/union */
5926
        /* struct/union */
5914
        s = type->ref;
5927
        s = type->ref;
-
 
5928
        *a = s->r;
5915
        *a = s->r;
5929
 
5916
        return s->c;
5930
        return s->c;
-
 
5931
    } else if (bt == VT_PTR) {
5917
    } else if (bt == VT_PTR) {
5932
 
5918
        if (type->t & VT_ARRAY) {
5933
        if (type->t & VT_ARRAY) {
-
 
5934
            s = type->ref;
5919
            s = type->ref;
5935
		size=type_size(&s->type, a) * s->c;
5920
            return type_size(&s->type, a) * s->c;
5936
            return size;//type_size(&s->type, a) * s->c;
5921
        } else {
5937
        } else {
5922
            *a = PTR_SIZE;
5938
            *a = PTR_SIZE;
5923
            return PTR_SIZE;
5939
            return PTR_SIZE;
5924
        }
5940
        }
Line 6579... Line 6595...
6579
                    if (v) {
6595
                    if (v) {
6580
                        /* add new memory data only if starting
6596
                        /* add new memory data only if starting
6581
                           bit field */
6597
                           bit field */
6582
                        if (lbit_pos == 0) {
6598
                        if (lbit_pos == 0) {
6583
                            if (a == TOK_STRUCT) {
6599
                            if (a == TOK_STRUCT) {
-
 
6600
				//17.09.2007
6584
                                c = (c + align - 1) & -align;
6601
                                //c = (c + align - 1) & -align;
6585
                                offset = c;
6602
                                offset = c;
6586
                                c += size;
6603
                                //c += size;
-
 
6604
				if (size<=4) {c=c+size;}
-
 
6605
					else
-
 
6606
					{c=c+align;}
6587
                            } else {
6607
                            } else {
6588
                                offset = 0;
6608
                                offset = 0;
6589
                                if (size > c)
6609
                                if (size > c)
6590
                                    c = size;
6610
                                    c = size;
6591
                            }
6611
                            }
Line 9347... Line 9367...
9347
    unsigned long func_addr, last_pc, pc;
9367
    unsigned long func_addr, last_pc, pc;
9348
    const char *incl_files[INCLUDE_STACK_SIZE];
9368
    const char *incl_files[INCLUDE_STACK_SIZE];
9349
    int incl_index, len, last_line_num, i;
9369
    int incl_index, len, last_line_num, i;
9350
    const char *str, *p;
9370
    const char *str, *p;
Line 9351... Line 9371...
9351
 
9371
 
Line 9352... Line 9372...
9352
    fprintf(stderr, "0x%08lx:", wanted_pc);
9372
    printf("0x%08lx:", wanted_pc);
9353
 
9373
 
9354
    func_name[0] = '\0';
9374
    func_name[0] = '\0';
9355
    func_addr = 0;
9375
    func_addr = 0;
Line 9442... Line 9462...
9442
                }
9462
                }
9443
            }
9463
            }
9444
        }
9464
        }
9445
    }
9465
    }
9446
    /* did not find any info: */
9466
    /* did not find any info: */
9447
    fprintf(stderr, " ???\n");
9467
    printf(" ???\n");
9448
    return;
9468
    return;
9449
 found:
9469
 found:
9450
    if (last_func_name[0] != '\0') {
9470
    if (last_func_name[0] != '\0') {
9451
        fprintf(stderr, " %s()", last_func_name);
9471
        printf(" %s()", last_func_name);
9452
    }
9472
    }
9453
    if (incl_index > 0) {
9473
    if (incl_index > 0) {
9454
        fprintf(stderr, " (%s:%d", 
9474
        printf(" (%s:%d", 
9455
                incl_files[incl_index - 1], last_line_num);
9475
                incl_files[incl_index - 1], last_line_num);
9456
        for(i = incl_index - 2; i >= 0; i--)
9476
        for(i = incl_index - 2; i >= 0; i--)
9457
            fprintf(stderr, ", included from %s", incl_files[i]);
9477
            printf(", included from %s", incl_files[i]);
9458
        fprintf(stderr, ")");
9478
        printf(")");
9459
    }
9479
    }
9460
    fprintf(stderr, "\n");
9480
    printf("\n");
9461
}
9481
}
Line 9462... Line 9482...
9462
 
9482
 
Line 9463... Line 9483...
9463
#if !defined(WIN32) && !defined(CONFIG_TCCBOOT)
9483
#if !defined(WIN32) && !defined(CONFIG_TCCBOOT)
Line 9469... Line 9489...
9469
#define REG_EIP EIP
9489
#define REG_EIP EIP
9470
#define REG_EBP EBP
9490
#define REG_EBP EBP
9471
#endif
9491
#endif
Line 9472... Line 9492...
9472
 
9492
 
-
 
9493
/* return the PC at frame level 'level'. Return non zero if not found */
9473
/* return the PC at frame level 'level'. Return non zero if not found */
9494
/*
9474
static int rt_get_caller_pc(unsigned long *paddr, 
9495
static int rt_get_caller_pc(unsigned long *paddr, 
9475
                            ucontext_t *uc, int level)
9496
                            ucontext_t *uc, int level)
9476
{
9497
{
9477
    unsigned long fp;
9498
    unsigned long fp;
Line 9493... Line 9514...
9493
        fp = uc->uc_mcontext.ebp;
9514
        fp = uc->uc_mcontext.ebp;
9494
#else
9515
#else
9495
        fp = uc->uc_mcontext.gregs[REG_EBP];
9516
        fp = uc->uc_mcontext.gregs[REG_EBP];
9496
#endif
9517
#endif
9497
        for(i=1;i
9518
        for(i=1;i
9498
            /* XXX: check address validity with program info */
9519
	// XXX: check address validity with program info 
9499
            if (fp <= 0x1000 || fp >= 0xc0000000)
9520
            if (fp <= 0x1000 || fp >= 0xc0000000)
9500
                return -1;
9521
                return -1;
9501
            fp = ((unsigned long *)fp)[0];
9522
            fp = ((unsigned long *)fp)[0];
9502
        }
9523
        }
9503
        *paddr = ((unsigned long *)fp)[1];
9524
        *paddr = ((unsigned long *)fp)[1];
9504
        return 0;
9525
        return 0;
9505
    }
9526
    }
9506
}
9527
}
-
 
9528
*/
9507
#else
9529
#else
Line 9508... Line 9530...
9508
 
9530
 
9509
#warning add arch specific rt_get_caller_pc()
9531
#warning add arch specific rt_get_caller_pc()
9510
 
9532
/*
9511
static int rt_get_caller_pc(unsigned long *paddr,
9533
static int rt_get_caller_pc(unsigned long *paddr,
9512
                            ucontext_t *uc, int level)
9534
                            ucontext_t *uc, int level)
9513
{
9535
{
9514
    return -1;
9536
    return -1;
-
 
9537
}
9515
}
9538
*/
Line 9516... Line 9539...
9516
#endif
9539
#endif
-
 
9540
 
9517
 
9541
/* emit a run time error at position 'pc' */
9518
/* emit a run time error at position 'pc' */
9542
/*
9519
void rt_error(ucontext_t *uc, const char *fmt, ...)
9543
void rt_error(ucontext_t *uc, const char *fmt, ...)
9520
{
9544
{
9521
    va_list ap;
9545
    va_list ap;
Line 9522... Line 9546...
9522
    unsigned long pc;
9546
    unsigned long pc;
9523
    int i;
9547
    int i;
9524
 
9548
 
9525
    va_start(ap, fmt);
9549
    va_start(ap, fmt);
9526
    fprintf(stderr, "Runtime error: ");
9550
    printf("Runtime error: ");
9527
    vfprintf(stderr, fmt, ap);
9551
    //vfprintf(stderr, fmt, ap);
9528
    fprintf(stderr, "\n");
9552
    printf("\n");
9529
    for(i=0;i
9553
    for(i=0;i
9530
        if (rt_get_caller_pc(&pc, uc, i) < 0)
9554
        if (rt_get_caller_pc(&pc, uc, i) < 0)
9531
            break;
9555
            break;
9532
        if (i == 0)
9556
        if (i == 0)
9533
            fprintf(stderr, "at ");
9557
            printf("at ");
9534
        else
9558
        else
9535
            fprintf(stderr, "by ");
9559
            printf("by ");
9536
        rt_printline(pc);
9560
        rt_printline(pc);
9537
    }
9561
    }
Line -... Line 9562...
-
 
9562
    exit(255);
9538
    exit(255);
9563
    va_end(ap);
-
 
9564
}
9539
    va_end(ap);
9565
 
9540
}
9566
*/
9541
 
9567
/* signal handler for fatal errors */
Line 9542... Line 9568...
9542
/* signal handler for fatal errors */
9568
/*
Line 9573... Line 9599...
9573
        rt_error(uc, "caught signal %d", signum);
9599
        rt_error(uc, "caught signal %d", signum);
9574
        break;
9600
        break;
9575
    }
9601
    }
9576
    exit(255);
9602
    exit(255);
9577
}
9603
}
-
 
9604
*/
9578
#endif
9605
#endif
Line -... Line 9606...
-
 
9606
 
9579
 
9607
 
9580
/* do all relocations (needed before using tcc_get_symbol()) */
9608
/* do all relocations (needed before using tcc_get_symbol()) */
9581
int tcc_relocate(TCCState *s1)
9609
int tcc_relocate(TCCState *s1)
9582
{
9610
{
9583
    Section *s;
9611
    Section *s;
Line 9634... Line 9662...
9634
    
9662
    
9635
    if (do_debug) {
9663
    if (do_debug) {
9636
#if defined(WIN32) || defined(CONFIG_TCCBOOT)
9664
#if defined(WIN32) || defined(CONFIG_TCCBOOT)
9637
        error("debug mode currently not available for Windows");
9665
        error("debug mode currently not available for Windows");
9638
#else        
9666
#else        
9639
        struct sigaction sigact;
9667
        //struct sigaction sigact;
9640
        /* install TCC signal handlers to print debug info on fatal
9668
        /* install TCC signal handlers to print debug info on fatal
9641
           runtime errors */
9669
           runtime errors */
9642
        sigact.sa_flags = SA_SIGINFO | SA_RESETHAND;
9670
        //sigact.sa_flags = SA_SIGINFO | SA_RESETHAND;
9643
        sigact.sa_sigaction = sig_error;
9671
        //sigact.sa_sigaction = sig_error;
9644
        sigemptyset(&sigact.sa_mask);
9672
        //sigemptyset(&sigact.sa_mask);
9645
        sigaction(SIGFPE, &sigact, NULL);
9673
        //sigaction(SIGFPE, &sigact, NULL);
9646
        sigaction(SIGILL, &sigact, NULL);
9674
        //sigaction(SIGILL, &sigact, NULL);
9647
        sigaction(SIGSEGV, &sigact, NULL);
9675
        //sigaction(SIGSEGV, &sigact, NULL);
9648
        sigaction(SIGBUS, &sigact, NULL);
9676
        //sigaction(SIGBUS, &sigact, NULL);
9649
        sigaction(SIGABRT, &sigact, NULL);
9677
        //sigaction(SIGABRT, &sigact, NULL);
9650
#endif
9678
#endif
Line 9651... Line 9679...
9651
    }
9679
    }
9652
 
9680
 
Line 9741... Line 9769...
9741
        snprintf(buf, sizeof(buf), "%s/lib", tcc_lib_path);
9769
        snprintf(buf, sizeof(buf), "%s/lib", tcc_lib_path);
9742
        tcc_add_library_path(s, buf);
9770
        tcc_add_library_path(s, buf);
9743
    }
9771
    }
9744
#else
9772
#else
9745
#ifdef TCC_TARGET_MEOS
9773
#ifdef TCC_TARGET_MEOS
-
 
9774
    tcc_add_library_path(s, ".//lib");
9746
#else
9775
#else
9747
    tcc_add_library_path(s, "/usr/local/lib");
9776
    tcc_add_library_path(s, "/usr/local/lib");
9748
    tcc_add_library_path(s, "/usr/lib");
9777
    tcc_add_library_path(s, "/usr/lib");
9749
    tcc_add_library_path(s, "/lib");
9778
    tcc_add_library_path(s, "/lib");
9750
#endif
9779
#endif
Line 10039... Line 10068...
10039
        /* XXX: reverse order needed if -isystem support */
10068
        /* XXX: reverse order needed if -isystem support */
10040
#if !defined(TCC_TARGET_PE) && !defined(TCC_TARGET_MEOS)
10069
#if !defined(TCC_TARGET_PE) && !defined(TCC_TARGET_MEOS)
10041
        tcc_add_sysinclude_path(s, "/usr/local/include");
10070
        tcc_add_sysinclude_path(s, "/usr/local/include");
10042
        tcc_add_sysinclude_path(s, "/usr/include");
10071
        tcc_add_sysinclude_path(s, "/usr/include");
10043
#endif
10072
#endif
-
 
10073
 
-
 
10074
#if defined(TCC_TARGET_MEOS)
-
 
10075
        tcc_add_sysinclude_path(s, ".//include");
-
 
10076
#endif
10044
        snprintf(buf, sizeof(buf), "%s/include", tcc_lib_path);
10077
        snprintf(buf, sizeof(buf), "%s/include", tcc_lib_path);
10045
        tcc_add_sysinclude_path(s, buf);
10078
        tcc_add_sysinclude_path(s, buf);
10046
#ifdef TCC_TARGET_PE
10079
#ifdef TCC_TARGET_PE
10047
        snprintf(buf, sizeof(buf), "%s/include/winapi", tcc_lib_path);
10080
        snprintf(buf, sizeof(buf), "%s/include/winapi", tcc_lib_path);
10048
        tcc_add_sysinclude_path(s, buf);
10081
        tcc_add_sysinclude_path(s, buf);
Line 10087... Line 10120...
10087
        tcc_add_file(s, CONFIG_TCC_CRT_PREFIX "/crti.o");
10120
        tcc_add_file(s, CONFIG_TCC_CRT_PREFIX "/crti.o");
10088
    }
10121
    }
10089
#endif
10122
#endif
10090
#if defined(TCC_TARGET_MEOS)
10123
#if defined(TCC_TARGET_MEOS)
10091
    if (s->output_type != TCC_OUTPUT_OBJ)
10124
    if (s->output_type != TCC_OUTPUT_OBJ)
10092
        tcc_add_file(s,".\\start.o");
10125
        tcc_add_file(s,".//start.o");
10093
#endif    
10126
#endif    
10094
    return 0;
10127
    return 0;
10095
}
10128
}
Line 10096... Line 10129...
10096
 
10129
 
Line 10227... Line 10260...
10227
           "  -static     static linking\n"
10260
           "  -static     static linking\n"
10228
           "  -rdynamic   export all global symbols to dynamic linker\n"
10261
           "  -rdynamic   export all global symbols to dynamic linker\n"
10229
           "  -r          relocatable output\n"
10262
           "  -r          relocatable output\n"
10230
           "Debugger options:\n"
10263
           "Debugger options:\n"
10231
           "  -g          generate runtime debug info\n"
10264
           "  -g          generate runtime debug info\n"
10232
#ifdef CONFIG_TCC_BCHECK
-
 
10233
           "  -b          compile with built-in memory and bounds checker (implies -g)\n"
-
 
10234
#endif
-
 
10235
           "  -bt N       show N callers in stack traces\n"
10265
           "  -bt N       show N callers in stack traces\n"
10236
           );
10266
           );
10237
}
10267
}
Line 10238... Line 10268...
10238
 
10268
 
Line 10349... Line 10379...
10349
static const char *outfile;
10379
static const char *outfile;
Line 10350... Line 10380...
10350
 
10380
 
10351
int parse_args(TCCState *s, int argc, char **argv)
10381
int parse_args(TCCState *s, int argc, char **argv)
10352
{
10382
{
-
 
10383
    int optind;
10353
    int optind;
10384
    int i;
10354
    const TCCOption *popt;
10385
    const TCCOption *popt;
10355
    const char *optarg, *p1, *r1;
10386
    const char *optarg, *p1, *r1;
-
 
10387
    char *r;
-
 
10388
    /*
Line -... Line 10389...
-
 
10389
    printf("\n%d\n",argc);
-
 
10390
 
-
 
10391
    for(i=0;i
-
 
10392
	{
-
 
10393
		printf("\n parameter  %d = %s",i+1,argv[i]);
-
 
10394
	}
10356
    char *r;
10395
    printf("\n");
10357
 
10396
    */
10358
    optind = 0;
10397
    optind = 0;
10359
    while (1) {
10398
    while (1) {
10360
        if (optind >= argc) {
10399
        if (optind >= argc) {
10361
            if (nb_files == 0 && !print_search_dirs)
10400
            if (nb_files == 0 && !print_search_dirs)
10362
                goto show_help;
10401
                  goto show_help;
10363
            else
10402
            else
10364
                break;
10403
                break;
10365
        }
10404
        }
-
 
10405
        r = argv[optind++];
10366
        r = argv[optind++];
10406
        if (r[0] != '-') {
10367
        if (r[0] != '-') {
10407
	
10368
            /* add a new file */
10408
            /* add a new file */
10369
            dynarray_add((void ***)&files, &nb_files, r);
10409
            dynarray_add((void ***)&files, &nb_files, r);
10370
            if (!multiple_files) {
10410
            if (!multiple_files) {
Line 10376... Line 10416...
10376
            /* find option in table (match only the first chars */
10416
            /* find option in table (match only the first chars */
10377
            popt = tcc_options;
10417
            popt = tcc_options;
10378
            for(;;) {
10418
            for(;;) {
10379
                p1 = popt->name;
10419
                p1 = popt->name;
10380
                if (p1 == NULL)
10420
                if (p1 == NULL)
10381
                    error("invalid option -- '%s'", r);
10421
                    printf("\n invalid option -- '%s'", r);
10382
                r1 = r + 1;
10422
                r1 = r + 1;
10383
                for(;;) {
10423
                for(;;) {
10384
                    if (*p1 == '\0')
10424
                    if (*p1 == '\0')
10385
                        goto option_found;
10425
                        goto option_found;
10386
                    if (*r1 != *p1)
10426
                    if (*r1 != *p1)
Line 10394... Line 10434...
10394
            if (popt->flags & TCC_OPTION_HAS_ARG) {
10434
            if (popt->flags & TCC_OPTION_HAS_ARG) {
10395
                if (*r1 != '\0' || (popt->flags & TCC_OPTION_NOSEP)) {
10435
                if (*r1 != '\0' || (popt->flags & TCC_OPTION_NOSEP)) {
10396
                    optarg = r1;
10436
                    optarg = r1;
10397
                } else {
10437
                } else {
10398
                    if (optind >= argc)
10438
                    if (optind >= argc)
10399
                        error("argument to '%s' is missing", r);
10439
                        printf("\n argument to '%s' is missing", r);
10400
                    optarg = argv[optind++];
10440
                    optarg = argv[optind++];
10401
                }
10441
                }
10402
            } else {
10442
            } else {
10403
                if (*r1 != '\0')
10443
                if (*r1 != '\0')
10404
                    goto show_help;
10444
                    goto show_help;
Line 10410... Line 10450...
10410
            show_help:
10450
            show_help:
10411
                help();
10451
                help();
10412
                exit(1);
10452
                exit(1);
10413
            case TCC_OPTION_I:
10453
            case TCC_OPTION_I:
10414
                if (tcc_add_include_path(s, optarg) < 0)
10454
                if (tcc_add_include_path(s, optarg) < 0)
10415
                    error("too many include paths");
10455
                    printf("\n too many include paths");
10416
                break;
10456
                break;
10417
            case TCC_OPTION_D:
10457
            case TCC_OPTION_D:
10418
                {
10458
                {
10419
                    char *sym, *value;
10459
                    char *sym, *value;
10420
                    sym = (char *)optarg;
10460
                    sym = (char *)optarg;
Line 10529... Line 10569...
10529
                        if (!strcmp(p, "coff")) {
10569
                        if (!strcmp(p, "coff")) {
10530
                            s->output_format = TCC_OUTPUT_FORMAT_COFF;
10570
                            s->output_format = TCC_OUTPUT_FORMAT_COFF;
10531
                        } else
10571
                        } else
10532
#endif
10572
#endif
10533
                        {
10573
                        {
10534
                            error("target %s not found", p);
10574
                            printf("\n target %s not found", p);
10535
                        }
10575
                        }
10536
                    } else {
10576
                    } else {
10537
                        error("unsupported linker option '%s'", optarg);
10577
                        printf("\n unsupported linker option '%s'", optarg);
10538
                    }
10578
                    }
10539
                }
10579
                }
10540
                break;
10580
                break;
10541
            default:
10581
            default:
10542
                if (s->warn_unsupported) {
10582
                if (s->warn_unsupported) {
10543
                unsupported_option:
10583
                unsupported_option:
10544
                    warning("unsupported option '%s'", r);
10584
                    warning("unsupported option '%s'", r);
-
 
10585
		    printf("\n unsupported option '%s'", r);
10545
                }
10586
                }
10546
                break;
10587
                break;
10547
            }
10588
            }
10548
        }
10589
        }
10549
    }
10590
    }
10550
    return optind;
10591
    return optind;
10551
}
10592
}
Line 10552... Line 10593...
10552
 
10593
 
10553
int main(int argc, char **argv)
10594
int app_main(int argc, char **argv)
10554
{
10595
{
10555
    int i;
10596
    int i;
10556
    TCCState *s;
10597
    TCCState *s;
10557
    int nb_objfiles, ret, optind;
10598
    int nb_objfiles, ret, optind;
10558
    char objfilename[1024];
10599
    char objfilename[1024];
-
 
10600
    int64_t start_time = 0;
Line -... Line 10601...
-
 
10601
    int bug;
10559
    int64_t start_time = 0;
10602
 
10560
 
10603
    printf("\nTinyC compiler started.\n ");
10561
#ifdef WIN32
10604
#ifdef WIN32
10562
    /* on win32, we suppose the lib and includes are at the location
10605
    /* on win32, we suppose the lib and includes are at the location
10563
       of 'tcc.exe' */
10606
       of 'tcc.exe' */
Line 10584... Line 10627...
10584
    files = NULL;
10627
    files = NULL;
10585
    nb_files = 0;
10628
    nb_files = 0;
10586
    nb_libraries = 0;
10629
    nb_libraries = 0;
10587
    reloc_output = 0;
10630
    reloc_output = 0;
10588
    print_search_dirs = 0;
10631
    print_search_dirs = 0;
-
 
10632
    printf("TinyC initializated.\n");
10589
 
10633
    bug=argc;
-
 
10634
    if (bug==0) {bug==1;}
10590
    optind = parse_args(s, argc - 1, argv + 1) + 1;
10635
    optind = parse_args(s, bug - 1, argv + 1) + 1;
-
 
10636
    printf("\n Arguments parsed.\n");
Line 10591... Line 10637...
10591
 
10637
 
10592
    if (print_search_dirs) {
10638
    if (print_search_dirs) {
10593
        /* enough for Linux kernel */
10639
        /* enough for Linux kernel */
10594
        printf("install: %s/\n", tcc_lib_path);
10640
        printf("install: %s/\n", tcc_lib_path);
Line 10600... Line 10646...
10600
    /* if outfile provided without other options, we output an
10646
    /* if outfile provided without other options, we output an
10601
       executable */
10647
       executable */
10602
    if (outfile && output_type == TCC_OUTPUT_MEMORY)
10648
    if (outfile && output_type == TCC_OUTPUT_MEMORY)
10603
        output_type = TCC_OUTPUT_EXE;
10649
        output_type = TCC_OUTPUT_EXE;
Line -... Line 10650...
-
 
10650
 
10604
 
10651
    /* check -c 
10605
    /* check -c consistency : only single file handled. XXX: checks file type */
10652
consistency : only single file handled. XXX: checks file type */
10606
    if (output_type == TCC_OUTPUT_OBJ && !reloc_output) {
10653
    if (output_type == TCC_OUTPUT_OBJ && !reloc_output) {
10607
        /* accepts only a single input file */
10654
        /* accepts only a single input file */
10608
        if (nb_objfiles != 1)
10655
        if (nb_objfiles != 1)
10609
            error("cannot specify multiple files with -c");
10656
            printf("\n cannot specify multiple files with -c");
10610
        if (nb_libraries != 0)
10657
        if (nb_libraries != 0)
10611
            error("cannot specify libraries with -c");
10658
            printf("\n cannot specify libraries with -c");
Line 10612... Line 10659...
10612
    }
10659
    }
10613
    
10660
    
10614
    if (output_type != TCC_OUTPUT_MEMORY) {
10661
    if (output_type != TCC_OUTPUT_MEMORY) {
Line 10700... Line 10747...
10700
#ifdef MEM_DEBUG
10747
#ifdef MEM_DEBUG
10701
    if (do_bench) {
10748
    if (do_bench) {
10702
        printf("memory: %d bytes, max = %d bytes\n", mem_cur_size, mem_max_size);
10749
        printf("memory: %d bytes, max = %d bytes\n", mem_cur_size, mem_max_size);
10703
    }
10750
    }
10704
#endif
10751
#endif
-
 
10752
    printf("\n TinyC finished work\n");
10705
    return ret;
10753
    return ret;
10706
}
10754
}
Line 10707... Line 10755...
10707
 
10755