mirror of
https://github.com/marketideas/qasm.git
synced 2025-08-14 23:27:25 +00:00
macros with vars now working
This commit is contained in:
67
asm.cpp
67
asm.cpp
@@ -1371,6 +1371,17 @@ int CLASS::callOpCode(std::string op, MerlinLine &line)
|
|||||||
char c;
|
char c;
|
||||||
std::string s;
|
std::string s;
|
||||||
|
|
||||||
|
// during MACRO definition no opcodes are called (except for MAC, EOM, <<)
|
||||||
|
if (macrostack.size() > 0)
|
||||||
|
{
|
||||||
|
// if something on the macro stack, then a macro is being defined
|
||||||
|
std::string upop = Poco::toUpper(op);
|
||||||
|
if (!((upop == "MAC") || (upop == "EOM") || (upop == "<<<")))
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (op.length() == 4) // check for 4 digit 'L' opcodes
|
if (op.length() == 4) // check for 4 digit 'L' opcodes
|
||||||
{
|
{
|
||||||
c = op[3] & 0x7F;
|
c = op[3] & 0x7F;
|
||||||
@@ -1966,7 +1977,16 @@ restart:
|
|||||||
off = mVec[0].offset;
|
off = mVec[0].offset;
|
||||||
len = mVec[0].length;
|
len = mVec[0].length;
|
||||||
s = oper.substr(off, len);
|
s = oper.substr(off, len);
|
||||||
|
|
||||||
|
sym = NULL;
|
||||||
|
if (expand_macrostack.size() > 0)
|
||||||
|
{
|
||||||
|
sym = findVariable(s, expand_macro.variables);
|
||||||
|
}
|
||||||
|
if (sym == NULL)
|
||||||
|
{
|
||||||
sym = findVariable(s, variables);
|
sym = findVariable(s, variables);
|
||||||
|
}
|
||||||
if (sym != NULL)
|
if (sym != NULL)
|
||||||
{
|
{
|
||||||
//printf("match |%s|\n",sym->var_text.c_str());
|
//printf("match |%s|\n",sym->var_text.c_str());
|
||||||
@@ -2148,6 +2168,7 @@ void CLASS::process(void)
|
|||||||
x = substituteVariables(line, outop);
|
x = substituteVariables(line, outop);
|
||||||
if (x > 0)
|
if (x > 0)
|
||||||
{
|
{
|
||||||
|
line.printoperand = outop;
|
||||||
line.operand = outop;
|
line.operand = outop;
|
||||||
}
|
}
|
||||||
x = parseOperand(line);
|
x = parseOperand(line);
|
||||||
@@ -2174,21 +2195,27 @@ void CLASS::process(void)
|
|||||||
if (op.length() > 0)
|
if (op.length() > 0)
|
||||||
{
|
{
|
||||||
TMacro *mac = NULL;
|
TMacro *mac = NULL;
|
||||||
if (macrostack.size() == 0)
|
bool inoperand = false;
|
||||||
{
|
|
||||||
mac = findMacro(op);
|
mac = findMacro(op);
|
||||||
if (mac == NULL)
|
if (mac == NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (op == ">>>") // specal merlin way of calling a macro
|
if (op == ">>>") // specal merlin way of calling a macro
|
||||||
{
|
{
|
||||||
mac = findMacro(operand);
|
Poco::StringTokenizer tok(operand, ", ", Poco::StringTokenizer::TOK_TRIM |
|
||||||
|
Poco::StringTokenizer::TOK_IGNORE_EMPTY);
|
||||||
|
std::string s="";
|
||||||
|
if (tok.count()>0)
|
||||||
|
{
|
||||||
|
s=tok[0];
|
||||||
}
|
}
|
||||||
else
|
mac = findMacro(s);
|
||||||
|
inoperand = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mac == NULL)
|
||||||
{
|
{
|
||||||
x = callOpCode(op, line);
|
x = callOpCode(op, line);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (mac != NULL)
|
if (mac != NULL)
|
||||||
{
|
{
|
||||||
expand_macrostack.push(expand_macro);
|
expand_macrostack.push(expand_macro);
|
||||||
@@ -2206,9 +2233,35 @@ void CLASS::process(void)
|
|||||||
expand_macro.sourceline = lineno;
|
expand_macro.sourceline = lineno;
|
||||||
expand_macro.variables.vars.clear();
|
expand_macro.variables.vars.clear();
|
||||||
// set the variables for the macro here SGQ
|
// set the variables for the macro here SGQ
|
||||||
|
|
||||||
|
std::string parms = line.operand;
|
||||||
|
if (inoperand)
|
||||||
|
{
|
||||||
|
Poco::StringTokenizer tok(parms, ", ", Poco::StringTokenizer::TOK_TRIM |
|
||||||
|
Poco::StringTokenizer::TOK_IGNORE_EMPTY);
|
||||||
|
parms = "";
|
||||||
|
if (tok.count() > 1)
|
||||||
|
{
|
||||||
|
parms = tok[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Poco::StringTokenizer tok(parms, ",;", Poco::StringTokenizer::TOK_TRIM |
|
||||||
|
Poco::StringTokenizer::TOK_IGNORE_EMPTY);
|
||||||
|
|
||||||
|
uint32_t ct = 0;
|
||||||
|
for (auto itr = tok.begin(); itr != tok.end(); ++itr)
|
||||||
|
{
|
||||||
|
//evaluate each of these strings, check for errors on pass 2
|
||||||
|
std::string expr = *itr;
|
||||||
|
std::string v = "]" + Poco::NumberFormatter::format(ct + 1);
|
||||||
|
//printf("var: %s %s\n", v.c_str(), expr.c_str());
|
||||||
|
addVariable(v, expr, expand_macro.variables, true);
|
||||||
|
ct++;
|
||||||
|
}
|
||||||
|
x = 0;
|
||||||
expand_macro.currentline = 0;
|
expand_macro.currentline = 0;
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((x > 0) && (codeSkipped())) // has a psuedo-op turned off code generation? (LUP, IF, etc)
|
if ((x > 0) && (codeSkipped())) // has a psuedo-op turned off code generation? (LUP, IF, etc)
|
||||||
|
11
psuedo.cpp
11
psuedo.cpp
@@ -35,14 +35,6 @@ int CLASS::doDO(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
|
|||||||
{
|
{
|
||||||
UNUSED(opinfo);
|
UNUSED(opinfo);
|
||||||
|
|
||||||
|
|
||||||
if (a.macrostack.size()>0)
|
|
||||||
{
|
|
||||||
// if defining a macro, do nothing with this
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TEvaluator eval(a);
|
TEvaluator eval(a);
|
||||||
|
|
||||||
int64_t eval_value = 0;
|
int64_t eval_value = 0;
|
||||||
@@ -223,8 +215,6 @@ int CLASS::doLUP(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
|
|||||||
|
|
||||||
std::string op = Poco::toUpper(line.opcode);
|
std::string op = Poco::toUpper(line.opcode);
|
||||||
|
|
||||||
if (a.macrostack.size() == 0) // if defining a macro (size>0), don't process here
|
|
||||||
{
|
|
||||||
if (op == "LUP")
|
if (op == "LUP")
|
||||||
{
|
{
|
||||||
line.flags |= FLAG_NOLINEPRINT;
|
line.flags |= FLAG_NOLINEPRINT;
|
||||||
@@ -312,7 +302,6 @@ int CLASS::doLUP(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
|
|||||||
//err = errUnexpectedOp;
|
//err = errUnexpectedOp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
out:
|
out:
|
||||||
if (err > 0)
|
if (err > 0)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user