forked from svn2github/nsl-assembler
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathStrCpyInstruction.java
More file actions
107 lines (96 loc) · 2.78 KB
/
StrCpyInstruction.java
File metadata and controls
107 lines (96 loc) · 2.78 KB
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
/*
* StrCpyInstruction.java
*/
package nsl.instruction;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import nsl.*;
import nsl.expression.*;
/**
* @author Stuart
*/
public class StrCpyInstruction extends AssembleExpression {
public static final String name = "StrCpy";
protected final String instructionName;
private final Expression string;
private final Expression maxLen;
private final Expression startOffset;
/**
* Class constructor.
*
* @param returns the number of values to return
*/
public StrCpyInstruction(int returns) {
this(returns, name);
}
/**
* Class constructor for subclasses with different instruction names.
*
* @param returns the number of values to return
* @param instructionName the name of the instruction (e.g., "StrCpy" or "UnsafeStrCpy")
*/
protected StrCpyInstruction(int returns, String instructionName) {
this.instructionName = instructionName;
if (PageExInfo.in())
throw new NslContextException(
EnumSet.of(NslContext.Section, NslContext.Function, NslContext.Global), instructionName);
if (returns != 1) throw new NslReturnValueException(instructionName, 1);
ArrayList<Expression> paramsList = Expression.matchList();
int paramsCount = paramsList.size();
if (paramsCount < 1 || paramsCount > 3) throw new NslArgumentException(instructionName, 1, 3);
this.string = paramsList.get(0);
if (paramsCount > 1) {
this.maxLen = paramsList.get(1);
if (paramsCount > 2) {
this.startOffset = paramsList.get(2);
} else {
this.startOffset = null;
}
} else {
this.maxLen = null;
this.startOffset = null;
}
}
/**
* Assembles the source code.
*
* @throws IOException
*/
@Override
public void assemble() throws IOException {
throw new UnsupportedOperationException("Not supported.");
}
/**
* Assembles the source code.
*
* @param var the variable to assign the value to
*/
@Override
public void assemble(Register var) throws IOException {
Expression varOrString = AssembleExpression.getRegisterOrExpression(this.string);
if (this.maxLen != null) {
Expression varOrMaxLen = AssembleExpression.getRegisterOrExpression(this.maxLen);
if (this.startOffset != null) {
Expression varOrStartOffset = AssembleExpression.getRegisterOrExpression(this.startOffset);
ScriptParser.writeLine(
instructionName
+ " "
+ var
+ " "
+ varOrString
+ " "
+ varOrMaxLen
+ " "
+ varOrStartOffset);
varOrStartOffset.setInUse(false);
} else {
ScriptParser.writeLine(instructionName + " " + var + " " + varOrString + " " + varOrMaxLen);
}
varOrMaxLen.setInUse(false);
} else {
ScriptParser.writeLine(instructionName + " " + var + " " + varOrString);
}
varOrString.setInUse(false);
}
}