05 May 2021, 20:26 | #1 |
Registered User
Join Date: Apr 2020
Location: CHICAGO / USA
Posts: 32
|
Stream parsing techniques
i'm using dissassembler.library but i want a bit more flexibility on the output it generates, so i'm parsing the output. since the lib uses a putchar function, i'm parsing the text as it appears, making it a bit more tricky than if i were parsing a text buffer. i ended up using indices in the text to flip bit flags on section starts and do stuff accordingly but i'd rather not be relying on indices since this could break in a future version of the lib. here's a snippet:
Code:
DL_ParseOutput: cmp.b #10,d0 beq.w DL_Parse_ResetLine move.w DL_Pos,d1 cmp.w #1,d1 beq.w DL_Parse_AddrStart cmp.w #13,d1 beq.w DL_Parse_HexStart cmp.w #40,d1 beq.w DL_Parse_MnemonicStart btst #DL_COMMENT,DL_Bits bne.w DL_Parse_InComment btst #DL_OPERANDS,DL_Bits bne.w DL_Parse_InOperands btst #DL_MNEMONIC,DL_Bits bne.w DL_Parse_InMnemonic btst #DL_HEX,DL_Bits bne.w DL_Parse_InHex btst #DL_ADDR,DL_Bits bne.w DL_Parse_InAddr p.s. if thor is reading this, an _LVODisassembleF would be nice |
05 May 2021, 20:44 | #2 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,504
|
Sorry, I do not quite understand.... what precisely is the problem?
|
05 May 2021, 21:44 | #3 |
Registered User
Join Date: Apr 2020
Location: CHICAGO / USA
Posts: 32
|
there is no problem.. i'm asking if some of the m68k gurus could provide tips or techniques they use for parsing structured data when it's coming in a byte at a time. that i'm trying to parse dissassembler.library's output is just to provide context
|
06 May 2021, 07:53 | #4 | |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,504
|
Quote:
Well, in this case it's quite simple: Wait for the LF = 0x0a to arrive, then parse the entire line. Or disassemble line by line, increasing the start of the disassembly each time again. The classical approaches for this problem - though complete overshooting for this problem - are either a state machine (keep an internal state such that is updated upon the input), or co-routines (essentially, a stack swap such that each call you receive looks like a return-from-subroutine to your function). The broader question I really had is why you would need to do some parsing? |
|
06 May 2021, 18:25 | #5 | |
Registered User
Join Date: Apr 2020
Location: CHICAGO / USA
Posts: 32
|
Quote:
i'm retrofitting disassembler.library in an application where having its output match the old format makes things much easier |
|
07 May 2021, 19:29 | #6 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,504
|
Coroutines aren't hard, there is just a lot of high-level mumble-jumble around it in some high level languages. There isn't really much required to get them working:
Code:
/* ** The following structure handles the coroutine */ struct Coroutine { struct StackSwapStruct cr_StackSwap; /* potentially more private stuff here */ UBYTE cr_Stack[CR_STACKSIZE]; /* Stack itself */ }; Code:
_CallCo: ;a0 = coroutine structure, a1 = parameter movem.l d2-d7/a2-a3/a5-a6,-(a7) ;save registers move.l cr_StackSwap+stk_Pointer(a0),a6 movem.l a0-a1,-(a6) ;push argument on new stack move.l a6,cr_StackSwap+stk_Pointer(a0) move.l _SysBase(a4),a6 jsr _LVOStackSwap(a6) movem.l (a7)+,d0-d7/a2-a3/a5-a6 ;retrieve parameter and registers of the caller. move.l d0,a0 ;also in a0 move.l d1,a1 move.l d1,d0 ;the return code is also the second argument rts It first creates a whirl in your head, but once you understand the idea, it is quite simple. Unlike what many high-level languages seem to imply, co-routines are quite simple. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Factory]3d polygon techniques | Samurai_Crow | project.Amiga Game Factory | 0 | 12 December 2017 09:06 |
Parsing an HTML file in Arexx | Gundam | Coders. General | 7 | 09 April 2014 00:16 |
xml parsing in arexx | amiga_user | Coders. General | 2 | 17 November 2011 15:42 |
error parsing global configuration file line 16 | DDNI | project.WHDLoad | 7 | 21 March 2011 13:09 |
|
|