├── .gitignore ├── .vs ├── crt.vcxproj ├── crt.vcxproj.filters ├── crt.vcxproj.user ├── dcc.sln ├── dcc.vcxproj ├── dcc.vcxproj.filters └── dcc.vcxproj.user ├── LICENSE ├── README.md ├── include ├── dcc │ ├── addr2line.h │ ├── assembler.h │ ├── byteorder.h │ ├── common.h │ ├── compiler.h │ ├── def-asm.inl │ ├── def-keywords.inl │ ├── dl.h │ ├── fundecl.h │ ├── gen.h │ ├── lexer.h │ ├── linker.h │ ├── preprocessor.h │ ├── stream.h │ ├── target-crt.h │ ├── target.h │ ├── type.h │ ├── unit.h │ └── vstack.h ├── dcc_winmin.h └── drt │ └── drt.h ├── lib ├── .objs │ ├── dbg-addr2line.c.o │ ├── dbg-crt1.c.o │ ├── dbg-int64.c.o │ ├── ndbg-crt1.c.o │ └── ndbg-int64.c.o ├── crt.o ├── dbg-crt.o ├── fixinclude │ ├── .readme.md │ ├── __stdinc-syntax.h │ ├── __stdinc.h │ ├── alloca.h │ ├── byteswap.h │ ├── ctype.h │ ├── dcc.h │ ├── endian.h │ ├── features.h │ ├── iso646.h │ ├── limits.h │ ├── malloc.h │ ├── memory.h │ ├── setjmp.h │ ├── stdarg.h │ ├── stdbool.h │ ├── stddef.h │ ├── stdint.h │ ├── stdio.h │ ├── stdlib.h │ ├── string.h │ ├── strings.h │ ├── time.h │ ├── uchar.h │ ├── varargs.h │ └── wchar.h ├── include │ ├── .readme.md │ ├── ar.h │ ├── assert.h │ ├── bits │ │ ├── byteswap.h │ │ ├── dirent.h │ │ ├── fcntl-linux.h │ │ ├── fcntl.h │ │ ├── stat.h │ │ └── types.h │ ├── crtdbg.h │ ├── ctype.h │ ├── direct.h │ ├── dirent.h │ ├── elf.h │ ├── errno.h │ ├── fcntl.h │ ├── features.h │ ├── malloc.h │ ├── mcheck.h │ ├── process.h │ ├── stdio.h │ ├── stdlib.h │ ├── string.h │ ├── strings.h │ ├── sys │ │ ├── dir.h │ │ ├── fcntl.h │ │ ├── stat.h │ │ └── types.h │ ├── time.h │ ├── unistd.h │ ├── wchar.h │ └── xlocale.h ├── make.sh ├── src │ ├── a2l │ │ ├── addr2line-common.c │ │ └── addr2line.h │ ├── crt │ │ ├── addr2line.c │ │ ├── alloca.S │ │ ├── chkstk.S │ │ ├── crt1.c │ │ ├── crtdbg.h │ │ └── int64.c │ └── libc │ │ ├── common.h │ │ ├── fcntl.c │ │ ├── string.c │ │ └── unistd.c └── test │ ├── constant_arithmetic.c │ ├── int64.c │ ├── intprom.c │ ├── reachable.c │ ├── runall.sh │ └── sizeof.c ├── make.sh └── src ├── dcc ├── __ice__ │ ├── code.c │ ├── code.h │ ├── gen-binary.c.inl │ ├── gen.c │ ├── lexer-ctype.c.inl │ ├── symbol.c │ └── symbol.h ├── addr2line.c ├── assembler.c ├── cmd-def.inl ├── cmd-help.c ├── cmd-parse.c.inl ├── cmd.c ├── cmd.h ├── common.c ├── compiler-std.c.inl ├── compiler.c ├── fundecl.c ├── gen-bin.c.inl ├── gen-cmp.c.inl ├── gen-jmp.c.inl ├── gen-large.c.inl ├── gen-misc.c.inl ├── gen-mov.c.inl ├── gen-one.c.inl ├── gen.c ├── lexer-asm.c.inl ├── lexer-attributes.c.inl ├── lexer-builtins-cpuid.c.inl ├── lexer-builtins-malloc.c.inl ├── lexer-builtins-string.c.inl ├── lexer-builtins-util.c.inl ├── lexer-builtins.c.inl ├── lexer-ctype-guess.c.inl ├── lexer-ctype-struct.c.inl ├── lexer-ctype.c.inl ├── lexer-decl.c.inl ├── lexer-expr.c.inl ├── lexer-init.c.inl ├── lexer-priv.h ├── lexer-stmt.c.inl ├── lexer.c ├── linker-elf.c.inl ├── linker-elf.h ├── linker-pe.c.inl ├── linker-pe.h ├── linker.c ├── preprocessor.c ├── tpp-wrapper.c ├── type.c ├── unit-debug.c ├── unit-export-elf.c.inl ├── unit-export.c ├── unit-export.h ├── unit-freedat.c.inl ├── unit-import-arch.c.inl ├── unit-import-def-dynamic.c.inl ├── unit-import-elf.c.inl ├── unit-import-pe-dynamic.c.inl ├── unit-import-pe-static.c.inl ├── unit-import-source.c.inl ├── unit-import.c ├── unit-import.h ├── unit-merge.c ├── unit-seccoll.c.inl ├── unit-secmem.c.inl ├── unit.c ├── vstack-cmp.c.inl ├── vstack-ext.c ├── vstack.c ├── x86_util-instrlen-ops.c.inl ├── x86_util-instrlen.c └── x86_util.h ├── drt ├── drt-sync.c.inl ├── drt-thread.c.inl ├── drt-user.c.inl ├── drt.c └── drt.h ├── main.c └── tpp ├── frontend.c ├── tpp-backwards-compatibility.h ├── tpp-defs.inl ├── tpp-gcc-defs.inl ├── tpp.c └── tpp.h /.gitignore: -------------------------------------------------------------------------------- 1 | bin/* 2 | build/* 3 | src/tpp/frontend.c 4 | .vs/*.sdf 5 | .vs/*.suo 6 | .vs/*.opensdf 7 | *.exe 8 | *.dat 9 | lib/.objs/* 10 | lib/.deps/* 11 | -------------------------------------------------------------------------------- /.vs/crt.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | WindowsLocalDebugger 7 | $(ProjectDir)..\bin\ 8 | 9 | 10 | 11 | 12 | WindowsLocalDebugger 13 | $(ProjectDir)..\bin\ 14 | 15 | -------------------------------------------------------------------------------- /.vs/dcc.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dcc", "dcc.vcxproj", "{86D226C5-EF62-4562-AC06-E6A753DFA7CF}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "crt", "crt.vcxproj", "{3E027BB2-167C-49CE-8B99-C1DD1538C103}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Win32 = Debug|Win32 13 | Release|Win32 = Release|Win32 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {86D226C5-EF62-4562-AC06-E6A753DFA7CF}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {86D226C5-EF62-4562-AC06-E6A753DFA7CF}.Debug|Win32.Build.0 = Debug|Win32 18 | {86D226C5-EF62-4562-AC06-E6A753DFA7CF}.Release|Win32.ActiveCfg = Release|Win32 19 | {86D226C5-EF62-4562-AC06-E6A753DFA7CF}.Release|Win32.Build.0 = Release|Win32 20 | {3E027BB2-167C-49CE-8B99-C1DD1538C103}.Debug|Win32.ActiveCfg = Debug|Win32 21 | {3E027BB2-167C-49CE-8B99-C1DD1538C103}.Release|Win32.ActiveCfg = Release|Win32 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /.vs/dcc.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -dg ../bin/input.c 5 | WindowsLocalDebugger 6 | $(ProjectDir)..\bin\ 7 | 8 | 9 | -dg ../bin/input.c 10 | WindowsLocalDebugger 11 | $(ProjectDir)..\bin\ 12 | 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ZLIB LICENSE (https://en.wikipedia.org/wiki/Zlib_License) 2 | 3 | Copyright (c) 2017 Griefer@Work 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgement in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | -------------------------------------------------------------------------------- /include/dcc/dl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_DCC_DL_H 20 | #define GUARD_DCC_DL_H 1 21 | 22 | #include "common.h" 23 | #include "target.h" 24 | 25 | #if !!(DCC_HOST_OS&DCC_OS_F_WINDOWS) 26 | #include 27 | 28 | DCC_DECL_BEGIN 29 | 30 | typedef HMODULE DCC(dl_t); 31 | #define DCC_DLERROR NULL 32 | #define DCC_DLERROR_IS_ZERO 1 33 | #define DCC_dlopen(filename) LoadLibraryA(filename) 34 | #define DCC_dlsym(dl,name) GetProcAddress(dl,name) 35 | #define DCC_dlclose(dl) FreeLibrary(dl) 36 | 37 | DCC_DECL_END 38 | 39 | #elif !!(DCC_HOST_OS&DCC_OS_F_UNIX) || __has_include() 40 | #include 41 | 42 | DCC_DECL_BEGIN 43 | 44 | typedef void *DCC(dl_t); 45 | #define DCC_DLERROR NULL 46 | #define DCC_DLERROR_IS_ZERO 1 47 | #define DCC_dlopen(filename) dlopen(filename,RTLD_GLOBAL|RTLD_LAZY) 48 | #define DCC_dlsym(dl,name) dlsym(dl,name) 49 | #define DCC_dlclose(dl) dlclose(dl) 50 | 51 | DCC_DECL_END 52 | 53 | #else 54 | #error FIXME 55 | #endif 56 | 57 | #ifndef DCC_DLERROR_IS_ZERO 58 | #define DCC_DLERROR_IS_ZERO 0 59 | #endif 60 | 61 | #endif /* !GUARD_DCC_DL_H */ 62 | -------------------------------------------------------------------------------- /include/dcc/fundecl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_DCC_FUNDECL_H 20 | #define GUARD_DCC_FUNDECL_H 1 21 | 22 | #include "common.h" 23 | #include "unit.h" 24 | #include "gen.h" 25 | 26 | DCC_DECL_BEGIN 27 | 28 | #define DCC_FUNCTIONFRAME_FLAG_NONE 0x00000000 29 | #define DCC_FUNCTIONFRAME_FLAG_NAKED 0x00000001 /*< Naked function declaration (aka. '__attribute__((naked))'). */ 30 | struct DCCFunctionFrame { 31 | struct DCCDecl *ff_old_fun; /*< [0..1] Old value for 'compiler.c_fun'. */ 32 | struct DCCSym *ff_old_funname; /*< [0..1] Old value for 'compiler.c_dfunname'. */ 33 | struct DCCSym *ff_old_bsym; /*< [0..1] Old value for 'compiler.c_bsym'. */ 34 | struct DCCSym *ff_old_csym; /*< [0..1] Old value for 'compiler.c_csym'. */ 35 | struct DCCSym *ff_old_return; /*< [0..1] Old value for 'compiler.c_return'. */ 36 | uint32_t ff_old_flags; /*< Old value for 'compiler.c_flags'. */ 37 | struct DCCVStack ff_old_vstack; /*< Old v-stack. */ 38 | struct DCCSection *ff_old_section; /*< [0..1] Old value for 'unit.u_curr'. */ 39 | struct DCCSection *ff_new_section; /*< [1..1] The section in which this function is being declared. */ 40 | struct DCCSym *ff_jmpsym; /*< [0..1] Target for an optional jmp instruction prior to the function, 41 | * and used to jump across when embedded inside another declaration. */ 42 | struct DCCDispFunction ff_dispinfo; /*< Function dispense information. */ 43 | uint32_t ff_flags; /*< Set of 'DCC_FUNCTIONFRAME_FLAG_*' */ 44 | struct DCCSym *ff_funsym; /*< [1..1] Entry-symbol for the function described by this frame. */ 45 | }; 46 | 47 | /* Enter/Leave, as well as initialize/dispose a give function frame. 48 | * >> These functions should be called after a function scope was created 49 | * using the 'DCCUnit_(Push|Pop)FunctionScope' macros from "unit.h" */ 50 | DCCFUN void DCCFunctionFrame_Enter(struct DCCFunctionFrame *__restrict self, 51 | struct DCCDecl *fun_decl, 52 | struct DCCSym *__restrict fun_sym, 53 | struct DCCAttrDecl const *__restrict fun_attr); 54 | DCCFUN void DCCFunctionFrame_Leave(struct DCCFunctionFrame *__restrict self); 55 | 56 | DCC_DECL_END 57 | 58 | #endif /* !GUARD_DCC_FUNDECL_H */ 59 | -------------------------------------------------------------------------------- /include/dcc/stream.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_DCC_STREAM_H 20 | #define GUARD_DCC_STREAM_H 1 21 | 22 | #include "common.h" 23 | #include "lexer.h" 24 | 25 | #if defined(_WIN16) || defined(WIN16) || \ 26 | defined(_WIN32) || defined(WIN32) || \ 27 | defined(_WIN64) || defined(WIN64) || \ 28 | defined(__WIN32__) || defined(__TOS_WIN__) || \ 29 | defined(_WIN32_WCE) || defined(WIN32_WCE) 30 | #include 31 | #else 32 | #include 33 | #include 34 | #endif 35 | 36 | #ifndef SEEK_SET 37 | #define SEEK_SET 0 38 | #define SEEK_CUR 1 39 | #define SEEK_END 2 40 | #endif 41 | 42 | DCC_DECL_BEGIN 43 | 44 | typedef uint32_t DCC(soff_t); /* File offset. */ 45 | 46 | #ifdef _WIN32 47 | #define DCC_STREAM_OPEN_R(filename) \ 48 | CreateFileA(filename,GENERIC_READ,\ 49 | FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,\ 50 | NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL) 51 | #define DCC_STREAM_OPEN_W(filename) \ 52 | CreateFileA(filename,GENERIC_WRITE,\ 53 | FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,\ 54 | NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL) 55 | #define DCC_STREAM_CLOSE(fd) CloseHandle(fd) 56 | #define DCC_STREAM_SEEK(fd,off,whence) (DCC(soff_t))SetFilePointer(fd,off,NULL,whence) 57 | DCC_LOCAL ptrdiff_t dcc_win32_stream_read(DCC(stream_t) fd, void *p, size_t s) { 58 | DWORD result; 59 | if (!ReadFile(fd,p,s,&result,NULL)) return -1; 60 | return (ptrdiff_t)result; 61 | } 62 | DCC_LOCAL ptrdiff_t dcc_win32_stream_write(DCC(stream_t) fd, void const *p, size_t s) { 63 | DWORD result; 64 | if (!WriteFile(fd,p,s,&result,NULL)) return -1; 65 | return (ptrdiff_t)result; 66 | } 67 | #define DCC_STREAM_READ(fd,p,s) dcc_win32_stream_read(fd,p,s) 68 | #define DCC_STREAM_WRITE(fd,p,s) dcc_win32_stream_write(fd,p,s) 69 | #define DCC_STREAM_STDIN GetStdHandle(STD_INPUT_HANDLE) 70 | #define DCC_STREAM_STDOUT GetStdHandle(STD_OUTPUT_HANDLE) 71 | #define DCC_STREAM_STDERR GetStdHandle(STD_ERROR_HANDLE) 72 | #else 73 | #define DCC_STREAM_OPEN_R(filename) open(filename,O_RDONLY) 74 | #define DCC_STREAM_OPEN_W(filename) open(filename,O_WRONLY|O_CREAT,0644) 75 | #define DCC_STREAM_CLOSE(fd) close(fd) 76 | #define DCC_STREAM_SEEK(fd,off,whence) lseek(fd,off,whence) 77 | #define DCC_STREAM_READ(fd,p,s) read(fd,p,s) 78 | #define DCC_STREAM_WRITE(fd,p,s) write(fd,p,s) 79 | #define DCC_STREAM_STDIN STDIN_FILENO 80 | #define DCC_STREAM_STDOUT STDOUT_FILENO 81 | #define DCC_STREAM_STDERR STDERR_FILENO 82 | #endif 83 | 84 | 85 | DCC_LOCAL int 86 | DCCStream_ReadAll(DCC(stream_t) fd, void *p, size_t s) { 87 | ptrdiff_t part; 88 | size_t total = 0; 89 | while ((part = DCC_STREAM_READ(fd,p,s)) > 0) { 90 | if ((size_t)part > s) part = s; /* Shouldn't happen, but lets be careful. */ 91 | s -= part; 92 | *(uintptr_t *)&p += part; 93 | } 94 | return total == s; 95 | } 96 | 97 | DCC_LOCAL int 98 | DCCStream_WriteAll(DCC(stream_t) fd, void const *p, size_t s) { 99 | ptrdiff_t part; 100 | size_t total = 0; 101 | while ((part = DCC_STREAM_WRITE(fd,p,s)) > 0) { 102 | if ((size_t)part > s) part = s; /* Shouldn't happen, but lets be careful. */ 103 | s -= part; 104 | *(uintptr_t *)&p += part; 105 | } 106 | return total == s; 107 | } 108 | 109 | DCCFUN int DCCStream_PadSize(DCC(stream_t) fd, size_t n_bytes); 110 | DCCFUN int DCCStream_PadAddr(DCC(stream_t) fd, DCC(soff_t) offset); 111 | 112 | #ifdef DCC_PRIVATE_API 113 | #define s_openr DCC_STREAM_OPEN_R 114 | #define s_openw DCC_STREAM_OPEN_W 115 | #define s_close DCC_STREAM_CLOSE 116 | #define s_seek DCC_STREAM_SEEK 117 | #define s_read DCC_STREAM_READ 118 | #define s_write DCC_STREAM_WRITE 119 | #define s_reada DCCStream_ReadAll 120 | #define s_writea DCCStream_WriteAll 121 | #endif 122 | 123 | DCC_DECL_END 124 | 125 | #endif /* !GUARD_DCC_STREAM_H */ 126 | -------------------------------------------------------------------------------- /include/dcc_winmin.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_WINMIN_H 20 | #define GUARD_WINMIN_H 1 21 | 22 | /* Don't need any of this $h1t */ 23 | 24 | #define NOGDICAPMASKS 25 | #define NOVIRTUALKEYCODES 26 | #define NOWINMESSAGES 27 | #define NOWINSTYLES 28 | #define NOSYSMETRICS 29 | #define NOMENUS 30 | #define NOICONS 31 | #define NOKEYSTATES 32 | #define NOSYSCOMMANDS 33 | #define NORASTEROPS 34 | #define NOSHOWWINDOW 35 | #define OEMRESOURCE 36 | #define NOATOM 37 | #define NOCLIPBOARD 38 | #define NOCOLOR 39 | #define NOCTLMGR 40 | #define NODRAWTEXT 41 | #define NOGDI 42 | #define NOKERNEL 43 | #define NOUSER 44 | #define NONLS 45 | #define NOMB 46 | #define NOMEMMGR 47 | #define NOMETAFILE 48 | #define NOMINMAX 49 | #define NOMSG 50 | #define NOOPENFILE 51 | #define NOSCROLL 52 | #define NOSERVICE 53 | #define NOSOUND 54 | #define NOTEXTMETRIC 55 | #define NOWH 56 | #define NOWINOFFSETS 57 | #define NOCOMM 58 | #define NOKANJI 59 | #define NOHELP 60 | #define NOPROFILER 61 | #define NODEFERWINDOWPOS 62 | #define NOMCX 63 | 64 | #define NOAPISET 65 | #define NOCRYPT 66 | #define NOIME 67 | 68 | #define WIN32_LEAN_AND_MEAN 69 | 70 | #ifndef _MSC_VER 71 | /* Disable more C7A9 */ 72 | #define _OLE2_H_ 73 | #define VER_H 74 | #define _WINREG_ 75 | #define _WINNETWK_ 76 | #define __STRALIGN_H_ 77 | #define _APIAPPCONTAINER_ 78 | #define _APISETREALTIME_ 79 | #define _PROCESSTOPOLOGYAPI_H_ 80 | #define _SYSTEMTOPOLOGY_H_ 81 | #define _APISETNAMESPACE_ 82 | #define _APISECUREBASE_ 83 | //#define _APISETLIBLOADER_ // Stuff crashes without this 84 | #define _WOW64APISET_H_ 85 | #define _JOBAPISET_H_ 86 | #define _BEM_H_ 87 | #define _THREADPOOLAPISET_H_ 88 | #define _THREADPOOLLEGACYAPISET_H_ 89 | //#define _MEMORYAPI_H_ // We actually need this one 90 | //#define _SYSINFOAPI_H_ // Stuff crashes without this 91 | //#define _PROCESSTHREADSAPI_H_ // Stuff crashes without this 92 | #define _INTERLOCKAPI_H_ 93 | #define _SYNCHAPI_H_ 94 | #define _IO_APISET_H_ 95 | #define _HEAPAPI_H_ 96 | #define _PROFILEAPI_H_ 97 | #define _NAMEDPIPE_H_ 98 | #define _FIBERS_H_ 99 | #define _ERRHANDLING_H_ 100 | //#define _APISETHANDLE_ // Need this one for CloseHandle() 101 | #define _APISETUTIL_ 102 | //#define _APISETDEBUG_ // OutputDebugStringA() 103 | //#define _APISETFILE_ // A buck of file functions 104 | //#define _PROCESSENV_ // GetStdHandle() 105 | #endif 106 | 107 | #include 108 | 109 | #undef NOGDICAPMASKS 110 | #undef NOVIRTUALKEYCODES 111 | #undef NOWINMESSAGES 112 | #undef NOWINSTYLES 113 | #undef NOSYSMETRICS 114 | #undef NOMENUS 115 | #undef NOICONS 116 | #undef NOKEYSTATES 117 | #undef NOSYSCOMMANDS 118 | #undef NORASTEROPS 119 | #undef NOSHOWWINDOW 120 | #undef OEMRESOURCE 121 | #undef NOATOM 122 | #undef NOCLIPBOARD 123 | #undef NOCOLOR 124 | #undef NOCTLMGR 125 | #undef NODRAWTEXT 126 | #undef NOGDI 127 | #undef NOKERNEL 128 | #undef NOUSER 129 | #undef NONLS 130 | #undef NOMB 131 | #undef NOMEMMGR 132 | #undef NOMETAFILE 133 | #undef NOMINMAX 134 | #undef NOMSG 135 | #undef NOOPENFILE 136 | #undef NOSCROLL 137 | #undef NOSERVICE 138 | #undef NOSOUND 139 | #undef NOTEXTMETRIC 140 | #undef NOWH 141 | #undef NOWINOFFSETS 142 | #undef NOCOMM 143 | #undef NOKANJI 144 | #undef NOHELP 145 | #undef NOPROFILER 146 | #undef NODEFERWINDOWPOS 147 | #undef NOMCX 148 | 149 | #endif /* !GUARD_WINMIN_H */ 150 | -------------------------------------------------------------------------------- /include/drt/drt.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrieferAtWork/dcc/e70803aef1d7dc83ecedc6134c3e7902e6b6bbca/include/drt/drt.h -------------------------------------------------------------------------------- /lib/.objs/dbg-addr2line.c.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrieferAtWork/dcc/e70803aef1d7dc83ecedc6134c3e7902e6b6bbca/lib/.objs/dbg-addr2line.c.o -------------------------------------------------------------------------------- /lib/.objs/dbg-crt1.c.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrieferAtWork/dcc/e70803aef1d7dc83ecedc6134c3e7902e6b6bbca/lib/.objs/dbg-crt1.c.o -------------------------------------------------------------------------------- /lib/.objs/dbg-int64.c.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrieferAtWork/dcc/e70803aef1d7dc83ecedc6134c3e7902e6b6bbca/lib/.objs/dbg-int64.c.o -------------------------------------------------------------------------------- /lib/.objs/ndbg-crt1.c.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrieferAtWork/dcc/e70803aef1d7dc83ecedc6134c3e7902e6b6bbca/lib/.objs/ndbg-crt1.c.o -------------------------------------------------------------------------------- /lib/.objs/ndbg-int64.c.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrieferAtWork/dcc/e70803aef1d7dc83ecedc6134c3e7902e6b6bbca/lib/.objs/ndbg-int64.c.o -------------------------------------------------------------------------------- /lib/crt.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrieferAtWork/dcc/e70803aef1d7dc83ecedc6134c3e7902e6b6bbca/lib/crt.o -------------------------------------------------------------------------------- /lib/dbg-crt.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrieferAtWork/dcc/e70803aef1d7dc83ecedc6134c3e7902e6b6bbca/lib/dbg-crt.o -------------------------------------------------------------------------------- /lib/fixinclude/.readme.md: -------------------------------------------------------------------------------- 1 | 2 | Fixed system headers optimized for use with DCC. 3 | These headers are meant to be used in conjunction with an existing C library! 4 | 5 | -------------------------------------------------------------------------------- /lib/fixinclude/__stdinc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_builtin 23 | #define __has_builtin(x) 0 24 | #endif 25 | #ifndef __has_attribute 26 | #define __has_attribute(x) 0 27 | #endif 28 | #ifndef __has_include 29 | #define __has_include(x) 0 30 | #endif 31 | #ifndef __has_include_next 32 | #define __has_include_next(x) 0 33 | #endif 34 | #ifndef __has_warning 35 | #define __has_warning(x) 0 36 | #endif 37 | 38 | #if __has_include_next(<__stdinc.h>) 39 | # include_next <__stdinc.h> 40 | #endif 41 | 42 | #ifndef __DCC_VERSION__ 43 | #ifdef __INTELLISENSE__ 44 | # include "__stdinc-syntax.h" 45 | #else 46 | # warning "These headers are only meant for DCC" 47 | #endif 48 | #endif /* !__DCC_VERSION__ */ 49 | 50 | #ifdef __PE__ 51 | # define __IMP __attribute__((__dllimport__)) 52 | #else 53 | # define __IMP 54 | #endif 55 | #define __WUNUSED __attribute__((__warn_unused_result__)) 56 | 57 | #if 0 58 | # define __CRT_DCC 1 59 | #elif defined(__KOS__) 60 | # define __CRT_KOS 1 61 | #elif defined(_WIN32) || defined(__CYGWIN32__) 62 | # define __CRT_MSVC 1 63 | # define __MS_LONG __int32 64 | #else 65 | # define __CRT_GLIBC 1 66 | #endif 67 | #ifdef __CRT_DCC 68 | # undef __CRT_GLIBC 69 | # undef __CRT_KOS 70 | # undef __CRT_MSVC 71 | #endif 72 | #ifdef __CRT_MSVC 73 | # undef __CRT_DCC 74 | # undef __CRT_GLIBC 75 | # undef __CRT_KOS 76 | #endif 77 | #ifdef __CRT_GLIBC 78 | # undef __CRT_DCC 79 | # undef __CRT_KOS 80 | # undef __CRT_MSVC 81 | #endif 82 | #ifdef __CRT_KOS 83 | # undef __CRT_DCC 84 | # undef __CRT_GLIBC 85 | # undef __CRT_KOS 86 | # undef __CRT_MSVC 87 | #endif 88 | 89 | #define __CRT_UNSUPPORTED(crt) [[__error__("Function is unsupported by <" crt ">")]] 90 | #define __CRT_WORKAROUND(crt) [[__warning__("Function only works in <" crt "> thanks to a workaround")]] 91 | 92 | #ifdef __CRT_MSVC 93 | # define __CRT_UNSUPPORTED_MSVC __CRT_UNSUPPORTED("MSVC") 94 | # define __CRT_WORKAROUND_MSVC __CRT_WORKAROUND("MSVC") 95 | #else 96 | # define __CRT_UNSUPPORTED_MSVC 97 | # define __CRT_WORKAROUND_MSVC 98 | #endif 99 | 100 | #ifdef __CRT_GLIBC 101 | # define __CRT_UNSUPPORTED_GLIBC __CRT_UNSUPPORTED("GLIBC") 102 | # define __CRT_WORKAROUND_GLIBC __CRT_WORKAROUND("GLIBC") 103 | #else 104 | # define __CRT_UNSUPPORTED_GLIBC 105 | # define __CRT_WORKAROUND_GLIBC 106 | #endif 107 | 108 | #ifdef __CRT_KOS 109 | # define __CRT_UNSUPPORTED_KOS __CRT_UNSUPPORTED("KOS") 110 | # define __CRT_WORKAROUND_KOS __CRT_WORKAROUND("KOS") 111 | #else 112 | # define __CRT_UNSUPPORTED_KOS 113 | # define __CRT_WORKAROUND_KOS 114 | #endif 115 | 116 | #ifdef __STRICT_ANSI__ 117 | # define __STRICT_ANSI_HEADER \ 118 | __pragma(tpp_exec("#warning \"<" __FILE__ "> should not be included when -ansi is passed\"\n")) 119 | #else 120 | # define __STRICT_ANSI_HEADER /* nothing */ 121 | #endif 122 | -------------------------------------------------------------------------------- /lib/fixinclude/alloca.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | __STRICT_ANSI_HEADER 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #endif 29 | 30 | /* Fixed/optimized system header for DCC */ 31 | 32 | 33 | /* void *alloca(size_t s); */ 34 | #define alloca(x) __builtin_alloca((x)) 35 | -------------------------------------------------------------------------------- /lib/fixinclude/byteswap.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | __STRICT_ANSI_HEADER 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #endif 29 | #if __has_include() 30 | #include_next 31 | #endif 32 | 33 | /* Fixed/optimized system header for DCC */ 34 | 35 | #ifdef __bswap_16 36 | # define bswap_16(x) __bswap_16(x) 37 | #else 38 | # define bswap_16(x) __builtin_bswap16(x) 39 | #endif 40 | #ifdef __bswap_32 41 | # define bswap_32(x) __bswap_32(x) 42 | #else 43 | # define bswap_32(x) __builtin_bswap32(x) 44 | #endif 45 | #ifdef __bswap_64 46 | # define bswap_64(x) __bswap_64(x) 47 | #else 48 | # define bswap_64(x) __builtin_bswap64(x) 49 | #endif 50 | -------------------------------------------------------------------------------- /lib/fixinclude/ctype.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | #include 24 | 25 | #if __has_include_next() 26 | # include_next 27 | #elif defined(__INTELLISENSE__) 28 | # include "../include/ctype.h" 29 | #endif 30 | 31 | #define isalpha(ch) __builtin_isalpha((ch)) 32 | #define isupper(ch) __builtin_isupper((ch)) 33 | #define islower(ch) __builtin_islower((ch)) 34 | #define isdigit(ch) __builtin_isdigit((ch)) 35 | #define isxdigit(ch) __builtin_isxdigit((ch)) 36 | #define isspace(ch) __builtin_isspace((ch)) 37 | #define ispunct(ch) __builtin_ispunct((ch)) 38 | #define isalnum(ch) __builtin_isalnum((ch)) 39 | #define isprint(ch) __builtin_isprint((ch)) 40 | #define isgraph(ch) __builtin_isgraph((ch)) 41 | #define iscntrl(ch) __builtin_iscntrl((ch)) 42 | #define toupper(ch) __builtin_toupper((ch)) 43 | #define tolower(ch) __builtin_tolower((ch)) 44 | #ifdef __USE_ISOC99 45 | #define isblank(ch) __builtin_isblank((ch)) 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /lib/fixinclude/dcc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | /* Compiler-intrinsic functionality for DCC */ 25 | typedef struct { 26 | char const *path; /*< [0..1] Path of the associated source file (Don't print when NULL). */ 27 | char const *file; /*< [0..1] File name of the associated source file. */ 28 | char const *name; /*< [0..1] Name of the surrounding function symbol. */ 29 | void *__pad1[1]; 30 | int line; /*< 1-based source line, or ZERO(0) when unknown. */ 31 | int col; /*< 1-based source column, or ZERO(0) when unknown. */ 32 | void *__pad2[2]; 33 | } lc_t; 34 | 35 | /* Quick and simple solution for retrieving source information 36 | * about a given address in debug-mode application builds. 37 | * WARNING: Only units compiled with '-g' include addr2line 38 | * debug information, and the whole application 39 | * must be linked with '-g' again to ensure that 40 | * this function is defined. 41 | * HINT: When given, '*INFO' is filled even upon failure. 42 | * @param: IP: Instruction pointer that should be queried. 43 | * @param: INFO: User-provided buffer to fill with information. 44 | * @return: 0: The given IP could not be found. 45 | * @return: !0: Successfully queried information about IP. */ 46 | extern _Bool _addr2line(void *__ip, lc_t *__info) 47 | #ifdef __DRT__ 48 | __asm__("__drt_dbg_addr2line") 49 | #else 50 | __asm__("__dcc_dbg_addr2line") 51 | #endif 52 | ; 53 | 54 | 55 | /* 64-bit arithmetic runtime functions. */ 56 | extern __INT64_TYPE__ __ashlti3(__INT64_TYPE__ __x, int __shift); /* 'return (uint64_t|int64_t)x << shift' */ 57 | extern __INT64_TYPE__ __ashrti3(__INT64_TYPE__ __x, int __shift); /* 'return (int64_t)x >> shift' */ 58 | extern __UINT64_TYPE__ __lshrti3(__UINT64_TYPE__ __x, int __shift); /* 'return (uint64_t)x >> shift' */ 59 | extern __UINT64_TYPE__ __udivti3(__UINT64_TYPE__ __x, __UINT64_TYPE__ __y); /* 'return (uint64_t)x / y' */ 60 | extern __INT64_TYPE__ __divti3(__INT64_TYPE__ __x, __INT64_TYPE__ __y); /* 'return (int64_t)x / y' */ 61 | extern __UINT64_TYPE__ __umodti3(__UINT64_TYPE__ __x, __INT64_TYPE__ __y); /* 'return (uint64_t)x % y' */ 62 | extern __INT64_TYPE__ __modti3(__INT64_TYPE__ __x, __INT64_TYPE__ __y); /* 'return (int64_t)x % y' */ 63 | extern __INT64_TYPE__ __multi3(__INT64_TYPE__ __x, __INT64_TYPE__ __y); /* 'return (uint64_t|int64_t)x * y' */ 64 | 65 | #if defined(__PE__) 66 | extern void *__stdcall __pe_alloca(__SIZE_TYPE__ s); 67 | #endif 68 | 69 | struct [[__packed__]] __cpuinfo { 70 | #if defined(__i386__) || defined(__x86_64__) 71 | unsigned __int32 __cpuid_1_eax; 72 | unsigned __int32 __cpuid_1_ebx; 73 | unsigned __int32 __cpuid_1_ecx; 74 | unsigned __int32 __cpuid_1_edx; 75 | unsigned __int32 __cpuid_7_ebx; 76 | unsigned __int32 __cpuid_7_edx; 77 | unsigned __int32 __cpuid_7_ecx; 78 | unsigned __int32 __cpuid_0_eax; 79 | unsigned __int32 __cpuid_0_ebx; 80 | #else 81 | int __placeholder; 82 | #endif 83 | }; 84 | 85 | 86 | /* CPU Information structure allocated and initialized 87 | * if the application calls '__builtin_cpu_init()' 88 | * NOTE: Access to this structure should always be performed using: 89 | * >> int __builtin_cpu_is(char const *cpuname); 90 | * >> int __builtin_cpu_supports(char const *feature); 91 | */ 92 | extern struct __cpuinfo __cpu_info [[__visbility__("hidden"),__weak__]]; 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /lib/fixinclude/endian.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | __STRICT_ANSI_HEADER 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #endif 29 | 30 | #include 31 | 32 | #define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ 33 | #define __BIG_ENDIAN __ORDER_BIG_ENDIAN__ 34 | #define __PDP_ENDIAN __ORDER_PDP_ENDIAN__ 35 | 36 | #if __has_include() 37 | # include 38 | #endif 39 | 40 | #define __BYTE_ORDER __BYTE_ORDER__ 41 | #define __FLOAT_WORD_ORDER __FLOAT_WORD_ORDER__ 42 | 43 | #ifdef __USE_MISC 44 | # define LITTLE_ENDIAN __LITTLE_ENDIAN 45 | # define BIG_ENDIAN __BIG_ENDIAN 46 | # define PDP_ENDIAN __PDP_ENDIAN 47 | # define BYTE_ORDER __BYTE_ORDER 48 | #endif 49 | 50 | #if __BYTE_ORDER == __LITTLE_ENDIAN 51 | # define __LONG_LONG_PAIR(HI,LO) LO,HI 52 | #elif __BYTE_ORDER == __BIG_ENDIAN 53 | # define __LONG_LONG_PAIR(HI,LO) HI,LO 54 | #endif 55 | 56 | #if defined(__USE_MISC) && !defined(__ASSEMBLER__) 57 | #if __has_include() || defined(__INTELLISENSE__) 58 | # include 59 | #endif 60 | #if __BYTE_ORDER == __LITTLE_ENDIAN 61 | # define htobe16(x) __bswap_16(x) 62 | # define htole16(x) (x) 63 | # define be16toh(x) __bswap_16(x) 64 | # define le16toh(x) (x) 65 | # define htobe32(x) __bswap_32(x) 66 | # define htole32(x) (x) 67 | # define be32toh(x) __bswap_32(x) 68 | # define le32toh(x) (x) 69 | # define htobe64(x) __bswap_64(x) 70 | # define htole64(x) (x) 71 | # define be64toh(x) __bswap_64(x) 72 | # define le64toh(x) (x) 73 | #else 74 | # define htobe16(x) (x) 75 | # define htole16(x) __bswap_16(x) 76 | # define be16toh(x) (x) 77 | # define le16toh(x) __bswap_16(x) 78 | # define htobe32(x) (x) 79 | # define htole32(x) __bswap_32(x) 80 | # define be32toh(x) (x) 81 | # define le32toh(x) __bswap_32(x) 82 | # define htobe64(x) (x) 83 | # define htole64(x) __bswap_64(x) 84 | # define be64toh(x) (x) 85 | # define le64toh(x) __bswap_64(x) 86 | #endif 87 | #endif 88 | -------------------------------------------------------------------------------- /lib/fixinclude/features.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | #if __has_include_next() 25 | # include_next 26 | #elif defined(__INTELLISENSE__) 27 | # include "../include/features.h" 28 | #endif 29 | 30 | /* Fixed/optimized system header for DCC */ 31 | 32 | #undef __USE_DCC 33 | 34 | /* '-Wextensions' is disabled by default, but enabled when any std 35 | * other than 'dcc' has been selected (such as through '-std=c99') 36 | * >> When using 'dcc' as std, enable DCC standard 37 | * library extensions through builtin functions. */ 38 | #if !__has_warning("-Wextensions") 39 | #undef _DCC_SOURCE 40 | #define _DCC_SOURCE 41 | #endif 42 | 43 | #ifdef _DCC_SOURCE 44 | #define __USE_DCC 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /lib/fixinclude/iso646.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | #if __has_include_next() 25 | #include_next 26 | #endif 27 | 28 | /* Fixed/optimized system header for DCC */ 29 | #define and && 30 | #define and_eq &= 31 | #define bitand & 32 | #define bitor | 33 | #define compl ~ 34 | #define not ! 35 | #define not_eq != 36 | #define or || 37 | #define or_eq |= 38 | #define xor ^ 39 | #define xor_eq ^= 40 | -------------------------------------------------------------------------------- /lib/fixinclude/limits.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | #if __has_include_next() 25 | #include_next 26 | #endif 27 | 28 | /* Fixed/optimized system header for DCC */ 29 | #define CHAR_BIT __CHAR_BIT__ 30 | #define SCHAR_MIN __SCHAR_MIN__ 31 | #define SCHAR_MAX __SCHAR_MAX__ 32 | #define UCHAR_MAX __UCHAR_MAX__ 33 | #define CHAR_MIN __CHAR_MIN__ 34 | #define CHAR_MAX __CHAR_MAX__ 35 | #define SHRT_MIN __SHRT_MIN__ 36 | #define SHRT_MAX __SHRT_MAX__ 37 | #define USHRT_MAX __USHRT_MAX__ 38 | #define INT_MIN __INT_MIN__ 39 | #define INT_MAX __INT_MAX__ 40 | #define UINT_MAX __UINT_MAX__ 41 | #define LONG_MIN __LONG_MIN__ 42 | #define LONG_MAX __LONG_MAX__ 43 | #define ULONG_MAX __ULONG_MAX__ 44 | #define LLONG_MIN __LONG_LONG_MIN__ 45 | #define LLONG_MAX __LONG_LONG_MAX__ 46 | #define ULLONG_MAX __ULONG_LONG_MAX__ 47 | -------------------------------------------------------------------------------- /lib/fixinclude/malloc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | __STRICT_ANSI_HEADER 25 | 26 | #if __has_include_next() 27 | #pragma push_macro(undef,"calloc","free","malloc","malloc_usable_size","mallopt",\ 28 | "realloc","cfree","memalign","aligned_alloc","pvalloc",\ 29 | "valloc","memdup","strdup","strndup","strdupf","vstrdupf") 30 | #include_next 31 | #pragma pop_macro(undef,"calloc","free","malloc","malloc_usable_size","mallopt",\ 32 | "realloc","cfree","memalign","aligned_alloc","pvalloc",\ 33 | "valloc","memdup","strdup","strndup","strdupf","vstrdupf") 34 | #elif defined(__INTELLISENSE__) 35 | # include "../include/malloc.h" 36 | #endif 37 | 38 | #ifdef alloca 39 | /* Re-define 'alloca' */ 40 | #if __has_builtin(__builtin_alloca) 41 | #define alloca __builtin_alloca 42 | #endif 43 | #endif 44 | 45 | 46 | -------------------------------------------------------------------------------- /lib/fixinclude/memory.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #pragma push_macro(undef,"calloc","free","malloc","malloc_usable_size","mallopt",\ 28 | "realloc","cfree","memalign","aligned_alloc","pvalloc",\ 29 | "valloc","memdup","strdup","strndup","strdupf","vstrdupf") 30 | #include_next 31 | #pragma pop_macro(undef,"calloc","free","malloc","malloc_usable_size","mallopt",\ 32 | "realloc","cfree","memalign","aligned_alloc","pvalloc",\ 33 | "valloc","memdup","strdup","strndup","strdupf","vstrdupf") 34 | #else /* Usually just an alias for */ 35 | #include 36 | #endif 37 | -------------------------------------------------------------------------------- /lib/fixinclude/setjmp.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | #if __has_include_next() 25 | #include_next 26 | #endif 27 | 28 | /* Fixed/optimized system header for DCC */ 29 | 30 | /* Use builtin functions to allow for compiler-optimizations. */ 31 | #undef jmp_buf 32 | typedef __INT8_TYPE__ jmp_buf[__SIZEOF_JMP_BUF__]; 33 | 34 | /* int setjmp(jmp_buf buf); */ 35 | #define setjmp(buf) __builtin_setjmp((buf)) 36 | 37 | /* void longjmp(jmp_buf buf, int sig) __attribute__((noreturn)); */ 38 | #define longjmp(buf,sig) __builtin_longjmp((buf),(sig)) 39 | 40 | -------------------------------------------------------------------------------- /lib/fixinclude/stdarg.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | //#pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | #if __has_include_next() 25 | #include_next 26 | #endif 27 | 28 | /* Fixed/optimized system header for DCC */ 29 | #undef va_list 30 | typedef __builtin_va_list va_list; 31 | 32 | /* void va_start(va_list &ap); */ 33 | /* void va_start(va_list &ap, type &last_argument); */ 34 | #define va_start __builtin_va_start 35 | 36 | /* void va_end(va_list &ap); */ 37 | #define va_end __builtin_va_end 38 | 39 | /* void va_copy(va_list &dst_ap, va_list &src_ap); */ 40 | #define va_copy __builtin_va_copy 41 | #define __va_copy __builtin_va_copy 42 | 43 | /* t va_arg(va_list &ap, type t); */ 44 | #define va_arg __builtin_va_arg 45 | 46 | 47 | -------------------------------------------------------------------------------- /lib/fixinclude/stdbool.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | #if __has_include_next() 25 | #include_next 26 | #endif 27 | 28 | /* Fixed/optimized system header for DCC */ 29 | #define __bool_true_false_are_defined 1 30 | #define bool _Bool 31 | #define true 1 32 | #define false 0 33 | 34 | -------------------------------------------------------------------------------- /lib/fixinclude/stddef.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | #if __has_include_next() 25 | #include_next 26 | #endif 27 | 28 | /* Fixed/optimized system header for DCC */ 29 | #undef ptrdiff_t 30 | #undef size_t 31 | 32 | typedef __PTRDIFF_TYPE__ ptrdiff_t; 33 | typedef __SIZE_TYPE__ size_t; 34 | 35 | #define offsetof(s,m) __builtin_offsetof(s,m) 36 | #define NULL __NULL__ 37 | 38 | -------------------------------------------------------------------------------- /lib/fixinclude/stdint.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | #if __has_include_next() 25 | #include_next 26 | #endif 27 | 28 | /* Fixed/optimized system header for DCC */ 29 | #undef intmax_t 30 | #undef uintmax_t 31 | #undef int8_t 32 | #undef uint8_t 33 | #undef int16_t 34 | #undef uint16_t 35 | #undef int32_t 36 | #undef uint32_t 37 | #undef int64_t 38 | #undef uint64_t 39 | #undef int_least8_t 40 | #undef uint_least8_t 41 | #undef int_least16_t 42 | #undef uint_least16_t 43 | #undef int_least32_t 44 | #undef uint_least32_t 45 | #undef int_least64_t 46 | #undef uint_least64_t 47 | #undef int_fast8_t 48 | #undef uint_fast8_t 49 | #undef int_fast16_t 50 | #undef uint_fast16_t 51 | #undef int_fast32_t 52 | #undef uint_fast32_t 53 | #undef int_fast64_t 54 | #undef uint_fast64_t 55 | #undef intptr_t 56 | #undef uintptr_t 57 | 58 | typedef __INTMAX_TYPE__ intmax_t; 59 | typedef __UINTMAX_TYPE__ uintmax_t; 60 | typedef __INT8_TYPE__ int8_t; 61 | typedef __UINT8_TYPE__ uint8_t; 62 | typedef __INT16_TYPE__ int16_t; 63 | typedef __UINT16_TYPE__ uint16_t; 64 | typedef __INT32_TYPE__ int32_t; 65 | typedef __UINT32_TYPE__ uint32_t; 66 | typedef __INT64_TYPE__ int64_t; 67 | typedef __UINT64_TYPE__ uint64_t; 68 | typedef __INT_LEAST8_TYPE__ int_least8_t; 69 | typedef __UINT_LEAST8_TYPE__ uint_least8_t; 70 | typedef __INT_LEAST16_TYPE__ int_least16_t; 71 | typedef __UINT_LEAST16_TYPE__ uint_least16_t; 72 | typedef __INT_LEAST32_TYPE__ int_least32_t; 73 | typedef __UINT_LEAST32_TYPE__ uint_least32_t; 74 | typedef __INT_LEAST64_TYPE__ int_least64_t; 75 | typedef __UINT_LEAST64_TYPE__ uint_least64_t; 76 | typedef __INT_FAST8_TYPE__ int_fast8_t; 77 | typedef __UINT_FAST8_TYPE__ uint_fast8_t; 78 | typedef __INT_FAST16_TYPE__ int_fast16_t; 79 | typedef __UINT_FAST16_TYPE__ uint_fast16_t; 80 | typedef __INT_FAST32_TYPE__ int_fast32_t; 81 | typedef __UINT_FAST32_TYPE__ uint_fast32_t; 82 | typedef __INT_FAST64_TYPE__ int_fast64_t; 83 | typedef __UINT_FAST64_TYPE__ uint_fast64_t; 84 | typedef __INTPTR_TYPE__ intptr_t; 85 | typedef __UINTPTR_TYPE__ uintptr_t; 86 | 87 | 88 | #define INTMAX_MIN __INTMAX_MIN__ 89 | #define INTMAX_MAX __INTMAX_MAX__ 90 | #define UINTMAX_MAX __UINTMAX_MAX__ 91 | #define INT8_MIN __INT8_MIN__ 92 | #define INT16_MIN __INT16_MIN__ 93 | #define INT32_MIN __INT32_MIN__ 94 | #define INT64_MIN __INT64_MIN__ 95 | #define INT8_MAX __INT8_MAX__ 96 | #define INT16_MAX __INT16_MAX__ 97 | #define INT32_MAX __INT32_MAX__ 98 | #define INT64_MAX __INT64_MAX__ 99 | #define UINT8_MAX __UINT8_MAX__ 100 | #define UINT16_MAX __UINT16_MAX__ 101 | #define UINT32_MAX __UINT32_MAX__ 102 | #define UINT64_MAX __UINT64_MAX__ 103 | #define INT_LEAST8_MIN __INT_LEAST8_MIN__ 104 | #define INT_LEAST16_MIN __INT_LEAST16_MIN__ 105 | #define INT_LEAST32_MIN __INT_LEAST32_MIN__ 106 | #define INT_LEAST64_MIN __INT_LEAST64_MIN__ 107 | #define INT_LEAST8_MAX __INT_LEAST8_MAX__ 108 | #define INT_LEAST16_MAX __INT_LEAST16_MAX__ 109 | #define INT_LEAST32_MAX __INT_LEAST32_MAX__ 110 | #define INT_LEAST64_MAX __INT_LEAST64_MAX__ 111 | #define UINT_LEAST8_MAX __UINT_LEAST8_MAX__ 112 | #define UINT_LEAST16_MAX __UINT_LEAST16_MAX__ 113 | #define UINT_LEAST32_MAX __UINT_LEAST32_MAX__ 114 | #define UINT_LEAST64_MAX __UINT_LEAST64_MAX__ 115 | #define INT_FAST8_MIN __INT_FAST8_MIN__ 116 | #define INT_FAST16_MIN __INT_FAST16_MIN__ 117 | #define INT_FAST32_MIN __INT_FAST32_MIN__ 118 | #define INT_FAST64_MIN __INT_FAST64_MIN__ 119 | #define INT_FAST8_MAX __INT_FAST8_MAX__ 120 | #define INT_FAST16_MAX __INT_FAST16_MAX__ 121 | #define INT_FAST32_MAX __INT_FAST32_MAX__ 122 | #define INT_FAST64_MAX __INT_FAST64_MAX__ 123 | #define UINT_FAST8_MAX __UINT_FAST8_MAX__ 124 | #define UINT_FAST16_MAX __UINT_FAST16_MAX__ 125 | #define UINT_FAST32_MAX __UINT_FAST32_MAX__ 126 | #define UINT_FAST64_MAX __UINT_FAST64_MAX__ 127 | #define INTPTR_MIN __INTPTR_MIN__ 128 | #define INTPTR_MAX __INTPTR_MAX__ 129 | #define UINTPTR_MAX __UINTPTR_MAX__ 130 | 131 | #define SIZE_MAX __SIZE_MAX__ 132 | #define PTRDIFF_MIN __PTRDIFF_MIN__ 133 | #define PTRDIFF_MAX __PTRDIFF_MAX__ 134 | #define SIG_ATOMIC_MIN __SIG_ATOMIC_MIN__ 135 | #define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__ 136 | #define WCHAR_MIN __WCHAR_MIN__ 137 | #define WCHAR_MAX __WCHAR_MAX__ 138 | #define WINT_MIN __WINT_MIN__ 139 | #define WINT_MAX __WINT_MAX__ 140 | 141 | #define INTMAX_C __INTMAX_C 142 | #define UINTMAX_C __UINTMAX_C 143 | #define INT8_C __INT8_C 144 | #define INT16_C __INT16_C 145 | #define INT32_C __INT32_C 146 | #define INT64_C __INT64_C 147 | #define UINT8_C __UINT8_C 148 | #define UINT16_C __UINT16_C 149 | #define UINT32_C __UINT32_C 150 | #define UINT64_C __UINT64_C 151 | -------------------------------------------------------------------------------- /lib/fixinclude/stdio.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | #if __has_include_next() 25 | # include_next 26 | #elif defined(__INTELLISENSE__) 27 | # include "../include/stdio.h" 28 | #endif 29 | 30 | /* Fixed/optimized system header for DCC */ 31 | 32 | #undef size_t 33 | typedef __SIZE_TYPE__ size_t; 34 | 35 | #define NULL __NULL__ 36 | -------------------------------------------------------------------------------- /lib/fixinclude/stdlib.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | #if __has_include_next() 25 | #pragma push_macro(undef,"calloc","free","malloc","malloc_usable_size","mallopt",\ 26 | "realloc","cfree","memalign","aligned_alloc","pvalloc",\ 27 | "valloc","memdup","strdup","strndup","strdupf","vstrdupf") 28 | #include_next 29 | #pragma pop_macro(undef,"calloc","free","malloc","malloc_usable_size","mallopt",\ 30 | "realloc","cfree","memalign","aligned_alloc","pvalloc",\ 31 | "valloc","memdup","strdup","strndup","strdupf","vstrdupf") 32 | #elif defined(__INTELLISENSE__) 33 | # include "../include/stdlib.h" 34 | #endif 35 | 36 | /* Fixed/optimized system header for DCC */ 37 | #undef size_t 38 | typedef __SIZE_TYPE__ size_t; 39 | 40 | #define NULL __NULL__ 41 | -------------------------------------------------------------------------------- /lib/fixinclude/strings.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | __STRICT_ANSI_HEADER 25 | 26 | #if __has_include_next() 27 | # include_next 28 | #elif defined(__INTELLISENSE__) 29 | # include "../include/strings.h" 30 | #endif 31 | 32 | #include 33 | 34 | #if _SVID_SOURCE || _BSD_SOURCE || \ 35 | _POSIX_C_SOURCE >= 200809L || \ 36 | _XOPEN_SOURCE >= 700 37 | # define ffs(x) __builtin_ffs((x)) 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /lib/fixinclude/time.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | #if __has_include_next() 25 | #include_next 26 | #endif 27 | 28 | #undef size_t 29 | typedef __SIZE_TYPE__ size_t; 30 | 31 | #define NULL __NULL__ 32 | 33 | -------------------------------------------------------------------------------- /lib/fixinclude/uchar.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | #if __has_include_next() 25 | #include_next 26 | #endif 27 | 28 | /* Fixed/optimized system header for DCC */ 29 | #define __STD_UTF_16__ 1 30 | #define __STD_UTF_32__ 1 31 | 32 | typedef __CHAR16_TYPE__ char16_t; 33 | typedef __CHAR32_TYPE__ char32_t; 34 | -------------------------------------------------------------------------------- /lib/fixinclude/varargs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | 21 | #include <__stdinc.h> 22 | 23 | #if __has_warning("-Wold-function-decl") 24 | #warning " is obsolete; new code should use instead" 25 | #endif 26 | 27 | #pragma GCC system_header 28 | #if __has_include_next() 29 | /* Many standard libraries still implement , only to 30 | * emit a #error directive telling you that they actually don't. 31 | * >> But DCC _does_ implement it! - So in order to shut up 32 | * #error, or #warning directives, we simply disable '-Wuser' 33 | * warning (aka. warnings explicitly emit by user-code). */ 34 | #pragma warning(push,"-Wno-user") 35 | #include_next 36 | #pragma warning(pop) 37 | #endif 38 | 39 | /* Fixed/optimized system header for DCC */ 40 | 41 | #undef va_list 42 | typedef __builtin_va_list va_list; 43 | 44 | /* NOTE: '__builtin_va_alist' could be refactored to anything... */ 45 | #define va_alist __builtin_va_alist 46 | #define va_dcl int __builtin_va_alist; ... 47 | 48 | /* void va_start(va_list &ap); */ 49 | /* void va_start(va_list &ap, type &last_argument); */ 50 | #define va_start __builtin_va_start 51 | 52 | /* void va_end(va_list &ap); */ 53 | #define va_end __builtin_va_end 54 | 55 | /* t va_arg(va_list &ap, type t); */ 56 | #define va_arg __builtin_va_arg 57 | 58 | -------------------------------------------------------------------------------- /lib/fixinclude/wchar.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | #if __has_include_next() 25 | #include_next 26 | #endif 27 | 28 | /* Fixed/optimized system header for DCC */ 29 | #undef size_t 30 | #undef wchar_t 31 | #undef wint_t 32 | typedef __SIZE_TYPE__ size_t; 33 | #ifndef __INTELLISENSE__ 34 | typedef __WCHAR_TYPE__ wchar_t; 35 | #endif 36 | typedef __WINT_TYPE__ wint_t; 37 | 38 | #define NULL __NULL__ 39 | #define WCHAR_MIN __WCHAR_MIN__ 40 | #define WCHAR_MAX __WCHAR_MAX__ 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /lib/include/.readme.md: -------------------------------------------------------------------------------- 1 | 2 | Default (and minimal) C standard library optimized for DCC 3 | These headers are still meant to be used in conjunction with /lib/fixinclude 4 | Note, that using these headers is fully optional, as they have been designed to act as a second abstraction layer between DCC and the host's system include path: 5 | 6 | #1: [REQUIRED] -/dcc/lib/fixinclude 7 | #2: [OPTIONAL] -/dcc/lib/include 8 | #3: [SYSTEM] /usr/include 9 | 10 | -------------------------------------------------------------------------------- /lib/include/ar.h: -------------------------------------------------------------------------------- 1 | /* Header describing `ar' archive file format. 2 | Copyright (C) 1996-2016 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | /* 20 | * Even though this file is part of the DCC source tree, 21 | * no additional copyright claims apply to this, other 22 | * that those taken from the source, which can be found above. 23 | * 24 | * NOTE: Some modifications have been made to the original file. 25 | */ 26 | 27 | #ifndef _AR_H 28 | #define _AR_H 1 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* Archive files start with the ARMAG identifying string. Then follows a 35 | `struct ar_hdr', and as many bytes of member file data as its `ar_size' 36 | member indicates, for each member file. */ 37 | 38 | #define ARMAG "!\n" /* String that begins an archive file. */ 39 | #define SARMAG 8 /* Size of that string. */ 40 | 41 | #define ARFMAG "`\n" /* String in ar_fmag at end of each header. */ 42 | 43 | struct ar_hdr { 44 | char ar_name[16]; /* Member file name, sometimes / terminated. */ 45 | char ar_date[12]; /* File date, decimal seconds since Epoch. */ 46 | char ar_uid[6], ar_gid[6]; /* User and group IDs, in ASCII decimal. */ 47 | char ar_mode[8]; /* File mode, in ASCII octal. */ 48 | char ar_size[10]; /* File size, in ASCII decimal. */ 49 | char ar_fmag[2]; /* Always contains ARFMAG. */ 50 | }; 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* ar.h */ 57 | -------------------------------------------------------------------------------- /lib/include/assert.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else 29 | #include <__stdinc.h> 30 | 31 | #ifndef __DCC_ASSERT_LIB_DEFINED 32 | #define __DCC_ASSERT_LIB_DEFINED 1 33 | #ifdef __CRT_MSVC 34 | __IMP void (__assertion_failed)(char const *,char const *,unsigned int) __asm__("_assert"); 35 | #elif defined(__CRT_DCC) 36 | __IMP void (__assertion_failed)(char const *,char const *,unsigned int); 37 | #else 38 | #error FIXME 39 | #endif 40 | #endif /* !__DCC_ASSERT_LIB_DEFINED */ 41 | 42 | /* NOTE: '__builtin_assume' will mark code flow as 43 | * unreachable for compile-time false expressions: 44 | * >> assert(0); // Mark control flow as unreachable, but check the fact at runtime! 45 | */ 46 | #ifdef NDEBUG 47 | # define assert __builtin_assume 48 | #else 49 | # define assert(expr) (void)((expr) || (__assertion_failed(#expr,__FILE__,__LINE__),__builtin_breakpoint(),0)) 50 | #endif 51 | #endif 52 | -------------------------------------------------------------------------------- /lib/include/bits/byteswap.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else 29 | #include <__stdinc.h> 30 | 31 | #define __bswap_16 __builtin_bswap16 32 | #define __bswap_32 __builtin_bswap32 33 | #define __bswap_64 __builtin_bswap64 34 | 35 | #endif /* !include_next... */ 36 | -------------------------------------------------------------------------------- /lib/include/bits/dirent.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else 29 | #include <__stdinc.h> 30 | #include 31 | 32 | #ifdef __CRT_MSVC 33 | struct dirent { 34 | #ifdef __USE_FILE_OFFSET64 35 | __ino64_t d_ino; 36 | #else 37 | __ino_t d_ino; 38 | #endif 39 | union{ 40 | unsigned char d_type; 41 | unsigned __msvc_attrib; 42 | }; 43 | #ifdef __USE_FILE_OFFSET64 44 | __time64_t __msvc_time_create; 45 | __time64_t __msvc_time_access; 46 | __time64_t __msvc_time_write; 47 | __UINT64_TYPE__ __msvc_size; 48 | #else 49 | __time32_t __msvc_time_create; 50 | __time32_t __msvc_time_access; 51 | __time32_t __msvc_time_write; 52 | __UINT32_TYPE__ __msvc_size; 53 | #endif 54 | char d_name[262]; 55 | }; 56 | 57 | struct dirent64 { 58 | __ino64_t d_ino; 59 | union{ 60 | unsigned char d_type; 61 | unsigned __msvc_attrib; 62 | }; 63 | __time64_t __msvc_time_create; 64 | __time64_t __msvc_time_access; 65 | __time64_t __msvc_time_write; 66 | __UINT64_TYPE__ __msvc_size; 67 | char d_name[262]; 68 | }; 69 | 70 | #undef _DIRENT_HAVE_D_NAMLEN 71 | #undef _DIRENT_HAVE_D_RECLEN 72 | #undef _DIRENT_HAVE_D_OFF 73 | #define _DIRENT_HAVE_D_TYPE 74 | 75 | #else /* __CRT_MSVC */ 76 | 77 | struct dirent { 78 | #ifndef __USE_FILE_OFFSET64 79 | __ino_t d_ino; 80 | __off_t d_off; 81 | #else 82 | __ino64_t d_ino; 83 | __off64_t d_off; 84 | #endif 85 | unsigned short int d_reclen; 86 | unsigned char d_type; 87 | char d_name[256]; 88 | }; 89 | #ifdef __USE_LARGEFILE64 90 | struct dirent64 { 91 | __ino64_t d_ino; 92 | __off64_t d_off; 93 | unsigned short int d_reclen; 94 | unsigned char d_type; 95 | char d_name[256]; 96 | }; 97 | #endif 98 | 99 | #define d_fileno d_ino 100 | 101 | #undef _DIRENT_HAVE_D_NAMLEN 102 | #define _DIRENT_HAVE_D_RECLEN 103 | #define _DIRENT_HAVE_D_OFF 104 | #define _DIRENT_HAVE_D_TYPE 105 | 106 | #if defined(__OFF_T_MATCHES_OFF64_T) && \ 107 | defined(__INO_T_MATCHES_INO64_T) 108 | #define _DIRENT_MATCHES_DIRENT64 1 109 | #endif 110 | 111 | #endif /* CRT... */ 112 | 113 | #endif /* !include_next... */ 114 | -------------------------------------------------------------------------------- /lib/include/bits/fcntl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else /* include_next... */ 29 | 30 | #include <__stdinc.h> 31 | #include 32 | #include 33 | 34 | #ifdef __x86_64__ 35 | # define __O_LARGEFILE 0 36 | # define F_GETLK64 5 37 | # define F_SETLK64 6 38 | # define F_SETLKW64 7 39 | #endif 40 | 41 | struct __CRT_UNSUPPORTED_MSVC flock { 42 | short int l_type; 43 | short int l_whence; 44 | #ifndef __USE_FILE_OFFSET64 45 | __off_t l_start; 46 | __off_t l_len; 47 | #else 48 | __off64_t l_start; 49 | __off64_t l_len; 50 | #endif 51 | __pid_t l_pid; 52 | }; 53 | 54 | #ifdef __USE_LARGEFILE64 55 | struct __CRT_UNSUPPORTED_MSVC flock64 { 56 | short int l_type; 57 | short int l_whence; 58 | __off64_t l_start; 59 | __off64_t l_len; 60 | __pid_t l_pid; 61 | }; 62 | #endif 63 | 64 | #include 65 | 66 | #endif /* !include_next... */ 67 | -------------------------------------------------------------------------------- /lib/include/ctype.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else 29 | #include <__stdinc.h> 30 | #include 31 | 32 | __IMP __WUNUSED int (isalpha)(int); 33 | __IMP __WUNUSED int (isupper)(int); 34 | __IMP __WUNUSED int (islower)(int); 35 | __IMP __WUNUSED int (isdigit)(int); 36 | __IMP __WUNUSED int (isxdigit)(int); 37 | __IMP __WUNUSED int (isspace)(int); 38 | __IMP __WUNUSED int (ispunct)(int); 39 | __IMP __WUNUSED int (isalnum)(int); 40 | __IMP __WUNUSED int (isprint)(int); 41 | __IMP __WUNUSED int (isgraph)(int); 42 | __IMP __WUNUSED int (iscntrl)(int); 43 | __IMP __WUNUSED int (toupper)(int); 44 | __IMP __WUNUSED int (tolower)(int); 45 | 46 | #ifdef __USE_ISOC99 47 | __IMP __WUNUSED int (isblank)(int); 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /lib/include/direct.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else 29 | #include <__stdinc.h> 30 | 31 | __STRICT_ANSI_HEADER 32 | 33 | #ifdef __CRT_MSVC 34 | # define __DIRECT_FUN(x) __asm__("_" x) 35 | #else 36 | # define __DIRECT_FUN(x) 37 | #endif 38 | 39 | #ifndef getcwd 40 | #if !defined(__CRT_MSVC) || (__SIZEOF_SIZE_T__ == 4) 41 | __IMP __WUNUSED char *(getcwd)(char *__buf, __SIZE_TYPE__ __bufsize) __DIRECT_FUN("getcwd"); 42 | #else 43 | __IMP __WUNUSED char *(__msvc_getcwd)(char *__buf, __UINT32_TYPE__ __bufsize) __DIRECT_FUN("getcwd"); 44 | # define getcwd(buf,bufsize) __msvc_getcwd(buf,(__UINT32_TYPE__)(bufsize)) 45 | #endif 46 | #endif 47 | 48 | __IMP int (chdir)(char const *__path) __DIRECT_FUN("chdir"); 49 | __IMP int (mkdir)(char const *__path) __DIRECT_FUN("mkdir"); 50 | __IMP int (rmdir)(char const *__path) __DIRECT_FUN("rmdir"); 51 | 52 | #undef __DIRECT_FUN 53 | #endif 54 | -------------------------------------------------------------------------------- /lib/include/malloc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else 29 | #include <__stdinc.h> 30 | 31 | __STRICT_ANSI_HEADER 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | __IMP __WUNUSED void *(malloc)(__SIZE_TYPE__ __size); 38 | __IMP __WUNUSED void *(calloc)(__SIZE_TYPE__ __nmemb, __SIZE_TYPE__ __size); 39 | __IMP __WUNUSED void *(realloc)(void *__ptr, __SIZE_TYPE__ __size); 40 | __IMP void (free)(void *__ptr); 41 | __IMP void (cfree)(void *__ptr) 42 | #if !defined(__CRT_GLIBC) && !defined(__CRT_KOS) 43 | __asm__("free") 44 | #endif 45 | ; 46 | 47 | __IMP __CRT_UNSUPPORTED_MSVC __WUNUSED void *(memalign)(__SIZE_TYPE__ __alignment, __SIZE_TYPE__ __size); 48 | __IMP __CRT_UNSUPPORTED_MSVC __WUNUSED void *(valloc)(__SIZE_TYPE__ __size); 49 | __IMP __CRT_UNSUPPORTED_MSVC __WUNUSED void *(pvalloc)(__SIZE_TYPE__ __size); 50 | 51 | struct __CRT_UNSUPPORTED_MSVC mallinfo { 52 | int arena; /* non-mmapped space allocated from system */ 53 | int ordblks; /* number of free chunks */ 54 | int smblks; /* number of fastbin blocks */ 55 | int hblks; /* number of mmapped regions */ 56 | int hblkhd; /* space in mmapped regions */ 57 | int usmblks; /* maximum total allocated space */ 58 | int fsmblks; /* space available in freed fastbin blocks */ 59 | int uordblks; /* total allocated space */ 60 | int fordblks; /* total free space */ 61 | int keepcost; /* top-most, releasable (via malloc_trim) space */ 62 | }; 63 | __IMP __CRT_UNSUPPORTED_MSVC __WUNUSED struct mallinfo (mallinfo)(void); 64 | 65 | #ifndef M_MXFAST 66 | #define M_MXFAST 1 /* maximum request size for "fastbins" */ 67 | #endif 68 | #ifndef M_NLBLKS 69 | #define M_NLBLKS 2 /* UNUSED in this malloc */ 70 | #endif 71 | #ifndef M_GRAIN 72 | #define M_GRAIN 3 /* UNUSED in this malloc */ 73 | #endif 74 | #ifndef M_KEEP 75 | #define M_KEEP 4 /* UNUSED in this malloc */ 76 | #endif 77 | 78 | #define M_TRIM_THRESHOLD (-1) 79 | #define M_TOP_PAD (-2) 80 | #define M_MMAP_THRESHOLD (-3) 81 | #define M_MMAP_MAX (-4) 82 | #define M_CHECK_ACTION (-5) 83 | #define M_PERTURB (-6) 84 | #define M_ARENA_TEST (-7) 85 | #define M_ARENA_MAX (-8) 86 | 87 | #if defined(__CRT_MSVC) && !defined(__INTELLISENSE__) 88 | # define mallopt(param,val) ((void)(param),(void)(val),0) 89 | # define malloc_trim(pad) ((void)(pad),0) 90 | # define malloc_stats(pad) ((void)0) 91 | #else 92 | __IMP int (mallopt)(int __param, int __val); 93 | __IMP int (malloc_trim)(__SIZE_TYPE__ __pad); 94 | __IMP void (malloc_stats)(void); 95 | #endif 96 | 97 | __IMP __WUNUSED __SIZE_TYPE__ (malloc_usable_size)(void *__ptr) 98 | #ifdef __CRT_MSVC 99 | __asm__("_msize") 100 | #endif 101 | ; 102 | 103 | __IMP __CRT_UNSUPPORTED_MSVC __CRT_UNSUPPORTED_KOS int (malloc_info)(int __options, FILE *__fp); 104 | __IMP __CRT_UNSUPPORTED_MSVC __CRT_UNSUPPORTED_KOS __WUNUSED void *(malloc_get_state)(void); 105 | __IMP __CRT_UNSUPPORTED_MSVC __CRT_UNSUPPORTED_KOS int (malloc_set_state)(void *__ptr); 106 | __IMP __CRT_UNSUPPORTED_MSVC __CRT_UNSUPPORTED_KOS void (*__malloc_initialize_hook)(void); 107 | __IMP __CRT_UNSUPPORTED_MSVC __CRT_UNSUPPORTED_KOS void (*__free_hook)(void *__ptr, const void *); 108 | __IMP __CRT_UNSUPPORTED_MSVC __CRT_UNSUPPORTED_KOS void *(*__malloc_hook)(__SIZE_TYPE__ __size, const void *); 109 | __IMP __CRT_UNSUPPORTED_MSVC __CRT_UNSUPPORTED_KOS void *(*__realloc_hook)(void *__ptr, __SIZE_TYPE__ __size, const void *); 110 | __IMP __CRT_UNSUPPORTED_MSVC __CRT_UNSUPPORTED_KOS void *(*__memalign_hook)(__SIZE_TYPE__ __alignment, __SIZE_TYPE__ __size, const void *); 111 | __IMP __CRT_UNSUPPORTED_MSVC __CRT_UNSUPPORTED_KOS void (*__after_morecore_hook)(void); 112 | __IMP __CRT_UNSUPPORTED_MSVC __CRT_UNSUPPORTED_KOS void (__malloc_check_init)(void); 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /lib/include/mcheck.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #include <__stdinc.h> 23 | 24 | #if __has_include_next() 25 | #include_next 26 | #else 27 | 28 | enum mcheck_status { 29 | MCHECK_DISABLED = -1, /* Consistency checking is not turned on. */ 30 | MCHECK_OK, /* Block is fine. */ 31 | MCHECK_FREE, /* Block freed twice. */ 32 | MCHECK_HEAD, /* Memory before the block was clobbered. */ 33 | MCHECK_TAIL /* Memory after the block was clobbered. */ 34 | }; 35 | 36 | #if defined(__CRT_GLIBC) 37 | /* Link original GLIBC functions. */ 38 | __IMP int (mcheck)(void (*__abortfunc)(enum mcheck_status)); 39 | __IMP int (mcheck_pedantic)(void (*__abortfunc)(enum mcheck_status)); 40 | __IMP void (mcheck_check_all)(void); 41 | __IMP enum mcheck_status (mprobe)(void *__ptr); 42 | __IMP void (mtrace)(void); 43 | __IMP void (muntrace)(void); 44 | #elif defined(__CRT_MSVC) 45 | /* Try to emulate mcheck-behavior as best as we can... */ 46 | __IMP extern int __msvc_crt_dbg_flag __asm__("_crtDbgFlag"); 47 | __IMP void mcheck_check_all(void) __asm__("_CrtCheckMemory"); 48 | # define mcheck(__abortfunc) (__msvc_crt_dbg_flag |= (0x01),0) 49 | # define mcheck_pedantic(__abortfunc) (__msvc_crt_dbg_flag |= (0x01|0x04),0) 50 | # define mprobe(p) (mcheck_check_all(),MCHECK_OK) 51 | # define mtrace() (void)(__msvc_crt_dbg_flag |= (0x01|0x04)) 52 | # define muntrace() (void)(__msvc_crt_dbg_flag &= ~(0x04)) 53 | #else 54 | /* Link stub-macros. */ 55 | # define mcheck(__abortfunc) 0 56 | # define mcheck_pedantic(__abortfunc) 0 57 | # define mcheck_check_all() (void)0 58 | # define mprobe(__ptr) MCHECK_OK 59 | # define mtrace() (void)0 60 | # define muntrace() (void)0 61 | #endif 62 | 63 | __END_DECLS 64 | #endif /* !include_next... */ 65 | -------------------------------------------------------------------------------- /lib/include/process.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else 29 | #include <__stdinc.h> 30 | 31 | __STRICT_ANSI_HEADER 32 | 33 | #include 34 | 35 | __IMP __CRT_UNSUPPORTED_GLIBC __CRT_UNSUPPORTED_KOS 36 | __UINTPTR_TYPE__ (_beginthread)(void (__cdecl *__entry_point)(void *), 37 | __UINT32_TYPE__ __stack_size, void *__arg); 38 | __IMP __CRT_UNSUPPORTED_GLIBC __CRT_UNSUPPORTED_KOS void (_endthread)(void); 39 | 40 | __IMP __CRT_UNSUPPORTED_GLIBC __CRT_UNSUPPORTED_KOS 41 | __UINTPTR_TYPE__ (_beginthreadex)(void *__security, __UINT32_TYPE__ __stack_size, 42 | __UINT32_TYPE__ (__stdcall *__entry_point)(void *), 43 | void * __arg, __UINT32_TYPE__ _InitFlag, 44 | __UINT32_TYPE__ *__thread_addr); 45 | __IMP __CRT_UNSUPPORTED_GLIBC __CRT_UNSUPPORTED_KOS 46 | void (_endthreadex)(__UINT32_TYPE__ __return_value); 47 | 48 | __IMP _Noreturn void (exit)(int __code); 49 | __IMP _Noreturn void (_exit)(int __code); 50 | __IMP _Noreturn void (abort)(void); 51 | 52 | 53 | #ifdef __CRT_MSVC 54 | # define __PROCESS_FUN(x) __asm__("_" x) 55 | #else 56 | # define __PROCESS_FUN(x) 57 | #endif 58 | 59 | /* MODE values for 'spawnxx'. */ 60 | #define P_WAIT 0 61 | #define P_NOWAIT 1 62 | #define P_OVERLAY 2 63 | #define OLD_P_OVERLAY P_OVERLAY 64 | #define P_NOWAITO 3 65 | #define P_DETACH 4 66 | 67 | /* Action codes for 'cwait'. */ 68 | #define WAIT_CHILD 0 69 | #define WAIT_GRANDCHILD 1 70 | 71 | #ifdef __CRT_MSVC 72 | #if __SIZEOF_POINTER__ == __SIZEOF_INT__ 73 | # define __PROC_RETURN __pid_t 74 | #else 75 | # define __PROC_RETURN __INTPTR_TYPE__ 76 | #endif 77 | #else 78 | # define __PROC_RETURN int 79 | #endif 80 | 81 | __IMP __PROC_RETURN (cwait)(int *__term_status, __PROC_RETURN __proc_handle, int __action) __PROCESS_FUN("cwait"); 82 | __IMP __PROC_RETURN (execl)(char const *__path, char const *__arg0, ...) __PROCESS_FUN("execl"); 83 | __IMP __PROC_RETURN (execle)(char const *__path, char const *__arg0, ...) __PROCESS_FUN("execle"); 84 | __IMP __PROC_RETURN (execlp)(char const *__file, char const *__arg0, ...) __PROCESS_FUN("execlp"); 85 | __IMP __PROC_RETURN (execlpe)(char const *__file, char const *__arg0, ...) __PROCESS_FUN("execlpe"); 86 | __IMP __PROC_RETURN (execv)(char const *__path, char *const __argv[]) __PROCESS_FUN("execv"); 87 | __IMP __PROC_RETURN (execve)(char const *__path, char *const __argv[], char *const __envp[]) __PROCESS_FUN("execve"); 88 | __IMP __PROC_RETURN (execvp)(char const *__file, char *const __argv[]) __PROCESS_FUN("execvp"); 89 | __IMP __PROC_RETURN (execvpe)(char const *__file, char *const __argv[], char *const __envp[]) __PROCESS_FUN("execvpe"); 90 | __IMP __PROC_RETURN (spawnl)(int __mode, char const *__path, char const *__arg0, ...) __PROCESS_FUN("spawnl"); 91 | __IMP __PROC_RETURN (spawnle)(int __mode, char const *__path, char const *__arg0, ...) __PROCESS_FUN("spawnle"); 92 | __IMP __PROC_RETURN (spawnlp)(int __mode, char const *__file, char const *__arg0, ...) __PROCESS_FUN("spawnlp"); 93 | __IMP __PROC_RETURN (spawnlpe)(int __mode, char const *__file, char const *__arg0, ...) __PROCESS_FUN("spawnlpe"); 94 | __IMP __PROC_RETURN (spawnv)(int __mode, char const *__path, char *const __argv[]) __PROCESS_FUN("spawnv"); 95 | __IMP __PROC_RETURN (spawnve)(int __mode, char const *__path, char *const __argv[], char *const __envp[]) __PROCESS_FUN("spawnve"); 96 | __IMP __PROC_RETURN (spawnvp)(int __mode, char const *__file, char *const __argv[]) __PROCESS_FUN("spawnvp"); 97 | __IMP __PROC_RETURN (spawnvpe)(int __mode, char const *__file, char *const __argv[], char *const __envp[]) __PROCESS_FUN("spawnvpe"); 98 | __IMP __pid_t (getpid)(void) __PROCESS_FUN("getpid"); 99 | #undef __PROC_RETURN 100 | 101 | #undef __PROCESS_FUN 102 | #endif 103 | -------------------------------------------------------------------------------- /lib/include/stdio.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else 29 | #include <__stdinc.h> 30 | #include 31 | 32 | #undef size_t 33 | typedef __SIZE_TYPE__ size_t; 34 | #define NULL __NULL__ 35 | 36 | #undef fpos_t 37 | #if defined(__CRT_MSVC) 38 | typedef __INT64_TYPE__ fpos_t; 39 | typedef struct { 40 | char *__msvcrt_ptr; 41 | __INT32_TYPE__ __msvcrt_cnt; 42 | char *__msvcrt_base; 43 | __INT32_TYPE__ __msvcrt_flag; 44 | __INT32_TYPE__ __msvcrt_file; 45 | __INT32_TYPE__ __msvcrt_charbuf; 46 | __INT32_TYPE__ __msvcrt_bufsiz; 47 | char *__msvcrt_tmpfname; 48 | } FILE; 49 | 50 | #define BUFSIZ 512 51 | #define EOF (-1) 52 | 53 | #define FILENAME_MAX 260 54 | #define FOPEN_MAX 20 55 | #define L_tmpnam 13 56 | #define TMP_MAX 32767 57 | 58 | #define _IOFBF 0x0000 59 | #define _IOLBF 0x0040 60 | #define _IONBF 0x0004 61 | 62 | __IMP FILE *__iob_func(void); 63 | 64 | #ifdef __INTELLISENSE__ 65 | FILE *stdin; 66 | FILE *stdout; 67 | FILE *stderr; 68 | #else 69 | # define stdin (&__iob_func()[0]) 70 | # define stdout (&__iob_func()[1]) 71 | # define stderr (&__iob_func()[2]) 72 | #endif 73 | 74 | #else 75 | #error FIXME 76 | #endif 77 | 78 | #define SEEK_SET 0 79 | #define SEEK_CUR 1 80 | #define SEEK_END 2 81 | 82 | __IMP int (remove)(char const *); 83 | __IMP int (rename)(char const *,char const *); 84 | 85 | /* TODO: unlink() and friends? */ 86 | 87 | __IMP __WUNUSED FILE *(tmpfile)(void); 88 | __IMP char *(tmpnam)(char *); 89 | 90 | __IMP int (fclose)(FILE *); 91 | __IMP int (fflush)(FILE *); 92 | __IMP __WUNUSED FILE *(fopen)(char const *,char const *); 93 | __IMP FILE *(freopen)(char const *,char const *,FILE *); 94 | __IMP void (setbuf)(FILE *,char *); 95 | __IMP int (setvbuf)(FILE *,char *,int,size_t); 96 | 97 | __IMP int (fprintf)(FILE *,char const *,...); 98 | __IMP int (fscanf)(FILE *,char const *,...); 99 | __IMP int (printf)(char const *,...); 100 | __IMP int (scanf)(char const *,...); 101 | 102 | __IMP int (sprintf)(char *,char const *,...); 103 | __IMP int (sscanf)(char const *,char const *,...); 104 | __IMP int (vfprintf)(FILE *,char const *,__builtin_va_list); 105 | __IMP int (vprintf)(char const *,__builtin_va_list); 106 | __IMP int (vsprintf)(char *,char const *,__builtin_va_list); 107 | 108 | #if defined(__USE_ISOC99) || defined(__USE_UNIX98) 109 | #if defined(__CRT_MSVC) && !defined(__INTELLISENSE__) 110 | __IMP int (__msvc_vsnprintf)(char *,size_t,char const *,__builtin_va_list) __asm__("_vsnprintf"); 111 | __IMP int (__msvc_vscprintf)(char const *,__builtin_va_list) __asm__("_vscprintf"); 112 | #define __vsnprintf(buf,bufsize,format,args) \ 113 | __extension__({\ 114 | int __r = -1; \ 115 | if ((bufsize)) { \ 116 | __builtin_va_list __acopy; \ 117 | __builtin_va_copy(__acopy,(args)); \ 118 | __r = __msvc_vsnprintf((buf),(bufsize),(format),__acopy); \ 119 | __builtin_va_end(__acopy);\ 120 | } \ 121 | if (__r < 0) __r = __msvc_vscprintf((format),(args)); \ 122 | __r; \ 123 | }) 124 | #define vsnprintf(buf,bufsize,format,args) \ 125 | __extension__({\ 126 | size_t const __bsiz = (#!bufsize);\ 127 | char const *const __fmt = (#!format);\ 128 | __builtin_va_list __args = (#!args);\ 129 | __vsnprintf((#!buf),__bsiz,__fmt,__args);\ 130 | }) 131 | __inline__ int (snprintf)(char *__buf, size_t __bufsiz, char const *__format, ...) { 132 | int __result; 133 | __builtin_va_list __va_list; 134 | __builtin_va_start(__va_list,__format); 135 | __result = __vsnprintf(__buf,__bufsiz,__format,__va_list); 136 | __builtin_va_end(__va_list); 137 | return __result; 138 | } 139 | #else 140 | __IMP int (snprintf)(char *,size_t,char const *,...); 141 | __IMP int (vsnprintf)(char *,size_t,char const *,__builtin_va_list); 142 | #endif 143 | __IMP int (vfscanf)(FILE *,char const *,__builtin_va_list); 144 | __IMP int (vscanf)(char const *,__builtin_va_list); 145 | __IMP int (vsscanf)(char const *,char const *,__builtin_va_list); 146 | #endif 147 | 148 | __IMP __WUNUSED int (fgetc)(FILE *); 149 | __IMP char *(fgets)(char *,int,FILE *); 150 | __IMP int (fputc)(int,FILE *); 151 | __IMP int (fputs)(char const *,FILE *); 152 | __IMP __WUNUSED int (getc)(FILE *); 153 | __IMP __WUNUSED int (getchar)(void); 154 | __IMP char *(gets)(char *); 155 | __IMP int (putc)(int,FILE *); 156 | __IMP int (putchar)(int,FILE *); 157 | __IMP int (puts)(char const *); 158 | __IMP int (ungetc)(int,FILE *); 159 | 160 | __IMP size_t (fread)(void *,size_t,size_t,FILE *); 161 | __IMP size_t (fwrite)(void const *,size_t,size_t,FILE *); 162 | 163 | __IMP int (fgetpos)(FILE *,fpos_t *); 164 | __IMP int (fseek)(FILE *,long,int); 165 | __IMP int (fsetpos)(FILE *,fpos_t const *); 166 | __IMP __WUNUSED long (ftell)(FILE *); 167 | __IMP void (rewind)(FILE *); 168 | 169 | __IMP void (clearerr)(FILE *); 170 | __IMP __WUNUSED int (feof)(FILE *); 171 | __IMP __WUNUSED int (ferror)(FILE *); 172 | __IMP void (perror)(char const *); 173 | 174 | #endif 175 | -------------------------------------------------------------------------------- /lib/include/strings.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else /* include_next... */ 29 | #include <__stdinc.h> 30 | #include 31 | 32 | #undef size_t 33 | typedef __SIZE_TYPE__ size_t; 34 | 35 | 36 | #if defined(__USE_MISC) || !defined(__USE_XOPEN2K8) 37 | #if defined(__CRT_GLIBC) || defined(__INTELLISENSE__) 38 | __IMP int (bcmp)(void const *__s1, void const *__s2, size_t __n); 39 | __IMP void (bcopy)(void const *__src, void *__dest, size_t __n); 40 | __IMP void (bzero)(void *__s, size_t __n); 41 | #endif 42 | #ifndef __INTELLISENSE__ 43 | #define bcmp(s1,s2,n) __builtin_memcmp((s1),(s2),(n)) 44 | #define bcopy(src,dest,n) (void)__builtin_memcpy((dest),(src),(n)) 45 | #define bzero(s,n) (void)__builtin_memset((s),0,(n)) 46 | #endif 47 | 48 | #if defined(__CRT_GLIBC) || defined(__INTELLISENSE__) 49 | __IMP char *(index)(char const *__s, int __c); 50 | __IMP char *(rindex)(char const *__s, int __c); 51 | #else 52 | #define index(s,c) ((c) ? __builtin_strchr(s,c) : __builtin_strend(s)) 53 | #define rindex(s,c) ((c) ? __builtin_strrchr(s,c) : __builtin_strend(s)) 54 | #endif 55 | #endif 56 | 57 | #if defined(__USE_MISC) || !defined(__USE_XOPEN2K8) || defined(__USE_XOPEN2K8XSI) 58 | #if defined(__CRT_GLIBC) || defined(__CRT_KOS) || defined(__INTELLISENSE__) 59 | __IMP int (ffs)(int __i); 60 | #endif 61 | #ifndef __INTELLISENSE__ 62 | #define ffs(i) __builtin_ffs((i)) 63 | #endif 64 | #endif 65 | 66 | __IMP int (strcasecmp)(char const *__s1, char const *__s2) 67 | #if defined(__CRT_MSVC) 68 | __asm__("_stricmp") 69 | #elif defined(__CRT_KOS) 70 | __asm__("stricmp") 71 | #endif 72 | ; 73 | __IMP int (strncasecmp)(char const *__s1, char const *__s2, size_t __n) 74 | #if defined(__CRT_MSVC) 75 | __asm__("_strnicmp") 76 | #elif defined(__CRT_KOS) 77 | __asm__("strnicmp") 78 | #endif 79 | ; 80 | 81 | #ifdef __USE_XOPEN2K8 82 | #include 83 | __IMP __CRT_UNSUPPORTED_KOS int (strcasecmp_l)(char const *__s1, char const *__s2, __locale_t __loc) 84 | #ifdef __CRT_MSVC 85 | __asm__("_stricmp_l") 86 | #endif 87 | ; 88 | __IMP __CRT_UNSUPPORTED_KOS int (strncasecmp_l)(char const *__s1, char const *__s2, size_t __n, __locale_t __loc) 89 | #ifdef __CRT_MSVC 90 | __asm__("_strnicmp_l") 91 | #endif 92 | ; 93 | #endif /* __USE_XOPEN2K8 */ 94 | 95 | #endif /* !include_next... */ 96 | -------------------------------------------------------------------------------- /lib/include/sys/dir.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else 29 | #include <__stdinc.h> 30 | 31 | __STRICT_ANSI_HEADER 32 | 33 | #include 34 | #define direct dirent 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /lib/include/sys/fcntl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else 29 | #include <__stdinc.h> 30 | 31 | __STRICT_ANSI_HEADER 32 | 33 | #include 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lib/include/sys/types.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else 29 | #include <__stdinc.h> 30 | 31 | __STRICT_ANSI_HEADER 32 | 33 | #include 34 | #include 35 | 36 | #ifdef __USE_MISC 37 | typedef __u_char u_char; 38 | typedef __u_short u_short; 39 | typedef __u_int u_int; 40 | typedef __u_long u_long; 41 | typedef __quad_t quad_t; 42 | typedef __u_quad_t u_quad_t; 43 | #ifdef __fsid_t 44 | typedef __fsid_t fsid_t; 45 | #endif 46 | #endif 47 | typedef __loff_t loff_t; 48 | 49 | typedef __dev_t dev_t; 50 | typedef __gid_t gid_t; 51 | typedef __mode_t mode_t; 52 | typedef __nlink_t nlink_t; 53 | typedef __uid_t uid_t; 54 | typedef __pid_t pid_t; 55 | typedef __ssize_t ssize_t; 56 | 57 | #ifndef __USE_FILE_OFFSET64 58 | typedef __ino_t ino_t; 59 | typedef __off_t off_t; 60 | #else 61 | typedef __ino64_t ino_t; 62 | typedef __off64_t off_t; 63 | #endif 64 | 65 | #ifdef __USE_LARGEFILE64 66 | typedef __ino64_t ino64_t; 67 | typedef __off64_t off64_t; 68 | #endif 69 | 70 | #if defined(__id_t) && \ 71 | (defined(__USE_XOPEN) || defined(__USE_XOPEN2K8)) 72 | typedef __id_t id_t; 73 | #endif 74 | 75 | 76 | #ifdef __USE_MISC 77 | #ifdef __daddr_t 78 | typedef __daddr_t daddr_t; 79 | #endif 80 | typedef __caddr_t caddr_t; 81 | #endif 82 | 83 | #if defined(__key_t) && \ 84 | (defined(__USE_MISC) || defined(__USE_XOPEN)) 85 | typedef __key_t key_t; 86 | #endif 87 | 88 | #if defined(__USE_XOPEN) || defined(__USE_XOPEN2K8) 89 | typedef __clock_t clock_t; 90 | #endif 91 | 92 | typedef __time_t time_t; 93 | #ifdef __timer_t 94 | typedef __timer_t timer_t; 95 | #endif 96 | #ifdef __clockid_t 97 | typedef __clockid_t clockid_t; 98 | #endif 99 | 100 | #ifdef __USE_XOPEN 101 | #ifdef __useconds_t 102 | typedef __useconds_t useconds_t; 103 | #endif 104 | #ifdef __suseconds_t 105 | typedef __suseconds_t suseconds_t; 106 | #endif 107 | #endif 108 | 109 | typedef __SIZE_TYPE__ size_t; 110 | 111 | #ifdef __USE_MISC 112 | typedef unsigned long int ulong; 113 | typedef unsigned short int ushort; 114 | typedef unsigned int uint; 115 | #endif 116 | 117 | typedef __INT8_TYPE__ int8_t; 118 | typedef __INT16_TYPE__ int16_t; 119 | typedef __INT32_TYPE__ int32_t; 120 | typedef __INT64_TYPE__ int64_t; 121 | typedef __UINT8_TYPE__ u_int8_t; 122 | typedef __UINT16_TYPE__ u_int16_t; 123 | typedef __UINT32_TYPE__ u_int32_t; 124 | typedef __UINT64_TYPE__ u_int64_t; 125 | 126 | typedef int register_t; 127 | 128 | #define __BIT_TYPES_DEFINED__ 1 129 | 130 | #ifdef __USE_MISC 131 | #if __has_include() 132 | # include 133 | #endif 134 | #if __has_include() 135 | # include 136 | #endif 137 | #if __has_include() 138 | # include 139 | #endif 140 | #endif /* Use misc. */ 141 | 142 | 143 | #if defined(__blksize_t) && \ 144 | (defined(__USE_UNIX98) || defined(__USE_XOPEN2K8)) 145 | typedef __blksize_t blksize_t; 146 | #endif 147 | 148 | #if defined(__blkcnt_t) && defined(__fsblkcnt_t) && defined(__fsfilcnt_t) 149 | #ifndef __USE_FILE_OFFSET64 150 | typedef __blkcnt_t blkcnt_t; 151 | typedef __fsblkcnt_t fsblkcnt_t; 152 | typedef __fsfilcnt_t fsfilcnt_t; 153 | #else 154 | typedef __blkcnt64_t blkcnt_t; 155 | typedef __fsblkcnt64_t fsblkcnt_t; 156 | typedef __fsfilcnt64_t fsfilcnt_t; 157 | #endif 158 | #ifdef __USE_LARGEFILE64 159 | typedef __blkcnt64_t blkcnt64_t; 160 | typedef __fsblkcnt64_t fsblkcnt64_t; 161 | typedef __fsfilcnt64_t fsfilcnt64_t; 162 | #endif 163 | #endif 164 | 165 | #if (defined(__USE_POSIX199506) || defined(__USE_UNIX98)) && \ 166 | __has_include() 167 | # include 168 | #endif 169 | 170 | #endif 171 | -------------------------------------------------------------------------------- /lib/include/time.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else 29 | #include <__stdinc.h> 30 | #include 31 | #include 32 | 33 | #undef size_t 34 | typedef __SIZE_TYPE__ size_t; 35 | 36 | #undef time_t 37 | typedef __time_t time_t; 38 | 39 | #undef clock_t 40 | typedef __clock_t clock_t; 41 | 42 | #define NULL __NULL__ 43 | 44 | struct tm; 45 | 46 | #ifdef __CRT_MSVC 47 | #define CLOCKS_PER_SEC 1000 48 | 49 | #ifdef _USE_32BIT_TIME_T 50 | # define __TIMENAM(n) __asm__("_" n "32") 51 | # define __TIMENAMS(n) __asm__("_" n "32_s") 52 | #else 53 | # define __TIMENAM(n) __asm__("_" n "64") 54 | # define __TIMENAMS(n) __asm__("_" n "64_s") 55 | #endif 56 | 57 | __IMP __WUNUSED double (difftime)(time_t __time1, time_t __time2) __TIMENAM("difftime"); 58 | __IMP __WUNUSED char *(ctime)(time_t const *__timep) __TIMENAM("ctime"); 59 | __IMP __WUNUSED struct tm *(gmtime)(time_t const *__timep) __TIMENAM("gmtime"); 60 | __IMP __WUNUSED struct tm *(localtime)(time_t const *__timep) __TIMENAM("localtime"); 61 | __IMP __WUNUSED time_t (mktime)(struct tm *__tm) __TIMENAM("mktime"); 62 | __IMP __WUNUSED time_t (time)(time_t *__timep) __TIMENAM("time"); 63 | 64 | __IMP __WUNUSED time_t (__cdecl __msvc_mkgmtime)(struct tm *__tm) __TIMENAM("mkgmtime"); 65 | __IMP /*errno_t*/int (__cdecl __msvc_ctime_s)(char *__buf, size_t __sizeinbytes, time_t const *__timep) __TIMENAMS("ctime"); 66 | __IMP /*errno_t*/int (__cdecl __msvc_gmtime_s)(struct tm *__tm, time_t const *__timep) __TIMENAMS("gmtime"); 67 | __IMP /*errno_t*/int (__cdecl __msvc_localtime_s)(struct tm *__tm, time_t const *__timep) __TIMENAMS("localtime"); 68 | __IMP /*errno_t*/int (__cdecl __msvc_asctime_s)(char *__buf, size_t __sizeinbytes, struct tm const *__tm) __TIMENAMS("asctime"); 69 | 70 | #ifdef __USE_POSIX 71 | #ifdef __INTELLISENSE__ 72 | char *(asctime_r)(const struct tm *tm, char *buf); 73 | char *(ctime_r)(const time_t *timep, char *buf); 74 | struct tm *(gmtime_r)(const time_t *timep, struct tm *result); 75 | struct tm *(localtime_r)(const time_t *timep, struct tm *result); 76 | #else 77 | # define asctime_r(tm,buf) __extension__({ char *const __buf = (buf); __msvc_asctime_s(__buf,(size_t)-1,tm) ? (char *)0 : __buf; }) 78 | # define ctime_r(tm,buf) __extension__({ char *const __buf = (buf); __msvc_ctime_s(__buf,(size_t)-1,tm) ? (char *)0 : __buf; }) 79 | # define gmtime_r(timep,result) __extension__({ struct tm *const __r = (result); __msvc_gmtime_s(__r,timep) ? (struct tm *)0 : __r; }) 80 | # define localtime_r(timep,result) __extension__({ struct tm *const __r = (result); __msvc_localtime_s(__r,timep) ? (struct tm *)0 : __r; }) 81 | #endif 82 | #endif 83 | 84 | #undef __TIMENAMS 85 | #undef __TIMENAM 86 | #else 87 | 88 | __IMP __WUNUSED double (difftime)(time_t __time1, time_t __time2); 89 | __IMP __WUNUSED char *(ctime)(time_t const *__timep); 90 | __IMP __WUNUSED struct tm *(gmtime)(time_t const *__timep); 91 | __IMP __WUNUSED struct tm *(localtime)(time_t const *__timep); 92 | __IMP __WUNUSED time_t (mktime)(struct tm *__tm); 93 | __IMP __WUNUSED time_t (time)(time_t *__timep); 94 | 95 | #ifdef __USE_POSIX 96 | __IMP char *(asctime_r)(const struct tm *, char *); 97 | __IMP char *(ctime_r)(const time_t *, char *); 98 | __IMP struct tm *(gmtime_r)(const time_t *, struct tm *); 99 | __IMP struct tm *(localtime_r)(const time_t *, struct tm *); 100 | #endif 101 | 102 | #endif 103 | 104 | __IMP __WUNUSED clock_t clock(void); 105 | 106 | struct tm { 107 | int tm_sec; /* seconds after the minute - [0,59] */ 108 | int tm_min; /* minutes after the hour - [0,59] */ 109 | int tm_hour; /* hours since midnight - [0,23] */ 110 | int tm_mday; /* day of the month - [1,31] */ 111 | int tm_mon; /* months since January - [0,11] */ 112 | int tm_year; /* years since 1900 */ 113 | int tm_wday; /* days since Sunday - [0,6] */ 114 | int tm_yday; /* days since January 1 - [0,365] */ 115 | int tm_isdst; /* daylight savings time flag */ 116 | #ifdef __CRT_GLIBC 117 | #ifdef __USE_MISC 118 | long int tm_gmtoff; /* Seconds east of UTC. */ 119 | char const *tm_zone; /* Timezone abbreviation. */ 120 | #else 121 | long int __tm_gmtoff; /* Seconds east of UTC. */ 122 | char const *__tm_zone; /* Timezone abbreviation. */ 123 | #endif 124 | #endif 125 | }; 126 | 127 | __IMP __WUNUSED char *(asctime)(struct tm const *); 128 | __IMP size_t (strftime)(char *,size_t,char const *,struct tm const *); 129 | 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /lib/include/wchar.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else 29 | #include <__stdinc.h> 30 | 31 | #ifndef __INTELLISENSE__ 32 | typedef __WCHAR_TYPE__ wchar_t; 33 | #endif 34 | 35 | /* TODO */ 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /lib/include/xlocale.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | #pragma GCC system_header 21 | 22 | #ifndef __has_include_next 23 | #define __has_include_next(x) 0 24 | #endif 25 | 26 | #if __has_include_next() 27 | #include_next 28 | #else 29 | #include <__stdinc.h> 30 | 31 | __STRICT_ANSI_HEADER 32 | 33 | #include 34 | 35 | #ifdef __CRT_MSVC 36 | #pragma push_macro(undef,"threadlocaleinfostruct","threadmbcinfostruct") 37 | typedef struct __locale_struct { 38 | struct threadlocaleinfostruct *__msvc_locinfo; 39 | struct threadmbcinfostruct *__msvc_mbcinfo; 40 | } *__locale_t; 41 | #pragma pop_macro("threadlocaleinfostruct","threadmbcinfostruct") 42 | #elif defined(__CRT_GLIBC) 43 | typedef struct __locale_struct { 44 | struct __locale_data *__locales[13]; 45 | __UINT16_TYPE__ const *__ctype_b; 46 | __INT32_TYPE__ const *__ctype_tolower; 47 | __INT32_TYPE__ const *__ctype_toupper; 48 | char const *__names[13]; 49 | } *__locale_t; 50 | #else 51 | typedef int *__locale_t; /* ??? */ 52 | #endif 53 | 54 | typedef __locale_t locale_t; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /lib/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CC="../bin/dcc" 4 | DCC_CC="/cygdrive/e/c/dcc/dcc/bin/dcc.exe" 5 | if [ -f "$DCC_CC" ]; then 6 | CC="$DCC_CC" 7 | fi 8 | 9 | DEPDIR=".deps" 10 | OBJDIR=".objs" 11 | 12 | src_changed() { 13 | return 1 14 | # inf="$1" 15 | # dpf="$2" 16 | # [ -f "$inf" ] || return 1 17 | # [ -f "$dpf" ] || return 1 18 | # ddt=`cat "$dpf" | tr -d '\\\\\n'` 19 | # first=1 20 | # for dep in $ddt; do 21 | # if [ "$first" == 1 ]; then first=0; else 22 | # if [ "$dep" -nt "$inf" ]; then 23 | # echo "Dependency has changed:" 24 | # echo -e "\tinput file: $inf" 25 | # echo -e "\tdepends on: $dep" 26 | # return 1 27 | # fi 28 | # fi 29 | # done 30 | # return 0 31 | } 32 | 33 | debug_objects=() 34 | ndebug_objects=() 35 | 36 | src() { 37 | local objfile 38 | local args 39 | local mode 40 | mode="$1" 41 | shift 42 | args=() 43 | while [[ $1 == "-"* ]]; do 44 | args+=("$1") 45 | shift 46 | done 47 | name="$(basename "$1")" 48 | if [[ "$mode" == *"D"* ]]; then 49 | objfile="$OBJDIR/dbg-$name.o" 50 | debug_objects+=("$objfile") 51 | depfile="$DEPDIR/dbg-$name.d" 52 | if ! src_changed "$objfile" "$depfile"; then 53 | echo "Compiling: $objfile" 54 | $CC "${args[@]}" -g -nostdlib -c -MMD -MF "$depfile" -o "$objfile" $* || exit $? 55 | fi 56 | fi 57 | if [[ "$mode" == *"N"* ]]; then 58 | objfile="$OBJDIR/ndbg-$name.o" 59 | ndebug_objects+=("$objfile") 60 | depfile="$DEPDIR/ndbg-$name.d" 61 | if ! src_changed "$objfile" "$depfile"; then 62 | echo "Compiling: $objfile" 63 | $CC "${args[@]}" -DNDEBUG -nostdlib -c -MMD -MF "$depfile" -o "$objfile" $* || exit $? 64 | fi 65 | fi 66 | } 67 | 68 | crt-src-c() { src "DN" $*; } 69 | crt-src-n() { src "N" $*; } 70 | crt-src-d() { src "D" $*; } 71 | 72 | mkdir -p "$DEPDIR" || exit $? 73 | mkdir -p "$OBJDIR" || exit $? 74 | 75 | crt-src-c "src/crt/crt1.c" 76 | crt-src-c "src/crt/int64.c" 77 | crt-src-d -DDCC_BUILDING_A2L_RUNTIME "src/crt/addr2line.c" "src/a2l/addr2line-common.c" 78 | crt-src-c "src/crt/chkstk.S" 79 | crt-src-c "src/crt/alloca.S" 80 | 81 | $CC -g -c -o dbg-crt.o ${debug_objects[@]} 82 | $CC -c -o crt.o ${ndebug_objects[@]} 83 | 84 | # -DDCC_BUILDING_A2L_RUNTIME -g -nostdlib -c -MMD -MF .deps/dbg-addr2line.c.d -o .objs/dbg-addr2line.c.o src/crt/addr2line.c src/a2l/addr2line-common.c 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /lib/src/crt/alloca.S: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | /* Only used for PE targets. */ 20 | #include "crtdbg.h" 21 | #if defined(__PE__) || defined(CRTDBG_INIT_ALLOCA) 22 | 23 | #ifdef __i386__ 24 | 25 | #define PAGESIZE 4096 26 | 27 | .hidden __pe_alloca 28 | .hidden __pe_alloca_eax 29 | __pe_alloca: 30 | popl %edx /* Return address. */ 31 | popl %eax /* Allocation count. */ 32 | jmp 7f 33 | __pe_alloca_eax: 34 | popl %edx /* Return address. */ 35 | 7: 36 | #ifdef CRTDBG_INIT_ALLOCA 37 | cmpl $8, %eax 38 | jl 1f 39 | pushfl 40 | pushl %edi 41 | leal -8(%eax), %ecx 42 | movl %esp, %edi 43 | decl %edi 44 | movb $CRTDBG_INIT_ALLOCA, %al 45 | std 46 | rep stosb 47 | incl %edi 48 | movl %edi, %eax 49 | popl %edi 50 | popfl 51 | movl $(0x01010101*CRTDBG_INIT_ALLOCA), -4(%esp) 52 | movl $(0x01010101*CRTDBG_INIT_ALLOCA), -8(%esp) 53 | movl %eax, %esp 54 | jmp 2f 55 | 1: decl %esp 56 | movb $CRTDBG_INIT_ALLOCA, (%esp) 57 | dec %eax 58 | test %eax, %eax 59 | jnz 1b 60 | movl %esp, %eax 61 | 2: 62 | #else 63 | cmpl $PAGESIZE, %eax 64 | jl 2f 65 | 1: subl $PAGESIZE, %esp /* Advance to the next page. */ 66 | testb $0, (%esp) /* Touch the page. */ 67 | subl $PAGESIZE, %eax /* Advance the size counter. */ 68 | jg 1b /* ZF == 0 && OF == SF */ 69 | 2: subl %eax, %esp 70 | #endif 71 | jmpl *%edx 72 | #ifdef NDEBUG 73 | nop 74 | #endif 75 | .size __pe_alloca_eax, . - __pe_alloca_eax 76 | .size __pe_alloca, . - __pe_alloca 77 | 78 | #else 79 | # error FIXME 80 | #endif 81 | #endif /* __PE__ || CRTDBG_INIT_ALLOCA */ 82 | -------------------------------------------------------------------------------- /lib/src/crt/crt1.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma comment(lib,"msvcrt") 20 | 21 | /* Declare everything with hidden visibility. */ 22 | #pragma GCC visibility push("hidden") 23 | 24 | #include <__stdinc.h> 25 | 26 | 27 | #define __UNKNOWN_APP 0 28 | #define __CONSOLE_APP 1 29 | #define __GUI_APP 2 30 | 31 | typedef struct { 32 | int newmode; 33 | } _startupinfo; 34 | 35 | int main(int argc, char **argv, char **env); 36 | 37 | __IMP void __set_app_type(int); 38 | __IMP void _controlfp(unsigned a, unsigned b); 39 | __IMP void __getmainargs(int *pargc, char ***pargv, char ***penv, int globb, _startupinfo*); 40 | __IMP [[noreturn]] void exit(int exitcode); 41 | 42 | [[noreturn,alias("_start")]] void __start(void); 43 | [[noreturn]] void _start(void) { 44 | int argc; char **argv; char **env; 45 | _startupinfo start_info = {0}; 46 | 47 | #ifdef _WIN32 48 | /* TODO: Register initial SEH handler. */ 49 | #endif 50 | 51 | _controlfp(0x10000,0x30000); 52 | __set_app_type(__CONSOLE_APP); 53 | __getmainargs(&argc,&argv,&env,0,&start_info); 54 | 55 | #if !defined(NDEBUG) && (defined(_WIN32) || defined(__CYGWIN32__)) && defined(__i386__) 56 | { extern void __dcc_dbg_init_exc_tracebacks(void); 57 | __dcc_dbg_init_exc_tracebacks(); 58 | } 59 | #endif 60 | exit(main(argc,argv,env)); 61 | } 62 | 63 | #pragma GCC visibility pop 64 | -------------------------------------------------------------------------------- /lib/src/crt/crtdbg.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #pragma once 20 | 21 | #ifndef NDEBUG 22 | #define CRTDBG_INIT_CHKSTK 0xcc 23 | #define CRTDBG_INIT_ALLOCA 0xac 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /lib/src/crt/int64.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | /* Compile with: $ dcc -nostdlib -c -o int64.o int64.c */ 20 | 21 | #include 22 | 23 | /* Declare everything with hidden visibility. */ 24 | #pragma GCC visibility push("hidden") 25 | 26 | #define CRTDEF [[visibility("hidden")]] 27 | 28 | CRTDEF int64_t __ashlti3(int64_t x, int shift); 29 | CRTDEF int64_t __ashrti3(int64_t x, int shift); 30 | CRTDEF uint64_t __lshrti3(uint64_t x, int shift); 31 | CRTDEF uint64_t __udivti3(uint64_t x, uint64_t y); 32 | CRTDEF int64_t __divti3 (int64_t x, int64_t y); 33 | CRTDEF uint64_t __umodti3(uint64_t x, uint64_t y); 34 | CRTDEF int64_t __modti3 (int64_t x, int64_t y); 35 | CRTDEF int64_t __multi3 (int64_t x, int64_t y); 36 | 37 | 38 | 39 | typedef union { 40 | int64_t s; 41 | uint64_t u; 42 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 43 | struct { int32_t los,his; }; 44 | struct { uint32_t lou,hiu; }; 45 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 46 | struct { int32_t his,los; }; 47 | struct { uint32_t hiu,lou; }; 48 | #else 49 | # error FIXME 50 | #endif 51 | } i64; 52 | #define X ((i64 &)x) 53 | #define Y ((i64 &)y) 54 | 55 | int64_t __ashlti3(int64_t x, int shift) { 56 | /* return x << shift; */ 57 | if (shift >= 32) { 58 | X.hiu = (X.lou << (shift-32)); 59 | X.lou = (0); 60 | } else if (shift) { 61 | X.hiu = (X.hiu << shift) | (X.lou >> (32-shift)); 62 | X.lou = (X.lou << shift); 63 | } 64 | return X.s; 65 | } 66 | 67 | int64_t __ashrti3(int64_t x, int shift) { 68 | /* return x >> shift; */ 69 | if (shift >= 32) { 70 | X.los = (X.his >> (shift-32)); 71 | X.his = (X.his >> 31); 72 | } else if (shift) { 73 | X.los = (X.lou >> shift) | (X.his << (32-shift)); 74 | X.his = (X.his >> shift); 75 | } 76 | return X.s; 77 | } 78 | 79 | uint64_t __lshrti3(uint64_t x, int shift) { 80 | /* return x >> shift; */ 81 | if (shift >= 32) { 82 | X.lou = (X.hiu >> (shift-32)); 83 | X.hiu = (0); 84 | } else if (shift) { 85 | X.lou = (X.lou >> shift) | (X.his << (32-shift)); 86 | X.hiu = (X.hiu >> shift); 87 | } 88 | return X.u; 89 | } 90 | 91 | uint64_t __udivti3(uint64_t x, uint64_t y) { 92 | /* TODO: return x / y; */ 93 | return (uint32_t)x / (uint32_t)y; 94 | } 95 | 96 | int64_t __divti3(int64_t x, int64_t y) { 97 | /* TODO: return x / y; */ 98 | return (int32_t)x / (int32_t)y; 99 | } 100 | 101 | uint64_t __umodti3(uint64_t x, uint64_t y) { 102 | /* TODO: return x % y; */ 103 | return (uint32_t)x % (uint32_t)y; 104 | } 105 | 106 | int64_t __modti3(int64_t x, int64_t y) { 107 | /* TODO: return x % y; */ 108 | return (int32_t)x % (int32_t)y; 109 | } 110 | 111 | int64_t __multi3(int64_t x, int64_t y) { 112 | /* TODO: return x * y; */ 113 | return (int32_t)x * (int32_t)y; 114 | } 115 | 116 | #pragma GCC visibility pop 117 | -------------------------------------------------------------------------------- /lib/src/libc/common.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_LIB_SRC_LIBC_COMMON_H 20 | #define GUARD_LIB_SRC_LIBC_COMMON_H 1 21 | 22 | #include <__stdinc.h> 23 | 24 | #ifndef __INTELLISENSE__ 25 | #define ASM{...} __asm__(#__VA_ARGS__); 26 | #endif 27 | 28 | /* Use a default symbol visibility of 'HIDDEN'. */ 29 | #pragma comment(compiler,"-fvisibility=hidden") 30 | 31 | #define DECL_BEGIN /* ... */ 32 | #define DECL_END /* ... */ 33 | #define PUBLIC [[visiblity("default")]] 34 | 35 | #define likely(x) (__builtin_expect(!!(x),1)) 36 | #define unlikely(x) (__builtin_expect(!!(x),0)) 37 | 38 | 39 | #ifdef _WIN32 40 | /* Yes! Window's handles don't actually need to be pointers. 41 | * It is always sufficient to use 'unsigned short' (aka. 'uint16_t') 42 | * And with the fact that 'int' being 32-bit on windows, we 43 | * can easily fit any kind of regular, old HANDLE inside! */ 44 | #define FD_MAX 65536 45 | extern void *w32_stdhandle(int fd); 46 | #define W32_FTOH(fd) ((unsigned int)(fd) <= 2 ? (HANDLE)w32_stdhandle(fd) : (HANDLE)(fd)) 47 | #define W32_HTOF(hd) ((int)(hd)) 48 | 49 | 50 | /* Fix the given filename 'name', forcing it to be absolute 51 | * by prepending the current directory, as well as formating 52 | * any slashes, and either return a pointer to 'buf', a 53 | * caller-provided wide-buffer with 'W32_FILENAME_BUFSIZE' 54 | * elements, or a newly allocated dynamic buffer. 55 | * In both cases, the caller should call 'w32_freefilename(return,buf)' 56 | * in order to clean up the return buffer. 57 | * HINT: This function never returns NULL. */ 58 | #define W32_FILENAME_BUFSIZE 512 59 | extern __WCHAR_TYPE__ *w32_allocfilename(__WCHAR_TYPE__ *__restrict buf, char const *__restrict name); 60 | extern __WCHAR_TYPE__ *w32_allocfilenameat(__WCHAR_TYPE__ *__restrict buf, int fd, char const *__restrict name); 61 | extern __WCHAR_TYPE__ *w32_allocfdname(__WCHAR_TYPE__ *__restrict buf, int fd); 62 | #define w32_freefilename(fname,buf) (void)((fname) == (buf) || (__builtin_free(fname),0)) 63 | 64 | #define W32_ERRORCTX_NONE 0 65 | #define W32_ERRORCTX_OPEN 1 66 | #define W32_ERRORCTX_FCNTL 2 67 | #define W32_ERRORCTX_FSYMC 3 68 | #define W32_ERRORCTX_DUP 4 69 | #define W32_ERRORCTX_DUP2 5 70 | #define W32_ERRORCTX_LSEEK 6 71 | #define W32_ERRORCTX_TRUNCATE 7 72 | #define W32_ERRORCTX_CLOSE 8 73 | #define W32_ERRORCTX_READ 9 74 | #define W32_ERRORCTX_WRITE 10 75 | #define W32_ERRORCTX_PIPE 11 76 | #define W32_ERRORCTX_LINK 12 77 | #define W32_ERRORCTX_SYMLINK 13 78 | 79 | /* Set 'errno' from GetLastError() 80 | * Always returns '-1' 81 | * @param: context: One of 'W32_ERRORCTX_*' */ 82 | extern int w32_seterror(int context); 83 | #else 84 | #define FD_MAX 65536 85 | #endif 86 | 87 | 88 | #endif /* !GUARD_LIB_SRC_LIBC_COMMON_H */ 89 | -------------------------------------------------------------------------------- /lib/test/int64.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #include 20 | #include 21 | #include 22 | 23 | #ifdef __INTELLISENSE__ 24 | #define U(x) ((uint64_t)(x)) 25 | #define S(x) ((int64_t)(x)) 26 | #else 27 | #define U(x) ({ volatile uint64_t __x = (x); __x; }) 28 | #define S(x) ({ volatile int64_t __x = (x); __x; }) 29 | #endif 30 | 31 | #define ASSERT_EQ(x,y) \ 32 | do{ auto __x = (x); auto __y = (y);\ 33 | if (__x != __y) { printf("%s(%d) : %llx == %llx\n",__FILE__,__LINE__,__x,__y); exit(1); }\ 34 | }while(0) 35 | 36 | 37 | int main(int argc, char *argv[]) { 38 | 39 | /* Check shift operations. */ 40 | ASSERT_EQ((U(__UINT64_C(0x0000000000000001)) << 1), __UINT64_C(0x0000000000000002)); 41 | ASSERT_EQ((U(__UINT64_C(0x0000000000000010)) << 1), __UINT64_C(0x0000000000000020)); 42 | ASSERT_EQ((U(__UINT64_C(0x0000000000000080)) << 1), __UINT64_C(0x0000000000000100)); 43 | ASSERT_EQ((U(__UINT64_C(0x0000000000000001)) << 31),__UINT64_C(0x0000000080000000)); 44 | ASSERT_EQ((U(__UINT64_C(0x0000000000000001)) << 32),__UINT64_C(0x0000000100000000)); 45 | ASSERT_EQ((U(__UINT64_C(0x0000000000000001)) << 63),__UINT64_C(0x8000000000000000)); 46 | ASSERT_EQ((S(__UINT64_C(0x8000000000000000)) >> 63),__UINT64_C(0xffffffffffffffff)); 47 | ASSERT_EQ((U(__UINT64_C(0x8000000000000000)) >> 63),__UINT64_C(0x0000000000000001)); 48 | ASSERT_EQ((U(__UINT64_C(0x8000000000000000)) >> 31),__UINT64_C(0x0000000100000000)); 49 | ASSERT_EQ((S(__UINT64_C(0x8000000000000000)) >> 31),__UINT64_C(0xffffffff00000000)); 50 | ASSERT_EQ((U(__UINT64_C(0x8000000000000000)) >> 32),__UINT64_C(0x0000000080000000)); 51 | ASSERT_EQ((S(__UINT64_C(0x8000000000000000)) >> 32),__UINT64_C(0xffffffff80000000)); 52 | ASSERT_EQ((U(__UINT64_C(0xffffffff00000000)) >> 32),__UINT64_C(0x00000000ffffffff)); 53 | ASSERT_EQ((U(__UINT64_C(0x00000000ffffffff)) << 32),__UINT64_C(0xffffffff00000000)); 54 | ASSERT_EQ((U(__UINT64_C(0x1234567800000000)) >> 32),__UINT64_C(0x0000000012345678)); 55 | ASSERT_EQ((U(__UINT64_C(0x0000000012345678)) << 32),__UINT64_C(0x1234567800000000)); 56 | 57 | return 0; 58 | } 59 | 60 | 61 | -------------------------------------------------------------------------------- /lib/test/intprom.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #pragma warning("-Wno-old-function-decl") 24 | 25 | /* NOTE: Optimally, this function should never be called. 26 | * Therefor we mark is as 'unused', as it should be optimized away! */ 27 | [[unused,noreturn]] 28 | static void ass_fail2(char const *f, int l, 29 | char const *t1, char const *tt1, 30 | char const *t2, char const *tt2) { 31 | printf("%s(%d) : Assertion failed ('%s':'%s' != '%s':'%s')\n", 32 | f,l,t1,tt1,t2,tt2); 33 | exit(1); 34 | } 35 | 36 | /* AssertSameType */ 37 | #define AST(T1,T2) \ 38 | (__builtin_types_compatible_p(T1,T2) || \ 39 | (ass_fail2(__FILE__,__LINE__,\ 40 | #T1,__builtin_typestr(T1),\ 41 | #T2,__builtin_typestr(T2)),0)) 42 | #define NAST(T1,T2) \ 43 | (!__builtin_types_compatible_p(T1,T2) || \ 44 | (ass_fail2(__FILE__,__LINE__,\ 45 | #T1,__builtin_typestr(T1),\ 46 | #T2,__builtin_typestr(T2)),0)) 47 | 48 | int main(int argc, char *argv[]) { 49 | 50 | char c [[unused]]; 51 | int i [[unused]]; 52 | long l [[unused]]; 53 | long long ll [[unused]]; 54 | unsigned int u [[unused]]; 55 | unsigned long ul [[unused]]; 56 | unsigned long long ull [[unused]]; 57 | 58 | /* Generic same-type assertions. */ 59 | #ifdef __CHAR_UNSIGNED__ 60 | AST(char,unsigned char); 61 | #else 62 | AST(char,signed char); 63 | #endif 64 | 65 | AST(short,short int); 66 | AST(short,signed short); 67 | AST(short,signed short int); 68 | AST(unsigned short,unsigned short int); 69 | 70 | AST(signed,int); 71 | AST(signed,signed int); 72 | AST(unsigned,unsigned int); 73 | 74 | AST(long,long int); 75 | AST(long,signed long); 76 | AST(long,signed long int); 77 | AST(unsigned long,unsigned long int); 78 | 79 | AST(long long,long long int); 80 | AST(long long,signed long long); 81 | AST(long long,signed long long int); 82 | AST(unsigned long long,unsigned long long int); 83 | 84 | NAST(int,short); 85 | AST (int,signed); 86 | NAST(int,unsigned); 87 | NAST(int,long); 88 | NAST(int,long long); 89 | NAST(unsigned int,short); 90 | NAST(unsigned int,signed); 91 | AST (unsigned int,unsigned); 92 | NAST(unsigned int,long); 93 | NAST(unsigned int,long long); 94 | 95 | /* Integer promotions. */ 96 | AST(char, __typeof__(c)); 97 | AST(int, __typeof__(+c)); 98 | #ifdef __CHAR_UNSIGNED__ 99 | AST(int, __typeof__(-(signed char)c)); 100 | #else 101 | AST(int, __typeof__(-c)); 102 | #endif 103 | AST(int, __typeof__(~c)); 104 | AST(int, __typeof__(i)); 105 | 106 | AST(int, __typeof__(i+i)); 107 | AST(int, __typeof__(i+c)); 108 | AST(int, __typeof__(c+i)); 109 | AST(int, __typeof__(c+c)); 110 | AST(long, __typeof__(l+l)); 111 | AST(long, __typeof__(l+i)); 112 | AST(long, __typeof__(l+c)); 113 | AST(long, __typeof__(i+l)); 114 | AST(long, __typeof__(c+l)); 115 | AST(long long, __typeof__(ll+c)); 116 | AST(long long, __typeof__(ll+i)); 117 | AST(long long, __typeof__(ll+l)); 118 | AST(long long, __typeof__(c+ll)); 119 | AST(long long, __typeof__(i+ll)); 120 | AST(long long, __typeof__(l+ll)); 121 | AST(unsigned int, __typeof__(u+c)); 122 | AST(unsigned int, __typeof__(u+i)); 123 | AST(unsigned int, __typeof__(c+u)); 124 | AST(unsigned int, __typeof__(i+u)); 125 | AST(unsigned long, __typeof__(ul+c)); 126 | AST(unsigned long, __typeof__(ul+i)); 127 | AST(unsigned long, __typeof__(ul+l)); 128 | AST(unsigned long, __typeof__(c+ul)); 129 | AST(unsigned long, __typeof__(i+ul)); 130 | AST(unsigned long, __typeof__(l+ul)); 131 | AST(unsigned long long,__typeof__(ull+c)); 132 | AST(unsigned long long,__typeof__(ull+i)); 133 | AST(unsigned long long,__typeof__(ull+l)); 134 | AST(unsigned long long,__typeof__(ull+ll)); 135 | AST(unsigned long long,__typeof__(c+ull)); 136 | AST(unsigned long long,__typeof__(i+ull)); 137 | AST(unsigned long long,__typeof__(l+ull)); 138 | AST(unsigned long long,__typeof__(ll+ull)); 139 | 140 | return 0; 141 | } 142 | 143 | 144 | -------------------------------------------------------------------------------- /lib/test/reachable.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | /* Never implemented to cause linker errors when referenced by reachable code. 25 | * > Calling this function from unreachable code will not create a reference. */ 26 | extern int nnn(void); 27 | 28 | /* Call a function that _is_ reachable. */ 29 | extern int yyy(void); 30 | 31 | /* Call a function that may be reachable (Currently the same as 'yyy()'). */ 32 | extern int mmm(void); 33 | 34 | int yyy(void) { return 0; } 35 | int mmm(void) { return 0; } 36 | _Noreturn int _nrt(int line) { 37 | printf("%s(%d) : Unreachable\n",__FILE__,line); 38 | exit(1); 39 | } 40 | #define nrt_() _nrt(__LINE__) 41 | #define nrt() (_nrt(__LINE__),nnn()) 42 | 43 | 44 | volatile int zero = 0; 45 | #define B if (zero) 46 | #define Q zero 47 | 48 | 49 | int dead_val(int x) { 50 | int result = 0; 51 | switch (x) { 52 | case 7: 53 | result += 42; 54 | if (0) { 55 | if (0) { case 0: result += 7; } 56 | if (0) { case 1: result += 3; } 57 | if (0) { case 2: result += 4; } 58 | if (0) { case 3: result += 9; } 59 | result *= 3; 60 | } 61 | result <<= 1; 62 | default: 63 | result -= 5; 64 | break; 65 | } 66 | return result; 67 | } 68 | 69 | 70 | int main(int argc, char *argv[]) { 71 | int x,y,z; 72 | 73 | /* make sure that dead jumps work correctly. */ 74 | assert(dead_val(0) == 37); 75 | assert(dead_val(1) == 13); 76 | assert(dead_val(2) == 19); 77 | assert(dead_val(3) == 49); 78 | assert(dead_val(4) == -5); 79 | assert(dead_val(5) == -5); 80 | assert(dead_val(6) == -5); 81 | assert(dead_val(7) == 79); 82 | assert(dead_val(8) == -5); 83 | 84 | /* Check linear reachability. */ 85 | B { yyy(); nrt_(); nnn(); } 86 | B { yyy(), nrt_(), nnn(); } 87 | 88 | if (1) yyy(); 89 | if (0) nnn(); 90 | if (Q) mmm(); 91 | 92 | /* Check conditional reachability using logical operators. */ 93 | B { yyy(); 1 || (nnn(), nrt(), nnn()); yyy(); } 94 | B { yyy(); 0 || (yyy(), nrt(), nnn()); nnn(); } 95 | B { yyy(); 0 || yyy() || nrt() || nnn(); nnn(); } 96 | B { yyy(); Q || mmm() || nrt() || nnn(); mmm(); } 97 | B { yyy(); 0 || Q || mmm() || nrt() || nnn(); mmm(); } 98 | B { yyy(); Q || 0 || mmm() || nrt() || nnn(); mmm(); } 99 | 100 | B { yyy(); 1 && (yyy(), nrt(), nnn()); nnn(); } 101 | B { yyy(); 0 && (nnn(), nrt(), nnn()); yyy(); } 102 | B { yyy(); 1 && yyy() && nrt() && nnn(); nnn(); } 103 | B { yyy(); Q && mmm() && nrt() && nnn(); mmm(); } 104 | B { yyy(); 1 && Q && mmm() && nrt() && nnn(); mmm(); } 105 | B { yyy(); Q && 1 && mmm() && nrt() && nnn(); mmm(); } 106 | 107 | x = 10,y = 20,z = 1; 108 | /* Check simple runtime-evaluation */ 109 | __asm__("nop\nnop\nnop\n"); 110 | ( (x != y)) || nrt(); 111 | __asm__("nop\nnop\nnop\n"); 112 | (!(x == y)) || nrt(); 113 | ( (x == y)) && nrt(); 114 | (!(x != y)) && nrt(); 115 | 116 | 117 | /* Check advanced runtime-evaluation */ 118 | ( (z == (x != y))) || nrt(); 119 | (!(z != (x != y))) || nrt(); 120 | ( (z != (x != y))) && nrt(); 121 | (!(z == (x != y))) && nrt(); 122 | ( (z != (x == y))) || nrt(); 123 | (!(z == (x == y))) || nrt(); 124 | ( (z == (x == y))) && nrt(); 125 | (!(z != (x == y))) && nrt(); 126 | 127 | /* Check conditional reachability using the ?: operator. */ 128 | B { 1 ? yyy() : nnn(); yyy(); } 129 | B { 0 ? nnn() : yyy(); yyy(); } 130 | B { 1 ? nrt() : nnn(); nnn(); } 131 | B { 0 ? nrt() : yyy(); yyy(); } 132 | B { 1 ? yyy() : nrt(); yyy(); } 133 | B { 0 ? nnn() : nrt(); nnn(); } 134 | B { Q ? mmm() : mmm(); yyy(); } 135 | B { Q ? nrt() : mmm(); mmm(); } 136 | B { Q ? mmm() : nrt(); mmm(); } 137 | B { Q ? nrt() : nrt(); nnn(); } 138 | 139 | return 0; 140 | } 141 | 142 | 143 | -------------------------------------------------------------------------------- /lib/test/runall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CC="/cygdrive/e/c/dcc/dcc/bin/dcc.exe" 4 | EXE_TEMP="a.exe" 5 | ALLOW_DRT=$($CC --has-feature drt 2>/dev/null) 6 | 7 | run_one() { 8 | echo "Testing: '$1'" 9 | if [ "$ALLOW_DRT" == "1" ]; then 10 | # Use DRT execution to prevent temporary files (Plus: it makes ) 11 | $CC -dg "$1" || exit $? 12 | else 13 | $CC -g -o "$EXE_TEMP" "$1" || exit $? 14 | "./$EXE_TEMP" || { 15 | E=$? 16 | echo "ERROR: $E" 17 | exit $E 18 | } 19 | fi 20 | } 21 | 22 | run_test() { 23 | for src in $*; do 24 | run_one "$src" 25 | done 26 | } 27 | 28 | run_test *.c 29 | 30 | rm -f "$EXE_TEMP" 31 | 32 | -------------------------------------------------------------------------------- /make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CC="gcc -pthread" 4 | F=("-g" "-Iinclude" "-DDCC_PRIVATE_API") 5 | LF="" 6 | out_bin="bin/dcc" 7 | obj_path="build/dcc" 8 | 9 | CC_DCC="/cygdrive/e/c/dcc/dcc/bin/dcc.exe" 10 | CC_DDC="/cygdrive/e/c/dcc/dcc/bin/ddc.exe" 11 | if [ -f "$CC_DDC" ]; then 12 | CC="$CC_DDC"; 13 | obj_path="build/ddd" 14 | out_bin="bin/ddd.exe" 15 | F+=("-D_VA_LIST_DEFINED") 16 | F+=("-D__SSE2__") 17 | F+=("-ID:/cygwin32/usr/include/w32api") 18 | elif [ -f "$CC_DCC" ]; then 19 | CC="$CC_DCC"; 20 | obj_path="build/ddc" 21 | out_bin="bin/ddc.exe" 22 | F+=("-D_VA_LIST_DEFINED") 23 | F+=("-D__SSE2__") 24 | F+=("-ID:/cygwin32/usr/include/w32api") 25 | else 26 | LF="$LF -ldl" 27 | fi 28 | 29 | build() { echo "$obj_path/$1"; } 30 | out() { echo "$(build $1).o"; } 31 | dep() { echo "$(build $1).d"; } 32 | 33 | object_list=() 34 | src_changed() { 35 | inf="$1" 36 | ouf="$(out $(basename "$inf"))" 37 | dpf="$(dep $(basename "$inf"))" 38 | [ -f "$ouf" ] || return 1 39 | [ -f "$dpf" ] || return 1 40 | ddt=`cat "$dpf" | tr -d '\\\\\n'` 41 | first=1 42 | for dep in $ddt; do 43 | if [ "$first" == 1 ]; then first=0; else 44 | if [ "$dep" -nt "$ouf" ]; then 45 | echo "Dependency has changed:" 46 | echo -e "\tinput file: $inf" 47 | echo -e "\tdepends on: $dep" 48 | return 1 49 | fi 50 | fi 51 | done 52 | return 0 53 | } 54 | src() { 55 | for inf in $*; do 56 | ouf="$(out $(basename "$inf"))" 57 | object_list+=("$ouf") 58 | if ! src_changed "$inf"; then 59 | dpf="$(dep $(basename "$inf"))" 60 | echo "Compiling: '$inf'" 61 | echo $CC "${F[@]}" -MMD -MF "$dpf" -c -o "$ouf" "$inf" || exit $? 62 | $CC "${F[@]}" -MMD -MF "$dpf" -c -o "$ouf" "$inf" || exit $? 63 | else 64 | echo "Unchanged: '$inf'" 65 | fi 66 | done 67 | } 68 | 69 | mkdir -p $(build "") || exit $? 70 | 71 | # Compile DCC source files 72 | src src/*.c 73 | src src/dcc/*.c 74 | src src/drt/*.c 75 | src lib/src/a2l/addr2line-common.c 76 | 77 | echo $CC -g -o "$out_bin" "${object_list[@]}" $LF 78 | $CC -g -o "$out_bin" "${object_list[@]}" $LF 79 | 80 | 81 | 82 | 83 | 84 | 85 | # -g -o ../bin/ddc.exe ../build/ddc/main.c.o ../build/ddc/addr2line.c.o ../build/ddc/assembler.c.o ../build/ddc/cmd-help.c.o ../build/ddc/cmd.c.o ../build/ddc/common.c.o ../build/ddc/compiler.c.o ../build/ddc/fundecl.c.o ../build/ddc/gen.c.o ../build/ddc/lexer.c.o ../build/ddc/linker.c.o ../build/ddc/preprocessor.c.o ../build/ddc/tpp-wrapper.c.o ../build/ddc/type.c.o ../build/ddc/unit-debug.c.o ../build/ddc/unit-export.c.o ../build/ddc/unit-import.c.o ../build/ddc/unit-merge.c.o ../build/ddc/unit.c.o ../build/ddc/vstack-ext.c.o ../build/ddc/vstack.c.o ../build/ddc/x86_util-instrlen.c.o ../build/ddc/addr2line-common.c.o 86 | # -g -I../include -DDCC_PRIVATE_API -D_VA_LIST_DEFINED -D__SSE2__ -ID:/cygwin32/usr/include/w32api -MMD -MF ../build/ddc/assembler.c.d -c -o ../build/ddc/assembler.c.o ../src/dcc/assembler.c 87 | # -g -I../include -DDCC_PRIVATE_API -D_VA_LIST_DEFINED -D__SSE2__ -ID:/cygwin32/usr/include/w32api -MMD -MF ../build/ddc/common.c.d -c -o ../build/ddc/common.c.o ../src/dcc/common.c 88 | # -g -I../include -DDCC_PRIVATE_API -DDCC_PRIVATE_API -D_VA_LIST_DEFINED -D__SSE2__ -ID:/cygwin32/usr/include/w32api -MMD -MF ../build/ddc/main.c.d -c -o ../build/ddc/main.c.o ../src/main.c 89 | # -g -o bin/ddc.exe build/ddc/main.c.o build/ddc/addr2line.c.o build/ddc/assembler.c.o build/ddc/cmd-help.c.o build/ddc/cmd.c.o build/ddc/common.c.o build/ddc/compiler.c.o build/ddc/fundecl.c.o build/ddc/gen.c.o build/ddc/lexer.c.o build/ddc/linker.c.o build/ddc/preprocessor.c.o build/ddc/tpp-wrapper.c.o build/ddc/type.c.o build/ddc/unit-debug.c.o build/ddc/unit-export.c.o build/ddc/unit-import.c.o build/ddc/unit-merge.c.o build/ddc/unit.c.o build/ddc/vstack-ext.c.o build/ddc/vstack.c.o build/ddc/x86_util-instrlen.c.o build/ddc/addr2line-common.c.o 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /src/dcc/cmd.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_DCC_CMD_H 20 | #define GUARD_DCC_CMD_H 1 21 | 22 | #include 23 | #include 24 | 25 | DCC_DECL_BEGIN 26 | 27 | #if !!(DCC_TARGET_OS&DCC_OS_F_WINDOWS) 28 | #define DCC_OUTFILE_EXTEXE ".exe" 29 | #else 30 | #define DCC_OUTFILE_EXTEXE ".out" 31 | #endif 32 | #define DCC_OUTFILE_EXTOBJ ".o" 33 | 34 | #define DCC_OUTFILE_STDEXE "a" DCC_OUTFILE_EXTEXE 35 | #define DCC_OUTFILE_STDOBJ "a" DCC_OUTFILE_EXTOBJ 36 | 37 | struct option { 38 | int16_t o_id; /*< Unique Option ID emit when it is encountered. */ 39 | #define OPTION_FLAG_NONE 0x0000 40 | #define OPTION_FLAG_VALUE 0x0001 /*< An option value follows immediately, or in the next argument. */ 41 | #define OPTION_FLAG_EQUAL 0x0002 /*< Set for options that expect a value following a '=' character */ 42 | #define OPTION_FLAG_PREFIX 0x1000 /*< The option name is a prefix (when countered, 'c_val' is set to the text following the prefix). 43 | * This can be used for processing dynamic options like '-f' or '-Wno-' */ 44 | #define OPTION_FLAG_NOOPT 0x2000 /*< Set when this is not meant to be an option, but should later be parsed as a source file (e.g.: 'dcc foo.c -lm') */ 45 | uint16_t o_flags; /*< Set of 'OPTION_FLAG_*' */ 46 | char const *o_short; /*< Short option name, or NULL when unused (e.g.: "E" for '-E') */ 47 | char const *o_long; /*< [0..1] Long option name, or NULL when unknown. */ 48 | struct option const *o_subopt; /*< [0..1] Sub-options that may be encountered as a comma-separated list 49 | * immediately following this option (e.g.: '-Wl,-subsystem=...') 50 | * NOTE: When this field is set, 'o_id' is ignored. */ 51 | }; 52 | #define OPTION_SENTINAL {0,0,NULL,NULL,NULL} 53 | #define OPTION_ISSENTINAL(o) (!(o)->o_short && !(o)->o_long) 54 | 55 | struct cmd { 56 | int c_argc; /*< Argument count. */ 57 | char **c_argv; /*< Argument count. */ 58 | char *c_arg; /*< [0..1] The current argument. */ 59 | struct option const *c_grp; /*< [0..1] The current group in nested options. */ 60 | uint16_t c_state; /*< Internal commandline state (initialize to ZERO) */ 61 | int16_t c_id; /*< Option id (copied from 'o_id') */ 62 | char *c_val; /*< [0..1] Option value (non-NULL when the option has a value) */ 63 | }; 64 | 65 | enum{ 66 | OPT_UNKNOWN = -1, 67 | OPT_EOF = 0, 68 | #define GROUP_BEGIN(n) /* nothing */ 69 | #define GROUP_END /* nothing */ 70 | #define OPTION(n,f,s,l,g) n, 71 | #define OPTION_ALIAS(n,f,s,l,g) /* nothing */ 72 | #define OPTION_UNNAMED(f,s,l,g) /* nothing */ 73 | #include "cmd-def.inl" 74 | #undef OPTION_UNNAMED 75 | #undef OPTION_ALIAS 76 | #undef OPTION 77 | #undef GROUP_END 78 | #undef GROUP_BEGIN 79 | }; 80 | 81 | enum{ 82 | #define GROUP_BEGIN(n) OPG_##n, 83 | #define GROUP_END /* nothing */ 84 | #define OPTION(n,f,s,l,g) /* nothing */ 85 | #define OPTION_ALIAS(n,f,s,l,g) /* nothing */ 86 | #define OPTION_UNNAMED(f,s,l,g) /* nothing */ 87 | #include "cmd-def.inl" 88 | #undef OPTION_UNNAMED 89 | #undef OPTION_ALIAS 90 | #undef OPTION 91 | #undef GROUP_END 92 | #undef GROUP_BEGIN 93 | OPG_COUNT 94 | }; 95 | 96 | #define cmd_init(self,argc,argv) \ 97 | do{ (self)->c_argc = (argc);\ 98 | (self)->c_argv = (argv);\ 99 | (self)->c_arg = NULL;\ 100 | (self)->c_grp = NULL;\ 101 | (self)->c_state = 0;\ 102 | }while(DCC_MACRO_FALSE) 103 | 104 | /* NOTE: Once all options have been parsed, the portion 105 | * of 'cmd' describes all non-command arguments. */ 106 | INTDEF uint16_t cmd_yield(struct cmd *__restrict c); 107 | 108 | 109 | INTDEF void exec_cmd(struct cmd *__restrict c, int from_cmd); 110 | 111 | /* Execute commandline options from 'grp'. 112 | * @param: grp: One of 'OPG_*' (e.g.: 'OPG_grp_main') 113 | * NOTE: Upon return, '*argc' and '*argv' will point to a 114 | * vector of non-option arguments (aka. the source files). 115 | * NOTE: The caller is responsible for popping the 116 | * application name from the argument vector. */ 117 | INTDEF void DCCCmd_Exec(int grp, int *argc, char ***argv); 118 | 119 | /* Same as 'DCCCmd_Exec', but the commandline isn't split into argc|argv. 120 | * NOTE: This function is used for implementing '#pragma comment(compiler|linker,...)' 121 | * WARNING: This function may modify the passed 'str..+=(len+1)' when non-empty. */ 122 | INTDEF void DCCCmd_ExecString(int grp, char *str, size_t len); 123 | 124 | DCC_DECL_END 125 | 126 | #endif /* !GUARD_DCC_CMD_H */ 127 | -------------------------------------------------------------------------------- /src/dcc/compiler-std.c.inl: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_DCC_COMPILER_STD_C_INL 20 | #define GUARD_DCC_COMPILER_STD_C_INL 1 21 | 22 | #define DCC(x) x 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | DCC_DECL_BEGIN 29 | 30 | PUBLIC struct DCCStdName const DCCCompiler_Std[] = { 31 | 32 | {"dcc",DCC_COMPILER_STD_DCC}, 33 | 34 | {"kr",DCC_COMPILER_STD_KR}, 35 | {"k-r",DCC_COMPILER_STD_KR}, 36 | {"k&r",DCC_COMPILER_STD_KR}, 37 | 38 | {"ansi",DCC_COMPILER_STD_C90}, 39 | {"c90",DCC_COMPILER_STD_C90}, 40 | {"c89",DCC_COMPILER_STD_C90}, 41 | {"iso9899:1990",DCC_COMPILER_STD_C90}, 42 | 43 | {"c99",DCC_COMPILER_STD_C99}, 44 | {"c9x",DCC_COMPILER_STD_C99}, 45 | {"iso9899:1999",DCC_COMPILER_STD_C99}, 46 | {"iso9899:199x",DCC_COMPILER_STD_C99}, 47 | 48 | {"c11",DCC_COMPILER_STD_C11}, 49 | {"c1x",DCC_COMPILER_STD_C11}, 50 | {"iso9899:2011",DCC_COMPILER_STD_C11}, 51 | 52 | {NULL,0}, 53 | }; 54 | 55 | PUBLIC void DCCCompiler_SetStd(int std) { 56 | if (!DCC_COMPILER_STD_KNOWN(std) || 57 | (std == DCC_COMPILER_STD_CURRENT)) return; 58 | /* Reset the lexer state to start with the same basis. */ 59 | TPPLexer_Reset(TPPLexer_Current, 60 | TPPLEXER_RESET_ESTATE| 61 | TPPLEXER_RESET_WSTATE); 62 | /* std=dcc is simply the default. */ 63 | if (std == DCC_COMPILER_STD_DCC) return; 64 | 65 | /* Disable extensions that may interfere with STD symtax. */ 66 | /*TPPLexer_DisableExtension(EXT_CXX11_ATTRIBUTE);*/ 67 | TPPLexer_DisableExtension(EXT_VOID_ARITHMETIC); 68 | TPPLexer_DisableExtension(EXT_STRUCT_COMPATIBLE); 69 | TPPLexer_DisableExtension(EXT_SHORT_EXT_KEYWORDS); 70 | /* Enable warnings about extensions. */ 71 | TPPLexer_SetWarningGroup(WG_EXTENSIONS,WSTATE_ERROR); 72 | 73 | switch (std) { 74 | case DCC_COMPILER_STD_KR: 75 | /* Enable traditional macros & tokens, and disable old-style warnings. */ 76 | TPPLexer_EnableExtension(EXT_TRADITIONAL_MACRO); 77 | CURRENT.l_extokens |= TPPLEXER_TOKEN_EQUALBINOP; 78 | TPPLexer_SetWarningGroup(WG_OLD_STORAGE_CLASS,WSTATE_DISABLED); 79 | TPPLexer_SetWarningGroup(WG_OLD_FUNCTION_DECL,WSTATE_DISABLED); 80 | TPPLexer_SetWarningGroup(WG_OLD_VARIABLE_INIT,WSTATE_DISABLED); 81 | break; 82 | case DCC_COMPILER_STD_C90: 83 | /* Disable C++-style comments. */ 84 | TPPLexer_Current->l_extokens &= ~(TPPLEXER_TOKEN_CPP_COMMENT); 85 | break; 86 | case DCC_COMPILER_STD_C99: 87 | /* Disable warnings about C99-specific syntax. */ 88 | TPPLexer_SetWarningGroup(WG_C99,WSTATE_DISABLED); 89 | break; 90 | case DCC_COMPILER_STD_C11: 91 | /* Disable warnings about C99/C11-specific syntax. */ 92 | TPPLexer_SetWarningGroup(WG_C99,WSTATE_DISABLED); 93 | TPPLexer_SetWarningGroup(WG_C11,WSTATE_DISABLED); 94 | break; 95 | default: break; 96 | } 97 | 98 | } 99 | 100 | 101 | DCC_DECL_END 102 | 103 | #endif /* !GUARD_DCC_COMPILER_STD_C_INL */ 104 | -------------------------------------------------------------------------------- /src/dcc/lexer-builtins-malloc.c.inl: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_DCC_LEXER_BUILTINS_MALLOC_C_INL 20 | #define GUARD_DCC_LEXER_BUILTINS_MALLOC_C_INL 1 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "lexer-priv.h" 30 | 31 | DCC_DECL_BEGIN 32 | 33 | #ifdef DCC_SYMFLAG_DLLIMPORT 34 | #define MALL_SYM(name) DCCUnit_NewSyms(name,DCC_SYMFLAG_DLLIMPORT) 35 | #else 36 | #define MALL_SYM(name) DCCUnit_NewSyms(name,DCC_SYMFLAG_NONE) 37 | #endif 38 | 39 | LEXPRIV void DCC_PARSE_CALL 40 | DCCParse_BuiltinMalloc(void) { 41 | int cmode; struct DCCSym *sym; 42 | /* void *__builtin_malloc(size_t n_bytes),__builtin_calloc(size_t count, size_t n_bytes); */ 43 | assert(TOK == KWD___builtin_malloc || 44 | TOK == KWD___builtin_calloc); 45 | cmode = TOK == KWD___builtin_calloc; 46 | sym = MALL_SYM(cmode ? "calloc" : "malloc"); 47 | YIELD(); 48 | DCCParse_ParPairBegin(); 49 | DCCParse_Expr1(); 50 | vcast_t(DCCTYPE_SIZE|DCCTYPE_UNSIGNED,0); 51 | vused(); 52 | if (cmode) { 53 | if (TOK != ',') WARN(W_EXPECTED_COMMA); 54 | else YIELD(); 55 | DCCParse_Expr1(); 56 | vcast_t(DCCTYPE_SIZE|DCCTYPE_UNSIGNED,0); 57 | vused(); 58 | } 59 | /* xxx: Compile-time optimizations for small malloc() sizes? */ 60 | if (TOK == ',') YIELD(),DCCParse_ExprDiscard(); 61 | sym ? DCCVStack_PushSym_vpfun(sym) : vpushv(); 62 | /* [count], n_bytes, malloc */ 63 | vlrot(2+cmode); /* malloc, [count], n_bytes */ 64 | vcall(1+cmode); /* ret */ 65 | DCCParse_ParPairEnd(); 66 | vwunused(); 67 | } 68 | 69 | LEXPRIV void DCC_PARSE_CALL 70 | DCCParse_BuiltinRealloc(void) { 71 | struct DCCSym *sym; 72 | /* void *__builtin_realloc(void *ptr, size_t n_bytes); */ 73 | sym = MALL_SYM("realloc"); 74 | YIELD(); 75 | DCCParse_ParPairBegin(); 76 | DCCParse_Expr1(); 77 | vcast_pt(DCCTYPE_VOID,0); 78 | vused(); 79 | if (TOK != ',') WARN(W_EXPECTED_COMMA); else YIELD(); 80 | DCCParse_Expr1(); 81 | vcast_t(DCCTYPE_SIZE|DCCTYPE_UNSIGNED,0); 82 | vused(); 83 | /* TODO: Compile-time optimization for 'realloc(NULL,42)' --> 'malloc(42)' */ 84 | sym ? DCCVStack_PushSym_vpfun(sym) : vpushv(); 85 | /* ptr, size, realloc */ 86 | vlrot(3); /* realloc, ptr, size */ 87 | vcall(2); /* ret */ 88 | DCCParse_ParPairEnd(); 89 | vwunused(); 90 | } 91 | 92 | LEXPRIV void DCC_PARSE_CALL 93 | DCCParse_BuiltinFree(void) { 94 | struct DCCSym *sym; 95 | /* void __builtin_free(void *ptr); */ 96 | assert(TOK == KWD___builtin_free); 97 | sym = MALL_SYM("free"); 98 | YIELD(); 99 | DCCParse_ParPairBegin(); 100 | DCCParse_Expr1(); 101 | vcast_pt(DCCTYPE_VOID,0); 102 | vused(); 103 | /* TODO: Compile-time optimization for 'free(NULL)' --> '(void)0' */ 104 | sym ? DCCVStack_PushSym_vfun(sym) : vpushv(); 105 | /* ptr, free */ 106 | vswap(); /* free, ptr */ 107 | vcall(1); /* ret */ 108 | DCCParse_ParPairEnd(); 109 | } 110 | 111 | 112 | DCC_DECL_END 113 | 114 | #endif /* !GUARD_DCC_LEXER_BUILTINS_MALLOC_C_INL */ 115 | -------------------------------------------------------------------------------- /src/dcc/linker-elf.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_DCC_LINKER_ELF_H 20 | #define GUARD_DCC_LINKER_ELF_H 1 21 | 22 | #include 23 | #include 24 | #include 25 | #include "../../lib/include/elf.h" 26 | 27 | DCC_DECL_BEGIN 28 | 29 | #ifdef DCC_PRIVATE_API 30 | #define DCC_TARGET_ELF_SIZE DCC_TARGET_SIZEOF_POINTER 31 | #if DCC_TARGET_ELF_SIZE == 4 32 | # define ELF_USE 32 33 | # define Elf(x) Elf32_##x 34 | # define ELF(x) ELF32_##x 35 | #elif DCC_TARGET_ELF_SIZE == 8 36 | # define ELF_USE 64 37 | # define Elf(x) Elf64_##x 38 | # define ELF(x) ELF64_##x 39 | #else 40 | # error FIXME 41 | #endif 42 | #endif 43 | 44 | 45 | 46 | #ifndef DCC_TARGET_ELFCLASS 47 | #if ELF_USE == 32 48 | # define DCC_TARGET_ELFCLASS ELFCLASS32 49 | #else 50 | # define DCC_TARGET_ELFCLASS ELFCLASS64 51 | #endif 52 | #endif /* !DCC_TARGET_ELFCLASS */ 53 | 54 | #ifndef DCC_TARGET_ELFDATA 55 | #if DCC_TARGET_BYTEORDER == 1234 56 | # define DCC_TARGET_ELFDATA ELFDATA2LSB 57 | #elif DCC_TARGET_BYTEORDER == 4321 58 | # define DCC_TARGET_ELFDATA ELFDATA2MSB 59 | #else 60 | # define DCC_TARGET_ELFDATA ELFDATANONE 61 | #endif 62 | #endif /* !DCC_TARGET_ELFDATA */ 63 | 64 | #ifndef DCC_TARGET_ELFVERSION 65 | # define DCC_TARGET_ELFVERSION EV_CURRENT 66 | #endif /* DCC_TARGET_ELFVERSION */ 67 | 68 | #ifndef DCC_TARGET_ELFOSABI 69 | #if DCC_TARGET_OS == DCC_OS_FREEBSD || \ 70 | DCC_TARGET_OS == DCC_OS_FREEBSD_KERNEL 71 | # define DCC_TARGET_ELFOSABI ELFOSABI_FREEBSD 72 | #elif DCC_TARGET_OS == DCC_OS_F_UNIX 73 | # define DCC_TARGET_ELFOSABI ELFOSABI_LINUX 74 | #else 75 | # define DCC_TARGET_ELFOSABI ELFOSABI_SYSV 76 | #endif 77 | #endif /* !DCC_TARGET_ELFOSABI */ 78 | 79 | #ifndef DCC_TARGET_ELF_MACHINE 80 | #if DCC_TARGET_HASM(M_I386) 81 | # define DCC_TARGET_ELF_MACHINE EM_386 82 | #elif DCC_TARGET_HASF(F_X86_64) 83 | # define DCC_TARGET_ELF_MACHINE EM_X86_64 84 | #else 85 | # error FIXME 86 | #endif 87 | #endif /* !DCC_TARGET_ELF_MACHINE */ 88 | 89 | 90 | /* Header for data segment pointed to by 'DT_GNU_HASH'. */ 91 | typedef struct { 92 | Elf32_Word gh_nbuckets; 93 | Elf32_Word gh_symbase; 94 | Elf32_Word gh_bitmask_nwords; 95 | Elf32_Word gh_gnushift; 96 | /* Variable-length vector of 32-bit integers ('gh_bitmask_nwords' elements long) */ 97 | /* array of gnu buckets as 32-bit integers ('gh_nbuckets' elements long) */ 98 | } Elf32_GNUHash; 99 | 100 | typedef struct { 101 | Elf64_Word gh_nbuckets; 102 | Elf64_Word gh_symbase; 103 | Elf64_Word gh_bitmask_nwords; 104 | Elf64_Word gh_gnushift; 105 | /* Variable-length vector of 64-bit integers ('gh_bitmask_nwords' elements long) */ 106 | /* array of gnu buckets as 32-bit integers ('gh_nbuckets' elements long) */ 107 | } Elf64_GNUHash; 108 | 109 | 110 | DCC_DECL_END 111 | 112 | #endif /* !GUARD_DCC_LINKER_ELF_H */ 113 | -------------------------------------------------------------------------------- /src/dcc/tpp-wrapper.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_DCC_TPP_WRAPPER_C 20 | #define GUARD_DCC_TPP_WRAPPER_C 1 21 | #define _GNU_SOURCE /* enable 'memrchr' */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) 36 | #include 37 | #endif 38 | 39 | DCC_DECL_BEGIN 40 | 41 | INTDEF void dcc_voutf(char const *fmt, va_list args); 42 | INTDEF void dcc_outf(char const *fmt, ...); 43 | 44 | PRIVATE void dcc_warnf(char const *fmt, ...) { 45 | va_list args; 46 | va_start(args,fmt); 47 | dcc_voutf(fmt,args); 48 | va_end(args); 49 | } 50 | 51 | PRIVATE int 52 | print_symaddr(struct DCCSymAddr const *__restrict symaddr) { 53 | char const *path; 54 | struct A2lState info; 55 | if (!DCCA2l_LookupAdr(&info,symaddr)) return 0; 56 | path = DCCA2lState_GetPath(&info); 57 | dcc_warnf(TPPLexer_Current->l_flags&TPPLEXER_FLAG_MSVC_MESSAGEFORMAT 58 | ? "%s%s%s(%d,%d) : %s : " : "%s%s%s:%d:%d: %s : ", 59 | path ? path : "",path ? "/" : "", 60 | DCCA2lState_GetFile(&info), 61 | DCCA2lState_GetLine(&info), 62 | DCCA2lState_GetCol(&info), 63 | DCCA2lState_GetName(&info)); 64 | return 1; 65 | } 66 | 67 | PRIVATE int print_sym(struct DCCSym *sym, target_off_t offset) { 68 | struct DCCSymAddr symaddr; 69 | symaddr.sa_sym = sym; 70 | symaddr.sa_off = offset; 71 | return print_symaddr(&symaddr); 72 | } 73 | 74 | 75 | #define TPP_USERLINES \ 76 | {\ 77 | struct DCCSection *sec; \ 78 | case W_UNRESOLVED_REFERENCE: \ 79 | sec = ARG(struct DCCSection *); \ 80 | if (!print_sym(&sec->sc_start,ARG(target_off_t))) goto default_lines; \ 81 | macro_name = NULL; \ 82 | } break; \ 83 | default_lines:; \ 84 | 85 | 86 | DCC_DECL_END 87 | 88 | #undef CURRENT 89 | #undef TOK 90 | #undef TOKEN 91 | #undef KWD 92 | #undef YIELD 93 | #undef HAS 94 | #undef WARN 95 | #undef OK 96 | #undef TPP 97 | #undef pushf 98 | #undef popf 99 | 100 | 101 | #undef PRIVATE 102 | #undef PUBLIC 103 | #undef LOCAL 104 | #undef likely 105 | #undef unlikely 106 | 107 | /* Re-define all private declarations as internal, 108 | * so that other parts of the compiler can re-use 109 | * some of the more useful helper functions. */ 110 | #define PRIVDEF INTDEF 111 | #define PRIVATE INTERN 112 | #define NO_INCLUDE_WINDOWS_H 113 | 114 | /* Custom warning print callback (used for adding colors). */ 115 | #define TPP_WARNF dcc_warnf 116 | 117 | #include "../tpp/tpp.c" 118 | 119 | #endif /* !GUARD_DCC_TPP_WRAPPER_C */ 120 | -------------------------------------------------------------------------------- /src/dcc/unit-export.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_DCC_UNIT_EXPORT_C 20 | #define GUARD_DCC_UNIT_EXPORT_C 1 21 | 22 | #define DCC(x) x 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "unit-export.h" 30 | 31 | DCC_DECL_BEGIN 32 | 33 | PUBLIC void DCCUNIT_EXPORTCALL 34 | DCCUnit_Export(struct DCCExpDef *__restrict def, 35 | char const *__restrict filename) { 36 | stream_t fd = s_openw(filename); 37 | if (fd == TPP_STREAM_INVALID) 38 | WARN(W_EXPORT_CANNOT_OPEN,filename); 39 | else DCCUnit_ExportStream(def,fd); 40 | s_close(fd); 41 | } 42 | 43 | PUBLIC void DCCUNIT_EXPORTCALL 44 | DCCUnit_ExportStream(struct DCCExpDef *__restrict def, 45 | stream_t fd) { 46 | assert(def); 47 | /* XXX: Format switch? */ 48 | DCCUnit_ExportElf(def,fd); 49 | } 50 | 51 | DCC_DECL_END 52 | 53 | #ifndef __INTELLISENSE__ 54 | #include "unit-export-elf.c.inl" 55 | #endif 56 | 57 | #endif /* !GUARD_DCC_UNIT_EXPORT_C */ 58 | -------------------------------------------------------------------------------- /src/dcc/unit-export.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_DCC_UNIT_EXPORT_H 20 | #define GUARD_DCC_UNIT_EXPORT_H 1 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | DCC_DECL_BEGIN 28 | 29 | INTDEF void DCCUNIT_EXPORTCALL 30 | DCCUnit_ExportElf(struct DCCExpDef *__restrict def, 31 | DCC(stream_t) fd); 32 | 33 | DCC_DECL_END 34 | 35 | #endif /* !GUARD_DCC_UNIT_EXPORT_H */ 36 | -------------------------------------------------------------------------------- /src/dcc/unit-import-source.c.inl: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_DCC_UNIT_IMPORT_SOURCE_C_INL 20 | #define GUARD_DCC_UNIT_IMPORT_SOURCE_C_INL 1 21 | 22 | #define DCC(x) x 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "unit-import.h" 32 | 33 | DCC_DECL_BEGIN 34 | 35 | PRIVATE void load_std_sections(void) { 36 | unit.u_text = DCCUnit_NewSecs(".text",DCC_SYMFLAG_SEC_X|DCC_SYMFLAG_SEC_R); 37 | unit.u_data = DCCUnit_NewSecs(".data",DCC_SYMFLAG_SEC_R); 38 | unit.u_bss = DCCUnit_NewSecs(".bss",DCC_SYMFLAG_SEC_R|DCC_SYMFLAG_SEC_W); 39 | unit.u_string = DCCUnit_NewSecs(".string",DCC_SYMFLAG_SEC_R|DCC_SYMFLAG_SEC_M); 40 | /* NOTE: Symbols within '.dbgstr' cannot be merged! */ 41 | unit.u_dbgstr = DCCUnit_NewSecs(A2L_STRING_SECTION,DCC_SYMFLAG_SEC_R); 42 | } 43 | 44 | 45 | INTERN void DCCUNIT_IMPORTCALL 46 | DCCUnit_LoadSrc_C(struct DCCLibDef *__restrict def) { 47 | (void)def; 48 | compiler.c_flags |= (DCC_COMPILER_FLAG_NOCGEN); 49 | /*CURRENT.l_flags |= (TPPLEXER_FLAG_TERMINATE_STRING_LF);*/ 50 | 51 | /* Load standard sections. */ 52 | load_std_sections(); 53 | CURRENT.l_extokens &= (TPPLEXER_TOKEN_EQUALBINOP); 54 | CURRENT.l_extokens |= (TPPLEXER_TOKEN_LANG_C| 55 | TPPLEXER_TOKEN_TILDETILDE); 56 | /* Yield the initial token. */ 57 | TPPLexer_Yield(); 58 | 59 | /* Select the text section and begin compiling. */ 60 | DCCUnit_SetCurr(unit.u_text); 61 | DCCParse_AllGlobal(); 62 | DCCUnit_SetCurr(NULL); 63 | } 64 | 65 | 66 | INTERN void DCCUNIT_IMPORTCALL 67 | DCCUnit_LoadSrc_ASM(struct DCCLibDef *__restrict def) { 68 | (void)def; 69 | CURRENT.l_flags |= (TPPLEXER_FLAG_ASM_COMMENTS| 70 | /*TPPLEXER_FLAG_TERMINATE_STRING_LF|*/ 71 | TPPLEXER_FLAG_COMMENT_NOOWN_LF| 72 | TPPLEXER_FLAG_WANTLF); 73 | CURRENT.l_extokens = TPPLEXER_TOKEN_LANG_ASM; 74 | compiler.c_flags |= DCC_COMPILER_FLAG_INASM; 75 | load_std_sections(); 76 | 77 | /* Yield the initial token. */ 78 | TPPLexer_Yield(); 79 | 80 | /* Select the text section and begin compiling. */ 81 | DCCUnit_SetCurr(unit.u_text); 82 | 83 | while (TOK > 0) { 84 | unsigned long old_num = TOKEN.t_num; 85 | DCCParse_AsmInstr(); 86 | if (old_num == TOKEN.t_num) YIELD(); 87 | } 88 | DCCUnit_SetCurr(NULL); 89 | } 90 | 91 | 92 | DCC_DECL_END 93 | 94 | #endif /* !GUARD_DCC_UNIT_IMPORT_SOURCE_C_INL */ 95 | -------------------------------------------------------------------------------- /src/drt/drt-user.c.inl: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_DRT_DRT_USER_C_INL 20 | #define GUARD_DRT_DRT_USER_C_INL 1 21 | 22 | #include 23 | #include 24 | #if DCC_CONFIG_HAVE_DRT 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "drt.h" 31 | 32 | #include 33 | 34 | DCC_DECL_BEGIN 35 | 36 | 37 | #if !!(DCC_HOST_CPUF&DCC_CPUF_X86_64) 38 | #define XCX rcx 39 | #define XDX rdx 40 | #else 41 | #define XCX ecx 42 | #define XDX edx 43 | #endif 44 | #ifdef _MSC_VER 45 | INTERN void DRT_USER __declspec(naked) 46 | DCC_ATTRIBUTE_FASTCALL DRT_U_ProbeN(void DRT_USER *p, size_t n) { 47 | (void)p; (void)n; 48 | /* TODO: Test all the bytes! */ 49 | __asm pushfd; 50 | __asm test dword ptr [XCX], 0x0; 51 | __asm popfd; 52 | __asm ret; 53 | } 54 | #else 55 | INTERN void DRT_USER DCC_ATTRIBUTE_FASTCALL 56 | DRT_U_ProbeN(void DRT_USER *p, size_t n); 57 | 58 | #if defined(__ELF__) || \ 59 | (!defined(__PE__) && (DCC_HOST_OS != DCC_OS_WINDOWS)) 60 | __asm__(".global DRT_U_ProbeN\n"); 61 | __asm__(".hidden DRT_U_ProbeN\n"); 62 | #endif 63 | __asm__("DRT_U_ProbeN:\n" 64 | /* TODO: Test all the bytes! */ 65 | " pushfl\n" 66 | " testl $0, (%" DCC_PP_STR(XCX) ")\n" 67 | " popfl\n" 68 | " ret\n" 69 | ".size DRT_U_ProbeN, . - DRT_U_ProbeN\n"); 70 | #endif 71 | #undef XDX 72 | #undef XCX 73 | 74 | 75 | #define EVENT drt.rt_event 76 | 77 | INTERN void DRT_USER DRT_U_WaitEvent(uint32_t code) { 78 | assert(EVENT.ue_code == DRT_EVENT_NONE); 79 | assert(code != DRT_EVENT_NONE); 80 | EVENT.ue_code = code; 81 | MEMORY_BARRIER(); 82 | if (drt.rt_flags&DRT_FLAG_JOINING2) { 83 | /* The compiler thread is no more. - We're in charge now! */ 84 | /* Really hacky: Do the synchronization ourself. */ 85 | if (DRT_H_Sync(1) == DRT_SYNC_UNRESOLVED) { 86 | /* Exit the thread if nothing else can be done! 87 | * NOTE: Warnings were already emit by 'DRT_H_Sync'. */ 88 | ExitThread(1); 89 | } 90 | } else { 91 | #if 0 /*< Don't do this to prevent deadlocks after a sync was triggered inside of printf() & friends. */ 92 | /* Flush various global buffers before starting to wait. 93 | * >> To be honest, this is mainly done to ensure 94 | * the printf() example working flawlessly. */ 95 | fflush(stdout); 96 | fflush(stderr); 97 | #endif 98 | if (!DCC_semaphore_wait(EVENT.ue_sem)) { 99 | fprintf(stderr,"Failed to wait for DRT event (%d)\n",(int)GetLastError()); 100 | ExitThread(1); 101 | } 102 | } 103 | } 104 | 105 | INTERN int DRT_USER 106 | DRT_U_FetchText(void DRT_USER *addr) { 107 | EVENT.ue_text.te_addr = addr; 108 | EVENT.ue_text.te_relc_ok = 0; 109 | EVENT.ue_text.te_size_ok = 0; 110 | EVENT.ue_text.te_size_total = 0; 111 | DRT_U_WaitEvent(DRT_EVENT_MIRROR_TEXT); 112 | return EVENT.ue_text.te_relc_ok || 113 | EVENT.ue_text.te_size_ok/* || 114 | EVENT.ue_text.te_size_total*/; 115 | } 116 | INTERN int DRT_USER 117 | DRT_U_FetchData(void DRT_USER *addr, size_t size) { 118 | EVENT.ue_data.de_addr = addr; 119 | EVENT.ue_data.de_size = size; 120 | DRT_U_WaitEvent(DRT_EVENT_MIRROR_DATA); 121 | return /*EVENT.ue_data.de_size &&*/ 122 | EVENT.ue_data.de_size != (size_t)-1; 123 | } 124 | INTERN int DRT_USER 125 | DRT_U_FetchRelo(void DRT_USER *addr, size_t size) { 126 | EVENT.ue_relo.re_addr = addr; 127 | EVENT.ue_relo.re_size = size; 128 | DRT_U_WaitEvent(DRT_EVENT_MIRROR_RELO); 129 | return EVENT.ue_relo.re_size != 0; 130 | } 131 | 132 | 133 | INTERN target_bool_t DRT_USER 134 | DRT_U_Addr2line(void DRT_USER *ip, target_lc_t *info) { 135 | EVENT.ue_a2l.ae_addr = ip; 136 | DRT_U_WaitEvent(DRT_EVENT_ADDR2LINE); 137 | if (info) { 138 | info->lc_path = EVENT.ue_a2l.ae_path; 139 | info->lc_file = EVENT.ue_a2l.ae_file; 140 | info->lc_name = EVENT.ue_a2l.ae_name; 141 | info->lc_line = EVENT.ue_a2l.ae_line; 142 | info->lc_col = EVENT.ue_a2l.ae_col; 143 | } 144 | return (EVENT.ue_a2l.ae_addr != DRT_EVENT_ADDR2LINE_FAULT) && 145 | (EVENT.ue_a2l.ae_addr != DRT_EVENT_ADDR2LINE_NOINFO); 146 | } 147 | 148 | 149 | #undef EVENT 150 | 151 | 152 | DCC_DECL_END 153 | #endif /* DCC_CONFIG_HAVE_DRT */ 154 | 155 | #endif /* !GUARD_DRT_DRT_USER_C_INL */ 156 | -------------------------------------------------------------------------------- /src/drt/drt.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Griefer@Work * 2 | * * 3 | * This software is provided 'as-is', without any express or implied * 4 | * warranty. In no event will the authors be held liable for any damages * 5 | * arising from the use of this software. * 6 | * * 7 | * Permission is granted to anyone to use this software for any purpose, * 8 | * including commercial applications, and to alter it and redistribute it * 9 | * freely, subject to the following restrictions: * 10 | * * 11 | * 1. The origin of this software must not be misrepresented; you must not * 12 | * claim that you wrote the original software. If you use this software * 13 | * in a product, an acknowledgement in the product documentation would be * 14 | * appreciated but is not required. * 15 | * 2. Altered source versions must be plainly marked as such, and must not be * 16 | * misrepresented as being the original software. * 17 | * 3. This notice may not be removed or altered from any source distribution. * 18 | */ 19 | #ifndef GUARD_SRC_DRT_DRT_H 20 | #define GUARD_SRC_DRT_DRT_H 1 21 | 22 | #include 23 | #include 24 | #if DCC_CONFIG_HAVE_DRT 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #ifdef _MSC_VER 31 | # include 32 | # pragma intrinsic(_ReadWriteBarrier) 33 | # define MEMORY_BARRIER _ReadWriteBarrier 34 | #else 35 | # define MEMORY_BARRIER() __asm__ __volatile__("" : : : "memory"); 36 | #endif 37 | 38 | #if !!(DCC_HOST_OS&DCC_OS_F_WINDOWS) 39 | # include 40 | #else 41 | # include 42 | # include 43 | # define GetLastError() errno 44 | # define ExitThread(code) pthread_exit((void *)(code)) 45 | #if __has_include() || \ 46 | defined(HAVE_ASM_CACHECTL) || \ 47 | defined(HAVE_INCLUDE_ASM_CACHECTL) 48 | # include 49 | # define FlushInstructionCache(h,p,s) cacheflush(p,s,ICACHE) 50 | #else 51 | # define NO_FlushInstructionCache 52 | # define FlushInstructionCache(h,p,s) (void)0 53 | #endif 54 | #endif 55 | 56 | 57 | DCC_DECL_BEGIN 58 | 59 | DCCFUN int DCC_ATTRIBUTE_FASTCALL DRT_H_Sync(int warn_failure); 60 | DCCFUN int DCC_ATTRIBUTE_FASTCALL DRT_H_SyncAll(target_int_t *exitcode); 61 | 62 | /* Find and return the address associated with the given user-section address 'addr'. */ 63 | INTDEF struct DCCSection *DRT_FindUserSection(void DRT_USER *addr); 64 | 65 | INTDEF int 66 | DCCSection_RTMirrorData(struct DCCSection *__restrict self, 67 | target_ptr_t addr, target_siz_t size, 68 | target_siz_t *__restrict psize_ok, 69 | int warn_failure); 70 | 71 | /* Try to resolve the given relocation 'rel' from 'sec', 72 | * targeting memory in 'uaddr' with section data from 'haddr'. */ 73 | INTDEF int 74 | DRT_ResolveRel(uint8_t DRT_USER *__restrict uaddr, 75 | uint8_t DRT_HOST *__restrict haddr, 76 | struct DCCRel const *__restrict rel, 77 | struct DCCSection const *__restrict sec, 78 | int warn_failure); 79 | 80 | /* Setup a faulty relocation that will trigger 81 | * a DRT data fetch when dereferenced. */ 82 | INTDEF void 83 | DRT_FaultRel(uint8_t DRT_USER *__restrict uaddr, 84 | struct DCCRel const *__restrict rel); 85 | 86 | #define DRT_U_STACKRESERVE 0x1000 /* Amount of user-stack bytes to reserve for DRT itself. */ 87 | #define DRT_U_FILLER 0xf4 /* hlt - Will raise a #GP because DCC isn't meant to run in kernel space. */ 88 | 89 | /* User-code functions. 90 | * All of these functions can be called either 91 | * directly, or indirectly from DRT user-space. */ 92 | 93 | /* Signal an event 'code' and wait for its completion. */ 94 | INTDEF void DRT_USER DRT_U_WaitEvent(uint32_t code); 95 | 96 | /* Fetch data & relocations within the given address range. 97 | * @param: min_size: The min amount of bytes to fetch. (ZERO isn't allowed) 98 | * @return: 0/1: Indicate success/failure of fetching data. */ 99 | INTDEF int DRT_USER DRT_U_FetchText(void DRT_USER *addr); 100 | INTDEF int DRT_USER DRT_U_FetchData(void DRT_USER *addr, size_t min_size); 101 | INTDEF int DRT_USER DRT_U_FetchRelo(void DRT_USER *addr, size_t size); 102 | 103 | #ifndef DCC_NO_ATTRIBUTE_FASTCALL 104 | INTDEF void DRT_USER DCC_ATTRIBUTE_FASTCALL DRT_U_ProbeN(void DRT_USER *p, size_t n); 105 | #else 106 | INTDEF void DRT_USER DRT_U_ProbeN(void); 107 | #endif 108 | 109 | /* Using the value in EAX as return value, exit the calling thread. */ 110 | INTDEF void DRT_U_ThreadExit(void); 111 | 112 | 113 | typedef struct { 114 | char DRT_USER const *lc_path; /*< [0..1] Path of the associated source file (Don't print when NULL). */ 115 | char DRT_USER const *lc_file; /*< [0..1] File name of the associated source file. */ 116 | char DRT_USER const *lc_name; /*< [0..1] Name of the surrounding function symbol. */ 117 | void *lc_pad1[1]; 118 | target_int_t lc_line; /*< 1-based source line, or ZERO(0) when unknown. */ 119 | target_int_t lc_col; /*< 1-based source column, or ZERO(0) when unknown. */ 120 | void *lc_pad2[2]; 121 | } target_lc_t; 122 | 123 | /* The function that '_addr2line' from is linked against in DRT mode. */ 124 | INTDEF target_bool_t DRT_USER DRT_U_Addr2line(void DRT_USER *ip, target_lc_t *info); 125 | 126 | 127 | DCC_DECL_END 128 | #endif /* DCC_CONFIG_HAVE_DRT */ 129 | 130 | #endif /* !GUARD_SRC_DRT_DRT_H */ 131 | -------------------------------------------------------------------------------- /src/tpp/tpp.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrieferAtWork/dcc/e70803aef1d7dc83ecedc6134c3e7902e6b6bbca/src/tpp/tpp.c --------------------------------------------------------------------------------