⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmain.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 2 页
字号:
/* 
Copyright 1994-2003 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.  

This program is derived from the cc68k complier by 
Matthew Brandt (mattb@walkingdog.net) 

You may contact the author of this derivative at:

mailto::camille@bluegrass.net

or by snail mail at:

David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222
 */
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <setjmp.h>
#include <signal.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "utype.h"	
#include "cmdline.h"	
#include "lists.h"
#include "expr.h"
#include "ccerr.h"
#include "c.h"
#include "diag.h"
#include "winmode.h"
#include "..\version.h"

#ifdef __CCDL__
    int _stklen = 100 * 1024;
    #ifdef MSDOS
        int __dtabuflen = 32 * 1024;
    #endif 
#endif 

// #define VERSION 206

extern char GLBDEFINE[], SOURCEXT[], OBJEXT[], ENVNAME[], PROGNAME[];
extern int packlevel;
extern ERRORS *errlist;
extern TABLE *tagtable;
extern int total_errors;
extern int diagcount;
extern char *errfile;
extern TABLE *gsyms;
int inputFile = 0;
FILE *listFile = 0,  *outputFile = 0,  *cppFile = 0,  *errFile = 0;
#ifdef ICODE
FILE *icdFile = 0;
#endif
int anyusedfloat;
int stoponerr = 0;
int has_output_file;
LIST *clist = 0;
LIST *deflist = 0;
int prm_linkreg = TRUE;
int prm_stackcheck = FALSE;
int prm_warning = TRUE, prm_extwarning = FALSE;
#ifdef ICODE
    int prm_asmfile = TRUE;
	int prm_icdfile = FALSE;
#else 
    #ifdef COLDFIRE
        int prm_asmfile = FALSE;
    #else 
        int prm_asmfile = FALSE;
    #endif 
#endif 
int prm_ansi = FALSE;
int prm_c99 = FALSE;
int prm_listfile = FALSE;
int prm_maxerr = 25;
int prm_diag = FALSE;
int prm_bss = TRUE;
int prm_cppfile = FALSE;
int prm_revbits = FALSE;
int prm_lines = TRUE;
int prm_cplusplus = FALSE;
int prm_cmangle = TRUE;
int prm_trigraph = FALSE;
int basear = 1, basedr = 1, basefr = 1;
int prm_debug = FALSE;
char version[256];
char copyright[256];
int prm_errfile = FALSE;
int prm_profiler = FALSE;
int prm_peepopt = TRUE;
int prm_optmult = TRUE;
int prm_intrinsic = FALSE;
int prm_asmopt = FALSE;
int prm_xcept = TRUE;
int prm_quieterrors = FALSE;
int prm_smartframes = TRUE;
int prm_oldfor = FALSE;
#ifdef i386
    int prm_compileonly = FALSE;
    #ifdef MSDOS
        int prm_winmode = DOS32A;
    #else 
        int prm_winmode = CONSOLE;
    #endif 
    int prm_crtdll;
    int prm_lscrtdll;
    extern int prm_nasm;
#endif 

char *prm_searchpath = 0;
char *sys_searchpath = 0;
char **set_searchpath = &prm_searchpath;

jmp_buf ctrlcreturn;
int file_count = 0;

char *infile, listfile[256], outfile[256], cppfile[256], errorfile[256];
#ifdef ICODE
char icdfile[256];
#endif
void bool_setup(char select, char *string);
void err_setup(char select, char *string);
void incl_setup(char select, char *string);
void def_setup(char select, char *string);
void codegen_setup(char select, char *string);
void optimize_setup(char select, char *string);
void warning_setup(char select, char *string);
void parsefile(char select, char *string);
void output_setup(char select, char *string);
#ifdef i386
    void winmode_setup(char select, char *string);
#endif 

