mirror of
https://github.com/hazemKrimi/jack-vm-translator.git
synced 2026-05-01 18:00:27 +00:00
Debugging single commands translation wip
This commit is contained in:
+8
-17
@@ -2,8 +2,8 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "operations.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "arithmetic.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ public:
|
|||||||
{
|
{
|
||||||
file << translatePush(filename, determineSegment(vec[1]), stoi(vec[2]));
|
file << translatePush(filename, determineSegment(vec[1]), stoi(vec[2]));
|
||||||
}
|
}
|
||||||
else
|
if (vec[0] == "pop")
|
||||||
{
|
{
|
||||||
file << translatePop(filename, determineSegment(vec[1]), stoi(vec[2]));
|
file << translatePop(filename, determineSegment(vec[1]), stoi(vec[2]));
|
||||||
}
|
}
|
||||||
@@ -47,23 +47,14 @@ public:
|
|||||||
|
|
||||||
if (vec.size() == 1)
|
if (vec.size() == 1)
|
||||||
{
|
{
|
||||||
int op = determineArithmeticOperator(vec[0]);
|
if (vec[0] == "add")
|
||||||
|
cout << translateAdd();
|
||||||
|
|
||||||
cout << op << " " << vec[0] << endl;
|
if (vec[0] == "sub")
|
||||||
|
cout << translateSub();
|
||||||
|
|
||||||
switch (determineArithmeticOperator(vec[0]))
|
if (vec[0] == "neg")
|
||||||
{
|
cout << translateNeg();
|
||||||
case ArithmeticOperator::ADD:
|
|
||||||
file << translateAdd();
|
|
||||||
break;
|
|
||||||
case ArithmeticOperator::SUB:
|
|
||||||
file << translateSub();
|
|
||||||
break;
|
|
||||||
case ArithmeticOperator::NEG:
|
|
||||||
default:
|
|
||||||
file << translateNeg();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file << endl;
|
file << endl;
|
||||||
|
|||||||
@@ -4,17 +4,17 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
ArithmeticOperator determineArithmeticOperator(string arithmeticOperator)
|
// Operation determineOperation(string operation)
|
||||||
{
|
// {
|
||||||
if (arithmeticOperator == "add")
|
// if (operation == "add")
|
||||||
return ArithmeticOperator::ADD;
|
// return Operation::ADD;
|
||||||
if (arithmeticOperator == "sub")
|
// if (operation == "sub")
|
||||||
return ArithmeticOperator::SUB;
|
// return Operation::SUB;
|
||||||
if (arithmeticOperator == "neg")
|
// if (operation == "neg")
|
||||||
return ArithmeticOperator::NEG;
|
// return Operation::NEG;
|
||||||
|
|
||||||
return ArithmeticOperator::NEG;
|
// return Operation::NEG;
|
||||||
}
|
// }
|
||||||
|
|
||||||
string translateAdd()
|
string translateAdd()
|
||||||
{
|
{
|
||||||
@@ -61,7 +61,7 @@ public:
|
|||||||
stringstream vmCodeStream(vmCode);
|
stringstream vmCodeStream(vmCode);
|
||||||
string text;
|
string text;
|
||||||
smatch matched;
|
smatch matched;
|
||||||
vector<vector<string>> tokens;
|
vector<vector<string>> commands;
|
||||||
|
|
||||||
while (getline(vmCodeStream, text, '\n'))
|
while (getline(vmCodeStream, text, '\n'))
|
||||||
{
|
{
|
||||||
@@ -77,10 +77,10 @@ public:
|
|||||||
{
|
{
|
||||||
matchedVector.push_back(text);
|
matchedVector.push_back(text);
|
||||||
}
|
}
|
||||||
tokens.push_back(matchedVector);
|
commands.push_back(matchedVector);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tokens;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeFile() {
|
void closeFile() {
|
||||||
|
|||||||
+11
-17
@@ -9,20 +9,14 @@ enum Segment
|
|||||||
TEMP,
|
TEMP,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ArithmeticOperator {
|
// enum Operation {
|
||||||
ADD,
|
// ADD,
|
||||||
SUB,
|
// SUB,
|
||||||
NEG
|
// NEG,
|
||||||
};
|
// EQ,
|
||||||
|
// GT,
|
||||||
enum ComparisonOperator {
|
// LT,
|
||||||
EQ,
|
// AND,
|
||||||
GT,
|
// OR,
|
||||||
LT,
|
// NOT
|
||||||
};
|
// };
|
||||||
|
|
||||||
enum LogicalOperator {
|
|
||||||
AND,
|
|
||||||
OR,
|
|
||||||
NOT
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user