Skip to content

Commit 7daffc1

Browse files
committed
kernel: remove unused print hooks
1 parent cd838d3 commit 7daffc1

File tree

6 files changed

+47
-120
lines changed

6 files changed

+47
-120
lines changed

src/exprs.c

+22-12
Original file line numberDiff line numberDiff line change
@@ -1194,29 +1194,39 @@ static void RecExpr2(Obj rec, Expr expr)
11941194

11951195
/****************************************************************************
11961196
**
1197-
*F PrintExpr(<expr>) . . . . . . . . . . . . . . . . . . print an expression
1197+
*V PrintExprFuncs[<type>] . . printing function for objects of type <type>
11981198
**
1199-
** 'PrintExpr' prints the expression <expr>.
1199+
** 'PrintExprFuncs' is the dispatching table that contains for every type of
1200+
** expressions a pointer to the printer for expressions of this type, i.e.,
1201+
** the function that should be called to print expressions of this type.
1202+
*/
1203+
static PrintExprFunc PrintExprFuncs[256];
1204+
1205+
1206+
/****************************************************************************
12001207
**
1201-
** 'PrintExpr' simply dispatches through the table 'PrintExprFuncs' to the
1202-
** appropriate printer.
1208+
*F InstallPrintExprFunc(<pos>,<f>)
12031209
*/
1204-
void PrintExpr (
1205-
Expr expr )
1210+
void InstallPrintExprFunc(unsigned int pos, PrintExprFunc f)
12061211
{
1207-
(*PrintExprFuncs[ TNUM_EXPR(expr) ])( expr );
1212+
GAP_ASSERT(pos < ARRAY_SIZE(PrintExprFuncs));
1213+
PrintExprFuncs[pos] = f;
12081214
}
12091215

12101216

12111217
/****************************************************************************
12121218
**
1213-
*V PrintExprFuncs[<type>] . . printing function for objects of type <type>
1219+
*F PrintExpr(<expr>) . . . . . . . . . . . . . . . . . . print an expression
12141220
**
1215-
** 'PrintExprFuncs' is the dispatching table that contains for every type of
1216-
** expressions a pointer to the printer for expressions of this type, i.e.,
1217-
** the function that should be called to print expressions of this type.
1221+
** 'PrintExpr' prints the expression <expr>.
1222+
**
1223+
** 'PrintExpr' simply dispatches through the table 'PrintExprFuncs' to the
1224+
** appropriate printer.
12181225
*/
1219-
PrintExprFunc PrintExprFuncs[256];
1226+
void PrintExpr(Expr expr)
1227+
{
1228+
(*PrintExprFuncs[TNUM_EXPR(expr)])(expr);
1229+
}
12201230

12211231

12221232
/****************************************************************************

src/exprs.h

+1-9
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,7 @@ void PrintExpr(Expr expr);
141141
void PrintRecExpr1(Expr expr); /* needed for printing
142142
function calls with options */
143143

144-
/****************************************************************************
145-
**
146-
*V PrintExprFuncs[<type>] . . printing function for objects of type <type>
147-
**
148-
** 'PrintExprFuncs' is the dispatching table that contains for every type of
149-
** expressions a pointer to the printer for expressions of this type, i.e.,
150-
** the function that should be called to print expressions of this type.
151-
*/
152-
extern PrintExprFunc PrintExprFuncs[256];
144+
void InstallPrintExprFunc(unsigned int pos, PrintExprFunc f);
153145

154146

