Bidirectional Grammars for Machine-Code Decoding and Encoding

Gang Tan, Greg Morrisett

Research output: Contribution to journalArticlepeer-review

9 Scopus citations


Binary analysis, which analyzes machine code, requires a decoder for converting bits into abstract syntax of machine instructions. Binary rewriting requires an encoder for converting instructions to bits. We propose a domain-specific language that enables the specification of both decoding and encoding in a single bidirectional grammar. With dependent types, a bigrammar enables the extraction of an executable decoder and encoder as well as a correctness proof showing their consistency. The bigrammar DSL is embedded in Coq with machine-checked proofs. We have used the bigrammar DSL to specify the decoding and encoding of subsets of the x86-32 and MIPS instruction sets. We have also extracted an executable decoder and encoder from the x86 bigrammar with competitive performance.

Original languageEnglish (US)
Pages (from-to)257-277
Number of pages21
JournalJournal of Automated Reasoning
Issue number3
StatePublished - Mar 1 2018

All Science Journal Classification (ASJC) codes

  • Software
  • Computational Theory and Mathematics
  • Artificial Intelligence


Dive into the research topics of 'Bidirectional Grammars for Machine-Code Decoding and Encoding'. Together they form a unique fingerprint.

Cite this