GitLab will be upgraded on 30 Jan 2023 from 2.00 pm (AEDT) to 3.00 pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

AST.hs 22.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-- |
-- Module      :  Mu.AST
-- Copyright   :  Author 2011-2012
-- License     :  BSD3
--
-- Maintainer  :  email@something.com
-- Stability   :  experimental
-- Portability :  unknown
--
-- Description
--

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
16
{-# LANGUAGE DeriveGeneric #-}
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module Mu.AST (
    HasName (..)
  , Name (..)
  , SignatureName (..)
  , TypedefName (..)
  , FunctionName (..)
  , FunctionVerName (..)
  , ConstantName (..)
  , GlobalCellName (..)
  , BasicBlockName (..)
  , InstructionName (..)
  , ExposeName (..)
  , CookieName (..)
  , VarName (..)
  , Version (..)
  , Bundle (..)
  , Definition (..)
  , ConstConstructor (..)
  , CallConvention (..)
  , Type (..)
  , ExceptionClause (..)
  , WPExceptionClause (..)
  , KeepAliveClause (..)
  , DestinationClause (..)
  , Flag (..)
  , BinaryOp (..)
  , CompareOp (..)
  , ConvertOp (..)
  , AtomicRMWOp (..)
  , MemoryOrder (..)
  , Expression (..)
  , CurStackClause (..)
  , NewStackClause (..)
  , Assigned (..)
  , BasicBlock (..)
  , versionedName
  , dot
55
  , (%)
56
57
  , CommInst (..)
  ) where
58

nathyong's avatar
nathyong committed
59
import Data.Monoid ((<>))
60
import Data.Binary (Binary)
61
import Data.ByteString.Char8 (ByteString)
62
import Data.String (IsString, fromString)
63
import GHC.Generics (Generic)
64
65
66
67

import Text.Printf (printf)
import Data.List (intersperse, concat, map)

68
69
import Mu.AST.CommInst

70
71
72
73
74
75
76
77
-------------------------------------------------- * Named things

-- For internal use only, hence the underscore_naming.
type Underlying_Name_Type = String

-- | A universal class for the various things that newtype off 'Name'.
class HasName a where
    nameOf :: a -> Underlying_Name_Type 
78
79
    nameOf = nameOf . toName

nathyong's avatar
nathyong committed
80
    toName :: a -> Name
81
82

newtype Name = Name Underlying_Name_Type 
83
84
85
    deriving (IsString, Eq, Ord, Generic)

instance Binary Name
86
87
88
89
90
91

instance Show Name where
    show (Name n) = n

instance HasName Name where
    nameOf (Name n) = n
nathyong's avatar
nathyong committed
92
    toName = id
93
94
95

-- A little bit disgusting, but it gives us type safety where previously we had
-- none.
96
97
98
99
100
101
newtype SignatureName = SignatureName Name
    deriving (HasName, Eq, Ord, Show, IsString, Generic)
newtype TypedefName = TypedefName Name
    deriving (HasName, Eq, Ord, Show, IsString, Generic)
newtype FunctionName = FunctionName Name
    deriving (HasName, Eq, Ord, Show, IsString, Generic)
nathyong's avatar
nathyong committed
102
103
newtype FunctionVerName = FunctionVerName Name
    deriving (HasName, Eq, Ord, Show, IsString, Generic)
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
newtype ConstantName = ConstantName Name
    deriving (HasName, Eq, Ord, Show, IsString, Generic)
newtype GlobalCellName = GlobalCellName Name
    deriving (HasName, Eq, Ord, Show, IsString, Generic)
newtype BasicBlockName = BasicBlockName Name
    deriving (HasName, Eq, Ord, Show, IsString, Generic)
newtype InstructionName = InstructionName Name
    deriving (HasName, Eq, Ord, Show, IsString, Generic)
newtype ExposeName = ExposeName Name
    deriving (HasName, Eq, Ord, Show, IsString, Generic)
newtype CookieName = CookieName Name
    deriving (HasName, Eq, Ord, Show, IsString, Generic)
newtype VarName = VarName Name
    deriving (HasName, Eq, Ord, Show, IsString, Generic)

instance Binary SignatureName
instance Binary TypedefName
instance Binary FunctionName
nathyong's avatar
nathyong committed
122
instance Binary FunctionVerName
123
124
125
126
127
128
129
130
instance Binary ConstantName
instance Binary GlobalCellName
instance Binary BasicBlockName
instance Binary InstructionName
instance Binary ExposeName
instance Binary CookieName
instance Binary VarName

131
newtype Version = Version Underlying_Name_Type deriving (Show, Generic)
132
133

instance Binary Version
134

nathyong's avatar
nathyong committed
135
136
137
versionedName :: FunctionName -> Version -> FunctionVerName
versionedName fn (Version vn) = FunctionVerName $ Name $ nameOf fn <> "." <> vn

138
-- | Create a new name for a Mu thing inside some other scope.
nathyong's avatar
nathyong committed
139
140
dot :: (HasName a, IsString b) => a -> Underlying_Name_Type -> b
dot a sub = fromString $ nameOf a <> "." <> sub
141

142
143
144
145
146
147
-- | Infix version of 'dot'.
--
-- Possibly a bad idea to use.
(%) :: (HasName a, IsString b) => a -> Underlying_Name_Type -> b
(%) = dot

148
149
-------------------------------------------------- * Intermediate Representation

150
151
152
153
-- $ir
-- See <https://gitlab.anu.edu.au/mu/mu-spec/blob/master/ir.rst>

-- | A representation of Mu Bundles.
154
newtype Bundle = Bundle { unBundle :: [Definition] }
155
156
157
    deriving (Monoid, Generic)

instance Binary Bundle
158
159
160

data Definition
    = TypeDefinition TypedefName Type
161
162
    | SignatureDefinition SignatureName [TypedefName] [TypedefName]
    | FunctionDefinition FunctionName Version SignatureName BasicBlock [BasicBlock]
163
164
165
    | Constant ConstantName TypedefName ConstConstructor
    | GlobalCell GlobalCellName TypedefName
    | ExposedFunction ExposeName FunctionName CallConvention CookieName
166
167
168
    deriving (Generic)

instance Binary Definition
169

nathyong's avatar
nathyong committed
170
171
172
173
174
175
176
177
178
179
180
instance HasName Definition where
    nameOf defn = case defn of
        TypeDefinition name _ -> nameOf name
        SignatureDefinition name _ _ -> nameOf name
        FunctionDefinition name _ _ _ _ -> nameOf name
        Constant name _ _ -> nameOf name
        GlobalCell name _ -> nameOf name
        ExposedFunction name _ _ _ -> nameOf name

    toName = Name . nameOf

181
data ConstConstructor = IntCtor Integer
182
183
                      | FloatCtor Float
                      | DoubleCtor Double
184
185
186
                      | ListCtor [ConstConstructor]
                      | NullCtor
                      | ExternCtor ByteString
187
188
189
                      deriving (Generic)

instance Binary ConstConstructor
190
191
192
193
194

-- | Represent the Mu Calling convention
data CallConvention
    = MuCallConvention -- ^ Mu represents the default calling convention, CCall
    | ForeignCallConvention String -- ^ Extra conventions can be invoked using the foreign Convention
195
196
197
    deriving (Eq, Show, Generic)

instance Binary CallConvention
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235

-- | Represent the Mu IR native types.
data Type
    = MuInt { intLen :: Int}
      -- ^ Integers of variable sizes (1, 8, 16, 32 & 64 bits)
    | MuFloat
      -- ^ IEEE single length floating point
    | MuDouble
      -- ^ IEEE double length floating point
    | Ref { refType :: TypedefName}
      -- ^ A reference to a Mu TypedefName
    | IRef { irefType :: TypedefName}
      -- ^ An internal refernce to a Mu TypedefName
    | WeakRef { weakRefType :: TypedefName}
      -- ^ A weak refernce to a Mu TypedefName
    | UPtr { uptrType :: TypedefName}
      -- ^ A pointer to a Mu TypedefName
    | Struct { structTypes :: [TypedefName]}
      -- ^ A struct of multiple Mu Types
    | Array { arrayType :: TypedefName
           ,  arrayLen :: Int}
      -- ^ An array of a set number of Mu Types
    | Hybrid { hybridTypes :: [TypedefName]
            ,  hybridType :: TypedefName}
      -- ^ A hybrid with a set 'header' of Mu types, then a variable
      -- number of A single Mu TypedefName
    | Void
    | ThreadRef
    | StackRef
    | FrameCursorRef
    | TagRef64
    | Vector { vectorType :: TypedefName
            ,  vectorLen :: Int}
      -- ^ Vector of multiple Mu types
    | FuncRef { funcRefSig :: SignatureName}
      -- ^ Function ref to a function signature
    | UFuncPtr { ufuncPtrSig :: SignatureName}
      -- ^ Function pointer to a function signature
236
237
238
    deriving (Eq, Ord, Generic)

instance Binary Type
239
240
241
242
243

-- | Represents an Exception Clause which are appended to certain instructions
data ExceptionClause = ExceptionClause
    { exceptionNor :: DestinationClause -- ^ The destination to go to if normal execution happens
    , exceptionExc :: DestinationClause -- ^ The exceptional destination
244
245
    } deriving (Eq, Show, Generic)
instance Binary ExceptionClause
246
247
248
249

-- | WP Exceptions are used for Watch Points
newtype WPExceptionClause = WPExceptionClause
    { wpExceptionDest :: DestinationClause
250
251
    } deriving (Eq, Show, Generic)
instance Binary WPExceptionClause
252
253
254
255

-- | Keep Alive clause used to keep certain variables alive outside their scope
newtype KeepAliveClause = KeepAlive
    { keepAliveVars :: [VarName]
256
257
    } deriving (Eq, Show, Generic)
instance Binary KeepAliveClause
258
259
260

-- | Destination clause, the call to move to a basic block e.g. %cont(%a)
data DestinationClause = DestinationClause
261
    { destClauseDestination :: BasicBlockName
262
    , destClauseArgList :: [VarName]
263
264
    } deriving (Eq, Show, Generic)
instance Binary DestinationClause
265
266
267
268

-- | Flags for Common Instructions and CCall, pp $ Flag "DEFAULT" == "#DEFAULT"
newtype Flag = Flag
    { flagValue :: String
269
270
    } deriving (Generic)
instance Binary Flag
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292

-- | Binary Ops as defined by the Mu Spec
-- | Binary Ops all use the same arguments, so these flags represent precisly which binary operation to display
data BinaryOp
    = Add
    | Sub
    | Mul
    | SDiv
    | SRem
    | UDiv
    | URem
    | Shl
    | LShr
    | AShr
    | And
    | Or
    | Xor
    | FAdd
    | FSub
    | FMul
    | FDiv
    | FRem
293
294
    deriving (Eq, Ord, Enum, Show, Generic)
instance Binary BinaryOp
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

-- | Compare Ops as defined by the Mu Spec
-- | See Binary Ops for more detail
data CompareOp
    = EQ
    | NE
    | SGE
    | SLE
    | SGT
    | SLT
    | UGE
    | UGT
    | ULE
    | ULT
    | FFALSE
    | FTRUE
    | FOEQ
    | FOGT
    | FOGE
    | FOLT
    | FOLE
    | FONE
    | FORD
    | FUEQ
    | FUGT
    | FUGE
    | FULT
    | FULE
    | FUNE
    | FUNO
325
326
327
    deriving (Eq, Ord, Enum, Show, Generic)

instance Binary CompareOp
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343

-- | Convert Ops as defined by the Mu Spec
-- | See Binary Ops for more detail
data ConvertOp
    = TRUNC
    | ZEXT
    | SEXT
    | FPTRUNC
    | FPEXT
    | FPTOUI
    | FPTOSI
    | UITOFP
    | SITOFP
    | BITCAST
    | REFCAST
    | PTRCAST
344
345
346
    deriving (Eq, Ord, Enum, Show, Generic)

instance Binary ConvertOp
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361

-- | Atomic RMW Ops as  defined by the mu spec
-- | See Binary Ops for more detail
data AtomicRMWOp
    = XCHG
    | ADD
    | SUB
    | AND
    | NAND
    | OR
    | XOR
    | MAX
    | MIN
    | UMAX
    | UMIN
362
363
364
    deriving (Eq, Ord, Enum, Show, Generic)

instance Binary AtomicRMWOp
365
366
367
368
369
370
371
372
373
374

-- | Memory Orders ad defined by the Mu Spec
data MemoryOrder
    = NOT_ATOMIC
    | RELAXED
    | CONSUME
    | ACQUIRE
    | RELEASE
    | ACQ_REL
    | SEQ_CST
375
376
377
    deriving (Eq, Ord, Enum, Show, Generic)

instance Binary MemoryOrder
378
379
380
381

-- | Expressions define all the operations which can be performed on Mu Data. This includes terminal instructions.
data Expression
    = BinaryOperation
382
383
      { -- | The operation to be performed (Add, sub ...)
         binOp :: BinaryOp
384
385
386
387
388
389
390
391
392
         -- | The type of both parameters (they must be the same type)
      ,  binType :: TypedefName
         -- | The first parameter
      ,  binV1 :: VarName
         -- | The second parameter
      ,  binV2 :: VarName
         -- | The optional exception clause
      ,  execClause :: Maybe ExceptionClause}
    | CompareOperation
393
394
      { -- | The compare operation, {EQ, SLE ... }
         cmpOp :: CompareOp
395
396
397
398
399
400
401
         -- | Type of both operands
      ,  cmpType :: TypedefName
         -- | first parameter
      ,  cmpV1 :: VarName
         -- | second parameter
      ,  cmpV2 :: VarName}
    | ConvertOperation
402
403
      { -- | Operation to be performed {TRUNC, SEXT ...}
         convOp :: ConvertOp
404
405
406
407
408
409
410
411
412
         -- | The source type, the type to be converted from
      ,  convTypeSrc :: TypedefName
         -- | The destination type, the type to be converted to
      ,  convTypeDest :: TypedefName
         -- | Variable to be converted
      ,  convV :: VarName
         -- | optional exception clause
      ,  convExceptionClause :: Maybe ExceptionClause}
    | AtomicRMWOperation
413
414
      {  -- | Bool indicates if Loc is a pointer
         aRMWIsPtr :: Bool
415
416
417
418
419
420
421
422
423
424
425
426
427
         -- | The memory order for the operation
      ,  aRMWMemOrd :: MemoryOrder
         -- | The operation to be performed
      ,  aRMWOp :: AtomicRMWOp
         -- | The type of loc
      ,  aRMWType :: TypedefName
         -- | The memory location/address to access.
      ,  aRMWLoc :: VarName
         -- | The literal to be used
      ,  aRMWOpnd :: VarName
         -- | The optional Exception clause
      ,  aRMWExecClause :: Maybe ExceptionClause}
    | CmpXchg
428
429
      {  -- | Bool indicating if loc is a pointer
         cmpXchgIsPtr :: Bool
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
         -- | Bool indicating if operation is weak
      ,  cmpXchgIsWeak :: Bool
         -- | Memory order for operation success
      ,  cmpXchgMemOrdSucc :: MemoryOrder
         -- | Memory order for operation failure
      ,  cmpXchgMemOrdFail :: MemoryOrder
         -- | The type of the operation. Must be EQ comparable
      ,  cmpXchgType :: TypedefName
         -- | variable of IRef<T> or UPtr<T>. The memory loc/addr to access
      ,  cmpXchgLoc :: VarName
         -- | Strong Variant represents expected value in memory
      ,  cmpXchgExpect :: VarName
         -- | Strong Variant represents Desired value in memory
      ,  cmpXchgDesired :: VarName
         -- | Optional exception clause
      ,  cmpXchgExecClause :: Maybe ExceptionClause}
    | Fence
447
448
      {  -- | Memory order for fence operation
         fenceMemOrd :: MemoryOrder}
449
    | New
450
451
      {  -- | Type to allocate from heap
         newType :: TypedefName
452
453
454
         -- | exception clause if operation fails
      ,  newExecClause :: Maybe ExceptionClause}
    | NewHybrid
455
456
      {  -- | Hybrid type to alloate from heap
         newHybridType :: TypedefName
457
458
459
460
461
462
463
         -- | Length of hybrid type (must be int)
      ,  newHybridLenType :: TypedefName
         -- | Length of hybrid
      ,  newHybridLen :: VarName
         -- | Exception clause if operation fails
      ,  newHybridExecClause :: Maybe ExceptionClause}
    | Alloca
464
465
      {  -- | Type to allocate
         allocaType :: TypedefName
466
467
468
         -- | Exception clause if operation fails
      ,  allocaExecClause :: Maybe ExceptionClause}
    | AllocaHybrid
469
470
      {  -- | Hybrid Type to allocate
         allocaHybridType :: TypedefName
471
472
473
474
475
476
477
         -- | Length of hybrid type (must be int)
      ,  allocaHybridLenType :: TypedefName
         -- | Length of hybrid
      ,  allocaHybridLen :: VarName
         -- | Exception clause if operation fails
      ,  allocaHybridExecClause :: Maybe ExceptionClause}
    | Return
478
479
      {  -- | Values to return (if any)
         returnValues :: [VarName]}
480
    | Throw
481
482
      {  -- | exceptional variable tor throw
         throwException :: VarName}
483
    | Call
484
485
      {  -- | Signature of Mu Function to call
         callSignature :: SignatureName
486
487
488
489
490
491
492
493
494
         -- | Variable of type funcref<@sig>
      ,  callCallee :: VarName
         -- | Arguments to pass to function
      ,  callArgList :: [VarName]
         -- | optional exception clause
      ,  callExceptionClause :: Maybe ExceptionClause
         -- | Optional keep alive clause
      ,  callKeepAliveClause :: Maybe KeepAliveClause}
    | CCall
495
496
      {  -- | Calling convention to follow (Mu or Other)
         ccallCallConv :: CallConvention
497
498
499
500
501
502
503
504
505
506
507
508
509
         -- | type of callee (ufuncptr<@sig>)
      ,  ccallType :: TypedefName
         -- | Signature of callee
      ,  ccallSig :: SignatureName
         -- | address of function to call. (.const @callee = ufuncptr<@sig> 0xdeadbeef)
      ,  ccallCallee :: VarName
         -- | Arguments to pass to function
      ,  ccallArgList :: [VarName]
         -- | optional exception clause
      ,  ccallExceptionClause :: Maybe ExceptionClause
         -- | optional keep alive clause
      ,  ccallKeepAliveClause :: Maybe KeepAliveClause}
    | TailCall
510
511
      {  -- | signature of function to call
         tailCallSignature :: SignatureName
512
513
514
515
516
         -- | function to call
      ,  tailCallCallee :: VarName
         -- | arguments to pass
      ,  tailCallArgList :: [VarName]}
    | Branch1
517
518
      {  -- | BasicBlock to branch to
         branch1Destination :: DestinationClause}
519
    | Branch2
520
521
      {  -- | Variable of type int<1>, condition on which to branch
         branch2Cond :: VarName
522
523
524
525
526
         -- | Branch if condition is true
      ,  branch2BranchTrue :: DestinationClause
         -- | Branch if condition is false
      ,  branch2BranchFalse :: DestinationClause}
    | WatchPoint
527
528
      {  -- | name of watchpoint
         watchpointname :: VarName
529
530
531
532
533
534
535
536
537
538
539
540
541
         -- | id of watchpoint
      ,  watchpointId :: Int
         -- | The types of the return values
      ,  watchpointTypes :: [TypedefName]
         -- | destination before watchpoint is enabled
      ,  watchpointdis :: DestinationClause
         -- | destination after watchpoint is enabled
      ,  watchpointena :: DestinationClause
         -- | optional exception clause for after watchpoint is enabled
      ,  watchpointWpExec :: Maybe WPExceptionClause
         -- | optional keep alive clause for after watchpoint is enabled
      ,  watchpointKeepAlive :: Maybe KeepAliveClause}
    | Trap
542
543
      {  -- | name of trap
         trapName :: VarName
544
545
546
547
548
549
550
         -- | the types of the values to return
      ,  trapTypes :: [TypedefName]
         -- | optional exception clause
      ,  trapExceptionClause :: Maybe ExceptionClause
         -- | optinoal keep alive clause
      ,  trapKeepAlive :: Maybe KeepAliveClause}
    | WPBranch
551
552
      {  -- | watchpoint id
         wpBranchId :: Int
553
554
555
556
557
         -- | destination to jump to if watchpoint is enabled
      ,  wpBranchDis :: DestinationClause
         -- | destination to jump to if watchpoint is disabled
      ,  wpBranchEna :: DestinationClause}
    | Switch
558
559
      {  -- | type of value to switch on
         switchType :: TypedefName
560
561
562
563
564
565
566
         -- | value to switch on
      ,  switchOpnd :: VarName
         -- | default destination (if all others fail)
      ,  switchDefault :: DestinationClause
         -- | list of (condition, destination) pairs
      ,  switchBlocks :: [(VarName, DestinationClause)]}
    | SwapStack
567
568
      {  -- | variable of type stackref (stack to swap to)
         swapStackSwapee :: VarName
569
570
571
572
573
574
575
576
577
         -- | cur stack clause to use
      ,  swapStackCurStackClause :: CurStackClause
         -- | new stack clause to use
      ,  swapStackNewStackClause :: NewStackClause
         -- | optional exception clause
      ,  swapStackExecClause :: Maybe ExceptionClause
         -- | optional keep alive clause
      ,  swapStackKeepAliveClause :: Maybe KeepAliveClause}
    | NewThread
578
579
      {  -- | variable of type stackref (stack to bind thread to)
         newThreadStack :: VarName
580
581
582
583
584
         -- | new stack clause to use
      ,  newThreadStackClause :: NewStackClause
         -- | optional exception clause to use
      ,  newThreadExceptionClause :: Maybe ExceptionClause}
    | Comminst
585
586
      {  -- | operation code of the common instruction
         comminstInst :: CommInst
587
         -- | optional flags to pass
588
      ,  comminstFlags :: [Flag]
589
         -- | types (if any) of the arguments to pass to comminst
590
      ,  comminstTypes :: [TypedefName]
591
         -- | arguments (if any) to pass to the comminst
592
      ,  comminstArgs :: [VarName]
593
594
595
596
597
         -- | optional exception clause
      ,  comminstExecClause :: Maybe ExceptionClause
         -- | optional keep alive clause
      ,  comminstKeepAliveClause :: Maybe KeepAliveClause}
    | Load
598
599
      {  -- | Bool indicating if Loc is a poiner
         loadIsPtr :: Bool
600
601
602
603
604
605
606
607
608
         -- | Optional Memory order (default NOT_ATOMIC)
      ,  loadMemOrd :: Maybe MemoryOrder
         -- | The referant type of loc
      ,  loadType :: TypedefName
         -- | Variable of type IRef or UPtr (the mem location to load from)
      ,  loadLoc :: VarName
         -- | Exception clause if operation fails
      ,  loadExecClause :: Maybe ExceptionClause}
    | Store
609
610
      {  -- | Bool indicating if loc is a pointer
         storeIsPtr :: Bool
611
612
613
614
615
616
617
618
619
620
         -- | Memory order for operation
      ,  storeMemOrd :: Maybe MemoryOrder
         -- | Type of loc
      ,  storeType :: TypedefName
         -- | variable of IRef or UPtr. Mem loc/addr to store into
      ,  storeLoc :: VarName
         -- | The new value to store
      ,  storeNewVal :: VarName
         -- | Optional exception clause
      ,  storeExecClause :: Maybe ExceptionClause}
621
    | ExtractValue { structExtractType :: TypedefName
622
                   ,  structExtractIndex :: Int
623
624
                   ,  structExtractStruct :: VarName}
    | InsertValue { structInsertType :: TypedefName
625
626
                  ,  structInsertIndex :: Int
                  ,  structInsertStruct :: VarName
627
628
                  ,  structInsertNewVal :: VarName}
    | ExtractElement { arrExtractType :: TypedefName
629
630
                  ,  arrExtractIndexType :: TypedefName
                  ,  arrExtractOpnd :: VarName
631
632
                  ,  arrExtractIndex :: VarName}
    | InsertElement { arrInsertType :: TypedefName
633
634
635
                 ,  arrInsertIndexType :: TypedefName
                 ,  arrInsertOpnd :: VarName
                 ,  arrInsertIndex :: VarName
636
                 ,  arrInsertNewVal :: VarName}
637
638
639
640
    | ShuffleVector { arrShuffleV1Type :: TypedefName
                   ,  arrShuffleV2Type :: TypedefName
                   ,  arrShuffleV1 :: VarName
                   ,  arrShuffleV2 :: VarName
641
                   ,  arrShuffleMask :: VarName}
642
    | GetIRef { getIRefType :: TypedefName
643
             ,  getIRefOpnd :: VarName}
644
645
646
    | GetFieldIRef { getFieldIRefPtr :: Bool
                  ,  getFieldIRefTypeOpnd :: TypedefName
                  ,  getFieldIRefIndex :: Int
647
                  ,  getFieldIRefOpnd :: VarName}
648
649
650
651
    | GetElemIRef { getElemIRefPtr :: Bool
                 ,  getElemIRefTypeOpnd :: TypedefName
                 ,  getElemIRefTypeIndex :: TypedefName
                 ,  getElemIRefOpnd :: VarName
652
                 ,  getElemIRefIndex :: VarName}
653
654
655
656
    | ShiftIRef { shiftIRefPtr :: Bool
               ,  shiftIRefTypeOpnd :: TypedefName
               ,  shiftIRefTypeIndex :: TypedefName
               ,  shiftIRefOpnd :: VarName
657
               ,  shiftIRefOffset :: VarName}
658
659
    | GetVarPartIRef { getVarPartIRefPtr :: Bool
                    ,  getVarPartIRefTypeOpnd :: TypedefName
660
                    ,  getVarPartIRefOpnd :: VarName}
661
662
663
    deriving (Generic)

instance Binary Expression
664
665
666
667

data CurStackClause
    = RetWith { retWithTypes :: [TypedefName]}
    | KillOld
668
669
670
    deriving (Generic)

instance Binary CurStackClause
671
672
673
674
675

data NewStackClause
    = PassValues { newStackTypes :: [TypedefName]
                ,  newStackValues :: [VarName]}
    | ThrowExc { throwExecExceptionClause :: VarName}
676
677
678
    deriving (Generic)

instance Binary NewStackClause
679

680
data Assigned a = (:=)
681
    { assignVarss :: [VarName]
682
683
    , assignExpr :: a
    } deriving (Generic)
684

685
instance Binary a => Binary (Assigned a)
686
687

data BasicBlock = BasicBlock
688
689
690
691
    { basicBlockName :: BasicBlockName
    , basicBlockParams :: [(VarName, TypedefName)]
    , basicBlockExcParam :: Maybe VarName
    , basicBlockInstructions :: [Assigned Expression]
692
693
    , basicBlockTerminst :: Expression
    }
694
695
696
    deriving (Generic)

instance Binary BasicBlock