Skip to content

Commit

Permalink
Add continuation lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdphk committed Mar 3, 2021
1 parent 29e411e commit b29f31d
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions pyreveng/instree.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,35 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

"""
InsTree -- A class for disassembling
This class turns a textual description close to what is typically used
for documenting CPUs into a skeleton disassembler.
instree = * (
(assypart (wordmap/bitmap) [pilspec]) \
('#' comment NL)
)
assypart = * (nonspacenonpipe WSP)
delim = ' ' / '|'
wordmap = '|' *(delim (hex|field)) '|'
bitmap = '|' bit *(delim (field|bit)) '|'
bit = '?' / '0' / '1'
hex = 2* ( bit / '2' / '3' / ... 'D' / 'E' / 'F' )
# Always upper case, at least two digits
pilspec = '{' NL IL_specificatoin NL '}' NL
XXX: wordmap has yet to be implemented
'''
InsTree -- A class for disassembling
====================================
This is the fundamental syntax in Bill Fenner approved ABNF:
spec = *(blankline / comment / specline)
blankline = *WSP LF
comment = *WSP "#" *(VCHAR / WSP) LF
specline = mnemonic 1*WSP operands 1*WSP wordspec 1*WSP [ pilspec ] LF
mnemonic = 1*VCHAR
operands = operand *( "," operand )
operand = 1*( %x21-2B / %x2D-7E )
wordspec = "|" 1*field
field = bitfield / hexfield / varfield / linebreak
bit = ( "0" / "1" / "?" )
bitfield = bit *( " " bit ) "|"
hexfield = *WSP 1*( DIGIT / %x41-46 ) *WSP "|"
varfield = *WSP %x61-7A 1*( %x61-7A / %x30-39 / "_" ) *WSP "|"
linebreak = *WSP "&" LF *WSP "|"
pilspec = *WSP "{" LF *pillines "}" LF
pillines = (HTAB / %x20-7C / "~") 1*(WSP / VCHAR ) LF
On top of this are other requirements, in particular the widths of fields.
"""
import sys
import re
class UsageTrouble(Exception):
pass
Expand Down Expand Up @@ -350,6 +348,10 @@ def load_string(self, s, handler=None):
i = 0
banned = False
s = s.expandtabs()

# Join continuation lines
s = re.sub("\\|\\s*&\n\\s*\\|", "|", s)

last = ''
while i < len(s):

Expand Down Expand Up @@ -468,5 +470,7 @@ def find(self, priv, adr, getmore):
Foo |0 1 0 1 0 1 0 1|1 1 1 1 1 1 1 1|
Foo2 |0 ? 0 1 0 1 0 1|1 1 1 1 1 1 1 1|
#Foo_05 | ca | data |0 0 0 0|foo |
Foo5 |0 ? 0 1 0 1 0 1| \
|1 1 1 1 1 1 1 1|
""")
IT.dump()

0 comments on commit b29f31d

Please sign in to comment.