mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 02:36:41 +00:00
Merge e19dc81b437c991d1560e5c27f06adc60cbc2ce5 into 35b48ddd95f710aea91bd561c3be8786e5120e30
This commit is contained in:
commit
575be382ca
171
Server/src/main/resources/static/js/editor.js
vendored
171
Server/src/main/resources/static/js/editor.js
vendored
@ -54,12 +54,7 @@ function checkForEQUInstruction(line, result, currentLine) {
|
|||||||
result.labels.push(tokens[0]);
|
result.labels.push(tokens[0]);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
result.annotations.push({
|
produceError(result, currentLine, "Usage: constant_name EQU immediate_value");
|
||||||
row: currentLine,
|
|
||||||
column: 0,
|
|
||||||
text: "Usage: constant_name EQU immediate_value",
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -102,12 +97,7 @@ function checkForORGInstruction(line, result, currentLine) {
|
|||||||
if (!isNaN(num) && num === Math.floor(num)) {
|
if (!isNaN(num) && num === Math.floor(num)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
result.annotations.push({
|
produceError(result, currentLine, "Invalid operand: " + tokens[1]);
|
||||||
row: currentLine,
|
|
||||||
column: 0,
|
|
||||||
text: "Invalid operand: " + tokens[1],
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,13 +130,7 @@ function parseDWInstruction(line, result, currentLine) {
|
|||||||
var strText = values[i].substr(1, values[i].length - 2);
|
var strText = values[i].substr(1, values[i].length - 2);
|
||||||
|
|
||||||
if (strText.match(MALFORMED_UTF16_RE) != null) {
|
if (strText.match(MALFORMED_UTF16_RE) != null) {
|
||||||
|
produceError(result, currentLine, "Malformed UTF-16 escape sequence");
|
||||||
result.annotations.push({
|
|
||||||
row: currentLine,
|
|
||||||
column: 0,
|
|
||||||
text: "Malformed UTF-16 escape sequence",
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,15 +141,8 @@ function parseDWInstruction(line, result, currentLine) {
|
|||||||
// console.log("is Imm " + values[i]);
|
// console.log("is Imm " + values[i]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
produceError(result, currentLine, "Usage: DW IMM, IMM ...");
|
||||||
result.annotations.push({
|
|
||||||
row: currentLine,
|
|
||||||
column: 0,
|
|
||||||
text: "Usage: DW IMM, IMM ...",
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,6 +237,38 @@ function getOperandType(text, result) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function produceError(result, currentLine, explanation) {
|
||||||
|
result.annotations.push({
|
||||||
|
row: currentLine,
|
||||||
|
column: 0,
|
||||||
|
text: explanation,
|
||||||
|
type: "error"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidMnemonic(mnemonic) {
|
||||||
|
return isDoubleOpMnemonic(mnemonic) || isSingleOpMnemonic(mnemonic) || isZeroOpMnemonic(mnemonic);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDoubleOpMnemonic(mnemonic) {
|
||||||
|
return new RegExp('\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|xor|rol|ror|sal|sar|rcl|xchg|rcr)\\b').test(mnemonic.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
function isSingleOpMnemonic(mnemonic) {
|
||||||
|
return new RegExp('\\b(?:push|mul|pop|div|neg|call|jnz|jg|jl|jge|jle|hwi|hwq|jz|js|jns|ret|jmp|not|' +
|
||||||
|
'jc|jnc|jo|jno|inc|dec|ja|jna)\\b').test(mnemonic.toLowerCase()) ||
|
||||||
|
isSetMnemonic(mnemonic);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isZeroOpMnemonic(mnemonic) {
|
||||||
|
return new RegExp('\\b(?:ret|brk|nop|pushf|popf)\\b').test(mnemonic.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
function isSetMnemonic(mnemonic) {
|
||||||
|
return new RegExp('\\b(?:seta|setnbe|setae|setnb|setnc|setbe|setna|setb|setc|setnae|sete|setz|setne|' +
|
||||||
|
'setnz|setg|setnle|setge|setnl|setle|setng|setl|setnge|seto|setno|sets|setns)\\b').test(mnemonic.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
function parseInstruction(line, result, currentLine) {
|
function parseInstruction(line, result, currentLine) {
|
||||||
line = removeComment(line);
|
line = removeComment(line);
|
||||||
line = removeLabel(line);
|
line = removeLabel(line);
|
||||||
@ -271,124 +280,70 @@ function parseInstruction(line, result, currentLine) {
|
|||||||
return; //Line is empty
|
return; //Line is empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!parseDWInstruction(line, result, currentLine)) {
|
if (!parseDWInstruction(line, result, currentLine)) {
|
||||||
|
|
||||||
if (new RegExp('\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|mul|push|pop|div|xor|hwi|hwq|nop|neg|' +
|
if (isValidMnemonic(mnemonic)) {
|
||||||
'seta|setnbe|setae|setnb|setnc|setbe|setna|setb|setc|setnae|sete|setz|setne|setnz|setg|setnle|setge|setnl|setle|setng|setl|setnge|seto|setno|sets|setns|' +
|
|
||||||
'call|ret|jmp|jnz|jg|jl|jge|jle|int|jz|js|jns|brk|not|jc|jnc|ror|rol|sal|sar|jo|jno|inc|dec|rcl|xchg|rcr|pushf|popf|ja|jna)\\b').test(mnemonic.toLowerCase())) {
|
|
||||||
|
|
||||||
|
|
||||||
if (line.indexOf(",") !== -1) {
|
if (line.indexOf(",") !== -1) {
|
||||||
//2 Operands
|
//2 Operands
|
||||||
var strO1 = line.substring(line.indexOf(mnemonic) + mnemonic.length, line.indexOf(','));
|
if (!isDoubleOpMnemonic(mnemonic)) {
|
||||||
var strO2 = line.substring(line.indexOf(',') + 1).trim();
|
produceError(result, currentLine, mnemonic + " instruction with 2 operands is illegal");
|
||||||
|
|
||||||
|
|
||||||
//Validate operand number
|
|
||||||
if (!new RegExp('\\b(?:mov|add|sub|and|or|test|cmp|shl|shr|xor|rol|ror|sal|sar|rcl|xchg|rcr)\\b').test(mnemonic.toLowerCase())) {
|
|
||||||
result.annotations.push({
|
|
||||||
row: currentLine,
|
|
||||||
column: 0,
|
|
||||||
text: mnemonic + " instruction with 2 operands is illegal",
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var op1 = line.substring(line.indexOf(mnemonic) + mnemonic.length, line.indexOf(','));
|
||||||
|
var op2 = line.substring(line.indexOf(',') + 1).trim();
|
||||||
|
|
||||||
//Validate operand type
|
//Validate operand type
|
||||||
var o1Type = getOperandType(strO1, result);
|
var op1Type = getOperandType(op1, result);
|
||||||
var o2Type = getOperandType(strO2, result);
|
var op2Type = getOperandType(op2, result);
|
||||||
if (o1Type === OPERAND_INVALID) {
|
if (op1Type === OPERAND_INVALID) {
|
||||||
result.annotations.push({
|
produceError(result, currentLine, "Invalid operand: " + op1);
|
||||||
row: currentLine,
|
|
||||||
column: 0,
|
|
||||||
text: "Invalid operand: " + strO1,
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (o2Type === OPERAND_INVALID) {
|
if (op2Type === OPERAND_INVALID) {
|
||||||
result.annotations.push({
|
produceError(result, currentLine, "Invalid operand: " + op2);
|
||||||
row: currentLine,
|
|
||||||
column: 0,
|
|
||||||
text: "Invalid operand: " + strO2,
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check for illegal operand combos:
|
//Check for illegal operand combos:
|
||||||
if (o1Type === OPERAND_IMM) {
|
if (op1Type === OPERAND_IMM) {
|
||||||
result.annotations.push({
|
produceError(result, currentLine, "Destination operand can't be an immediate value");
|
||||||
row: currentLine,
|
|
||||||
column: 0,
|
|
||||||
text: "Destination operand can't be an immediate value",
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else if (tokens.length > 1) {
|
} else if (tokens.length > 1) {
|
||||||
//1 Operand
|
//1 Operand
|
||||||
strO1 = line.substring(line.indexOf(mnemonic) + mnemonic.length).trim();
|
if (!isSingleOpMnemonic(mnemonic)) {
|
||||||
|
produceError(result, currentLine, mnemonic + " instruction with 1 operand is illegal");
|
||||||
//Validate operand number
|
|
||||||
if (!new RegExp('\\b(?:push|mul|pop|div|neg|call|jnz|jg|jl|jge|jle|hwi|hwq|jz|js|jns|ret|jmp|not|jc|jnc|jo|jno|inc|dec|ja|jna|seta|setnbe|setae|setnb|setnc|setbe|setna|setb|setc|setnae|sete|setz|setne|setnz|setg|setnle|setge|setnl|setle|setng|setl|setnge|seto|setno|sets|setns)\\b').test(mnemonic.toLowerCase())) {
|
|
||||||
result.annotations.push({
|
|
||||||
row: currentLine,
|
|
||||||
column: 0,
|
|
||||||
text: mnemonic + " instruction with 1 operand is illegal",
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var op1 = line.substring(line.indexOf(mnemonic) + mnemonic.length).trim();
|
||||||
|
|
||||||
//Validate operand type
|
//Validate operand type
|
||||||
if (getOperandType(strO1, result) === OPERAND_INVALID) {
|
if (getOperandType(op1, result) === OPERAND_INVALID) {
|
||||||
result.annotations.push({
|
produceError(result, currentLine, "Invalid operand: " + op1);
|
||||||
row: currentLine,
|
|
||||||
column: 0,
|
|
||||||
text: "Invalid operand: " + strO1,
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new RegExp('\\b(?:seta|setnbe|setae|setnb|setnc|setbe|setna|setb|setc|setnae|sete|setz|setne|setnz|setg|setnle|setge|setnl|setle|setng|setl|setnge|seto|setno|sets|setns)\\b').test(mnemonic.toLowerCase())) {
|
if (isSetMnemonic(mnemonic)) {
|
||||||
if (getOperandType(strO1, result) === OPERAND_IMM) {
|
if (getOperandType(op1, result) === OPERAND_IMM) {
|
||||||
result.annotations.push({
|
produceError(result, currentLine, "Invalid operand type: " + op1);
|
||||||
row: currentLine,
|
|
||||||
column: 0,
|
|
||||||
text: "Invalid operand type: " + strO1,
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//No operand
|
//No Operand
|
||||||
if (!new RegExp('\\b(?:ret|brk|nop|pushf|popf)\\b').test(mnemonic.toLowerCase())) {
|
if (!isZeroOpMnemonic(mnemonic)) {
|
||||||
|
produceError(result, currentLine, mnemonic + " instruction with no operand is illegal");
|
||||||
//Validate operand number
|
|
||||||
result.annotations.push({
|
|
||||||
row: currentLine,
|
|
||||||
column: 0,
|
|
||||||
text: mnemonic + " instruction with no operand is illegal",
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result.annotations.push({
|
produceError(result, currentLine, "Unknown mnemonic: " + mnemonic);
|
||||||
row: currentLine,
|
|
||||||
column: 0,
|
|
||||||
text: "Unknown mnemonic: " + mnemonic,
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user