[Lldb-commits] [lldb] r151953 - /lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
Chris Lattner
clattner at apple.com
Fri Mar 2 16:41:28 PST 2012
On Mar 2, 2012, at 3:22 PM, Sean Callanan wrote:
> Author: spyffe
> Date: Fri Mar 2 17:22:53 2012
> New Revision: 151953
>
> URL: http://llvm.org/viewvc/llvm-project?rev=151953&view=rev
> Log:
> Added a function to the disassembler that checks
> (from the mnemonic) whether an instruction is a
> branch. This function's result is exposed through
> DoesBranch().
hi Sean,
The m_disasm.GetArchitecture().GetMachine(); call isn't very fast. Is there a way to get (and cache) this enum at a higher level? Is there a way to propagate the "isBranch" information that the MC tables already know up through these APIs?
-Chris
>
> Modified:
> lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
>
> Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp?rev=151953&r1=151952&r2=151953&view=diff
> ==============================================================================
> --- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp (original)
> +++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp Fri Mar 2 17:22:53 2012
> @@ -37,7 +37,8 @@
> m_disasm(disasm),
> m_is_valid(false),
> m_no_comments(true),
> - m_comment_stream()
> + m_comment_stream(),
> + m_does_branch(eLazyBoolCalculate)
> {
> }
>
> @@ -147,7 +148,7 @@
> virtual bool
> DoesBranch () const
> {
> - return false;
> + return m_does_branch == eLazyBoolYes;
> }
>
> virtual size_t
> @@ -251,6 +252,90 @@
> }
> }
>
> + bool StringRepresentsBranch (const char *data, size_t size)
> + {
> + const char *cursor = data;
> +
> + bool inWhitespace = true;
> +
> + while (inWhitespace && cursor < data + size)
> + {
> + switch (*cursor)
> + {
> + default:
> + inWhitespace = false;
> + break;
> + case ' ':
> + break;
> + case '\t':
> + break;
> + }
> +
> + if (inWhitespace)
> + ++cursor;
> + }
> +
> + if (cursor >= data + size)
> + return false;
> +
> + llvm::Triple::ArchType arch = m_disasm.GetArchitecture().GetMachine();
> +
> + switch (arch)
> + {
> + default:
> + return false;
> + case llvm::Triple::x86:
> + case llvm::Triple::x86_64:
> + switch (cursor[0])
> + {
> + default:
> + return false;
> + case 'j':
> + return true;
> + case 'c':
> + if (cursor[1] == 'a' &&
> + cursor[2] == 'l' &&
> + cursor[3] == 'l')
> + return true;
> + else
> + return false;
> + }
> + case llvm::Triple::arm:
> + case llvm::Triple::thumb:
> + switch (cursor[0])
> + {
> + default:
> + return false;
> + case 'b':
> + {
> + switch (cursor[1])
> + {
> + default:
> + return false;
> + case 'l':
> + case 'x':
> + case ' ':
> + case '\t':
> + return true;
> + }
> + return false;
> + }
> + case 'c':
> + {
> + switch (cursor[1])
> + {
> + default:
> + return false;
> + case 'b':
> + return true;
> + }
> + }
> + }
> + }
> +
> + return false;
> + }
> +
> template <bool Reparse> bool Parse (const lldb_private::Address &address,
> lldb_private::AddressClass addr_class,
> const DataExtractor &extractor,
> @@ -279,6 +364,10 @@
> out_string.data(),
> out_string.size());
>
> + if (m_does_branch == eLazyBoolCalculate)
> + m_does_branch = (StringRepresentsBranch (out_string.data(), out_string.size()) ?
> + eLazyBoolYes : eLazyBoolNo);
> +
> m_comment_stream.Flush();
> m_no_comments = false;
>
> @@ -331,6 +420,7 @@
>
> bool m_no_comments;
> StreamString m_comment_stream;
> + LazyBool m_does_branch;
>
> static bool s_regex_compiled;
> static ::regex_t s_regex;
>
>
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
More information about the lldb-commits
mailing list