155147
/****************************************************************************

src/hookintrprtr.c

-54
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ struct InterpreterHooks * activeHooks[HookCount];
3030
// Number of active hooks
3131
static Int HookActiveCount;
3232

33-
// If a print hook is current active
34-
static Int PrintHookActive;
35-
3633
/****************************************************************************
3734
**
3835
** Store the true values of each function we wrap for hooking. These always
@@ -44,9 +41,6 @@ ExecStatFunc OriginalExecStatFuncsForHook[256];
4441
EvalExprFunc OriginalEvalExprFuncsForHook[256];
4542
EvalBoolFunc OriginalEvalBoolFuncsForHook[256];
4643

47-
PrintStatFunc OriginalPrintStatFuncsForHook[256];
48-
PrintExprFunc OriginalPrintExprFuncsForHook[256];
49-
5044
/****************************************************************************
5145
**
5246
** These functions install implementations of eval/expr functions,
@@ -83,26 +77,6 @@ void InstallExecStatFunc(Int pos, ExecStatFunc f)
8377
HashUnlock(&activeHooks);
8478
}
8579

86-
void InstallPrintStatFunc(Int pos, PrintStatFunc f)
87-
{
88-
OriginalPrintStatFuncsForHook[pos] = f;
89-
HashLock(&activeHooks);
90-
if(!PrintHookActive) {
91-
PrintStatFuncs[pos] = f;
92-
}
93-
HashUnlock(&activeHooks);
94-
}
95-
96-
void InstallPrintExprFunc(Int pos, PrintExprFunc f)
97-
{
98-
OriginalPrintExprFuncsForHook[pos] = f;
99-
HashLock(&activeHooks);
100-
if(!PrintHookActive) {
101-
PrintExprFuncs[pos] = f;
102-
}
103-
HashUnlock(&activeHooks);
104-
}
105-
10680
static ExecStatus ProfileExecStatPassthrough(Stat stat)
10781
{
10882
GAP_HOOK_LOOP(visitStat, stat);
@@ -191,34 +165,6 @@ Int DeactivateHooks(struct InterpreterHooks * hook)
191165
return 1;
192166
}
193167

194-
void ActivatePrintHooks(struct PrintHooks * hook)
195-
{
196-
Int i;
197-
198-
if (PrintHookActive) {
199-
return;
200-
}
201-
PrintHookActive = 1;
202-
for (i = 0; i < ARRAY_SIZE(ExecStatFuncs); i++) {
203-
if (hook->printStatPassthrough) {
204-
PrintStatFuncs[i] = hook->printStatPassthrough;
205-
}
206-
if (hook->printExprPassthrough) {
207-
PrintExprFuncs[i] = hook->printExprPassthrough;
208-
}
209-
}
210-
}
211-
212-
void DeactivatePrintHooks(struct PrintHooks * hook)
213-
{
214-
if (!PrintHookActive) {
215-
return;
216-
}
217-
PrintHookActive = 0;
218-
memcpy(PrintStatFuncs, OriginalPrintStatFuncsForHook, sizeof(PrintStatFuncs));
219-
memcpy(PrintExprFuncs, OriginalPrintExprFuncsForHook, sizeof(PrintExprFuncs));
220-
}
221-
222168
/****************************************************************************
223169
**
224170
*F * * * * * * * * * * * * * initialize module * * * * * * * * * * * * * * *

src/hookintrprtr.h

-24
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
void InstallEvalBoolFunc(Int, EvalBoolFunc);
2020
void InstallEvalExprFunc(Int, EvalExprFunc);
2121
void InstallExecStatFunc(Int, ExecStatFunc);
22-
void InstallPrintStatFunc(Int, PrintStatFunc);
23-
void InstallPrintExprFunc(Int, PrintExprFunc);
2422

2523

2624
/****************************************************************************
@@ -36,9 +34,6 @@ extern ExecStatFunc OriginalExecStatFuncsForHook[256];
3634
extern EvalExprFunc OriginalEvalExprFuncsForHook[256];
3735
extern EvalBoolFunc OriginalEvalBoolFuncsForHook[256];
3836

39-
extern PrintStatFunc OriginalPrintStatFuncsForHook[256];
40-
extern PrintExprFunc OriginalPrintExprFuncsForHook[256];
41-
4237

4338
/****************************************************************************
4439
**
@@ -91,25 +86,6 @@ extern struct InterpreterHooks * activeHooks[HookCount];
9186
Int ActivateHooks(struct InterpreterHooks * hook);
9287
Int DeactivateHooks(struct InterpreterHooks * hook);
9388

94-
/****************************************************************************
95-
**
96-
** A struct to represent the hooks allowed into printing functions
97-
**
98-
**
99-
** This struct represents a list of functions which will be called whenever
100-
** a statement or expression is printed. They can be used to provide
101-
** simple customisation of printing. At the moment they are used by
102-
** profiling.c, to mark statements which have been executed.
103-
** Look at that code to get an idea how to use them.
104-
*/
105-
struct PrintHooks {
106-
void (*printStatPassthrough)(Stat stat);
107-
void (*printExprPassthrough)(Expr stat);
108-
};
109-
110-
void ActivatePrintHooks(struct PrintHooks * hook);
111-
void DeactivatePrintHooks(struct PrintHooks * hook);
112-
11389
/****************************************************************************
11490
**
11591
** We need the functions in the next three functions to be in the header,

src/stats.c

+23-12
Original file line numberDiff line numberDiff line change
@@ -1137,31 +1137,42 @@ void ClearError ( void )
11371137
}
11381138
}
11391139

1140+
11401141
/****************************************************************************
11411142
**
1142-
*F PrintStat(<stat>) . . . . . . . . . . . . . . . . . . . print a statement
1143+
*V PrintStatFuncs[<type>] . . print function for statements of type <type>
11431144
**
1144-
** 'PrintStat' prints the statements <stat>.
1145+
** 'PrintStatFuncs' is the dispatching table that contains for every type of
1146+
** statements a pointer to the printer for statements of this type, i.e.,
1147+
** the function that should be called to print statements of this type.
1148+
*/
1149+
static PrintStatFunc PrintStatFuncs[256];
1150+
1151+
1152+
/****************************************************************************
11451153
**
1146-
** 'PrintStat' simply dispatches through the table 'PrintStatFuncs' to the
1147-
** appropriate printer.
1154+
*F InstallPrintStatFunc(<pos>,<f>)
11481155
*/
1149-
void PrintStat (
1150-
Stat stat )
1156+
void InstallPrintStatFunc(unsigned int pos, PrintStatFunc f)
11511157
{
1152-
(*PrintStatFuncs[TNUM_STAT(stat)])( stat );
1158+
GAP_ASSERT(pos < ARRAY_SIZE(PrintStatFuncs));
1159+
PrintStatFuncs[pos] = f;
11531160
}
11541161

