1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-15 14:29:32 +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 {
| lda screen
| tax
| stx score
| tay
| sty score
| cmp score
| ldx score
| txa
| ldy score
| tya
| sta screen
| }
= .org 0
= .word $0801
@ -236,10 +239,13 @@ No duplicate declarations.
= main:
= lda screen
= tax
= stx score
= tay
= sty score
= cmp score
= ldx score
= txa
= ldy score
= tya
= sta screen
= rts

View File

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

View File

@ -29,7 +29,9 @@ blockUsedLocations [] = []
blockUsedLocations (instr: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]
-- TODO: JSR...
instrUsedLocations (IFEQ b1 b2) =

View File

@ -35,9 +35,18 @@ emitInstrs _ _ [] = ""
emitInstrs p r (instr:instrs) =
" " ++ emitInstr p r instr ++ "\n" ++ emitInstrs p r instrs
emitInstr p r (LOAD A (NamedLocation label)) = "lda " ++ label
emitInstr p r (LOAD X (NamedLocation label)) = "ldx " ++ label
emitInstr p r (LOAD Y (NamedLocation label)) = "ldy " ++ label
emitInstr p r (LOADIMM A val) = "lda #" ++ (show val)
emitInstr p r (LOADIMM X val) = "ldx #" ++ (show val)
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 (COPY A X) = "tax"

View File

@ -4,6 +4,7 @@ module SixtyPical.Model where
-- -- -- -- 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 LocationName = String
@ -45,7 +46,7 @@ data Decl = Assign LocationName Size Address -- .alias
type RoutineName = String
data Instruction = LOAD StorageLocation StorageLocation
data Instruction = LOADIMM StorageLocation DataValue
| COPY StorageLocation StorageLocation
| CMP StorageLocation StorageLocation
| JSR RoutineName

View File

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