NEW AUTO 3,1 *-------------------------------------- * Input : ZPLineBufPtr, Y,A = T/Q, X = SC * CS : Reset Buffer * CC : Reuse Buffer * Output : Y,A = VarID *-------------------------------------- CC.SYM.New >STYA ZPPtr2 T/Q stx ZPPtr3 SC bit bPass2 bpl CC.SYM.New.1 bit bLocalScope bmi CC.SYM.New.1 >PUSHB.G CC.hScopes Global Scope >PUSHW ZPLineBufPtr >SYSCALL SListLookup bcs CC.SYM.New.9 >STYA.G CC.SymID Y,A = KeyID jsr CC.SkipX X = KeyLen >PUSHB.G CC.hScopes >PUSHW.G CC.SymID >PUSHW ZPSymBufPtr >PUSHWI 65535 all >PUSHWZ From Start >SYSCALL SListGetData bcc CC.SYM.New.2 CC.SYM.New.9 rts Y,A = SymSize *-------------------------------------- CC.SYM.New.1 jsr CC.SYM.BufInitYAX set buf according C ldy ScopeIdx lda (pData),y jsr CC.SYM.NewKey bcs CC.SYM.New.9 >STYA.G CC.SymID Y,A = KeyID jsr CC.SkipX X = KeyLen *-------------------------------------- CC.SYM.New.2 jsr CC.GetCharNB bcs .98 cmp #';' bne .1 lda ZPPtr3 cmp #SYM.SC.TYPEDEF bne CC.SYM.SetAddr clc rts .1 cmp #'(' bne CC.SYM.NewV ldy #SYM.Q lda #SYM.Q.FUNC ora (ZPSymBufPtr),y sta (ZPSymBufPtr),y jmp CC.F.Decl .98 lda #E.CSYN sec .99 rts *-------------------------------------- CC.SYM.NewV cmp #'[' bne CC.SYM.SetAddr ldy #SYM.Q lda (ZPSymBufPtr),y and #%11001111 sta (ZPSymBufPtr),y lda #SYM.Def ldy #SYM.DefSize sta (ZPSymBufPtr),y ldy #SYM.Q .1 lda (ZPSymBufPtr),y clc adc #SYM.Q.ARRAY sta (ZPSymBufPtr),y jsr CC.GetNextCharNB Skip [ bcs .98 cmp #']' bne .2 ldy #SYM.Q lda (ZPSymBufPtr),y and #SYM.Q.PPPOINTER beq .98 [] only allowed for * jsr CC.SYM.Add0000 set as [0] (deref) bcs .99 bra .3 .2 jsr CC.EXP.IntConst bcs .98 jsr CC.SYM.AddWord bcs .99 jsr CC.GetCharNB bcs .98 cmp #']' bne .98 .3 jsr CC.GetNextCharNB Skip ] bcs CC.SYM.SetAddr cmp #'[' bne CC.SYM.SetAddr ldy #SYM.Q lda (ZPSymBufPtr),y and #SYM.Q.AAARRAY cmp #SYM.Q.AAARRAY bne .1 already [][][] ? .98 lda #E.CSYN sec .99 rts *-------------------------------------- CC.SYM.SetAddr ldy #SYM.SizeOf lda (ZPSymBufPtr),y iny ora (ZPSymBufPtr),y bne .1 jsr CC.SYM.GetSymSizeOfInAXC jsr CC.SYM.SetSizeOf .1 ldy #SYM.Q lda (ZPSymBufPtr),y and #SYM.Q.FUNC bne .9 ldy #SYM.SC lda (ZPSymBufPtr),y beq CC.SYM.SetAddrG SYM.SC.STATIC cmp #SYM.SC.AUTO beq CC.SYM.SetAddrL .9 lda #E.TMISMATCH sec rts *-------------------------------------- CC.SYM.SetAddrG ldy #SYM.Addr lda ZPCCData sta (ZPSymBufPtr),y iny lda ZPCCData+1 sta (ZPSymBufPtr),y ldy #SYM.SizeOf lda (ZPSymBufPtr),y clc adc ZPCCData sta ZPCCData iny lda (ZPSymBufPtr),y adc ZPCCData+1 sta ZPCCData+1 clc rts *-------------------------------------- CC.SYM.SetAddrL ldy #SYM.SizeOf+1 lda (ZPSymBufPtr),y bne .9 dey SYM.SizeOf lda (ZPSymBufPtr),y clc adc LocalPtr sta LocalPtr bcs .9 ldy #SYM.Addr sta (ZPSymBufPtr),y ldy #SYM.SizeOf lda (ZPSymBufPtr),y jsr CODE.nAddLocal clc rts .9 lda #E.BUF sec rts *-------------------------------------- CC.SYM.BufInitYAX pha tya sta (ZPSymBufPtr) #SYM.T pla ldy #SYM.Q sta (ZPSymBufPtr),y txa iny #SYM.SC sta (ZPSymBufPtr),y bcc .8 DONT reset buffer iny lda #0 .1 sta (ZPSymBufPtr),y iny cpy #SYM.Def bne .1 tya ldy #SYM.DefSize sta (ZPSymBufPtr),y .8 rts *-------------------------------------- CC.SYM.PushAddr ldy #SYM.SC lda (ZPSymBufPtr),y beq .1 SYM.SC.STATIC * LOCAL >LDYA L.PCC.PushLAddrH jsr CODE.EmitPCC bcs .9 ldy #SYM.Addr lda (ZPSymBufPtr),y eor #$FF inc jsr CODE.LDAI bcs .9 >LDYA L.PCC.PushLAddrL jmp CODE.EmitPCC * GLOBAL .1 ldy #SYM.Addr+1 lda (ZPSymBufPtr),y tax dey lda (ZPSymBufPtr),y jsr CODE.LDAXI bcs .9 ldy #SYM.Q lda (ZPSymBufPtr),y and #SYM.Q.CONST beq .2 >LDYA L.PCC.PushIAddr jmp CODE.EmitPCC .2 >LDYA L.PCC.PushUAddr jmp CODE.EmitPCC .9 rts *-------------------------------------- CC.SYM.GetAddr1 ldy #SYM.SC lda (ZPSymBufPtr),y beq .1 SYM.SC.STATIC * LOCAL ldy #SYM.Addr lda (ZPSymBufPtr),y eor #$FF inc jsr CODE.LDAI bcs .9 >LDYA L.PCC.GetLAddr1 jmp CODE.EmitPCC * GLOBAL .1 ldy #SYM.Addr+1 lda (ZPSymBufPtr),y tax dey lda (ZPSymBufPtr),y jsr CODE.LDAXI bcs .9 ldy #SYM.Q lda (ZPSymBufPtr),y and #SYM.Q.CONST beq .2 >LDYA L.PCC.GetIAddr1 jmp CODE.EmitPCC .2 >LDYA L.PCC.GetUAddr1 jmp CODE.EmitPCC .9 rts *-------------------------------------- CC.SYM.GetAddr2 ldy #SYM.SC lda (ZPSymBufPtr),y beq .1 SYM.SC.STATIC * LOCAL ldy #SYM.Addr lda (ZPSymBufPtr),y eor #$FF inc jsr CODE.LDAI bcs .9 >LDYA L.PCC.GetLAddr2 jmp CODE.EmitPCC * GLOBAL .1 ldy #SYM.Addr+1 lda (ZPSymBufPtr),y tax dey lda (ZPSymBufPtr),y jsr CODE.LDAXI bcs .9 ldy #SYM.Q lda (ZPSymBufPtr),y and #SYM.Q.CONST beq .2 >LDYA L.PCC.GetIAddr2 jmp CODE.EmitPCC .2 >LDYA L.PCC.GetUAddr2 jmp CODE.EmitPCC .9 rts *-------------------------------------- CC.SYM.NewKey >PUSHA >PUSHW ZPLineBufPtr >SYSCALL SListNewKey bcs .9 .9 rts Y,A = KeyID, X = KeyLen *-------------------------------------- CC.SYM.Add0000 >LDYAI 0 *-------------------------------------- CC.SYM.AddWord phy pha ldy #SYM.DefSize lda (ZPSymBufPtr),y clc adc #2 bcs .9 sta (ZPSymBufPtr),y tay dey pla A sta (ZPSymBufPtr),y dey pla Y pha sta (ZPSymBufPtr),y iny lda (ZPSymBufPtr),y get back A ply get back Y * clc rts .9 pla pla lda #E.BUF sec rts *-------------------------------------- CC.SYM.AddName jsr CC.GetCharNB bcs .98 jsr CC.IsLetter bcs .98 .1 jsr CC.SYM.AddByte bcs .99 jsr CC.GetNextCharNB bcs .98 jsr CC.IsLetterOrDigit bcc .1 lda #0 bra CC.SYM.AddByte .98 lda #E.CSYN sec .99 rts *-------------------------------------- CC.SYM.AddByte pha ldy #SYM.DefSize lda (ZPSymBufPtr),y inc beq .9 sta (ZPSymBufPtr),y dec tay pla sta (ZPSymBufPtr),y clc rts .9 pla lda #E.BUF sec rts *-------------------------------------- CC.SYM.NewCPSID >LDYA.G CC.CPSID >STYA.G CC.CPSPFX+2 >LDA.G CC.CPSID+1 inc cmp #'Z'+1 bne .1 dey CC.CPSID lda (pData),y inc cmp #'Z'+1 beq .9 sta (pData),y lda #'A' iny CC.CPSID+1 .1 sta (pData),y clc rts .9 lda #E.OOH * sec rts *-------------------------------------- CC.SYM.NewA bit bPass2 bmi .8 >STA.G CC.CPSPFX A = "B"reak, "C"ontinue... >PUSHB.G CC.hScopes Global Scope >PUSHEA.G CC.CPSPFX >SYSCALL SListNewKey bcs .99 >STYA.G CC.SymID Y,A = KeyID lda #SYM.T.VOID sta (ZPSymBufPtr) #SYM.T lda #SYM.Q.POINTER ldy #SYM.Q sta (ZPSymBufPtr),y lda #SYM.SC.STATIC iny #SYM.SC sta (ZPSymBufPtr),y iny lda #0 .1 sta (ZPSymBufPtr),y iny cpy #SYM.Def bne .1 tya ldy #SYM.DefSize sta (ZPSymBufPtr),y >LDYA ZPCCCode jsr CC.SYM.SetAddrYA >LDA.G CC.hScopes Global Scope jmp CC.SYM.Store.1 .8 clc .99 rts *-------------------------------------- CC.SYM.StoreF >LDA.G CC.hScopes bit bPass2 bpl CC.SYM.Store.1 clc rts *-------------------------------------- CC.SYM.Store bit bPass2 bpl CC.SYM.StoreL Store Global & Local at Pass 1 bit bLocalScope Store Local at Pass 2 bmi CC.SYM.StoreL clc rts CC.SYM.StoreL ldy ScopeIdx lda (pData),y CC.SYM.Store.1 >PUSHA >PUSHW.G CC.SymID >PUSHW ZPSymBufPtr >PUSHBI 0 ldy #SYM.DefSize lda (ZPSymBufPtr),y >PUSHA >SYSCALL SListAddData rts *-------------------------------------- CC.SYM.NewScope ldy ScopeIdx cpy #CC.hScopes+SCOPE.MAX bcs .9 >SYSCALL SListNew bcs .99 inc ScopeIdx ldy ScopeIdx sta (pData),y dec bLocalScope clc rts .9 lda #E.OOH sec .99 rts *-------------------------------------- CC.SYM.FreeScope ldy ScopeIdx cpy #CC.hScopes beq * lda (pData),y >SYSCALL SListFree dec ScopeIdx inc bLocalScope rts *-------------------------------------- CC.SYM.Lookup >LDA.G CC.LookupIdx cmp #CC.LookupIdx+LOOKUP.MAX beq .99 >PUSHB ScopeIdx .1 tay lda (pData),y jsr CC.SListLookup bcc .8 lda (pstack) cmp #CC.hScopes beq .9 dec sta (pstack) bra .1 .9 inc pStack lda #E.NOKEY sec rts .8 inc pStack >STYA.G CC.LookupSymSize >INC.G CC.LookupIdx tay txa sta (pdata),y >SYSCALL GetMemPtr >STYA ZPLookupSymPtr * clc rts .99 lda #E.OOH * sec rts *-------------------------------------- CC.SYM.LookupA bit bPass2 bmi .1 ldx #0 ldy #0 clc rts .1 >STA.G CC.CPSPFX A = "B"reak, "C"ontinue... >PUSHB.G CC.hScopes Global Scope >PUSHEA.G CC.CPSPFX >SYSCALL SListLookup bcs .99 >STYA.G CC.SymID Y,A = KeyID >PUSHB.G CC.hScopes >PUSHW.G CC.SymID >PUSHW ZPSymBufPtr >PUSHWI 65535 all >PUSHWZ From Start >SYSCALL SListGetData bcs .99 ldy #SYM.Addr lda (ZPSymBufPtr),y tax iny lda (ZPSymBufPtr),y tay * clc .99 rts *-------------------------------------- CC.SYM.LookupFree >LDA.G CC.LookupIdx cmp #CC.LookupIdx beq .9 tay lda (pdata),y >SYSCALL FreeMem bcs .99 >DEC.G CC.LookupIdx cmp #CC.LookupIdx beq .8 tay lda (pdata),y >SYSCALL GetMemPtr >STYA ZPLookupSymPtr .8 clc rts .9 lda E.INVH * sec .99 rts *-------------------------------------- * ZPPtr2 = expected T/Q * ZPLookupSymPtr *-------------------------------------- CC.SYM.LookupCheckTQ lda ZPPtr2 target T bne .1 lda (ZPLookupSymPtr) SYM.T sta ZPPtr2 T ldy #SYM.Q lda (ZPLookupSymPtr),y and #$F8 ignore VOLATILE|FUNC|FASTCALL sta ZPPtr2+1 Q clc rts .1 cmp #SYM.T.VOID beq .2 lda (ZPLookupSymPtr) SYM.T cmp #SYM.T.VOID beq .2 cmp ZPPtr2 T bne .9 .2 lda ZPPtr2+1 Q ldy #SYM.Q eor (ZPLookupSymPtr),y and #$F8 ignore VOLATILE|FUNC|FASTCALL bne .9 clc rts .9 lda #E.TMISMATCH sec .99 rts *-------------------------------------- * on RT stack : Addr,value *-------------------------------------- CC.SYM.PopValue jsr CC.SYM.GetYASizeOfInAXC tax dex bne .1 >LDYA L.PCC.PopValue1 jmp CODE.EmitPCC .1 cpx #1 bne .2 >LDYA L.PCC.PopValue2 jmp CODE.EmitPCC .2 jsr CODE.LDXI bcs .9 >LDYA L.PCC.PopValueX jmp CODE.EmitPCC .9 rts *-------------------------------------- * out : Y,A = T/Q *-------------------------------------- CC.SYM.GetTypeInYA ldy #SYM.Q lda (ZPSymBufPtr),y pha lda (ZPSymBufPtr) tay pla rts *-------------------------------------- * out : A,X,C = size *-------------------------------------- CC.SYM.GetSymSizeOfInAXC ldy #SYM.Q lda (ZPSymBufPtr),y pha lda (ZPSymBufPtr) SYM.T tay pla CC.SYM.GetYASizeOfInAXC bit #SYM.Q.PPPOINTER beq .1 lda #2 pointer ldx #0 sec +1 for hMem Storage rts .1 bit #SYM.Q.AAARRAY bne .2 lda CC.TYPESIZE-1,y ldx #0 clc rts .2 ldx CC.TYPESIZE-1,y ldy #SYM.Def lda (ZPSymBufPtr),y >PUSHA iny lda (ZPSymBufPtr),y >PUSHA ldy #1 .3 dex beq .5 .4 lda (pStack),y clc adc (pStack),y sta (pStack),y lda (pStack) adc (pStack) sta (pStack) dex bne .4 .5 >PULLA tax >PULLA clc rts *-------------------------------------- * in/out : A,X,C = size *-------------------------------------- CC.SYM.SetSizeOf ldy #SYM.SizeOf sta (ZPSymBufPtr),y pha iny txa sta (ZPSymBufPtr),y pla rts *-------------------------------------- CC.SYM.SetAddrYA phy ldy #SYM.Addr+1 sta (ZPSymBufPtr),y pla dey sta (ZPSymBufPtr),y rts *-------------------------------------- MAN SAVE usr/src/bin/cc.s.sym LOAD usr/src/bin/cc.s ASM