Skip to content

Commit 928161d

Browse files
committed
Make VM config output optional with new -cfg flag
- move the code to the universe Signed-off-by: Stefan Marr <git@stefan-marr.de>
1 parent e0cfbb7 commit 928161d

File tree

2 files changed

+40
-35
lines changed

2 files changed

+40
-35
lines changed

src/Main.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,6 @@
3838
int32_t main(int32_t argc, char** argv) {
3939
cout << "This is SOM++" << endl;
4040

41-
if (GC_TYPE == GENERATIONAL) {
42-
cout << "\tgarbage collector: generational" << endl;
43-
} else if (GC_TYPE == COPYING) {
44-
cout << "\tgarbage collector: copying" << endl;
45-
} else if (GC_TYPE == MARK_SWEEP) {
46-
cout << "\tgarbage collector: mark-sweep" << endl;
47-
} else if (GC_TYPE == DEBUG_COPYING) {
48-
cout << "\tgarbage collector: debug copying" << endl;
49-
} else {
50-
cout << "\tgarbage collector: unknown" << endl;
51-
}
52-
53-
if (USE_TAGGING) {
54-
cout << "\twith tagged integers" << endl;
55-
} else {
56-
cout << "\tnot tagging integers" << endl;
57-
}
58-
59-
if (CACHE_INTEGER) {
60-
cout << "\tcaching integers from " << INT_CACHE_MIN_VALUE << " to "
61-
<< INT_CACHE_MAX_VALUE << endl;
62-
} else {
63-
cout << "\tnot caching integers" << endl;
64-
}
65-
66-
cout << "--------------------------------------" << endl;
67-
6841
Universe::Start(argc, argv);
6942

7043
Quit(ERR_SUCCESS);

src/vm/Universe.cpp

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,35 @@ void Universe::Shutdown() {
141141
#endif
142142
}
143143

144+
static void printVmConfig() {
145+
if (GC_TYPE == GENERATIONAL) {
146+
cout << "\tgarbage collector: generational\n";
147+
} else if (GC_TYPE == COPYING) {
148+
cout << "\tgarbage collector: copying\n";
149+
} else if (GC_TYPE == MARK_SWEEP) {
150+
cout << "\tgarbage collector: mark-sweep\n";
151+
} else if (GC_TYPE == DEBUG_COPYING) {
152+
cout << "\tgarbage collector: debug copying\n";
153+
} else {
154+
cout << "\tgarbage collector: unknown\n";
155+
}
156+
157+
if (USE_TAGGING) {
158+
cout << "\twith tagged integers\n";
159+
} else {
160+
cout << "\tnot tagging integers\n";
161+
}
162+
163+
if (CACHE_INTEGER) {
164+
cout << "\tcaching integers from " << INT_CACHE_MIN_VALUE << " to "
165+
<< INT_CACHE_MAX_VALUE << "\n";
166+
} else {
167+
cout << "\tnot caching integers\n";
168+
}
169+
170+
cout << "--------------------------------------\n";
171+
}
172+
144173
vector<std::string> Universe::handleArguments(int32_t argc, char** argv) {
145174
vector<std::string> vmArgs = vector<std::string>();
146175
dumpBytecodes = 0;
@@ -154,6 +183,8 @@ vector<std::string> Universe::handleArguments(int32_t argc, char** argv) {
154183
setupClassPath(std::string(argv[++i]));
155184
} else if (strncmp(argv[i], "-d", 2) == 0) {
156185
++dumpBytecodes;
186+
} else if (strncmp(argv[i], "-cfg", 4) == 0) {
187+
printVmConfig();
157188
} else if (strncmp(argv[i], "-g", 2) == 0) {
158189
++gcVerbosity;
159190
} else if (strncmp(argv[i], "-H", 2) == 0) {
@@ -238,14 +269,15 @@ void Universe::addClassPath(const std::string& cp) {
238269
void Universe::printUsageAndExit(char* executable) {
239270
cout << "Usage: " << executable << " [-options] [args...]\n\n";
240271
cout << "where options include:\n";
241-
cout << " -cp <directories separated by " << pathSeparator << ">\n";
242-
cout << " set search path for application classes\n";
243-
cout << " -d enable disassembling (twice for tracing)\n";
244-
cout << " -g enable garbage collection details:\n"
245-
<< " 1x - print statistics when VM shuts down\n"
246-
<< " 2x - print statistics upon each collection\n"
247-
<< " 3x - print statistics and dump heap upon each \n"
248-
<< "collection\n";
272+
cout << " -cp <directories separated by " << pathSeparator << ">\n";
273+
cout << " set search path for application classes\n";
274+
cout << " -d enable disassembling (twice for tracing)\n";
275+
cout << " -cfg print VM configuration\n";
276+
cout << " -g enable garbage collection details:\n"
277+
<< " 1x - print statistics when VM shuts down\n"
278+
<< " 2x - print statistics upon each collection\n"
279+
<< " 3x - print statistics and dump heap upon each collection\n"
280+
<< "\n";
249281
cout << " -HxMB set the heap size to x MB (default: 1 MB)\n";
250282
cout << " -HxKB set the heap size to x KB (default: 1 MB)\n";
251283
cout << " -h show this help\n";

0 commit comments

Comments
 (0)