Added command line option for enabling interpreter stats collection
'-d' or '-d0' to collect and print basic stats, '-d1' etc. for alternative output formats.
This commit is contained in:
parent
97030639f1
commit
31b08382db
|
@ -512,6 +512,9 @@ struct Picoc_Struct {
|
||||||
struct Table StringTable;
|
struct Table StringTable;
|
||||||
struct TableEntry *StringHashTable[STRING_TABLE_SIZE];
|
struct TableEntry *StringHashTable[STRING_TABLE_SIZE];
|
||||||
char *StrEmpty;
|
char *StrEmpty;
|
||||||
|
|
||||||
|
/* stats */
|
||||||
|
int CollectStats;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* table.c */
|
/* table.c */
|
||||||
|
|
24
picoc.c
24
picoc.c
|
@ -23,17 +23,20 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int ParamCount = 1;
|
int ParamCount = 1;
|
||||||
int DontRunMain = false;
|
int DontRunMain = false;
|
||||||
|
int CollectStats = false;
|
||||||
|
int StatsType = 0;
|
||||||
int StackSize = getenv("STACKSIZE") ? atoi(getenv("STACKSIZE")) : PICOC_STACK_SIZE;
|
int StackSize = getenv("STACKSIZE") ? atoi(getenv("STACKSIZE")) : PICOC_STACK_SIZE;
|
||||||
Picoc pc;
|
Picoc pc;
|
||||||
|
|
||||||
if (argc < 2 || strcmp(argv[ParamCount], "-h") == 0) {
|
if (argc < 2 || strcmp(argv[ParamCount], "-h") == 0) {
|
||||||
printf(PICOC_VERSION " \n"
|
printf(PICOC_VERSION " \n"
|
||||||
"Format:\n\n"
|
"Format:\n\n"
|
||||||
"> picoc <file1.c>... [- <arg1>...] : run a program, calls main() as the entry point\n"
|
"> picoc <file1.c>... [- <arg1>...] : run a program, calls main() as the entry point\n"
|
||||||
"> picoc -s <file1.c>... [- <arg1>...] : run a script, runs the program without calling main()\n"
|
"> picoc -s <file1.c>... [- <arg1>...] : run a script, runs the program without calling main()\n"
|
||||||
"> picoc -i : interactive mode, Ctrl+d to exit\n"
|
"> picoc -d[type] <file1.c>... [- <arg1>...] : run a program, outputting debugging stats\n"
|
||||||
"> picoc -c : copyright info\n"
|
"> picoc -i : interactive mode, Ctrl+d to exit\n"
|
||||||
"> picoc -h : this help message\n");
|
"> picoc -c : copyright info\n"
|
||||||
|
"> picoc -h : this help message\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +51,13 @@ int main(int argc, char **argv)
|
||||||
DontRunMain = true;
|
DontRunMain = true;
|
||||||
PicocIncludeAllSystemHeaders(&pc);
|
PicocIncludeAllSystemHeaders(&pc);
|
||||||
ParamCount++;
|
ParamCount++;
|
||||||
|
} else if (strncmp(argv[ParamCount], "-d", 2) == 0) {
|
||||||
|
if (strlen(argv[ParamCount]) > 2) {
|
||||||
|
StatsType = atoi(&argv[ParamCount][2]);
|
||||||
|
}
|
||||||
|
CollectStats = true;
|
||||||
|
pc.CollectStats = true;
|
||||||
|
ParamCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > ParamCount && strcmp(argv[ParamCount], "-i") == 0) {
|
if (argc > ParamCount && strcmp(argv[ParamCount], "-i") == 0) {
|
||||||
|
@ -68,7 +78,9 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
PicocCleanup(&pc);
|
PicocCleanup(&pc);
|
||||||
|
|
||||||
stats_print_tokens(0);
|
if (CollectStats) {
|
||||||
|
stats_print_tokens(StatsType == 1);
|
||||||
|
}
|
||||||
|
|
||||||
return pc.PicocExitValue;
|
return pc.PicocExitValue;
|
||||||
}
|
}
|
||||||
|
|
14
stats.c
14
stats.c
|
@ -120,14 +120,20 @@ struct LexTokenStat LexTokenStats[NO_TOKENS] = {
|
||||||
|
|
||||||
|
|
||||||
void stats_log_statement(enum LexToken token, struct ParseState *parser) {
|
void stats_log_statement(enum LexToken token, struct ParseState *parser) {
|
||||||
fprintf(stderr, "Parsing Statement %s (%d) in %s (%d) at %s:%d:%d\n", LexTokenStats[token].name, token, RunModeNames[parser->Mode], parser->Mode, parser->FileName, parser->Line, parser->CharacterPos);
|
if (parser->pc->CollectStats) {
|
||||||
LexTokenStats[token].count[parser->Mode]++;
|
fprintf(stderr, "Parsing Statement %s (%d) in %s (%d) at %s:%d:%d\n", LexTokenStats[token].name, token,
|
||||||
|
RunModeNames[parser->Mode], parser->Mode, parser->FileName, parser->Line, parser->CharacterPos);
|
||||||
|
LexTokenStats[token].count[parser->Mode]++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void stats_log_expression(enum LexToken token, struct ParseState *parser) {
|
void stats_log_expression(enum LexToken token, struct ParseState *parser) {
|
||||||
fprintf(stderr, "Parsing Expression %s (%d) in %s (%d) at %s:%d:%d\n", LexTokenStats[token].name, token, RunModeNames[parser->Mode], parser->Mode, parser->FileName, parser->Line, parser->CharacterPos);
|
if (parser->pc->CollectStats) {
|
||||||
LexTokenStats[token].count[parser->Mode]++;
|
fprintf(stderr, "Parsing Expression %s (%d) in %s (%d) at %s:%d:%d\n", LexTokenStats[token].name, token,
|
||||||
|
RunModeNames[parser->Mode], parser->Mode, parser->FileName, parser->Line, parser->CharacterPos);
|
||||||
|
LexTokenStats[token].count[parser->Mode]++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue