4421
Clean up the rat's nest that all my trace management globals had gradually turned into. a) Get rid of 'Start_tracing'. Horryibly named, I don't know how I missed that until now. b) Never use START_TRACING_UNTIL_END_OF_SCOPE in main(). It's confusing to combine it with atexit(delete Trace_stream), because the atexit() never has to run. Instead we'll just manually initialize Trace_stream and let atexit() clean up. c) If we run tests we only want a trace for the test run itself. So delete the Trace_stream that was initialized at the top of main -- once it's clear we had no load-time errors. d) Clean up horribly "Load Recipes" waypoints, combine them with the better name, "Mu Prelude". Putting these together, we have the following manual tests: - CFLAGS=-g mu x.mu Should not create last_run. - CFLAGS=-g mu --trace x.mu Should create last_run. Should write it out exactly once. - CFLAGS=-g mu --trace x.mu # when x.mu has an error Should create last_run. Should write it out exactly once. - CFLAGS=-g mu --trace test copy_literal # C test Should create last_run. Should write it out exactly once. - CFLAGS=-g mu --trace test recipe_with_header # Mu test Should create last_run. Should write it out exactly once. I don't know how to automate these scenarios yet. We need a way to run our build toolchain atop our stack.
This commit is contained in:
parent
3b798ea2c9
commit
257add0f7e
23
003trace.cc
23
003trace.cc
|
@ -85,6 +85,28 @@ Hide_errors = false;
|
|||
Dump_trace = false;
|
||||
Dump_label = "";
|
||||
|
||||
//: Support for tracing an entire run.
|
||||
//: Traces can have a lot of overhead, so only turn them on when asked.
|
||||
:(before "End Commandline Options(*arg)")
|
||||
else if (is_equal(*arg, "--trace")) {
|
||||
Save_trace = true;
|
||||
}
|
||||
:(before "End Commandline Parsing")
|
||||
if (Save_trace) {
|
||||
cerr << "initializing trace\n";
|
||||
Trace_stream = new trace_stream;
|
||||
}
|
||||
:(code)
|
||||
void cleanup_main() {
|
||||
if (!Trace_stream) return;
|
||||
if (Save_trace)
|
||||
Trace_stream->save();
|
||||
delete Trace_stream;
|
||||
Trace_stream = NULL;
|
||||
}
|
||||
:(before "End One-time Setup")
|
||||
atexit(cleanup_main);
|
||||
|
||||
:(before "End Types")
|
||||
// Pre-define some global constants that trace_stream needs to know about.
|
||||
// Since they're in the Types section, they'll be included in any cleaved
|
||||
|
@ -118,6 +140,7 @@ struct trace_stream {
|
|||
}
|
||||
|
||||
void save() {
|
||||
cerr << "saving trace to last_run\n";
|
||||
ofstream fout("last_run");
|
||||
fout << readable_contents("");
|
||||
fout.close();
|
||||
|
|
3
010vm.cc
3
010vm.cc
|
@ -218,7 +218,8 @@ setup_recipes();
|
|||
assert(MAX_PRIMITIVE_RECIPES < 200); // level 0 is primitives; until 199
|
||||
Next_recipe_ordinal = 200;
|
||||
put(Recipe_ordinal, "main", Next_recipe_ordinal++);
|
||||
// End Load Recipes
|
||||
// Load Mu Prelude
|
||||
// End Mu Prelude
|
||||
:(before "End Commandline Parsing")
|
||||
assert(Next_recipe_ordinal < 1000); // recipes being tested didn't overflow into test space
|
||||
:(before "End Reset")
|
||||
|
|
43
020run.cc
43
020run.cc
|
@ -192,11 +192,7 @@ const vector<instruction>& routine::steps() const {
|
|||
|
||||
//:: Startup flow
|
||||
|
||||
//: Step 1: load all .mu files with numeric prefixes (in order)
|
||||
:(before "End Load Recipes")
|
||||
// Load Mu Prelude
|
||||
//? Save_trace = true;
|
||||
//? START_TRACING_UNTIL_END_OF_SCOPE;
|
||||
:(before "End Mu Prelude")
|
||||
load_file_or_directory("core.mu");
|
||||
//? DUMP("");
|
||||
//? exit(0);
|
||||
|
@ -204,8 +200,6 @@ load_file_or_directory("core.mu");
|
|||
//: Step 2: load any .mu files provided at the commandline
|
||||
:(before "End Commandline Parsing")
|
||||
// Check For .mu Files
|
||||
//? START_TRACING_UNTIL_END_OF_SCOPE
|
||||
//? Dump_trace = true;
|
||||
if (argc > 1) {
|
||||
// skip argv[0]
|
||||
++argv;
|
||||
|
@ -226,9 +220,11 @@ transform_all();
|
|||
//? cerr << to_original_string(get(Recipe, get(Recipe_ordinal, "event-loop"))) << '\n';
|
||||
//? DUMP("");
|
||||
//? exit(0);
|
||||
if (trace_contains_errors()) {
|
||||
if (Start_tracing && Trace_stream) Trace_stream->save();
|
||||
return 1;
|
||||
if (trace_contains_errors()) return 1;
|
||||
if (Trace_stream && Run_tests) {
|
||||
// We'll want a trace per test. Clear the trace.
|
||||
delete Trace_stream;
|
||||
Trace_stream = NULL;
|
||||
}
|
||||
save_snapshots();
|
||||
|
||||
|
@ -238,14 +234,9 @@ save_snapshots();
|
|||
if (!Run_tests && contains_key(Recipe_ordinal, "main") && contains_key(Recipe, get(Recipe_ordinal, "main"))) {
|
||||
// Running Main
|
||||
reset();
|
||||
if (Start_tracing && Trace_stream == NULL) {
|
||||
Trace_stream = new trace_stream;
|
||||
Save_trace = true;
|
||||
}
|
||||
trace(2, "run") << "=== Starting to run" << end();
|
||||
assert(Num_calls_to_transform_all == 1);
|
||||
run_main(argc, argv);
|
||||
if (Start_tracing && Trace_stream) Trace_stream->save();
|
||||
}
|
||||
:(code)
|
||||
void run_main(int argc, char* argv[]) {
|
||||
|
@ -253,26 +244,6 @@ void run_main(int argc, char* argv[]) {
|
|||
if (r) run(r);
|
||||
}
|
||||
|
||||
//: By default we don't maintain the trace while running main because its
|
||||
//: overheads can grow rapidly. However, it's useful when debugging.
|
||||
:(before "End Globals")
|
||||
bool Start_tracing = false;
|
||||
:(before "End Commandline Options(*arg)")
|
||||
else if (is_equal(*arg, "--trace")) {
|
||||
Start_tracing = true;
|
||||
}
|
||||
|
||||
:(code)
|
||||
void cleanup_main() {
|
||||
if (!Trace_stream) return;
|
||||
if (Save_trace)
|
||||
Trace_stream->save();
|
||||
delete Trace_stream;
|
||||
Trace_stream = NULL;
|
||||
}
|
||||
:(before "End One-time Setup")
|
||||
atexit(cleanup_main);
|
||||
|
||||
:(code)
|
||||
void load_file_or_directory(string filename) {
|
||||
if (is_directory(filename)) {
|
||||
|
@ -422,7 +393,7 @@ void run(const string& form) {
|
|||
transform_all();
|
||||
if (tmp.empty()) return;
|
||||
if (trace_contains_errors()) {
|
||||
if (Start_tracing && Trace_stream) Trace_stream->save();
|
||||
if (Save_trace && Trace_stream) Trace_stream->save();
|
||||
return;
|
||||
}
|
||||
// if a test defines main, it probably wants to start there regardless of
|
||||
|
|
|
@ -197,10 +197,8 @@ if (Test_only_app && Num_core_mu_scenarios < SIZE(Scenarios)) {
|
|||
:(after "Test Runs")
|
||||
for (int i = 0; i < SIZE(Scenarios); ++i) {
|
||||
if (Scenarios.at(i).name == argv[argc-1]) {
|
||||
if (Start_tracing) {
|
||||
if (Save_trace)
|
||||
Trace_stream = new trace_stream;
|
||||
Save_trace = true;
|
||||
}
|
||||
run_mu_scenario(Scenarios.at(i));
|
||||
if (Passed) cerr << ".\n";
|
||||
return 0;
|
||||
|
|
|
@ -215,7 +215,7 @@ void unstash_snapshots() {
|
|||
Scenario_names_snapshot = Scenario_names_snapshot_stash; Scenario_names_snapshot_stash.clear();
|
||||
}
|
||||
|
||||
:(before "End Load Recipes")
|
||||
:(before "End Mu Prelude")
|
||||
load(string(
|
||||
"recipe interactive [\n") + // just a dummy version to initialize the Recipe_ordinal and so on
|
||||
"]\n" +
|
||||
|
|
Loading…
Reference in New Issue