Bladeren bron

HPCC-8739 Minor improvements to IR output for help with debugging

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 12 jaren geleden
bovenliggende
commit
9af4dc2e6a
2 gewijzigde bestanden met toevoegingen van 42 en 0 verwijderingen
  1. 41 0
      ecl/hql/hqlir.cpp
  2. 1 0
      ecl/hql/hqlir.hpp

+ 41 - 0
ecl/hql/hqlir.cpp

@@ -19,6 +19,8 @@
 #include "jiface.hpp"
 #include "hqlir.hpp"
 
+//#define ADD_ACTIVE_SCOPE_AS_COMMENT
+
 namespace EclIR
 {
 
@@ -821,6 +823,7 @@ public:
     _ATOM name;
     unsigned __int64 sequence;
     IdArray args;
+    IdArray comment;
 };
 
 class ExprAnnotationBuilderInfo
@@ -1442,6 +1445,17 @@ protected:
             line.append(" : ");
             appendId(info.type);
         }
+        if (info.comment.ordinality())
+        {
+            line.append("  // ");
+            ForEachItemIn(i, info.comment)
+            {
+                if (i)
+                    line.append(",");
+                appendId(info.comment.item(i));
+            }
+        }
+
     }
 
     void appendConstantText(const ConstantBuilderInfo & info)
@@ -1884,6 +1898,7 @@ id_t ExpressionIRPlayer::processExpr(IHqlExpression * expr)
     IInterface * match = expr->queryTransformExtra();
     if (match)
     {
+        //Check for recursion
         if (match == expr)
             throwUnexpected();
         return static_cast<ExpressionId *>(match)->id;
@@ -1926,6 +1941,18 @@ id_t ExpressionIRPlayer::doProcessExpr(IHqlExpression * expr)
     ForEachChild(i, expr)
         info.args.append(processExpr(expr->queryChild(i)));
 
+#ifdef ADD_ACTIVE_SCOPE_AS_COMMENT
+    HqlExprCopyArray inScope;
+    expr->gatherTablesUsed(NULL, &inScope);
+    ForEachItemIn(i, inScope)
+    {
+        IHqlExpression * cur = &inScope.item(i);
+        if (cur == expr) // add 0 to list if is own active selector
+            cur = NULL;
+        info.comment.append(processExpr(cur));
+    }
+#endif
+
     if (getRequiredTypeCode(op) == type_none)
         info.type = processType(expr->queryType());
     info.sequence = expr->querySequenceExtra();
@@ -2086,6 +2113,20 @@ extern HQL_API void dump_ir(IHqlExpression * expr1, IHqlExpression * expr2)
     reader.play(expr2);
 }
 
+extern HQL_API void dump_irn(unsigned n, ...)
+{
+    FileIRBuilder output(defaultDumpOptions, stdout);
+    ExpressionIRPlayer reader(&output);
+    va_list args;
+    va_start(args, n);
+    for (unsigned i=0; i < n;i++)
+    {
+        IHqlExpression * expr = va_arg(args, IHqlExpression *);
+        reader.play(expr);
+    }
+    va_end(args);
+}
+
 //-- Dump the IR for the expression(s)/type to DBGLOG ----------------------------------------------------------------
 
 extern HQL_API void dbglogIR(IHqlExpression * expr)

+ 1 - 0
ecl/hql/hqlir.hpp

@@ -54,6 +54,7 @@ extern HQL_API void dump_ir(const HqlExprArray & exprs);
 //The following are useful for finding the differences between two types or expressions - the output between the two returns
 extern HQL_API void dump_ir(ITypeInfo * type1, ITypeInfo * type2);
 extern HQL_API void dump_ir(IHqlExpression * expr1, IHqlExpression * expr2);
+extern HQL_API void dump_irn(unsigned n, ...);
 
 extern HQL_API void dbglogIR(IHqlExpression * expr);
 extern HQL_API void dbglogIR(ITypeInfo * type);