/* setup for ARGS.C */
ARGLIST ArgList[] = 
{
    {
        '9', ARG_BOOL, bool_setup
    }
    , 
    {
        'c', ARG_BOOL, bool_setup
    }
    , 
    {
        'i', ARG_BOOL, bool_setup
    }
    , 
    {
        'e', ARG_BOOL, bool_setup
    }
    , 
    {
        'f', ARG_CONCATSTRING, parsefile
    }
    , 
    {
        'l', ARG_BOOL, bool_setup
    }
    , 
    {
        'o', ARG_CONCATSTRING, output_setup
    }
    , 
    {
        'v', ARG_BOOL, bool_setup
    }
    , 
    {
        'w', ARG_CONCATSTRING, warning_setup
    }
    , 
    {
        'A', ARG_BOOL, bool_setup
    }
    , 
    {
        'C', ARG_CONCATSTRING, codegen_setup
    }
    , 
    {
        'O', ARG_CONCATSTRING, optimize_setup
    }
    , 
    {
        'E', ARG_CONCATSTRING, err_setup
    }
    , 
    {
        'I', ARG_CONCATSTRING, incl_setup
    }
    , 
    {
        'D', ARG_CONCATSTRING, def_setup
    }
    , 
    {
        'S', ARG_BOOL, bool_setup
    }
    , 
    {
        'R', ARG_BOOL, bool_setup
    }
    , 
    {
        'X', ARG_BOOL, bool_setup
    }
    , 
    {
        'Q', ARG_BOOL, bool_setup
    }
    , 
    #ifdef i386
        {
            'W', ARG_CONCATSTRING, winmode_setup
        }
        , 
    #endif 
    {
        0, 0, 0
    }
};
#ifdef i386
    void winmode_setup(char select, char *string)
    {
        switch (string[0])
        {
            case 'a':
                prm_winmode = DOS32A;
                break;
            case 'd':
                prm_winmode = DLL;
                break;
            case 'c':
                prm_winmode = CONSOLE;
                break;
            case 'g':
                prm_winmode = GUI;
                break;
            case 'e':
                prm_winmode = DOS;
                break;
            default:
                fatal("Invalid executable type");
        }
        if (string[1] == 'c')
        {
            if (prm_winmode == DOS)
                fatal("Invalid use of CRTDLL");
            prm_crtdll = TRUE;
#ifdef i386
        } else if (string[1] == 'l') {
            if (prm_winmode == DOS)
                fatal("Invalid use of LSCRTDLL");
            prm_lscrtdll = TRUE;
        }
#endif
    }
#endif 


void bool_setup(char select, char *string)
/*
 * activation routine (callback) for boolean command line arguments
 */
{
    int bool = (int)string;
    if (select == '9')
        prm_c99 = bool;
    if (select == 'S' && OBJEXT[0])
        prm_asmfile = bool;
    if (select == 'l')
        prm_listfile = bool;
    if (select == 'i')
        prm_cppfile = bool;
    if (select == 'e')
        prm_errfile = bool;
    if (select == 'v' && OBJEXT[0])
    {
        prm_debug = bool;
        prm_smartframes = !bool;
    }
    if (select == 'A')
        prm_ansi = bool;
    if (select == 'Q')
        prm_quieterrors = bool;
    #ifdef i386
        if (select == 'S')
        {
            prm_asmfile = bool;
            prm_nasm = bool;
            prm_compileonly = TRUE;
        }
        if (select == 'c')
        {
            prm_compileonly = bool;
            prm_asmfile = FALSE;
        }
    #else 
        if (select == 'S')
        {
            prm_asmfile = bool;
        }
    #endif 
    if (select == 'R' || select == 'X')
    {
        prm_xcept = bool;
    }
}

//-------------------------------------------------------------------------

