Debian Codegraph @

include/x86-main.h

raw symbols SCIP
1 /* Copyright (C) 2009,2019-2020 Matthew Fluet.
2 * Copyright (C) 2000-2007 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 *
5 * MLton is released under a HPND-style license.
6 * See the file MLton-LICENSE for details.
7 */
8
9 #ifndef _X86_MAIN_H_
10 #define _X86_MAIN_H_
11
12 #include "common-main.h"
13
14 /* Globals */
15 PRIVATE Word32 applyFFTempFun;
16 PRIVATE Word32 applyFFTempArg;
17 PRIVATE Word32 checkTemp;
18 PRIVATE Word32 cReturnTemp[16];
19 PRIVATE Pointer c_stackP;
20 PRIVATE Word32 divTemp;
21 PRIVATE Word32 fildTemp;
22 PRIVATE Word32 fpswTemp;
23 PRIVATE Word32 indexTemp;
24 PRIVATE Word32 overflowCheckTemp;
25 PRIVATE Word32 raTemp1;
26 PRIVATE Real64 raTemp2;
27 PRIVATE Real64 realTemp1D;
28 PRIVATE Real64 realTemp2D;
29 PRIVATE Real64 realTemp3D;
30 PRIVATE Real32 realTemp1S;
31 PRIVATE Real32 realTemp2S;
32 PRIVATE Real32 realTemp3S;
33 PRIVATE Word32 spill[16];
34 PRIVATE Word32 stackTopTemp;
35 PRIVATE Word8 wordTemp1B;
36 PRIVATE Word16 wordTemp1W;
37 PRIVATE Word32 wordTemp1L;
38
39 #ifndef DEBUG_X86CODEGEN
40 #define DEBUG_X86CODEGEN FALSE
41 #endif
42
43 PRIVATE struct GC_state gcState;
44
45 PRIVATE GC_state MLton_gcState() {
46 return &gcState;
47 }
48
49 static GC_frameIndex returnAddressToFrameIndex (GC_returnAddress ra) {
50 return *((GC_frameIndex*)(ra - sizeof(GC_frameIndex)));
51 }
52
53 static inline pointer getJumpFromStackTop (GC_state s) {
54 return *(pointer*)(s->stackTop - GC_RETURNADDRESS_SIZE);
55 }
56
57 PRIVATE void MLton_jumpToSML (pointer jump);
58
59 #define MLtonCallFromC() \
60 static void MLton_callFromC (CPointer localOpArgsResPtr) { \
61 pointer jump; \
62 GC_state s = MLton_gcState(); \
63 if (DEBUG_X86CODEGEN) \
64 fprintf (stderr, "MLton_callFromC() starting\n"); \
65 s->callFromCOpArgsResPtr = localOpArgsResPtr; \
66 GC_setSavedThread (s, GC_getCurrentThread (s)); \
67 s->atomicState += 3; \
68 if (s->signalsInfo.signalIsPending) \
69 s->limit = s->limitPlusSlop - GC_HEAP_LIMIT_SLOP; \
70 /* Return to the C Handler thread. */ \
71 GC_switchToThread (s, GC_getCallFromCHandlerThread (s), 0); \
72 jump = getJumpFromStackTop (s); \
73 MLton_jumpToSML (jump); \
74 s->atomicState += 1; \
75 GC_switchToThread (s, GC_getSavedThread (s), 0); \
76 s->atomicState -= 1; \
77 if (0 == s->atomicState && s->signalsInfo.signalIsPending) \
78 s->limit = 0; \
79 if (DEBUG_X86CODEGEN) \
80 fprintf (stderr, "MLton_callFromC() done\n"); \
81 return; \
82 }
83
84 #define MLtonMain(al, mg, mfs, mmc, pk, ps, ml) \
85 PUBLIC int MLton_main (int argc, char* argv[]) { \
86 extern unsigned char ml; \
87 pointer jump; \
88 GC_state s = MLton_gcState(); \
89 Initialize (s, al, mg, mfs, mmc, pk, ps); \
90 if (s->amOriginal) { \
91 jump = (pointer)&ml; \
92 } else { \
93 jump = getJumpFromStackTop (s); \
94 } \
95 MLton_jumpToSML (jump); \
96 return 1; \
97 }
98
99 #define MLtonLibrary(al, mg, mfs, mmc, pk, ps, ml) \
100 PUBLIC void LIB_OPEN(LIBNAME) (int argc, char* argv[]) { \
101 extern unsigned char ml; \
102 pointer jump; \
103 GC_state s = MLton_gcState(); \
104 Initialize (s, al, mg, mfs, mmc, pk, ps); \
105 if (s->amOriginal) { \
106 jump = (pointer)&ml; \
107 } else { \
108 jump = getJumpFromStackTop (s); \
109 } \
110 MLton_jumpToSML(jump); \
111 } \
112 PUBLIC void LIB_CLOSE(LIBNAME) () { \
113 pointer jump; \
114 GC_state s = MLton_gcState(); \
115 jump = getJumpFromStackTop (s); \
116 MLton_jumpToSML(jump); \
117 GC_done(s); \
118 }
119
120 #endif /* #ifndef _X86_MAIN_H_ */