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:
+9
-18
@@ -2,8 +2,8 @@
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include "types.h"
|
||||
#include "operations.h"
|
||||
#include "memory.h"
|
||||
#include "arithmetic.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -32,14 +32,14 @@ public:
|
||||
void translate()
|
||||
{
|
||||
for (const auto &vec : commands)
|
||||
{
|
||||
{
|
||||
if (vec.size() > 1)
|
||||
{
|
||||
if (vec[0] == "push")
|
||||
{
|
||||
file << translatePush(filename, determineSegment(vec[1]), stoi(vec[2]));
|
||||
}
|
||||
else
|
||||
if (vec[0] == "pop")
|
||||
{
|
||||
file << translatePop(filename, determineSegment(vec[1]), stoi(vec[2]));
|
||||
}
|
||||
@@ -47,23 +47,14 @@ public:
|
||||
|
||||
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]))
|
||||
{
|
||||
case ArithmeticOperator::ADD:
|
||||
file << translateAdd();
|
||||
break;
|
||||
case ArithmeticOperator::SUB:
|
||||
file << translateSub();
|
||||
break;
|
||||
case ArithmeticOperator::NEG:
|
||||
default:
|
||||
file << translateNeg();
|
||||
break;
|
||||
}
|
||||
if (vec[0] == "neg")
|
||||
cout << translateNeg();
|
||||
}
|
||||
|
||||
file << endl;
|
||||
|
||||
@@ -4,17 +4,17 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
ArithmeticOperator determineArithmeticOperator(string arithmeticOperator)
|
||||
{
|
||||
if (arithmeticOperator == "add")
|
||||
return ArithmeticOperator::ADD;
|
||||
if (arithmeticOperator == "sub")
|
||||
return ArithmeticOperator::SUB;
|
||||
if (arithmeticOperator == "neg")
|
||||
return ArithmeticOperator::NEG;
|
||||
// Operation determineOperation(string operation)
|
||||
// {
|
||||
// if (operation == "add")
|
||||
// return Operation::ADD;
|
||||
// if (operation == "sub")
|
||||
// return Operation::SUB;
|
||||
// if (operation == "neg")
|
||||
// return Operation::NEG;
|
||||
|
||||
return ArithmeticOperator::NEG;
|
||||
}
|
||||
// return Operation::NEG;
|
||||
// }
|
||||
|
||||
string translateAdd()
|
||||
{
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
stringstream vmCodeStream(vmCode);
|
||||
string text;
|
||||
smatch matched;
|
||||
vector<vector<string>> tokens;
|
||||
vector<vector<string>> commands;
|
||||
|
||||
while (getline(vmCodeStream, text, '\n'))
|
||||
{
|
||||
@@ -77,10 +77,10 @@ public:
|
||||
{
|
||||
matchedVector.push_back(text);
|
||||
}
|
||||
tokens.push_back(matchedVector);
|
||||
commands.push_back(matchedVector);
|
||||
}
|
||||
|
||||
return tokens;
|
||||
return commands;
|
||||
}
|
||||
|
||||
void closeFile() {
|
||||
|
||||
+11
-17
@@ -9,20 +9,14 @@ enum Segment
|
||||
TEMP,
|
||||
};
|
||||
|
||||
enum ArithmeticOperator {
|
||||
ADD,
|
||||
SUB,
|
||||
NEG
|
||||
};
|
||||
|
||||
enum ComparisonOperator {
|
||||
EQ,
|
||||
GT,
|
||||
LT,
|
||||
};
|
||||
|
||||
enum LogicalOperator {
|
||||
AND,
|
||||
OR,
|
||||
NOT
|
||||
};
|
||||
// enum Operation {
|
||||
// ADD,
|
||||
// SUB,
|
||||
// NEG,
|
||||
// EQ,
|
||||
// GT,
|
||||
// LT,
|
||||
// AND,
|
||||
// OR,
|
||||
// NOT
|
||||
// };
|
||||
|
||||
Reference in New Issue
Block a user