source: proto/pabloH/PabloIR.hs @ 5778

Last change on this file since 5778 was 4863, checked in by cameron, 4 years ago

Pablo prototypes in Haskell

File size: 1.2 KB
Line 
1module PabloIR where
2
3data PabloIR = IR [BasicBlock]
4
5type BlockLabel = String 
6data BasicBlock = Block(BlockLabel, [PabloInstruction])
7
8data Operand = IRvar String | IRnum Int
9data Operator = BitwiseAnd | BitwiseOr | BitwiseXor | PabloAdd | ShiftLeft
10data PabloInstruction = IRassign (String, Operand) | Binary(String, Operator, Operand, Operand) | 
11                        Branch(BlockLabel) | CondBranch(Operand, BlockLabel, BlockLabel) | Ret
12instance Show Operand where
13  show (IRvar s) = '%' : s
14  show (IRnum n) = show n
15
16instance Show Operator where
17  show BitwiseAnd = "and"
18  show BitwiseOr = "or"
19  show BitwiseXor = "xor"
20  show PabloAdd = "add"
21  show ShiftLeft = "shl"
22
23instance Show PabloInstruction where
24  show (IRassign(v,e)) = "  %" ++ v ++ " = " ++ (show e) ++ "\n"
25  show (Binary(v, op, e1, e2)) = "  %" ++ v ++ " = " ++ (show op) ++ " " ++ (show e1) ++ ", " ++ (show e2) ++ "\n"
26  show (Branch(lbl)) = "  br %" ++ lbl ++ "\n"
27  show (CondBranch(e, lbl1, lbl2)) = "  cbr " ++ (show e) ++ ", %" ++ lbl1 ++ ", %" ++ lbl2 ++ "\n"
28  show Ret = "  ret\n" 
29
30instance Show BasicBlock where
31  show (Block(lbl, instrs)) = lbl ++ ":\n" ++ (concatMap show instrs)
32
33instance Show PabloIR where
34  show (IR bbs) = concatMap show bbs
Note: See TracBrowser for help on using the repository browser.