文件
Paze AI 251ee470bf feat: Paze C Compiler - 完整改造自 tcc 0.9.28rc
- 所有 tcc 文件/内容/宏改名为 pcc (tcc.c->pcc.c, tccelf.c->pccelf.c, libtcc.c->libpcc.c 等)
- 支持架构: i386, x86_64, ARM, ARM64, RISC-V, C67
- 支持格式: PE, ELF, Mach-O, COFF
- 完整预处理、代码生成、链接器、调试信息
- 构建成功: pcc.exe (x86_64 Windows)
- 功能测试通过: 递归/结构体/浮点/switch/循环
- 自编译测试通过: pcc 可以编译自身
2026-08-16 13:30:01 +08:00

105 行
2.7 KiB
C

// =============================================
// crt1.c
// _UNICODE for tchar.h, UNICODE for API
#include <tchar.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#define _UNKNOWN_APP 0
#define _CONSOLE_APP 1
#define _GUI_APP 2
#define _MCW_PC 0x00030000 // Precision Control
#define _PC_24 0x00020000 // 24 bits
#define _PC_53 0x00010000 // 53 bits
#define _PC_64 0x00000000 // 64 bits
#ifdef _UNICODE
#define __tgetmainargs __wgetmainargs
#define _tstart _wstart
#define _tmain wmain
#define _runtmain _runwmain
#else
#define __tgetmainargs __getmainargs
#define _tstart _start
#define _tmain main
#define _runtmain _runmain
#endif
typedef struct { int newmode; } _startupinfo;
int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
void __cdecl __set_app_type(int apptype);
unsigned int __cdecl _controlfp(unsigned int new_value, unsigned int mask);
extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]);
#include "crtinit.c"
/* Allow command-line globbing with "int _dowildcard = 1;" in the user source */
int _dowildcard;
static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex)
{
return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex);
}
void _tstart(void)
{
int ret;
_startupinfo start_info = {0};
SetUnhandledExceptionFilter(catch_sig);
// Sets the current application type
__set_app_type(_CONSOLE_APP);
// Set default FP precision to 53 bits (8-byte double)
// _MCW_PC (Precision control) is not supported on ARM
#if defined __i386__ || defined __x86_64__
_controlfp(_PC_53, _MCW_PC);
#endif
__tgetmainargs( &__argc, &__targv, &_tenviron, _dowildcard, &start_info);
run_ctors(__argc, __targv, _tenviron);
ret = _tmain(__argc, __targv, _tenviron);
run_dtors();
exit(ret);
}
// =============================================
// for 'pcc -run ,,,'
__attribute__((weak)) extern int __run_on_exit();
int _runtmain(int argc, /* as pcc passed in */ char **argv)
{
int ret;
#if defined UNICODE || defined __aarch64__
_startupinfo start_info = {0};
__tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info);
#endif
#ifdef UNICODE
/* may be wrong when pcc has received wildcards (*.c) */
if (argc < __argc) {
__targv += __argc - argc;
__argc = argc;
}
#else
__argc = argc;
__targv = argv;
#endif
#if defined __i386__ || defined __x86_64__
_controlfp(_PC_53, _MCW_PC);
#endif
run_ctors(__argc, __targv, _tenviron);
ret = _tmain(__argc, __targv, _tenviron);
fflush(stdout);
fflush(stderr);
run_dtors();
__run_on_exit(ret);
return ret;
}
// =============================================