typenative 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +2 -2
- package/package.json +1 -1
- package/tcc/doc/tcc-doc.html +2418 -0
- package/tcc/doc/tcc-win32.txt +156 -0
- package/tcc/examples/dll.c +12 -0
- package/tcc/examples/fib.c +23 -0
- package/tcc/examples/hello_dll.c +19 -0
- package/tcc/examples/hello_win.c +163 -0
- package/tcc/examples/libtcc_test.c +76 -0
- package/tcc/include/_mingw.h +139 -0
- package/tcc/include/assert.h +54 -0
- package/tcc/include/conio.h +409 -0
- package/tcc/include/ctype.h +281 -0
- package/tcc/include/dir.h +31 -0
- package/tcc/include/direct.h +68 -0
- package/tcc/include/dirent.h +135 -0
- package/tcc/include/dos.h +55 -0
- package/tcc/include/errno.h +75 -0
- package/tcc/include/excpt.h +123 -0
- package/tcc/include/fcntl.h +52 -0
- package/tcc/include/fenv.h +108 -0
- package/tcc/include/float.h +57 -0
- package/tcc/include/inttypes.h +297 -0
- package/tcc/include/io.h +418 -0
- package/tcc/include/limits.h +111 -0
- package/tcc/include/locale.h +91 -0
- package/tcc/include/malloc.h +175 -0
- package/tcc/include/math.h +777 -0
- package/tcc/include/mem.h +13 -0
- package/tcc/include/memory.h +40 -0
- package/tcc/include/process.h +176 -0
- package/tcc/include/sec_api/conio_s.h +42 -0
- package/tcc/include/sec_api/crtdbg_s.h +19 -0
- package/tcc/include/sec_api/io_s.h +33 -0
- package/tcc/include/sec_api/mbstring_s.h +52 -0
- package/tcc/include/sec_api/search_s.h +25 -0
- package/tcc/include/sec_api/stdio_s.h +145 -0
- package/tcc/include/sec_api/stdlib_s.h +67 -0
- package/tcc/include/sec_api/stralign_s.h +30 -0
- package/tcc/include/sec_api/string_s.h +41 -0
- package/tcc/include/sec_api/sys/timeb_s.h +34 -0
- package/tcc/include/sec_api/tchar_s.h +266 -0
- package/tcc/include/sec_api/time_s.h +61 -0
- package/tcc/include/sec_api/wchar_s.h +128 -0
- package/tcc/include/setjmp.h +160 -0
- package/tcc/include/share.h +28 -0
- package/tcc/include/signal.h +63 -0
- package/tcc/include/stdarg.h +41 -0
- package/tcc/include/stdbool.h +10 -0
- package/tcc/include/stddef.h +28 -0
- package/tcc/include/stdint.h +209 -0
- package/tcc/include/stdio.h +429 -0
- package/tcc/include/stdlib.h +580 -0
- package/tcc/include/string.h +164 -0
- package/tcc/include/sys/fcntl.h +13 -0
- package/tcc/include/sys/file.h +14 -0
- package/tcc/include/sys/locking.h +30 -0
- package/tcc/include/sys/stat.h +290 -0
- package/tcc/include/sys/time.h +69 -0
- package/tcc/include/sys/timeb.h +133 -0
- package/tcc/include/sys/types.h +118 -0
- package/tcc/include/sys/unistd.h +14 -0
- package/tcc/include/sys/utime.h +146 -0
- package/tcc/include/tcclib.h +78 -0
- package/tcc/include/tchar.h +1102 -0
- package/tcc/include/time.h +287 -0
- package/tcc/include/vadefs.h +11 -0
- package/tcc/include/values.h +4 -0
- package/tcc/include/varargs.h +12 -0
- package/tcc/include/wchar.h +871 -0
- package/tcc/include/wctype.h +172 -0
- package/tcc/include/winapi/basetsd.h +149 -0
- package/tcc/include/winapi/basetyps.h +85 -0
- package/tcc/include/winapi/guiddef.h +151 -0
- package/tcc/include/winapi/intrin.h +11 -0
- package/tcc/include/winapi/poppack.h +8 -0
- package/tcc/include/winapi/pshpack1.h +8 -0
- package/tcc/include/winapi/pshpack2.h +8 -0
- package/tcc/include/winapi/pshpack4.h +8 -0
- package/tcc/include/winapi/pshpack8.h +8 -0
- package/tcc/include/winapi/reason.h +80 -0
- package/tcc/include/winapi/specstrings.h +7 -0
- package/tcc/include/winapi/stralign.h +154 -0
- package/tcc/include/winapi/tvout.h +79 -0
- package/tcc/include/winapi/winbase.h +2951 -0
- package/tcc/include/winapi/wincon.h +301 -0
- package/tcc/include/winapi/windef.h +293 -0
- package/tcc/include/winapi/windows.h +123 -0
- package/tcc/include/winapi/winerror.h +3166 -0
- package/tcc/include/winapi/wingdi.h +4080 -0
- package/tcc/include/winapi/winnetwk.h +476 -0
- package/tcc/include/winapi/winnls.h +765 -0
- package/tcc/include/winapi/winnt.h +5770 -0
- package/tcc/include/winapi/winreg.h +272 -0
- package/tcc/include/winapi/winuser.h +5651 -0
- package/tcc/include/winapi/winver.h +160 -0
- package/tcc/lib/gdi32.def +337 -0
- package/tcc/lib/kernel32.def +765 -0
- package/tcc/lib/libtcc1.a +0 -0
- package/tcc/lib/msvcrt.def +1399 -0
- package/tcc/lib/user32.def +654 -0
- package/tcc/libtcc/libtcc.def +38 -0
- package/tcc/libtcc/libtcc.h +100 -0
- package/tcc/libtcc.dll +0 -0
- package/tcc/tcc.exe +0 -0
- package/tcc/tiny_impdef.exe +0 -0
- package/tcc/tiny_libmaker.exe +0 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
|
|
2
|
+
TinyCC
|
|
3
|
+
======
|
|
4
|
+
|
|
5
|
+
This file contains specific information for usage of TinyCC
|
|
6
|
+
under MS-Windows. See tcc-doc.html to have all the features.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Installation from the binary ZIP package:
|
|
10
|
+
-----------------------------------------
|
|
11
|
+
Unzip the package to a directory of your choice.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Set the system PATH:
|
|
15
|
+
--------------------
|
|
16
|
+
To be able to invoke the compiler from everywhere on your computer by
|
|
17
|
+
just typing "tcc", please add the directory containing tcc.exe to your
|
|
18
|
+
system PATH.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
Examples:
|
|
22
|
+
---------
|
|
23
|
+
Open a console window (DOS box) and 'cd' to the examples directory.
|
|
24
|
+
|
|
25
|
+
For the 'Fibonacci' example type:
|
|
26
|
+
|
|
27
|
+
tcc fib.c
|
|
28
|
+
|
|
29
|
+
For the 'Hello Windows' GUI example type:
|
|
30
|
+
|
|
31
|
+
tcc hello_win.c
|
|
32
|
+
|
|
33
|
+
For the 'Hello DLL' example type
|
|
34
|
+
|
|
35
|
+
tcc -shared dll.c
|
|
36
|
+
tiny_impdef dll.dll (optional)
|
|
37
|
+
tcc hello_dll.c dll.def
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
Using libtcc as JIT compiler in your program
|
|
41
|
+
--------------------------------------------
|
|
42
|
+
Check out the 'libtcc_test' example:
|
|
43
|
+
|
|
44
|
+
- Running it from source:
|
|
45
|
+
tcc -I libtcc libtcc/libtcc.def -run examples/libtcc_test.c
|
|
46
|
+
|
|
47
|
+
- Compiling with TCC:
|
|
48
|
+
tcc examples/libtcc_test.c -I libtcc libtcc/libtcc.def
|
|
49
|
+
|
|
50
|
+
- Compiling with MinGW:
|
|
51
|
+
gcc examples/libtcc_test.c -I libtcc libtcc.dll
|
|
52
|
+
|
|
53
|
+
- Compiling with MSVC:
|
|
54
|
+
lib /def:libtcc\libtcc.def /out:libtcc.lib
|
|
55
|
+
cl /MD examples/libtcc_test.c -I libtcc libtcc.lib
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
Import Definition Files:
|
|
59
|
+
------------------------
|
|
60
|
+
To link with Windows system DLLs, TCC uses import definition
|
|
61
|
+
files (.def) instead of libraries.
|
|
62
|
+
|
|
63
|
+
The included 'tiny_impdef' program may be used to make additional
|
|
64
|
+
.def files for any DLL. For example:
|
|
65
|
+
|
|
66
|
+
tiny_impdef.exe opengl32.dll
|
|
67
|
+
|
|
68
|
+
Put opengl32.def into the tcc/lib directory. Specify -lopengl32 at
|
|
69
|
+
the TCC commandline to link a program that uses opengl32.dll.
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
Header Files:
|
|
73
|
+
-------------
|
|
74
|
+
The system header files (except _mingw.h) are from the MinGW
|
|
75
|
+
distribution:
|
|
76
|
+
|
|
77
|
+
http://www.mingw.org/
|
|
78
|
+
|
|
79
|
+
From the windows headers, only a minimal set is included. If you need
|
|
80
|
+
more, get MinGW's "w32api" package. Extract the files from "include"
|
|
81
|
+
into your "tcc/include/winapi" directory.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
Resource Files:
|
|
85
|
+
---------------
|
|
86
|
+
TCC can link windows resources in coff format as generated by MinGW's
|
|
87
|
+
windres.exe. For example:
|
|
88
|
+
|
|
89
|
+
windres -O coff app.rc -o appres.o
|
|
90
|
+
tcc app.c appres.o -o app.exe
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
Tiny Libmaker:
|
|
94
|
+
--------------
|
|
95
|
+
The included tiny_libmaker tool by Timovj Lahde can be used as
|
|
96
|
+
'ar' replacement to make a library from several object files:
|
|
97
|
+
|
|
98
|
+
tiny_libmaker [rcs] library objectfiles ...
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
Compilation from source:
|
|
102
|
+
------------------------
|
|
103
|
+
* You can use the MinGW and MSYS tools available at
|
|
104
|
+
|
|
105
|
+
http://www.mingw.org
|
|
106
|
+
|
|
107
|
+
Untar the TCC archive and type in the MSYS shell:
|
|
108
|
+
|
|
109
|
+
./configure [--prefix installpath]
|
|
110
|
+
make
|
|
111
|
+
make install
|
|
112
|
+
|
|
113
|
+
The default install location is c:\Program Files\tcc
|
|
114
|
+
|
|
115
|
+
* Alternatively you can compile TCC with just GCC from MinGW using
|
|
116
|
+
|
|
117
|
+
build-tcc.bat (from the win32 directory)
|
|
118
|
+
|
|
119
|
+
To install, copy the entire contents of the win32 directory to
|
|
120
|
+
where you want.
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
Limitations:
|
|
124
|
+
------------
|
|
125
|
+
- On the object file level, currently TCC supports only the ELF format,
|
|
126
|
+
not COFF as used by MinGW and MSVC. It is not possible to exchange
|
|
127
|
+
object files or libraries between TCC and these compilers. However
|
|
128
|
+
libraries for TCC from objects by TCC can be made using tiny_libmaker
|
|
129
|
+
or MinGW's ar.
|
|
130
|
+
|
|
131
|
+
- No leading underscore is generated in the ELF symbols.
|
|
132
|
+
|
|
133
|
+
- Bounds checking (option -b) is not supported on 64-bit OS.
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
Documentation and License:
|
|
137
|
+
--------------------------
|
|
138
|
+
TCC is distributed under the GNU Lesser General Public License. (See
|
|
139
|
+
COPYING file or http://www.gnu.org/licenses/lgpl-2.1.html)
|
|
140
|
+
|
|
141
|
+
TinyCC homepage is at:
|
|
142
|
+
|
|
143
|
+
http://fabrice.bellard.free.fr/tcc/
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
WinAPI Help and 3rd-party tools:
|
|
147
|
+
--------------------------------
|
|
148
|
+
The Windows API documentation (Win95) in a single .hlp file is
|
|
149
|
+
available on the lcc-win32 site as "win32hlp.exe" or from other
|
|
150
|
+
locations as "win32hlp_big.zip".
|
|
151
|
+
|
|
152
|
+
A nice RAD tool to create windows resources (dialog boxes etc.) is
|
|
153
|
+
"ResEd", available at the RadASM website.
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
--- grischka
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//+---------------------------------------------------------------------------
|
|
2
|
+
//
|
|
3
|
+
// dll.c - Windows DLL example - dynamically linked part
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
#include <windows.h>
|
|
7
|
+
#define DLL_EXPORT __declspec(dllexport)
|
|
8
|
+
|
|
9
|
+
DLL_EXPORT void HelloWorld (void)
|
|
10
|
+
{
|
|
11
|
+
MessageBox (0, "Hello World!", "From DLL", MB_ICONINFORMATION);
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#include <stdio.h>
|
|
2
|
+
|
|
3
|
+
int fib(n)
|
|
4
|
+
{
|
|
5
|
+
if (n <= 2)
|
|
6
|
+
return 1;
|
|
7
|
+
else
|
|
8
|
+
return fib(n-1) + fib(n-2);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
int main(int argc, char **argv)
|
|
12
|
+
{
|
|
13
|
+
int n;
|
|
14
|
+
if (argc < 2) {
|
|
15
|
+
printf("usage: fib n\n"
|
|
16
|
+
"Compute nth Fibonacci number\n");
|
|
17
|
+
return 1;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
n = atoi(argv[1]);
|
|
21
|
+
printf("fib(%d) = %d\n", n, fib(n));
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//+---------------------------------------------------------------------------
|
|
2
|
+
//
|
|
3
|
+
// HELLO_DLL.C - Windows DLL example - main application part
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
#include <windows.h>
|
|
7
|
+
|
|
8
|
+
void HelloWorld (void);
|
|
9
|
+
|
|
10
|
+
int WINAPI WinMain(
|
|
11
|
+
HINSTANCE hInstance,
|
|
12
|
+
HINSTANCE hPrevInstance,
|
|
13
|
+
LPSTR lpCmdLine,
|
|
14
|
+
int nCmdShow)
|
|
15
|
+
{
|
|
16
|
+
HelloWorld();
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
//+---------------------------------------------------------------------------
|
|
2
|
+
//
|
|
3
|
+
// HELLO_WIN.C - Windows GUI 'Hello World!' Example
|
|
4
|
+
//
|
|
5
|
+
//+---------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
#include <windows.h>
|
|
8
|
+
|
|
9
|
+
#define APPNAME "HELLO_WIN"
|
|
10
|
+
|
|
11
|
+
char szAppName[] = APPNAME; // The name of this application
|
|
12
|
+
char szTitle[] = APPNAME; // The title bar text
|
|
13
|
+
const char *pWindowText;
|
|
14
|
+
|
|
15
|
+
void CenterWindow(HWND hWnd);
|
|
16
|
+
|
|
17
|
+
//+---------------------------------------------------------------------------
|
|
18
|
+
//
|
|
19
|
+
// Function: WndProc
|
|
20
|
+
//
|
|
21
|
+
// Synopsis: very unusual type of function - gets called by system to
|
|
22
|
+
// process windows messages.
|
|
23
|
+
//
|
|
24
|
+
// Arguments: same as always.
|
|
25
|
+
//----------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
28
|
+
{
|
|
29
|
+
switch (message) {
|
|
30
|
+
|
|
31
|
+
// ----------------------- first and last
|
|
32
|
+
case WM_CREATE:
|
|
33
|
+
CenterWindow(hwnd);
|
|
34
|
+
break;
|
|
35
|
+
|
|
36
|
+
case WM_DESTROY:
|
|
37
|
+
PostQuitMessage(0);
|
|
38
|
+
break;
|
|
39
|
+
|
|
40
|
+
// ----------------------- get out of it...
|
|
41
|
+
case WM_RBUTTONUP:
|
|
42
|
+
DestroyWindow(hwnd);
|
|
43
|
+
break;
|
|
44
|
+
|
|
45
|
+
case WM_KEYDOWN:
|
|
46
|
+
if (VK_ESCAPE == wParam)
|
|
47
|
+
DestroyWindow(hwnd);
|
|
48
|
+
break;
|
|
49
|
+
|
|
50
|
+
// ----------------------- display our minimal info
|
|
51
|
+
case WM_PAINT:
|
|
52
|
+
{
|
|
53
|
+
PAINTSTRUCT ps;
|
|
54
|
+
HDC hdc;
|
|
55
|
+
RECT rc;
|
|
56
|
+
hdc = BeginPaint(hwnd, &ps);
|
|
57
|
+
|
|
58
|
+
GetClientRect(hwnd, &rc);
|
|
59
|
+
SetTextColor(hdc, RGB(240,240,96));
|
|
60
|
+
SetBkMode(hdc, TRANSPARENT);
|
|
61
|
+
DrawText(hdc, pWindowText, -1, &rc, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
|
|
62
|
+
|
|
63
|
+
EndPaint(hwnd, &ps);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ----------------------- let windows do all other stuff
|
|
68
|
+
default:
|
|
69
|
+
return DefWindowProc(hwnd, message, wParam, lParam);
|
|
70
|
+
}
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//+---------------------------------------------------------------------------
|
|
75
|
+
//
|
|
76
|
+
// Function: WinMain
|
|
77
|
+
//
|
|
78
|
+
// Synopsis: standard entrypoint for GUI Win32 apps
|
|
79
|
+
//
|
|
80
|
+
//----------------------------------------------------------------------------
|
|
81
|
+
int APIENTRY WinMain(
|
|
82
|
+
HINSTANCE hInstance,
|
|
83
|
+
HINSTANCE hPrevInstance,
|
|
84
|
+
LPSTR lpCmdLine,
|
|
85
|
+
int nCmdShow
|
|
86
|
+
)
|
|
87
|
+
{
|
|
88
|
+
MSG msg;
|
|
89
|
+
WNDCLASS wc;
|
|
90
|
+
HWND hwnd;
|
|
91
|
+
|
|
92
|
+
pWindowText = lpCmdLine[0] ? lpCmdLine : "Hello Windows!";
|
|
93
|
+
|
|
94
|
+
// Fill in window class structure with parameters that describe
|
|
95
|
+
// the main window.
|
|
96
|
+
|
|
97
|
+
ZeroMemory(&wc, sizeof wc);
|
|
98
|
+
wc.hInstance = hInstance;
|
|
99
|
+
wc.lpszClassName = szAppName;
|
|
100
|
+
wc.lpfnWndProc = (WNDPROC)WndProc;
|
|
101
|
+
wc.style = CS_DBLCLKS|CS_VREDRAW|CS_HREDRAW;
|
|
102
|
+
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
|
103
|
+
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
|
104
|
+
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
|
105
|
+
|
|
106
|
+
if (FALSE == RegisterClass(&wc))
|
|
107
|
+
return 0;
|
|
108
|
+
|
|
109
|
+
// create the browser
|
|
110
|
+
hwnd = CreateWindow(
|
|
111
|
+
szAppName,
|
|
112
|
+
szTitle,
|
|
113
|
+
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
|
|
114
|
+
CW_USEDEFAULT,
|
|
115
|
+
CW_USEDEFAULT,
|
|
116
|
+
360,//CW_USEDEFAULT,
|
|
117
|
+
240,//CW_USEDEFAULT,
|
|
118
|
+
0,
|
|
119
|
+
0,
|
|
120
|
+
hInstance,
|
|
121
|
+
0);
|
|
122
|
+
|
|
123
|
+
if (NULL == hwnd)
|
|
124
|
+
return 0;
|
|
125
|
+
|
|
126
|
+
// Main message loop:
|
|
127
|
+
while (GetMessage(&msg, NULL, 0, 0) > 0) {
|
|
128
|
+
TranslateMessage(&msg);
|
|
129
|
+
DispatchMessage(&msg);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return msg.wParam;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//+---------------------------------------------------------------------------
|
|
136
|
+
|
|
137
|
+
//+---------------------------------------------------------------------------
|
|
138
|
+
|
|
139
|
+
void CenterWindow(HWND hwnd_self)
|
|
140
|
+
{
|
|
141
|
+
HWND hwnd_parent;
|
|
142
|
+
RECT rw_self, rc_parent, rw_parent;
|
|
143
|
+
int xpos, ypos;
|
|
144
|
+
|
|
145
|
+
hwnd_parent = GetParent(hwnd_self);
|
|
146
|
+
if (NULL == hwnd_parent)
|
|
147
|
+
hwnd_parent = GetDesktopWindow();
|
|
148
|
+
|
|
149
|
+
GetWindowRect(hwnd_parent, &rw_parent);
|
|
150
|
+
GetClientRect(hwnd_parent, &rc_parent);
|
|
151
|
+
GetWindowRect(hwnd_self, &rw_self);
|
|
152
|
+
|
|
153
|
+
xpos = rw_parent.left + (rc_parent.right + rw_self.left - rw_self.right) / 2;
|
|
154
|
+
ypos = rw_parent.top + (rc_parent.bottom + rw_self.top - rw_self.bottom) / 2;
|
|
155
|
+
|
|
156
|
+
SetWindowPos(
|
|
157
|
+
hwnd_self, NULL,
|
|
158
|
+
xpos, ypos, 0, 0,
|
|
159
|
+
SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//+---------------------------------------------------------------------------
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Simple Test program for libtcc
|
|
3
|
+
*
|
|
4
|
+
* libtcc can be useful to use tcc as a "backend" for a code generator.
|
|
5
|
+
*/
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
#include <stdio.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
|
|
10
|
+
#include "libtcc.h"
|
|
11
|
+
|
|
12
|
+
/* this function is called by the generated code */
|
|
13
|
+
int add(int a, int b)
|
|
14
|
+
{
|
|
15
|
+
return a + b;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
char my_program[] =
|
|
19
|
+
"int fib(int n)\n"
|
|
20
|
+
"{\n"
|
|
21
|
+
" if (n <= 2)\n"
|
|
22
|
+
" return 1;\n"
|
|
23
|
+
" else\n"
|
|
24
|
+
" return fib(n-1) + fib(n-2);\n"
|
|
25
|
+
"}\n"
|
|
26
|
+
"\n"
|
|
27
|
+
"int foo(int n)\n"
|
|
28
|
+
"{\n"
|
|
29
|
+
" printf(\"Hello World!\\n\");\n"
|
|
30
|
+
" printf(\"fib(%d) = %d\\n\", n, fib(n));\n"
|
|
31
|
+
" printf(\"add(%d, %d) = %d\\n\", n, 2 * n, add(n, 2 * n));\n"
|
|
32
|
+
" return 0;\n"
|
|
33
|
+
"}\n";
|
|
34
|
+
|
|
35
|
+
int main(int argc, char **argv)
|
|
36
|
+
{
|
|
37
|
+
TCCState *s;
|
|
38
|
+
int (*func)(int);
|
|
39
|
+
|
|
40
|
+
s = tcc_new();
|
|
41
|
+
if (!s) {
|
|
42
|
+
fprintf(stderr, "Could not create tcc state\n");
|
|
43
|
+
exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* if tcclib.h and libtcc1.a are not installed, where can we find them */
|
|
47
|
+
if (argc == 2 && !memcmp(argv[1], "lib_path=",9))
|
|
48
|
+
tcc_set_lib_path(s, argv[1]+9);
|
|
49
|
+
|
|
50
|
+
/* MUST BE CALLED before any compilation */
|
|
51
|
+
tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
|
|
52
|
+
|
|
53
|
+
if (tcc_compile_string(s, my_program) == -1)
|
|
54
|
+
return 1;
|
|
55
|
+
|
|
56
|
+
/* as a test, we add a symbol that the compiled program can use.
|
|
57
|
+
You may also open a dll with tcc_add_dll() and use symbols from that */
|
|
58
|
+
tcc_add_symbol(s, "add", add);
|
|
59
|
+
|
|
60
|
+
/* relocate the code */
|
|
61
|
+
if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
|
|
62
|
+
return 1;
|
|
63
|
+
|
|
64
|
+
/* get entry symbol */
|
|
65
|
+
func = tcc_get_symbol(s, "foo");
|
|
66
|
+
if (!func)
|
|
67
|
+
return 1;
|
|
68
|
+
|
|
69
|
+
/* run the code */
|
|
70
|
+
func(32);
|
|
71
|
+
|
|
72
|
+
/* delete the state */
|
|
73
|
+
tcc_delete(s);
|
|
74
|
+
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* _mingw.h
|
|
3
|
+
*
|
|
4
|
+
* This file is for TinyCC and not part of the Mingw32 package.
|
|
5
|
+
*
|
|
6
|
+
* THIS SOFTWARE IS NOT COPYRIGHTED
|
|
7
|
+
*
|
|
8
|
+
* This source code is offered for use in the public domain. You may
|
|
9
|
+
* use, modify or distribute it freely.
|
|
10
|
+
*
|
|
11
|
+
* This code is distributed in the hope that it will be useful but
|
|
12
|
+
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
|
|
13
|
+
* DISCLAIMED. This includes but is not limited to warranties of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#ifndef __MINGW_H
|
|
19
|
+
#define __MINGW_H
|
|
20
|
+
|
|
21
|
+
/* some winapi files define these before including _mingw.h --> */
|
|
22
|
+
#undef __cdecl
|
|
23
|
+
#undef _X86_
|
|
24
|
+
#undef WIN32
|
|
25
|
+
/* <-- */
|
|
26
|
+
|
|
27
|
+
#include <stddef.h>
|
|
28
|
+
#include <stdarg.h>
|
|
29
|
+
|
|
30
|
+
#define __int8 char
|
|
31
|
+
#define __int16 short
|
|
32
|
+
#define __int32 int
|
|
33
|
+
#define __int64 long long
|
|
34
|
+
|
|
35
|
+
#define __cdecl __attribute__((__cdecl__))
|
|
36
|
+
#define __declspec(x) __attribute__((x))
|
|
37
|
+
#define __unaligned __attribute__((packed))
|
|
38
|
+
#define __fastcall __attribute__((fastcall))
|
|
39
|
+
|
|
40
|
+
#define __MSVCRT__ 1
|
|
41
|
+
#undef _MSVCRT_
|
|
42
|
+
#define __MINGW_IMPORT extern __declspec(dllimport)
|
|
43
|
+
#define __MINGW_ATTRIB_NORETURN
|
|
44
|
+
#define __MINGW_ATTRIB_CONST
|
|
45
|
+
#define __MINGW_ATTRIB_DEPRECATED
|
|
46
|
+
#define __MINGW_ATTRIB_MALLOC
|
|
47
|
+
#define __MINGW_ATTRIB_PURE
|
|
48
|
+
#define __MINGW_ATTRIB_NONNULL(arg)
|
|
49
|
+
#define __MINGW_NOTHROW
|
|
50
|
+
#define __GNUC_VA_LIST
|
|
51
|
+
|
|
52
|
+
#define _CRTIMP extern
|
|
53
|
+
#define __CRT_INLINE extern __inline__
|
|
54
|
+
|
|
55
|
+
#define _CRT_ALIGN(x) __attribute__((aligned(x)))
|
|
56
|
+
#define DECLSPEC_ALIGN(x) __attribute__((aligned(x)))
|
|
57
|
+
#define _CRT_PACKING 8
|
|
58
|
+
#define __CRT_UNALIGNED
|
|
59
|
+
#define _CONST_RETURN
|
|
60
|
+
|
|
61
|
+
#define __CRT_STRINGIZE(_Value) #_Value
|
|
62
|
+
#define _CRT_STRINGIZE(_Value) __CRT_STRINGIZE(_Value)
|
|
63
|
+
#define __CRT_WIDE(_String) L ## _String
|
|
64
|
+
#define _CRT_WIDE(_String) __CRT_WIDE(_String)
|
|
65
|
+
|
|
66
|
+
#ifdef _WIN64
|
|
67
|
+
#define __stdcall
|
|
68
|
+
#define _AMD64_ 1
|
|
69
|
+
#define __x86_64 1
|
|
70
|
+
#define USE_MINGW_SETJMP_TWO_ARGS
|
|
71
|
+
#define mingw_getsp tinyc_getbp
|
|
72
|
+
#define __TRY__
|
|
73
|
+
#else
|
|
74
|
+
#define __stdcall __attribute__((__stdcall__))
|
|
75
|
+
#define _X86_ 1
|
|
76
|
+
#define WIN32 1
|
|
77
|
+
#define _USE_32BIT_TIME_T
|
|
78
|
+
#define __TRY__ void __try__(void**), *_sehrec[6]; __try__(_sehrec);
|
|
79
|
+
#endif
|
|
80
|
+
|
|
81
|
+
/* in stddef.h */
|
|
82
|
+
#define _SIZE_T_DEFINED
|
|
83
|
+
#define _SSIZE_T_DEFINED
|
|
84
|
+
#define _PTRDIFF_T_DEFINED
|
|
85
|
+
#define _WCHAR_T_DEFINED
|
|
86
|
+
#define _UINTPTR_T_DEFINED
|
|
87
|
+
#define _INTPTR_T_DEFINED
|
|
88
|
+
|
|
89
|
+
#define _INTEGRAL_MAX_BITS 64
|
|
90
|
+
|
|
91
|
+
typedef long __time32_t;
|
|
92
|
+
#define _TIME32_T_DEFINED
|
|
93
|
+
typedef __int64 __time64_t;
|
|
94
|
+
#define _TIME64_T_DEFINED
|
|
95
|
+
#ifdef _USE_32BIT_TIME_T
|
|
96
|
+
typedef __time32_t time_t;
|
|
97
|
+
#define _TIME_T_DEFINED
|
|
98
|
+
#else
|
|
99
|
+
typedef __time64_t time_t;
|
|
100
|
+
#define _TIME_T_DEFINED
|
|
101
|
+
#endif
|
|
102
|
+
|
|
103
|
+
typedef unsigned long size_t;
|
|
104
|
+
#define _SIZE_T_DEFINED
|
|
105
|
+
typedef long ssize_t;
|
|
106
|
+
#define _SSIZE_T_DEFINED
|
|
107
|
+
|
|
108
|
+
typedef unsigned int wint_t;
|
|
109
|
+
typedef unsigned short wctype_t;
|
|
110
|
+
#define _WCTYPE_T_DEFINED
|
|
111
|
+
typedef unsigned short wchar_t;
|
|
112
|
+
#define _WCHAR_T_DEFINED
|
|
113
|
+
|
|
114
|
+
typedef int errno_t;
|
|
115
|
+
#define _ERRCODE_DEFINED
|
|
116
|
+
|
|
117
|
+
typedef struct threadlocaleinfostruct *pthreadlocinfo;
|
|
118
|
+
typedef struct threadmbcinfostruct *pthreadmbcinfo;
|
|
119
|
+
typedef struct localeinfo_struct _locale_tstruct,*_locale_t;
|
|
120
|
+
|
|
121
|
+
/* for winapi */
|
|
122
|
+
#define _ANONYMOUS_UNION
|
|
123
|
+
#define _ANONYMOUS_STRUCT
|
|
124
|
+
#define DECLSPEC_NORETURN
|
|
125
|
+
#define DECLARE_STDCALL_P(type) __stdcall type
|
|
126
|
+
#define NOSERVICE 1
|
|
127
|
+
#define NOMCX 1
|
|
128
|
+
#define NOIME 1
|
|
129
|
+
#ifndef WIN32_LEAN_AND_MEAN
|
|
130
|
+
# define WIN32_LEAN_AND_MEAN 1
|
|
131
|
+
#endif
|
|
132
|
+
#ifndef WINVER
|
|
133
|
+
# define WINVER 0x0502
|
|
134
|
+
#endif
|
|
135
|
+
#ifndef _WIN32_WINNT
|
|
136
|
+
# define _WIN32_WINNT 0x502
|
|
137
|
+
#endif
|
|
138
|
+
|
|
139
|
+
#endif /* __MINGW_H */
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file has no copyright assigned and is placed in the Public Domain.
|
|
3
|
+
* This file is part of the w64 mingw-runtime package.
|
|
4
|
+
* No warranty is given; refer to the file DISCLAIMER within this package.
|
|
5
|
+
*/
|
|
6
|
+
#ifndef __ASSERT_H_
|
|
7
|
+
#define __ASSERT_H_
|
|
8
|
+
|
|
9
|
+
#include <_mingw.h>
|
|
10
|
+
#ifdef __cplusplus
|
|
11
|
+
#include <stdlib.h>
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
#ifdef NDEBUG
|
|
15
|
+
#ifndef assert
|
|
16
|
+
#define assert(_Expression) ((void)0)
|
|
17
|
+
#endif
|
|
18
|
+
#else
|
|
19
|
+
|
|
20
|
+
#ifndef _CRT_TERMINATE_DEFINED
|
|
21
|
+
#define _CRT_TERMINATE_DEFINED
|
|
22
|
+
void __cdecl __MINGW_NOTHROW exit(int _Code) __MINGW_ATTRIB_NORETURN;
|
|
23
|
+
_CRTIMP void __cdecl __MINGW_NOTHROW _exit(int _Code) __MINGW_ATTRIB_NORETURN;
|
|
24
|
+
#if !defined __NO_ISOCEXT /* extern stub in static libmingwex.a */
|
|
25
|
+
/* C99 function name */
|
|
26
|
+
void __cdecl _Exit(int) __MINGW_ATTRIB_NORETURN;
|
|
27
|
+
__CRT_INLINE __MINGW_ATTRIB_NORETURN void __cdecl _Exit(int status)
|
|
28
|
+
{ _exit(status); }
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
#pragma push_macro("abort")
|
|
32
|
+
#undef abort
|
|
33
|
+
void __cdecl __declspec(noreturn) abort(void);
|
|
34
|
+
#pragma pop_macro("abort")
|
|
35
|
+
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#ifdef __cplusplus
|
|
39
|
+
extern "C" {
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
extern void __cdecl _wassert(const wchar_t *_Message,const wchar_t *_File,unsigned _Line);
|
|
43
|
+
|
|
44
|
+
#ifdef __cplusplus
|
|
45
|
+
}
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
#ifndef assert
|
|
49
|
+
#define assert(_Expression) (void)((!!(_Expression)) || (_wassert(_CRT_WIDE(#_Expression),_CRT_WIDE(__FILE__),__LINE__),0))
|
|
50
|
+
#endif
|
|
51
|
+
|
|
52
|
+
#endif
|
|
53
|
+
|
|
54
|
+
#endif
|