1 | /*
|
---|
2 | * File: MOperand.h
|
---|
3 | * Author: rick
|
---|
4 | *
|
---|
5 | * Created on November 19, 2008, 1:17 AM
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef _MOPERAND_H
|
---|
9 | #define _MOPERAND_H
|
---|
10 |
|
---|
11 | #include <cstdio>
|
---|
12 | #include "IOperand.h"
|
---|
13 | #include "globals.h"
|
---|
14 | #include <string>
|
---|
15 |
|
---|
16 | #define NO_OFFSET INT_MIN
|
---|
17 |
|
---|
18 | using namespace std;
|
---|
19 |
|
---|
20 | // The type of an operand
|
---|
21 | typedef enum __moperandtype {
|
---|
22 | MT_UNKNOWN, // Unknown (yet)
|
---|
23 | MT_INT, // Integer immediate
|
---|
24 | MT_REAL, // Real immediate
|
---|
25 | MT_LABEL, // Label name e.k.a. string
|
---|
26 | MT_REGISTER, // Integer Register
|
---|
27 | MT_ADDRESS, // Address operand
|
---|
28 | MT_OFFSET // Register + offset address
|
---|
29 | } MOperandType;
|
---|
30 |
|
---|
31 | /* Do not use virtuals, just one mapping will do */
|
---|
32 | class MOperand {
|
---|
33 | public:
|
---|
34 | // Constructor/destructor
|
---|
35 | MOperand(MOperandType mtype, int value);
|
---|
36 | MOperand(MOperandType mtype, float value);
|
---|
37 | MOperand(MOperandType mtype, MRegisterType value);
|
---|
38 | MOperand(MOperandType mtype, string newLabel);
|
---|
39 | MOperand(MOperandType mtype, MRegisterType reg, int offset);
|
---|
40 | ~MOperand();
|
---|
41 |
|
---|
42 |
|
---|
43 | // Set operand type handling
|
---|
44 | void SetOperandType(MOperandType type);
|
---|
45 | MOperandType GetOperandType() const;
|
---|
46 |
|
---|
47 |
|
---|
48 | // constant value based
|
---|
49 | int GetIntValue() const;
|
---|
50 | void SetIntValue(int value);
|
---|
51 | float GetRealValue() const;
|
---|
52 | void SetRealValue(float value);
|
---|
53 |
|
---|
54 | // register entries
|
---|
55 | void SetRegisterNumber(int value);
|
---|
56 | int GetRegisterNumber() const;
|
---|
57 | void SetRegisterType(MRegisterType value);
|
---|
58 | MRegisterType GetRegisterType() const;
|
---|
59 |
|
---|
60 |
|
---|
61 | void SetOffset(int value);
|
---|
62 | int GetOffset() const;
|
---|
63 |
|
---|
64 | void SetAddress(int value);
|
---|
65 | void SetAddress(MRegisterType value);
|
---|
66 |
|
---|
67 | int GetAddress() const;
|
---|
68 |
|
---|
69 | void SetLabel(string newLabel);
|
---|
70 | string GetLabel() const;
|
---|
71 |
|
---|
72 | // Dump
|
---|
73 | void Dump(FILE *file);
|
---|
74 |
|
---|
75 | private:
|
---|
76 | int iValue;
|
---|
77 | float rValue;
|
---|
78 | int registerNumber;
|
---|
79 | string label;
|
---|
80 | int offset;
|
---|
81 | int address;
|
---|
82 | MOperandType mType;
|
---|
83 | };
|
---|
84 |
|
---|
85 | #endif /* _MOPERAND_H */
|
---|
86 |
|
---|