summaryrefslogtreecommitdiff
path: root/PCode.h
blob: 601cfdc5cf7818cb71de01d8ed55401d45da9082 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#pragma once

typedef struct _PCodeArg {
    unsigned int _0;
    unsigned int _4;
    unsigned int _8;
} PCodeArg;

typedef struct _PCode {
    struct _PCode *nextPCode;
    struct _PCode *prevPCode;
    struct _PCBlock *block;
    unsigned int xx_C;
    unsigned int _10;
    int flags;
    unsigned int _18;
    unsigned int _1C;
    short op;
    short argCount;
    PCodeArg args[0];
} PCode;

typedef struct _PCLabel {
    struct _PCLabel *nextLabel;
    struct _PCBlock *block;
    short resolved;
    short index;
} PCLabel;

typedef struct _PCLink {
    struct _PCLink *nextLink;
    struct _PCBlock *block;
} PCLink;

typedef struct _PCBlock {
    struct _PCBlock *nextBlock;
    struct _PCBlock *prevBlock;
    PCLabel *labels;
    PCLink *predecessors;
    PCLink *successors;
    PCode *firstPCode;
    PCode *lastPCode;
    int blockIndex;
    int codeOffset; // in bytes
    int loopWeight;
    short pcodeCount;
    unsigned short flags;
} PCBlock;

/* PCode Flags */
enum {
    fPCodeFlag1 = 1,
    fPCodeFlag2 = 2,
    fPCodeFlag4 = 4,
    fPCodeFlag8 = 8,
    fPCodeFlag10 = 0x10,
    fIsPtrOp = 0x20,
    fIsConst = 0x40,
    fIsVolatile = 0x80,
    fSideEffects = 0x100,
    fPCodeFlag200 = 0x200,
    fPCodeFlag400 = 0x400,
    fPCodeFlag800 = 0x800,
    fPCodeFlag1000 = 0x1000,
    fCommutative = 0x2000,
    fIsCSE = 0x4000,
    fOverflow = 0x800000,
    fLink = 0x1000000,
    fBranchNotTaken = 0x4000000,
    fBranchTaken = 0x8000000,
    fAbsolute = 0x10000000,
    fSetsCarry = 0x10000000,
};

enum {
    fPCBlockFlag1 = 1,
    fPCBlockFlag2 = 2,
    fPCBlockFlag4 = 4,
    fPCBlockFlag8 = 8,
    fPCBlockFlag10 = 0x10,
    fPCBlockFlag20 = 0x20
};

extern PCBlock *pcbasicblocks;
extern PCBlock *pclastblock;
extern void *prologue;
extern void *epilogue;
extern PCBlock **depthfirstordering;
extern int pcblockcount;
extern int pcloopweight;

extern void initpcode();
extern PCode *makepcode(short op, ...);
extern void emitpcode(short op, ...);
extern PCode *copypcode(PCode *pcode);
extern PCLabel *makepclabel();
extern PCBlock *makepcblock();
extern void pclabel(PCBlock *block, PCLabel *label);
extern void pcbranch(PCBlock *block, PCLabel *label);
extern void pccomputepredecessors();
extern void deleteblock(PCBlock *block);
extern void deleteunreachableblocks();
extern void appendpcode(PCBlock *block, PCode *pcode);
extern void deletepcode(PCode *pcode);
extern void insertpcodebefore(PCode *anchor, PCode *newpcode);
extern void insertpcodeafter(PCode *anchor, PCode *newpcode);
extern void setpcodeflags(int flags);
extern void clearpcodeflags(int flags);
extern int pccomputeoffsets();
extern void computedepthfirstordering();