From bef71f29e27421fd9850baf04a91aeb6759d6fea Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 18 Oct 2016 10:17:09 +0200 Subject: [PATCH] - make generation of the AST dump a command line parameter instead of having it depend on running a debug build. - disable generation of the parser's trace file in debug builds. This increases parsing time by a factor of 15 and is only needed when debugging a problem in the grammar. --- src/scripting/zscript/zcc_parser.cpp | 31 +++++++++++++++------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/scripting/zscript/zcc_parser.cpp b/src/scripting/zscript/zcc_parser.cpp index cc8d187d31..9fefa537d0 100644 --- a/src/scripting/zscript/zcc_parser.cpp +++ b/src/scripting/zscript/zcc_parser.cpp @@ -39,6 +39,7 @@ #include "cmdlib.h" #include "m_alloc.h" #include "i_system.h" +#include "m_argv.h" #include "v_text.h" #include "zcc_parser.h" #include "zcc_compile.h" @@ -297,7 +298,7 @@ static void DoParse(int lumpnum) parser = ZCCParseAlloc(malloc); ZCCParseState state; -#ifdef _DEBUG +#if 0 // this costs a lot of time and should only be activated when it's really needed. FILE *f = fopen("trace.txt", "w"); char prompt = '\0'; ZCCParseTrace(f, &prompt); @@ -331,24 +332,26 @@ static void DoParse(int lumpnum) I_Error("%d errors while parsing %s", FScriptPosition::ErrorCounter, Wads.GetLumpFullPath(lumpnum)); } - { - // Make a dump of the AST before running the compiler for diagnostic purposes. -#ifdef _DEBUG +#if 0 if (f != NULL) { fclose(f); } - FString ast = ZCC_PrintAST(state.TopNode); - FString filename = Wads.GetLumpFullName(lumpnum); - FString astfile = ExtractFileBase(filename, false); - astfile << "-before.ast"; - f = fopen(astfile, "w"); - if (f != NULL) - { - fputs(ast.GetChars(), f); - fclose(f); - } #endif + + // Make a dump of the AST before running the compiler for diagnostic purposes. + if (Args->CheckParm("-dumpast")) + { + FString ast = ZCC_PrintAST(state.TopNode); + FString filename = Wads.GetLumpFullName(lumpnum); + FString astfile = ExtractFileBase(filename, false); + astfile << ".ast"; + FILE *ff = fopen(astfile, "w"); + if (ff != NULL) + { + fputs(ast.GetChars(), ff); + fclose(ff); + } } PSymbolTable symtable;