From 39238b3983b4ef8a84d7e06b156aeb5ece1a474f Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Sun, 31 Oct 2010 00:30:07 +0200 Subject: [PATCH 1/1] 3a_asm: first attempt for a proper datastructe for our new dataformat --- 3a_asm/DTFormat.hs | 33 +++++++++++++++++++++++++++++++++ 3a_asm/Main.hs | 18 +++++++++++++++--- 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 3a_asm/DTFormat.hs diff --git a/3a_asm/DTFormat.hs b/3a_asm/DTFormat.hs new file mode 100644 index 0000000..819e083 --- /dev/null +++ b/3a_asm/DTFormat.hs @@ -0,0 +1,33 @@ +module DTFormat where + +import Data.Word +import Text.Printf + +type Address = Word32 +type Value = Word32 +type ValueToParse = String +type Code = String +type Label = String +type Comment = String + +data DTF = + DTF_Data Address Value Code Label Comment | + DTF_Instr Address Value Code Label Comment | + DTF_Comment Comment | + DTF_Label Label | + DTF_ToParse Address ValueToParse Code Label Comment + +instance Show (DTF) where + showsPrec n = showsDTF + +showsDTF :: DTF -> ShowS +showsDTF (DTF_Data a v c l s) = (++) (datins "0" a v c l s) +showsDTF (DTF_Instr a v c l s) = (++) (datins "1" a v c l s) +showsDTF (DTF_Comment c) = (++) (printf "2;%s\n" c) +showsDTF (DTF_Label l) = (++) (printf "3;%s\n" l) +showsDTF (DTF_ToParse a v c l s) = (++) (printf "lulz\n") + + +datins :: String -> Address -> Value -> Code -> Label -> Comment -> String +datins = printf "%s;%08x;%08x;%s;%s;%s\n" + diff --git a/3a_asm/Main.hs b/3a_asm/Main.hs index 25b46bb..d83e022 100644 --- a/3a_asm/Main.hs +++ b/3a_asm/Main.hs @@ -4,6 +4,7 @@ module Main where import DT +import DTFormat import Control.Applicative hiding ((<|>),many) @@ -12,6 +13,7 @@ import System.Environment import Text.Printf import Text.Parsec import Text.Parsec.String +import Text.Parsec.Combinator import qualified Data.Map as M import Data.List import qualified Data.ByteString.Lazy as BL @@ -20,11 +22,21 @@ import qualified Data.ByteString.Lazy as BL main :: IO () main = do args <- getArgs - src <- getContents + content <- getContents + let src = convertDTF (filter ((/=) "") $ lines content) print args + print src + +{- case runParser DT.parseInstructions () "stdin" src of Left err -> print err Right val -> do - -- TODO: nicht nur das erste element :/ sequence_ [printf "0x%08X\n" x | x <- val] - -- mapM (printf "0x%08X\n") val +-} + +-- data instr +-- convertDTF :: [String] -> Dict -> Dict -> ([DTF],Labels) + +convertDTF :: [String] -> [DTF] +convertDTF [] = [] +convertDTF (str:xs) = (DTF_Comment str):(convertDTF xs) -- 2.25.1