From 8dcb4fbeea696360b8c260d92b06735812a7bbcf Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9C=A4=EC=A7=80=EC=98=81/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 4 Mar 2019 18:22:07 +0900 Subject: [PATCH] [enco/gdb] Upgrade enco dump for instruction in gdb (#3035) * [enco/gdb] Upgrade enco dump for instruction in gdb Add enco_dump_instr function in gdb Signed-off-by: Jiyoung Yun * Add todo comments --- contrib/enco/core/src/Support/Debugging.cpp | 48 +++++++++++++++++++++++++++-- contrib/enco/core/src/Support/Debugging.h | 8 +++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/contrib/enco/core/src/Support/Debugging.cpp b/contrib/enco/core/src/Support/Debugging.cpp index 85e787a..8941875 100644 --- a/contrib/enco/core/src/Support/Debugging.cpp +++ b/contrib/enco/core/src/Support/Debugging.cpp @@ -285,7 +285,7 @@ pp::LinearDocument describe(const coco::Op *op) return doc; } -pp::LinearDocument describe(const OpTree &t) +pp::LinearDocument describe(const OpTree &t, bool verbose = false) { pp::LinearDocument doc; @@ -339,6 +339,14 @@ pp::LinearDocument describe(const OpTree &t) doc.indent(); stack.top().advance(); + + // TODO Need to update it to better design for verbose flag + if (verbose) + { + auto set = [op](pp::LinearDocument &doc) { doc.append(describe(op)); }; + auto desc = section("op").build(set); + doc.append(desc); + } } else if (indicator < op->arity() + 1) { @@ -407,7 +415,7 @@ std::string kind(const coco::Instr *ins) return ins->accept(v); } -pp::LinearDocument describe(const coco::Instr *ins) +pp::LinearDocument describe(const coco::Instr *ins, bool verbose = false) { pp::LinearDocument doc; @@ -415,6 +423,34 @@ pp::LinearDocument describe(const coco::Instr *ins) doc.append("kind: ", kind(ins)); doc.append("parent: ", ins->parent()); + // TODO Need to update it to better design for verbose flag + if (verbose) + { + if (auto eval = ins->asEval()) + { + auto optset = [eval, verbose](pp::LinearDocument &doc) { + doc.append(describe(OpTree(eval->op()), verbose)); + }; + auto optdesc = section("op").build(optset); + doc.append(optdesc); + + auto outset = [eval](pp::LinearDocument &doc) { doc.append(describe(eval->out())); }; + auto outdesc = section("out").build(outset); + doc.append(outdesc); + } + else if (auto copy = ins->asCopy()) + { + auto from = [copy](pp::LinearDocument &doc) { doc.append(describe(copy->from())); }; + auto into = [copy](pp::LinearDocument &doc) { doc.append(describe(copy->into())); }; + + auto fdesc = section("from").build(from); + doc.append(fdesc); + + auto idesc = section("into").build(into); + doc.append(idesc); + } + } + return doc; } @@ -434,6 +470,14 @@ DEBUGGING_API_P(enco_dump_all_instrs, coco::Module, m) } } +DEBUGGING_API_P(enco_dump_instr, coco::Instr, ins) +{ + auto setter = [ins](pp::LinearDocument &doc) { doc.append(describe(ins, true)); }; + auto desc = section("instr").build(setter); + + std::cout << desc << std::endl; +} + /** * SECTION: Block */ diff --git a/contrib/enco/core/src/Support/Debugging.h b/contrib/enco/core/src/Support/Debugging.h index a492d25..dc0bd03 100644 --- a/contrib/enco/core/src/Support/Debugging.h +++ b/contrib/enco/core/src/Support/Debugging.h @@ -82,6 +82,14 @@ DEBUGGING_API_P(enco_dump_all_ops, coco::Module); DEBUGGING_API_P(enco_dump_all_instrs, coco::Module); /** + * Print the details of a given coco::Instr + * + * (gdb) call enco_dump_instr(instr) + * (gdb) call enco_dump_instr(0x...) + */ +DEBUGGING_API_P(enco_dump_instr, coco::Instr); + +/** * Print the details of all the instruction in a given block * * (gdb) call enco_dump_block(b) -- 2.7.4