ScriptStack 1.0.4
Loading...
Searching...
No Matches
Instruction.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Text;
4
6{
7
11 public class Instruction
12 {
13
14 #region Private Variables
15
16 private uint address;
17 private OpCode opcode;
18 private Operand first;
19 private Operand second;
20
21 #endregion
22
23 #region private Methods
24
25 private string ToLiteral(string input)
26 {
27 var literal = new StringBuilder(input.Length + 2);
28 //literal.Append("\"");
29 foreach (var c in input)
30 {
31 switch (c)
32 {
33 case '\'': literal.Append(@"\'"); break;
34 case '\"': literal.Append("\\\""); break;
35 case '\\': literal.Append(@"\\"); break;
36 case '\0': literal.Append(@"\0"); break;
37 case '\a': literal.Append(@"\a"); break;
38 case '\b': literal.Append(@"\b"); break;
39 case '\f': literal.Append(@"\f"); break;
40 case '\n': literal.Append(@"\n"); break;
41 case '\r': literal.Append(@"\r"); break;
42 case '\t': literal.Append(@"\t"); break;
43 case '\v': literal.Append(@"\v"); break;
44 default:
45 if (Char.GetUnicodeCategory(c) != System.Globalization.UnicodeCategory.Control)
46 {
47 literal.Append(c);
48 }
49 else
50 {
51 literal.Append(@"\u");
52 literal.Append(((ushort)c).ToString("x4"));
53 }
54 break;
55 }
56 }
57 //literal.Append("\"");
58 return literal.ToString();
59 }
60
61 #endregion
62
63 #region Public Methods
64
65 public Instruction(OpCode opcode, Operand first, Operand second)
66 {
67 address = 0;
68 this.opcode = opcode;
69 this.first = first;
70 this.second = second;
71 }
72
73 public Instruction(OpCode opcode, Operand operand0)
74 : this(opcode, operand0, null)
75 {
76 }
77
78 public Instruction(OpCode opcode)
79 : this(opcode, null, null)
80 {
81 }
82
83 public override string ToString()
84 {
85
86 if (opcode == OpCode.DBG)
87 {
88
89 int lineNumber = (int)first.Value;
90 return "Verarbeite Zeile: " + lineNumber + "\n" + second.Value;
91
92 }
93
94 StringBuilder stringBuilder = new StringBuilder();
95
96 stringBuilder.Append("["+string.Format(address.ToString("X8"))+"]");
97 stringBuilder.Append(" ");
98
99 stringBuilder.Append(opcode.ToString());
100 int iOpcodeLength = opcode.ToString().Length;
101 if (iOpcodeLength == 2)
102 stringBuilder.Append(" ");
103 if (iOpcodeLength == 3)
104 stringBuilder.Append(" ");
105
106 if (first != null)
107 {
108 stringBuilder.Append(" ");
109 stringBuilder.Append(first.ToString());
110 }
111
112 if (second != null)
113 {
114 stringBuilder.Append(", ");
115 stringBuilder.Append(second.ToString());
116 }
117
118 return stringBuilder.ToString();
119 }
120
121 #endregion
122
123 #region Public Properties
124
125 public uint Address
126 {
127 get { return address; }
128 set { address = value; }
129 }
130
132 {
133 get { return opcode; }
134 set { opcode = value; }
135 }
136
138 {
139 get { return first; }
140 set { first = value; }
141 }
142
144 {
145 get { return second; }
146 set { second = value; }
147 }
148
149 #endregion
150
151 }
152
153}
Instruction(OpCode opcode, Operand first, Operand second)
Instruction(OpCode opcode, Operand operand0)