/
AllEmitters.cs
192 lines (161 loc) · 8.2 KB
/
AllEmitters.cs
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
using System;
using Spruce.Attribs;
using Spruce.Tokens;
using XSharp.Tokens;
using XSharp.x86;
namespace XSharp.Emitters
{
// Emitters does the actual translation from X# (via Spruce) to x86 (via Assemblers)
public class AllEmitters : Emitters
{
public AllEmitters(Compiler aCompiler, x86.Assemblers.Assembler aAsm) : base(aCompiler, aAsm)
{
}
// ===============================================================
// Keywords
// ===============================================================
[Emitter(typeof(Variable), typeof(OpEquals), typeof(Variable))]
protected void VariableAssignment(object aVariableName, string aOpEquals, object aValue)
{
}
// if AL = #Vs2Ds_Noop return
[Emitter(typeof(If), typeof(Compare), typeof(Return))]
protected void IfConditionReturn(string aOpIf, object[] aCompareData, object aOpReturn)
{
}
[Emitter(typeof(If), typeof(Compare), typeof(OpOpenBrace))]
protected void IfConditionBlockStart(string aOpIf, object[] aCompareData, object aOpOpenBrace)
{
}
[Emitter(typeof(If), typeof(Compare), typeof(GotoKeyword), typeof(Identifier))]
protected void IfConditionGoto(string aOpIf, object[] aCompareData, string aGotoKeyword, string aLabel)
{
}
// if AL = #Vs2Ds_Noop return
[Emitter(typeof(If), typeof(Size), typeof(CompareVar), typeof(Return))]
protected void IfConditionReturn(string aOpIf, string aSize, object[] aCompareData, object aOpReturn)
{
}
[Emitter(typeof(If), typeof(Size), typeof(CompareVar), typeof(OpOpenBrace))]
protected void IfConditionBlockStart(string aOpIf, string aSize, object[] aCompareData, object aOpOpenBrace)
{
}
[Emitter(typeof(If), typeof(Size), typeof(CompareVar), typeof(GotoKeyword), typeof(Identifier))]
protected void IfConditionGoto(string aOpIf, string aSize, object[] aCompareData, string aGotoKeyword, string aLabel)
{
}
// If = return
[Emitter(typeof(If), typeof(OpPureComparators), typeof(Return))]
protected void IfConditionPureReturn(string aOpIf, string aPureComparator, string aReturns)
{
}
[Emitter(typeof(If), typeof(OpPureComparators), typeof(OpOpenBrace))]
protected void IfConditionPureBlockStart(string aOpIf, string aOpPureComparators, string aOpOpenBrace)
{
}
[Emitter(typeof(If), typeof(OpPureComparators), typeof(GotoKeyword), typeof(Identifier))]
protected void IfConditionPureGoto(string aOpIf, string aOpPureComparators, string aGotoKeyword, string aLabel)
{
}
[Emitter(typeof(While), typeof(Compare), typeof(OpOpenBrace))]
protected void WhileConditionBlockStart(string aOpWhile, object[] aCompareData, object aOpOpenBrace)
{
}
[Emitter(typeof(While), typeof(Size), typeof(CompareWithMem), typeof(OpOpenBrace))]
protected void WhileConditionWithMemoryBlockStart(string aOpWhile, string aSize, object[] aCompareData, object aOpOpenBrace)
{
}
[Emitter(typeof(While), typeof(OpPureComparators), typeof(OpOpenBrace))]
protected void WhileConditionPureBlockStart(string aOpWhile, string aOpPureComparators, string aOpOpenBrace)
{
}
[Emitter(typeof(Repeat), typeof(Int32u), typeof(Times), typeof(OpOpenBrace))]
protected void RepeatBlockStart(string aOpRepeat, UInt32 loops, string aOpTimes, string aOpOpenBrace)
{
}
// const i = 0
[Emitter(typeof(ConstKeyword), typeof(Identifier), typeof(OpEquals), typeof(Int32u))]
[Emitter(typeof(ConstKeyword), typeof(Identifier), typeof(OpEquals), typeof(StringLiteral))]
protected void ConstDefinition(string aConstKeyword, string aConstName, string oOpEquals, object aConstValue)
{
Compiler.WriteLine($"{Compiler.CurrentNamespace}_Const_{aConstName} equ {aConstValue}");
}
[Emitter(typeof(VarKeyword), typeof(Identifier), typeof(OpEquals), typeof(Int32u))]
[Emitter(typeof(VarKeyword), typeof(Identifier), typeof(OpEquals), typeof(StringLiteral))]
[Emitter(typeof(VarKeyword), typeof(Identifier), typeof(OpEquals), typeof(Const))]
[Emitter(typeof(VarKeyword), typeof(Identifier), typeof(OpEquals), typeof(Variable))]
[Emitter(typeof(VarKeyword), typeof(Identifier), typeof(OpEquals), typeof(VariableAddress))]
protected void VariableDefinition(string aVarKeyword, string aVariableName, string oOpEquals, object aVariableValue)
{
}
[Emitter(typeof(VarKeyword), typeof(Identifier))]
protected void VariableDefinition(string aVarKeyword, string aVariableName)
{
Compiler.WriteLine($"{Compiler.CurrentNamespace}_{aVariableName} dd 0");
}
[Emitter(typeof(VarKeyword), typeof(Identifier), typeof(Size), typeof(OpOpenBracket), typeof(Int32u), typeof(OpCloseBracket))]
protected void VariableArrayDefinition(string aVarKeyword, string aVariableName, string aSize, string aOpOpenBracket, object aNumberOfItems, string aOpCloseBracket)
{
}
[Emitter(typeof(Reg), typeof(OpBitwise), typeof(Const))]
[Emitter(typeof(Reg), typeof(OpBitwise), typeof(Variable))]
[Emitter(typeof(Reg08), typeof(OpBitwise), typeof(Reg08))]
[Emitter(typeof(Reg08), typeof(OpBitwise), typeof(Int08u))]
[Emitter(typeof(Reg16), typeof(OpBitwise), typeof(Reg16))]
[Emitter(typeof(Reg16), typeof(OpBitwise), typeof(Int16u))]
[Emitter(typeof(Reg32), typeof(OpBitwise), typeof(Reg32))]
[Emitter(typeof(Reg32), typeof(OpBitwise), typeof(Int32u))]
[Emitter(typeof(Reg32), typeof(OpBitwise), typeof(VariableAddress))]
protected void BitwiseArithmetic(Register aRegister, string aOpBitwise, object aValue)
{
}
[Emitter(typeof(Reg08), typeof(OpEquals), typeof(OpTilde), typeof(Reg08))]
[Emitter(typeof(Reg16), typeof(OpEquals), typeof(OpTilde), typeof(Reg16))]
[Emitter(typeof(Reg32), typeof(OpEquals), typeof(OpTilde), typeof(Reg32))]
protected void BitwiseNot(Register aRegister, string aOpEquals, string aOpTilde, Register aSourceRegister)
{
}
[Emitter(typeof(Reg), typeof(OpShift), typeof(Int08u))]
protected void BitwiseShift(Register aRegister, string aBitwiseShift, object aNumberBits)
{
}
[Emitter(typeof(Reg), typeof(OpRotate), typeof(Int08u))]
protected void RotateRegister(Register aRegister, object aOpRotate, object aNumBits)
{
}
// interrupt iNmae123 {
[Emitter(typeof(Interrupt), typeof(Identifier), typeof(OpOpenBrace))]
protected void InterruptDefinitionStart(string interruptKeyword, string functionName, string opOpenBraces)
{
}
// function fName123 {
[Emitter(typeof(FunctionKeyword), typeof(Identifier), typeof(OpOpenBrace))]
protected void FunctionDefinitionStart(string aFunctionKeyword, string aFunctionName, string opOpenBraces)
{
Compiler.CurrentFunction = aFunctionName;
Compiler.WriteLine($"{Compiler.CurrentNamespace}_{aFunctionName}:");
}
// }
[Emitter(typeof(OpCloseBrace))]
protected void BlockEnd(string opCloseBrace)
{
}
[Emitter(typeof(GotoKeyword), typeof(Identifier))]
protected void Goto(string aGotoKeyword, string aLabelName)
{
}
// Important! All that start with AlphaNum MUST be last to allow fall through to prevent early claims over keywords.
// fName ()
[Emitter(typeof(Identifier), typeof(OpOpenParen), typeof(OpCloseParen))]
protected void FunctionCall(string aFunctionName, string aOpOpenParenthesis, string aOpCloseParenthesis)
{
Compiler.WriteLine($"Call {Compiler.CurrentNamespace}_{aFunctionName}");
}
// Label
[Emitter(typeof(Identifier), typeof(OpColon))]
protected void LabelDefinition(string aLabelName, string aOpColon)
{
Compiler.WriteLine($"{Compiler.CurrentNamespace}_{aLabelName}:");
}
}
}