From f2350d6c993e4735d8160945201c7ee7038c6779 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 18 Jul 2017 08:09:59 +0000 Subject: Add annotations --- ABC/Assembler.dcl | 9 +++++++++ ABC/Assembler.icl | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'ABC') diff --git a/ABC/Assembler.dcl b/ABC/Assembler.dcl index 03b8820..63880e7 100644 --- a/ABC/Assembler.dcl +++ b/ABC/Assembler.dcl @@ -12,6 +12,14 @@ from ABC.Machine.GraphStore import ::Desc :: DescLabel :== Label :: NrInstr :== Int +:: Annotation + = DAnnot Int [BasicType] + | OAnnot Int [BasicType] + +:: BasicType + = BT_Bool + | BT_Int + :: Assembler :== [Statement] :: Statement @@ -77,6 +85,7 @@ from ABC.Machine.GraphStore import ::Desc | MulI | SubI | Comment String + | Annotation Annotation instance toString Assembler instance toString Statement diff --git a/ABC/Assembler.icl b/ABC/Assembler.icl index 8167f70..087945d 100644 --- a/ABC/Assembler.icl +++ b/ABC/Assembler.icl @@ -16,8 +16,9 @@ where instance <<< Assembler where <<< f [] = f - <<< f [stm=:(Label l):r] = f <<< stm <<< "\r\n" <<< r + <<< f [stm=:(Label _):r] = f <<< stm <<< "\r\n" <<< r <<< f [stm=:(Descriptor _ _ _ _):r] = f <<< r + <<< f [stm=:(Annotation _):r] = f <<< stm <<< "\r\n" <<< r <<< f [stm :r] = f <<< "\t" <<< stm <<< "\r\n" <<< r instance <<< Statement where <<< f st = f <<< toString st @@ -26,6 +27,17 @@ generic gPrint a :: !a -> [Char] gPrint{|Int|} x = fromString (toString x) gPrint{|Bool|} x = map toLower (fromString (toString x)) gPrint{|String|} x = fromString x +gPrint{|Annotation|} x = fromString (printAnnot x) +where + printAnnot :: Annotation -> String + printAnnot (DAnnot a bs) = ".d " <+ a <+ " " <+ length bs <+ " " <+ types bs + printAnnot (OAnnot a bs) = ".o " <+ a <+ " " <+ length bs <+ " " <+ types bs + + types :: ([BasicType] -> [Char]) + types = map toC + where + toC BT_Bool = 'b' + toC BT_Int = 'i' gPrint{|UNIT|} x = [] gPrint{|EITHER|} fl fr (LEFT x) = fl x gPrint{|EITHER|} fl fr (RIGHT x) = fr x @@ -37,6 +49,7 @@ gPrint{|CONS of d|} fx (CONS x) = case d.gcd_name of "Dump" = ['dump\t"'] ++ quote (fx x) ++ ['"'] "Print" = ['print\t"'] ++ quote (fx x) ++ ['"'] "Comment" = ['| '] ++ fx x + "Annotation" = fx x name = tl (cons (fromString name)) ++ ['\t':fx x] where cons :: ![Char] -> [Char] @@ -106,6 +119,7 @@ translate [] _ _ = [] translate [Label _ :r] lc syms = translate r lc syms translate [Descriptor _ _ _ _:r] lc syms = translate r lc syms translate [Comment _ :r] lc syms = translate r lc syms +translate [Annotation _ :r] lc syms = translate r lc syms translate [stm :r] lc syms = [trans stm lc syms:translate r (lc+1) syms] where -- cgit v1.2.3