11551162

11561163
/****************************************************************************
11571164
**
1158-
*V PrintStatFuncs[<type>] . . print function for statements of type <type>
1165+
*F PrintStat(<stat>) . . . . . . . . . . . . . . . . . . . print a statement
11591166
**
1160-
** 'PrintStatFuncs' is the dispatching table that contains for every type of
1161-
** statements a pointer to the printer for statements of this type, i.e.,
1162-
** the function that should be called to print statements of this type.
1167+
** 'PrintStat' prints the statements <stat>.
1168+
**
1169+
** 'PrintStat' simply dispatches through the table 'PrintStatFuncs' to the
1170+
** appropriate printer.
11631171
*/
1164-
PrintStatFunc PrintStatFuncs[256];
1172+
void PrintStat(Stat stat)
1173+
{
1174+
(*PrintStatFuncs[TNUM_STAT(stat)])(stat);
1175+
}
11651176

11661177

11671178
/****************************************************************************

src/stats.h

+1-9
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,7 @@ void InterruptExecStat(void);
109109
void PrintStat(Stat stat);
110110

111111

112-
/****************************************************************************
113-
**
114-
*V PrintStatFuncs[<type>] . . print function for statements of type <type>
115-
**
116-
** 'PrintStatFuncs' is the dispatching table that contains for every type of
117-
** statements a pointer to the printer for statements of this type, i.e.,
118-
** the function that should be called to print statements of this type.
119-
*/
120-
extern PrintStatFunc PrintStatFuncs[256];
112+
void InstallPrintStatFunc(unsigned int pos, PrintStatFunc f);
121113

122114

123115
/****************************************************************************

0 commit comments

Comments
 (0)