void codegen_setup(char select, char *string)
/*
 * activation for code-gen type command line arguments
 */
{
    int bool = TRUE;
    while (*string)
    {
        switch (*string)
        {
            //               case 'f':
            //                  prm_smartframes = bool ;
            //                  break ;
            case 'd':
                prm_diag = bool;
                break;
            case 'r':
                prm_revbits = bool;
                break;
            case 'b':
                prm_bss = bool;
                break;
            case 'l':
                prm_lines = bool;
                break;
            case 'm':
                prm_cmangle = bool;
                break;
                #ifndef i386
                case 'R':
                    prm_linkreg = bool;
                    break;
                #endif 
            case 'S':
                prm_stackcheck = bool;
                break;
                /*               case 'T': */
                /*                  prm_trigraph = bool ; */
                /*                  break ; */
                /*          case 'X': This overrides something in confcodegen */
                /*            prm_xcept = bool; */
                break;
            case 'O':
                prm_oldfor = bool;
                break;
            case 'Z':
                prm_profiler = bool;
                break;
            case '-':
                bool = FALSE;
                break;
            case '+':
                bool = TRUE;
                break;
            default:
                if (!confcodegen(*string, bool))
                    fatal("Illegal codegen parameter ");
        }
        string++;
    }
}

//-------------------------------------------------------------------------

void optimize_setup(char select, char *string)
/*
 * activation for optimizer command line arguments
 */
{
    int bool = TRUE;
    while (*string)
    {
        switch (*string)
        {
            case 'a':
                prm_asmopt = bool;
                break;
            case 'i':
                prm_intrinsic = bool;
                break;
            case 'p':
                prm_peepopt = bool;
                break;
            case 'm':
                prm_optmult = bool;
                break;
            case 'R':
            case 'r':
                string++;
                while (*string &&  *string != '+' &&  *string != '-')
                {
                    switch (*string++)
                    {
                    case 'a':
                    case 'A':
                        basear = bool;
                        break;
                    case 'd':
                    case 'D':
                        basedr = bool;
                        break;
                    case 'f':
                    case 'F':
                        basefr = bool;
                        break;
                    default:
                        goto errorx;
                    }
                    if (! *string)
                        return ;
                }
                break;
#ifdef ICODE
			case 'Z':
				prm_icdfile = bool;
				break ;
#endif
            case '-':
                bool = FALSE;
                break;
            case '+':
                bool = TRUE;
                break;
            default:
                errorx: 
                #ifdef ICODE
                    if (!confoptgen(*string, bool))
                #endif 
                    fatal("Illegal optimizer parameter");
        }
        string++;
    }
}

//-------------------------------------------------------------------------

void err_setup(char select, char *string)
/*
 * activation for the max errs argument
 */
{
    if (*string == '+')
    {
        prm_extwarning = TRUE;
        string++;
    }
    else
    if (*string == '-')
    {
        prm_extwarning = FALSE;
        string++;
    }
    prm_maxerr = atoi(string);
}

//-------------------------------------------------------------------------

void incl_setup(char select, char *string)
/*
 * activation for include paths
 */
{
    if (*set_searchpath)
    {
        *set_searchpath = realloc(*set_searchpath, strlen(string) + strlen
            (*set_searchpath) + 2);
        strcat(*set_searchpath, ";");
    }
    else
    {
        *set_searchpath = malloc(strlen(string) + 1);
        *set_searchpath[0] = 0;
    }
    fflush(stdout);
    strcat(*set_searchpath, string);
}

//-------------------------------------------------------------------------

void def_setup(char select, char *string)
/*
 * activation for command line #defines
 */
{
    char *s = malloc(strlen(string) + 1);
    LIST *l = malloc(sizeof(LIST));
    strcpy(s, string);
    l->link = deflist;
    deflist = l;
    l->data = s;
}

//-------------------------------------------------------------------------

void output_setup(char select, char *string)
{
    strcpy(outfile, string);
    has_output_file = TRUE;
}

//-------------------------------------------------------------------------

void setglbdefs(void)
/*
 * function declares any global defines from the command line and also
 * declares a couple of other macros so we can tell what the compiler is
 * doing
 */
{
    LIST *l = deflist;
    char buf[256],  *p;
    int major, minor;
    while (l)
    {
        char *s = l->data;
        char *n = s;
        while (*s &&  *s != '=')
            s++;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -