1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2025-08-19 03:27:28 +00:00

COPY is loads and stores and xfers, LOADIMM immediate. st? ops.

This commit is contained in:
Cat's Eye Technologies
2014-04-01 15:49:54 +01:00
parent 5af7c458ea
commit b458569edb
6 changed files with 51 additions and 11 deletions

View File

@@ -219,12 +219,15 @@ No duplicate declarations.
| routine main { | routine main {
| lda screen | lda screen
| tax | tax
| stx score
| tay | tay
| sty score
| cmp score | cmp score
| ldx score | ldx score
| txa | txa
| ldy score | ldy score
| tya | tya
| sta screen
| } | }
= .org 0 = .org 0
= .word $0801 = .word $0801
@@ -236,10 +239,13 @@ No duplicate declarations.
= main: = main:
= lda screen = lda screen
= tax = tax
= stx score
= tay = tay
= sty score
= cmp score = cmp score
= ldx score = ldx score
= txa = txa
= ldy score = ldy score
= tya = tya
= sta screen
= rts = rts

View File

@@ -9,7 +9,7 @@ import SixtyPical.Model
-- -- -- -- data-flow-analysis context -- -- -- -- -- -- -- -- data-flow-analysis context -- -- -- --
data Usage = Unknown data Usage = Unknown
| Value StorageLocation -- obviously a bit daft for now | Value DataValue -- obviously a bit daft for now
| Retained StorageLocation | Retained StorageLocation
deriving (Show, Ord, Eq) deriving (Show, Ord, Eq)
@@ -62,8 +62,8 @@ checkRoutine (Routine name (instr : instrs)) progCtx routCtx =
in in
checkRoutine (Routine name instrs) progCtx routCtx' checkRoutine (Routine name instrs) progCtx routCtx'
checkInstr (LOAD reg addr) progCtx routCtx = checkInstr (LOADIMM reg imm) progCtx routCtx =
Map.insert reg (Value addr) routCtx Map.insert reg (Value imm) routCtx
checkInstr (COPY src dst) progCtx routCtx = checkInstr (COPY src dst) progCtx routCtx =
Map.insert dst (Map.findWithDefault Unknown src routCtx) routCtx Map.insert dst (Map.findWithDefault Unknown src routCtx) routCtx
checkInstr (JSR name) progCtx routCtx = checkInstr (JSR name) progCtx routCtx =

View File

@@ -29,7 +29,9 @@ blockUsedLocations [] = []
blockUsedLocations (instr:instrs) = blockUsedLocations (instr:instrs) =
(instrUsedLocations instr) ++ blockUsedLocations instrs (instrUsedLocations instr) ++ blockUsedLocations instrs
instrUsedLocations (LOAD reg (NamedLocation loc)) = [loc] --instrUsedLocations (LOADIMM reg (NamedLocation loc)) = [loc]
instrUsedLocations (COPY (NamedLocation loc) _) = [loc]
instrUsedLocations (COPY _ (NamedLocation loc)) = [loc]
instrUsedLocations (CMP reg (NamedLocation loc)) = [loc] instrUsedLocations (CMP reg (NamedLocation loc)) = [loc]
-- TODO: JSR... -- TODO: JSR...
instrUsedLocations (IFEQ b1 b2) = instrUsedLocations (IFEQ b1 b2) =

View File

@@ -35,9 +35,18 @@ emitInstrs _ _ [] = ""
emitInstrs p r (instr:instrs) = emitInstrs p r (instr:instrs) =
" " ++ emitInstr p r instr ++ "\n" ++ emitInstrs p r instrs " " ++ emitInstr p r instr ++ "\n" ++ emitInstrs p r instrs
emitInstr p r (LOAD A (NamedLocation label)) = "lda " ++ label emitInstr p r (LOADIMM A val) = "lda #" ++ (show val)
emitInstr p r (LOAD X (NamedLocation label)) = "ldx " ++ label emitInstr p r (LOADIMM X val) = "ldx #" ++ (show val)
emitInstr p r (LOAD Y (NamedLocation label)) = "ldy " ++ label emitInstr p r (LOADIMM Y val) = "ldy #" ++ (show val)
emitInstr p r (COPY A (NamedLocation label)) = "sta " ++ label
emitInstr p r (COPY X (NamedLocation label)) = "stx " ++ label
emitInstr p r (COPY Y (NamedLocation label)) = "sty " ++ label
emitInstr p r (COPY (NamedLocation label) A) = "lda " ++ label
emitInstr p r (COPY (NamedLocation label) X) = "ldx " ++ label
emitInstr p r (COPY (NamedLocation label) Y) = "ldy " ++ label
emitInstr p r (CMP A (NamedLocation label)) = "cmp " ++ label emitInstr p r (CMP A (NamedLocation label)) = "cmp " ++ label
emitInstr p r (COPY A X) = "tax" emitInstr p r (COPY A X) = "tax"

View File

@@ -4,6 +4,7 @@ module SixtyPical.Model where
-- -- -- -- machine model -- -- -- -- -- -- -- -- machine model -- -- -- --
type DataValue = Int -- LET'S ASSUME THIS IS AT LEAST 8 BITS
type Address = Int -- LET'S ASSUME THIS IS AT LEAST 16 BITS type Address = Int -- LET'S ASSUME THIS IS AT LEAST 16 BITS
type LocationName = String type LocationName = String
@@ -45,7 +46,7 @@ data Decl = Assign LocationName Size Address -- .alias
type RoutineName = String type RoutineName = String
data Instruction = LOAD StorageLocation StorageLocation data Instruction = LOADIMM StorageLocation DataValue
| COPY StorageLocation StorageLocation | COPY StorageLocation StorageLocation
| CMP StorageLocation StorageLocation | CMP StorageLocation StorageLocation
| JSR RoutineName | JSR RoutineName

View File

@@ -74,6 +74,7 @@ block = do
command :: Parser Instruction command :: Parser Instruction
command = cmp <|> (try lda) <|> (try ldx) <|> (try ldy) <|> command = cmp <|> (try lda) <|> (try ldx) <|> (try ldy) <|>
(try sta) <|> (try stx) <|> (try sty) <|>
(try txa) <|> (try tax) <|> (try tya) <|> (try tay) <|> (try txa) <|> (try tax) <|> (try tya) <|> (try tay) <|>
beq <|> nop beq <|> nop
@@ -95,21 +96,42 @@ lda = do
string "lda" string "lda"
spaces spaces
l <- locationName l <- locationName
return (LOAD A (NamedLocation l)) return (COPY (NamedLocation l) A)
ldx :: Parser Instruction ldx :: Parser Instruction
ldx = do ldx = do
string "ldx" string "ldx"
spaces spaces
l <- locationName l <- locationName
return (LOAD X (NamedLocation l)) return (COPY (NamedLocation l) X)
ldy :: Parser Instruction ldy :: Parser Instruction
ldy = do ldy = do
string "ldy" string "ldy"
spaces spaces
l <- locationName l <- locationName
return (LOAD Y (NamedLocation l)) return (COPY (NamedLocation l) Y)
sta :: Parser Instruction
sta = do
string "sta"
spaces
l <- locationName
return (COPY A (NamedLocation l))
stx :: Parser Instruction
stx = do
string "stx"
spaces
l <- locationName
return (COPY X (NamedLocation l))
sty :: Parser Instruction
sty = do
string "sty"
spaces
l <- locationName
return (COPY Y (NamedLocation l))
txa :: Parser Instruction txa :: Parser Instruction
txa = do txa = do