2019-11-11 23:56:03 +00:00
|
|
|
#define ADD_ERROR_STRINGS
|
|
|
|
#include "asm.h"
|
|
|
|
#include "eval.h"
|
2019-11-13 01:03:51 +00:00
|
|
|
#include "psuedo.h"
|
2019-11-19 19:27:17 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
|
|
|
|
#define CLASS MerlinLine
|
|
|
|
|
|
|
|
|
|
|
|
CLASS::CLASS()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
CLASS::CLASS(std::string line)
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
set(line);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CLASS::setError(uint32_t ecode)
|
|
|
|
{
|
|
|
|
errorcode = ecode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLASS::print(uint32_t lineno)
|
|
|
|
{
|
2019-11-17 03:33:22 +00:00
|
|
|
uint32_t l, i, savpcol, pcol;
|
|
|
|
bool commentprinted = false;
|
2019-11-14 03:37:26 +00:00
|
|
|
static bool checked = false;
|
|
|
|
static bool nc1 = false;
|
2019-11-13 23:45:39 +00:00
|
|
|
bool nc = false;
|
2019-11-17 16:02:55 +00:00
|
|
|
uint8_t commentcol = tabs[2];
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-15 05:21:03 +00:00
|
|
|
uint32_t b = 4; // how many bytes show on the first line
|
|
|
|
|
2019-11-15 07:35:04 +00:00
|
|
|
if (datafillct > 0)
|
|
|
|
{
|
|
|
|
l = datafillct;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
l = outbytect;
|
|
|
|
}
|
2019-11-15 05:21:03 +00:00
|
|
|
if (l > b)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-15 05:21:03 +00:00
|
|
|
l = b;
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-16 17:27:24 +00:00
|
|
|
if (errorcode > 0)
|
|
|
|
{
|
2019-11-18 14:07:44 +00:00
|
|
|
if (merlinerrors)
|
2019-11-16 17:27:24 +00:00
|
|
|
{
|
|
|
|
//printf("errorcode=%d\n",errorcode);
|
2019-11-17 03:33:22 +00:00
|
|
|
printf("\n%s in line: %d", errStrings[errorcode].c_str(), lineno + 1);
|
2019-11-16 17:27:24 +00:00
|
|
|
if (errorText != "")
|
|
|
|
{
|
2019-11-17 22:15:45 +00:00
|
|
|
printf(" (%s)", errorText.c_str());
|
2019-11-16 17:27:24 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
flags &= (~FLAG_NOLINEPRINT);
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-16 17:27:24 +00:00
|
|
|
if (flags & FLAG_NOLINEPRINT)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-11-14 03:37:26 +00:00
|
|
|
if (!checked)
|
|
|
|
{
|
|
|
|
nc1 = getBool("option.nocolor", false);
|
|
|
|
checked = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nc = nc1;
|
|
|
|
}
|
|
|
|
|
2019-11-18 14:07:44 +00:00
|
|
|
if ((!isatty(STDOUT_FILENO)) || (merlinerrors))
|
2019-11-14 03:37:26 +00:00
|
|
|
{
|
|
|
|
nc = true;
|
|
|
|
}
|
|
|
|
|
2019-11-13 23:45:39 +00:00
|
|
|
if (!nc)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-13 23:45:39 +00:00
|
|
|
if (errorcode > 0)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-13 23:45:39 +00:00
|
|
|
if (errorcode >= errFatal)
|
|
|
|
{
|
|
|
|
SetColor(CL_WHITE | CL_BOLD | BG_RED);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetColor(CL_YELLOW | CL_BOLD | BG_NORMAL);
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-13 23:45:39 +00:00
|
|
|
SetColor(CL_WHITE | CL_BOLD | BG_NORMAL);
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bool empty = false;
|
2019-11-19 19:27:17 +00:00
|
|
|
if ((printlable == "") && (opcode == "") && (printoperand == ""))
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
|
|
|
empty = true;
|
|
|
|
}
|
|
|
|
|
2019-11-13 04:32:10 +00:00
|
|
|
pcol = 0;
|
2019-11-16 02:51:30 +00:00
|
|
|
|
|
|
|
bool saddr = flags & FLAG_FORCEADDRPRINT;
|
|
|
|
saddr = (outbytect > 0) ? true : saddr;
|
|
|
|
saddr = (printlable != "") ? true : saddr;
|
|
|
|
|
|
|
|
if (saddr)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-13 04:32:10 +00:00
|
|
|
pcol += printf("%02X/%04X:", (startpc >> 16), startpc & 0xFFFF);
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-13 04:32:10 +00:00
|
|
|
pcol += printf(" ");
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < l; i++)
|
|
|
|
{
|
2019-11-15 07:35:04 +00:00
|
|
|
uint8_t a = datafillbyte;
|
|
|
|
if (datafillct == 0)
|
|
|
|
{
|
|
|
|
a = outbytes[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
pcol += printf("%02X ", a);
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
for (i = l; i < b; i++)
|
|
|
|
{
|
2019-11-13 04:32:10 +00:00
|
|
|
pcol += printf(" ");
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
2019-11-15 07:35:04 +00:00
|
|
|
pcol += printf("%6d ", lineno + 1);
|
|
|
|
|
2019-11-13 01:03:51 +00:00
|
|
|
if (showmx)
|
2019-11-12 08:15:47 +00:00
|
|
|
{
|
2019-11-15 07:35:04 +00:00
|
|
|
if ((outbytect + datafillct) > 0)
|
2019-11-12 08:15:47 +00:00
|
|
|
{
|
2019-11-13 04:32:10 +00:00
|
|
|
pcol += printf("%%%c%c ", linemx & 02 ? '1' : '0', linemx & 01 ? '1' : '0');
|
2019-11-12 08:15:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-13 04:32:10 +00:00
|
|
|
pcol += printf(" ");
|
2019-11-12 08:15:47 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-12 18:13:15 +00:00
|
|
|
|
2019-11-13 01:03:51 +00:00
|
|
|
if (isDebug() > 1)
|
2019-11-12 08:15:47 +00:00
|
|
|
{
|
2019-11-13 04:32:10 +00:00
|
|
|
pcol += printf("%02X ", addressmode & 0xFF);
|
2019-11-12 08:15:47 +00:00
|
|
|
}
|
2019-11-13 04:32:10 +00:00
|
|
|
|
2019-11-17 03:33:22 +00:00
|
|
|
savpcol = pcol; // this is how many bytes are in the side margin
|
2019-11-13 04:32:10 +00:00
|
|
|
pcol = 0; // reset pcol here because this is where source code starts
|
2019-11-12 08:15:47 +00:00
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
if (empty)
|
|
|
|
{
|
2019-11-13 04:32:10 +00:00
|
|
|
if (comment.length() > 0)
|
|
|
|
{
|
|
|
|
if (comment[0] == ';')
|
|
|
|
{
|
|
|
|
while (pcol < commentcol)
|
|
|
|
{
|
|
|
|
pcol += printf(" ");
|
|
|
|
}
|
|
|
|
}
|
2019-11-17 03:33:22 +00:00
|
|
|
//else
|
2019-11-16 02:51:30 +00:00
|
|
|
{
|
2019-11-17 03:33:22 +00:00
|
|
|
int comct = 0;
|
|
|
|
for (uint32_t cc = 0; cc < comment.length(); cc++)
|
|
|
|
{
|
|
|
|
pcol += printf("%c", comment[cc]);
|
|
|
|
comct++;
|
2019-11-19 17:22:27 +00:00
|
|
|
if ((comment[cc] <= ' ') && (pcol >= (commentcol + savpcol + 20)))
|
2019-11-17 03:33:22 +00:00
|
|
|
{
|
|
|
|
printf("\n");
|
|
|
|
pcol = 0;
|
|
|
|
while (pcol < (commentcol + savpcol))
|
|
|
|
{
|
|
|
|
pcol += printf(" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//pcol += printf("%s", comment.c_str());
|
|
|
|
|
2019-11-16 02:51:30 +00:00
|
|
|
}
|
2019-11-17 03:33:22 +00:00
|
|
|
commentprinted = true;
|
2019-11-13 04:32:10 +00:00
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-17 16:02:55 +00:00
|
|
|
pcol += printf("%s ", printlable.c_str());
|
2019-11-17 03:33:22 +00:00
|
|
|
while (pcol < tabs[0])
|
|
|
|
{
|
|
|
|
pcol += printf(" ");
|
|
|
|
}
|
2019-11-17 16:02:55 +00:00
|
|
|
pcol += printf("%s ", opcode.c_str());
|
2019-11-17 03:33:22 +00:00
|
|
|
while (pcol < tabs[1])
|
|
|
|
{
|
|
|
|
pcol += printf(" ");
|
|
|
|
}
|
2019-11-19 21:41:27 +00:00
|
|
|
if (isDebug() > 1)
|
2019-11-19 20:06:08 +00:00
|
|
|
{
|
|
|
|
pcol += printf("%s ", operand.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-21 12:53:10 +00:00
|
|
|
if (printoperand.length() > 0)
|
|
|
|
{
|
|
|
|
pcol += printf("%s ", printoperand.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pcol += printf("%s ", operand.c_str());
|
|
|
|
}
|
2019-11-19 20:06:08 +00:00
|
|
|
}
|
2019-11-17 03:33:22 +00:00
|
|
|
//pcol += printf("%-12s %-8s %-10s ", printlable.c_str(), opcode.c_str(), operand.c_str());
|
2019-11-16 02:30:12 +00:00
|
|
|
}
|
2019-11-18 14:07:44 +00:00
|
|
|
if ((errorcode > 0) && (!merlinerrors))
|
2019-11-16 02:30:12 +00:00
|
|
|
{
|
|
|
|
while (pcol < commentcol)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-16 02:30:12 +00:00
|
|
|
pcol += printf(" ");
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-17 22:15:45 +00:00
|
|
|
pcol += printf(":[Error] %s", errStrings[errorcode].c_str());
|
|
|
|
if (errorText.length() > 0)
|
|
|
|
{
|
2019-11-18 03:54:48 +00:00
|
|
|
pcol += printf(" (%s)", errorText.c_str());
|
2019-11-17 22:15:45 +00:00
|
|
|
}
|
2019-11-16 02:30:12 +00:00
|
|
|
}
|
2019-11-17 03:33:22 +00:00
|
|
|
else if (!commentprinted)
|
2019-11-16 02:30:12 +00:00
|
|
|
{
|
|
|
|
while (pcol < commentcol)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-16 02:30:12 +00:00
|
|
|
pcol += printf(" ");
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-16 02:30:12 +00:00
|
|
|
pcol += printf("%s", comment.c_str());
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-16 02:30:12 +00:00
|
|
|
//printf("\n");
|
|
|
|
|
2019-11-13 23:45:39 +00:00
|
|
|
if ((!nc) && (errorcode > 0))
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
|
|
|
SetColor(CL_NORMAL | BG_NORMAL);
|
|
|
|
}
|
2019-11-15 05:21:03 +00:00
|
|
|
|
2019-11-15 07:35:04 +00:00
|
|
|
uint32_t obc = datafillct;
|
|
|
|
if (obc == 0)
|
2019-11-15 05:21:03 +00:00
|
|
|
{
|
2019-11-15 07:35:04 +00:00
|
|
|
obc = outbytect;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t ct = 1;
|
2019-11-17 03:33:22 +00:00
|
|
|
if ((obc > b) && ((truncdata & 0x01) == 0))
|
2019-11-15 07:35:04 +00:00
|
|
|
{
|
|
|
|
ct = 0;
|
|
|
|
uint8_t db;
|
|
|
|
uint32_t t = b;
|
|
|
|
char *s = (char *)" ";
|
|
|
|
|
|
|
|
b = 8;
|
2019-11-15 05:21:03 +00:00
|
|
|
|
|
|
|
//printf("t=%d ct=%d\n",t,outbytect);
|
2019-11-15 07:35:04 +00:00
|
|
|
printf("\n");
|
|
|
|
while (t < obc)
|
2019-11-15 05:21:03 +00:00
|
|
|
{
|
2019-11-15 07:35:04 +00:00
|
|
|
db = datafillbyte;
|
|
|
|
if (datafillct == 0)
|
|
|
|
{
|
|
|
|
db = outbytes[t];
|
|
|
|
}
|
|
|
|
if (ct == 0)
|
|
|
|
{
|
|
|
|
printf("%s", s);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%02X ", db);
|
2019-11-15 05:21:03 +00:00
|
|
|
t++;
|
|
|
|
ct++;
|
2019-11-15 07:35:04 +00:00
|
|
|
if (ct >= b)
|
2019-11-15 05:21:03 +00:00
|
|
|
{
|
|
|
|
printf("\n");
|
2019-11-15 07:35:04 +00:00
|
|
|
ct = 0;
|
2019-11-15 05:21:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-15 07:35:04 +00:00
|
|
|
if (ct > 0)
|
|
|
|
{
|
|
|
|
printf("\n");
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLASS::clear()
|
|
|
|
{
|
|
|
|
syntax = SYNTAX_MERLIN;
|
2019-11-21 12:53:10 +00:00
|
|
|
wholetext = "";
|
2019-11-11 23:56:03 +00:00
|
|
|
lable = "";
|
2019-11-13 01:03:51 +00:00
|
|
|
printlable = "";
|
2019-11-11 23:56:03 +00:00
|
|
|
opcode = "";
|
|
|
|
opcodelower = "";
|
|
|
|
operand = "";
|
2019-11-19 20:06:08 +00:00
|
|
|
printoperand = "";
|
2019-11-11 23:56:03 +00:00
|
|
|
comment = "";
|
|
|
|
operand_expr = "";
|
2019-11-12 03:51:26 +00:00
|
|
|
operand_expr2 = "";
|
2019-11-11 23:56:03 +00:00
|
|
|
addrtext = "";
|
2019-11-18 19:34:20 +00:00
|
|
|
merlinerrors = false;
|
2019-11-12 08:15:47 +00:00
|
|
|
linemx = 0;
|
2019-11-11 23:56:03 +00:00
|
|
|
bytect = 0;
|
|
|
|
opflags = 0;
|
|
|
|
pass0bytect = 0;
|
|
|
|
startpc = 0;
|
|
|
|
errorcode = 0;
|
2019-11-12 18:13:15 +00:00
|
|
|
errorText = "";
|
2019-11-11 23:56:03 +00:00
|
|
|
outbytect = 0;
|
2019-11-15 07:35:04 +00:00
|
|
|
datafillct = 0;
|
|
|
|
datafillbyte = 0;
|
2019-11-12 03:51:26 +00:00
|
|
|
lineno = 0;
|
2019-11-11 23:56:03 +00:00
|
|
|
outbytes.clear();
|
|
|
|
addressmode = 0;
|
|
|
|
expr_value = 0;
|
2019-11-13 14:54:48 +00:00
|
|
|
eval_result = 0;
|
2019-11-11 23:56:03 +00:00
|
|
|
flags = 0;
|
|
|
|
outbytes.clear();
|
|
|
|
}
|
|
|
|
|
2019-11-19 06:29:06 +00:00
|
|
|
std::string operEx[] =
|
|
|
|
{
|
2019-11-19 16:38:49 +00:00
|
|
|
"^(\\S*)(#?)([<>\\^|]?)([\"\'])(.*)(\\4)([\\S]*)", // catches the normal delims
|
|
|
|
"^(\\s*)([!-~])([!-~]*?)([^;]*)\\2(\\S*)", // catches the unusual delims
|
|
|
|
"^(\\s*)(\\S+)", // captures everything else
|
2019-11-19 06:29:06 +00:00
|
|
|
""
|
|
|
|
};
|
2019-11-19 16:38:49 +00:00
|
|
|
|
2019-11-19 06:29:06 +00:00
|
|
|
std::string commentEx = "^(\\s*)((;|\\/{2}))+(.*)";
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
void CLASS::set(std::string line)
|
|
|
|
{
|
|
|
|
int state = 0;
|
2019-12-03 16:44:50 +00:00
|
|
|
int l = (int)line.length();
|
2019-11-11 23:56:03 +00:00
|
|
|
int i = 0;
|
2019-11-13 01:03:51 +00:00
|
|
|
int x;
|
2019-11-12 03:51:26 +00:00
|
|
|
char c, delim;
|
2019-11-18 06:16:00 +00:00
|
|
|
bool isascii;
|
2019-11-19 06:29:06 +00:00
|
|
|
std::string opupper, s;
|
|
|
|
std::string restofline;
|
|
|
|
std::string tline = line;
|
2019-11-11 23:56:03 +00:00
|
|
|
clear();
|
|
|
|
|
2019-11-21 12:53:10 +00:00
|
|
|
wholetext = line;
|
2019-11-18 06:16:00 +00:00
|
|
|
isascii = false;
|
2019-11-16 00:15:58 +00:00
|
|
|
delim = 0;
|
2019-11-11 23:56:03 +00:00
|
|
|
while (i < l)
|
|
|
|
{
|
2019-11-19 06:29:06 +00:00
|
|
|
c = tline[i++];
|
2019-11-11 23:56:03 +00:00
|
|
|
switch (state)
|
|
|
|
{
|
2019-11-19 16:38:49 +00:00
|
|
|
case 7:
|
|
|
|
if (c >= ' ')
|
|
|
|
{
|
|
|
|
comment += c;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i = l;
|
|
|
|
}
|
|
|
|
break;
|
2019-11-11 23:56:03 +00:00
|
|
|
case 0: // start of line state
|
2019-11-12 18:13:15 +00:00
|
|
|
if ((c == ';') || (c == '*') || (c == '/'))
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
|
|
|
comment += c;
|
|
|
|
state = 7;
|
|
|
|
}
|
|
|
|
else if (c > ' ')
|
|
|
|
{
|
|
|
|
lable += c;
|
|
|
|
state = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state = 2;
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 1: // read in entire lable until whitespace
|
|
|
|
if (c > ' ')
|
|
|
|
{
|
|
|
|
lable += c;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state = 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2: // read whitespace between label and opcode
|
|
|
|
if (c == ';')
|
|
|
|
{
|
|
|
|
comment += c;
|
|
|
|
state = 7;
|
|
|
|
}
|
2019-11-12 18:13:15 +00:00
|
|
|
else if (((c == '*') || (c == '/')) && (lable.length() == 0))
|
|
|
|
{
|
|
|
|
comment += c;
|
|
|
|
state = 7;
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
else if (c > ' ')
|
|
|
|
{
|
|
|
|
opcode += c;
|
|
|
|
state = 3;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2019-11-19 16:38:49 +00:00
|
|
|
{
|
|
|
|
if (c > ' ')
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-19 16:38:49 +00:00
|
|
|
opcode += c;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i--;
|
|
|
|
state = 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4: // read whitespace between opcode and operand
|
|
|
|
{
|
|
|
|
std::vector<std::string> strs;
|
|
|
|
std::string s;
|
|
|
|
|
|
|
|
Poco::RegularExpression comEx(commentEx, 0, true);
|
|
|
|
restofline = Poco::trim(tline.substr(i, tline.length())) + " ";
|
|
|
|
//printf("ROL: |%s|\n",restofline.c_str());
|
|
|
|
|
2019-11-19 17:59:03 +00:00
|
|
|
if (restofline == "")
|
2019-11-19 17:22:27 +00:00
|
|
|
{
|
2019-11-19 17:59:03 +00:00
|
|
|
i = l;
|
2019-11-19 17:22:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-11-19 16:38:49 +00:00
|
|
|
strs.clear();
|
|
|
|
x = 0;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
x = comEx.split(restofline, strs, 0);
|
|
|
|
}
|
|
|
|
catch (Poco::Exception &e)
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
if (isDebug() > 3)
|
2019-11-18 19:34:20 +00:00
|
|
|
{
|
2019-11-19 16:38:49 +00:00
|
|
|
cout << e.displayText() << endl;
|
2019-11-18 19:34:20 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-19 16:38:49 +00:00
|
|
|
if (x > 0)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-19 16:38:49 +00:00
|
|
|
// if the comment detector above is true, then the rest of line is comment;
|
|
|
|
operand = "";
|
|
|
|
comment = strs[0];
|
|
|
|
//printf("comment=%s\n", comment.c_str());
|
|
|
|
i = l;
|
|
|
|
break;
|
|
|
|
}
|
2019-11-19 06:29:06 +00:00
|
|
|
|
2019-11-19 16:38:49 +00:00
|
|
|
int ct = 0;
|
|
|
|
int x = 0;
|
|
|
|
bool match = false;
|
|
|
|
s = operEx[ct];
|
|
|
|
while (s != "")
|
|
|
|
{
|
|
|
|
RegularExpression regex(s, 0, true);
|
2019-11-19 06:29:06 +00:00
|
|
|
strs.clear();
|
|
|
|
x = 0;
|
|
|
|
try
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-19 16:38:49 +00:00
|
|
|
x = regex.split(restofline, strs, 0);
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-19 06:29:06 +00:00
|
|
|
catch (Poco::Exception &e)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-19 06:29:06 +00:00
|
|
|
x = 0;
|
|
|
|
if (isDebug() > 3)
|
|
|
|
{
|
|
|
|
cout << e.displayText() << endl;
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-19 06:29:06 +00:00
|
|
|
if (x > 0)
|
2019-11-18 03:54:48 +00:00
|
|
|
{
|
2019-11-19 16:38:49 +00:00
|
|
|
//printf("%d regex %d match |%s|\n", ct, x, restofline.c_str());
|
|
|
|
operand = strs[0];
|
|
|
|
//printf("which=%d operand=|%s|\n",ct,operand.c_str());
|
2019-12-03 16:44:50 +00:00
|
|
|
i = (int)operand.length();
|
2019-11-19 16:38:49 +00:00
|
|
|
restofline = restofline.substr(i, restofline.length());
|
|
|
|
comment = Poco::trim(restofline);
|
|
|
|
match = true;
|
2019-11-19 06:29:06 +00:00
|
|
|
break;
|
2019-11-18 03:54:48 +00:00
|
|
|
}
|
2019-11-19 16:38:49 +00:00
|
|
|
ct++;
|
2019-11-19 06:29:06 +00:00
|
|
|
s = operEx[ct];
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-19 16:38:49 +00:00
|
|
|
i = l;
|
|
|
|
if (!match)
|
|
|
|
{
|
2019-11-19 17:22:27 +00:00
|
|
|
// if you are here, there probably isn't an operand and/or comment after opcode
|
2019-11-19 16:38:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-13 01:03:51 +00:00
|
|
|
printlable = lable;
|
2019-12-03 16:44:50 +00:00
|
|
|
x = (int)lable.length();
|
2019-11-13 01:03:51 +00:00
|
|
|
if (x > 1)
|
|
|
|
{
|
2019-11-19 17:59:03 +00:00
|
|
|
// M32 syntax allows a colon after lable, and it is not part of the lable
|
2019-11-19 19:27:17 +00:00
|
|
|
if ((syntax & SYNTAX_MERLIN32) == SYNTAX_MERLIN32)
|
2019-11-13 01:03:51 +00:00
|
|
|
{
|
2019-11-19 17:59:03 +00:00
|
|
|
while ((x > 1) && (lable[x - 1] == ':'))
|
|
|
|
{
|
|
|
|
lable = lable.substr(0, x - 1);
|
|
|
|
x--;
|
|
|
|
}
|
|
|
|
//printf("linelable: |%s|\n", lable.c_str());
|
2019-11-13 01:03:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
opcodelower = Poco::toLower(opcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CLASS
|
|
|
|
#define CLASS TFileProcessor
|
|
|
|
|
|
|
|
CLASS::CLASS()
|
|
|
|
{
|
2019-11-19 19:27:17 +00:00
|
|
|
int x;
|
2019-11-13 01:03:51 +00:00
|
|
|
errorct = 0;
|
2019-11-19 19:27:17 +00:00
|
|
|
|
|
|
|
win_columns = -1;
|
|
|
|
win_rows = -1;
|
|
|
|
struct winsize w;
|
|
|
|
x = ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
|
|
|
if (x == 0)
|
|
|
|
{
|
|
|
|
win_columns = w.ws_col;
|
|
|
|
win_rows = w.ws_row;
|
|
|
|
}
|
|
|
|
//printf("cols=%d rows=%d\n",win_columns,win_rows);
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CLASS::~CLASS()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLASS::errorOut(uint16_t code)
|
|
|
|
{
|
|
|
|
printf("error: %d\n", code);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLASS::init(void)
|
|
|
|
{
|
2019-11-16 02:30:12 +00:00
|
|
|
int ts, tabpos;
|
|
|
|
std::string s;
|
|
|
|
|
2019-11-14 17:32:11 +00:00
|
|
|
filenames.clear();
|
2019-11-12 03:51:26 +00:00
|
|
|
starttime = GetTickCount();
|
2019-11-14 17:32:11 +00:00
|
|
|
initialdir = Poco::Path::current();
|
2019-11-19 17:59:03 +00:00
|
|
|
syntax = SYNTAX_MERLIN;
|
2019-11-14 15:28:42 +00:00
|
|
|
filecount = 0;
|
2019-11-16 02:30:12 +00:00
|
|
|
|
2019-11-19 17:59:03 +00:00
|
|
|
s = getConfig("option.syntax", "merlin16");
|
|
|
|
s = Poco::toUpper(Poco::trim(s));
|
|
|
|
if ((s == "MERLIN") || (s == "MERLIN16"))
|
|
|
|
{
|
|
|
|
syntax = SYNTAX_MERLIN;
|
|
|
|
}
|
|
|
|
else if (s == "MERLIN32")
|
|
|
|
{
|
|
|
|
syntax = SYNTAX_MERLIN32;
|
|
|
|
}
|
|
|
|
else if (s == "QASM")
|
|
|
|
{
|
|
|
|
syntax = SYNTAX_QASM;
|
|
|
|
}
|
|
|
|
|
2019-11-16 02:30:12 +00:00
|
|
|
std::string tabstr = getConfig("reformat.tabs", "8,16,32");
|
|
|
|
tabstr = Poco::trim(tabstr);
|
|
|
|
|
|
|
|
memset(tabs, 0x00, sizeof(tabs));
|
|
|
|
|
|
|
|
Poco::StringTokenizer t(tabstr, ",;", 0);
|
|
|
|
tabpos = 0;
|
|
|
|
for (auto itr = t.begin(); itr != t.end(); ++itr)
|
|
|
|
{
|
|
|
|
s = Poco::trim(*itr);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ts = Poco::NumberParser::parse(s);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
ts = 0;
|
|
|
|
}
|
|
|
|
if ((ts >= 0) && (ts < 240))
|
|
|
|
{
|
|
|
|
tabs[tabpos++] = ts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLASS::complete(void)
|
|
|
|
{
|
2019-11-12 08:15:47 +00:00
|
|
|
|
2019-11-12 03:51:26 +00:00
|
|
|
uint64_t n = GetTickCount();
|
2019-11-16 06:27:43 +00:00
|
|
|
//if (isDebug())
|
2019-11-12 03:51:26 +00:00
|
|
|
{
|
2019-11-15 01:04:35 +00:00
|
|
|
//cout << "Processing Time: " << n - starttime << "ms" << endl;
|
2019-11-15 07:35:04 +00:00
|
|
|
uint64_t x = n - starttime;
|
|
|
|
uint32_t x1 = x & 0xFFFFFFFF;
|
2019-11-16 06:27:43 +00:00
|
|
|
printf("Elapsed time: %u ms\n", x1);
|
2019-11-15 01:04:35 +00:00
|
|
|
|
2019-11-12 03:51:26 +00:00
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLASS::process(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
int CLASS::doline(int lineno, std::string line)
|
|
|
|
{
|
2019-11-15 11:40:35 +00:00
|
|
|
UNUSED(lineno);
|
|
|
|
UNUSED(line);
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
int res = -1;
|
|
|
|
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
2019-11-14 17:32:11 +00:00
|
|
|
std::string CLASS::processFilename(std::string fn, std::string curDir, int level)
|
|
|
|
{
|
|
|
|
std::string res = fn;
|
|
|
|
std::string s, s1;
|
|
|
|
Path p = Poco::Path(fn);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int n = p.depth();
|
2019-11-14 18:47:50 +00:00
|
|
|
//LOG_DEBUG << "n=" << n << " " << fn << endl;
|
|
|
|
if (n == 0)
|
|
|
|
{
|
|
|
|
res = curDir + fn;
|
|
|
|
}
|
2019-11-14 17:32:11 +00:00
|
|
|
if (n > 0)
|
|
|
|
{
|
|
|
|
std::string d1 = p[0];
|
|
|
|
uint32_t v = 100;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
v = Poco::NumberParser::parseUnsigned(d1);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
v = 99;
|
|
|
|
}
|
2019-11-15 11:40:35 +00:00
|
|
|
if (v < 10)
|
2019-11-14 17:32:11 +00:00
|
|
|
{
|
|
|
|
Poco::Path p1 = p.popFrontDirectory();
|
|
|
|
s = p1.toString();
|
|
|
|
s1 = "global.path" + Poco::NumberFormatter::format(v);
|
|
|
|
switch (v)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-11-14 18:47:50 +00:00
|
|
|
s = initialdir + s;
|
2019-11-14 17:32:11 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
s = getConfig(s1, ".") + "/" + s;
|
|
|
|
if (level < 5)
|
|
|
|
{
|
|
|
|
s = processFilename(s, curDir, level + 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p = s;
|
|
|
|
p.makeAbsolute();
|
|
|
|
}
|
|
|
|
res = p.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Poco::Exception &e)
|
|
|
|
{
|
|
|
|
if (isDebug() > 2)
|
|
|
|
{
|
|
|
|
cout << "exception: " << e.displayText() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (std::exception &e)
|
|
|
|
{
|
|
|
|
if (isDebug() > 2)
|
|
|
|
{
|
|
|
|
cout << e.what() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-14 18:47:50 +00:00
|
|
|
p = res;
|
|
|
|
p.makeAbsolute();
|
|
|
|
res = p.toString();
|
|
|
|
|
|
|
|
char buff[PATH_MAX + 1];
|
|
|
|
memset(buff, 0x00, sizeof(buff));
|
|
|
|
char *rp = realpath(res.c_str(), buff);
|
|
|
|
if (rp != NULL)
|
|
|
|
{
|
|
|
|
//printf("realpath: %s\n", buff);
|
|
|
|
res = rp;
|
|
|
|
}
|
|
|
|
p = res;
|
2019-11-14 17:32:11 +00:00
|
|
|
p.makeAbsolute();
|
2019-11-14 18:47:50 +00:00
|
|
|
res = p.toString();
|
|
|
|
|
|
|
|
//LOG_DEBUG << "convert: |" << res << "|" << endl;
|
|
|
|
|
2019-11-14 17:32:11 +00:00
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
2019-11-14 18:47:50 +00:00
|
|
|
int CLASS::processfile(std::string p, std::string &newfilename)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
|
|
|
//Poco::File fn(p);
|
|
|
|
int c;
|
|
|
|
int res = -1;
|
|
|
|
uint32_t linect;
|
|
|
|
bool done, valid;
|
2019-11-14 17:32:11 +00:00
|
|
|
std::string currentdir;
|
2019-11-11 23:56:03 +00:00
|
|
|
std::string p1;
|
|
|
|
std::string line, op;
|
|
|
|
|
|
|
|
linect = 0;
|
|
|
|
done = false;
|
|
|
|
|
2019-11-19 16:38:49 +00:00
|
|
|
p = Poco::trim(p);
|
2019-11-14 17:32:11 +00:00
|
|
|
currentdir = Poco::Path::current();
|
|
|
|
|
|
|
|
if (filecount == 0)
|
|
|
|
{
|
2019-11-14 18:47:50 +00:00
|
|
|
initialdir = currentdir;
|
2019-11-14 17:32:11 +00:00
|
|
|
//printf("initialdir=%s\n",initialdir.c_str());
|
|
|
|
}
|
|
|
|
|
2019-11-14 18:47:50 +00:00
|
|
|
//printf("currentdir=%s initialdir=%s\n", currentdir.c_str(), initialdir.c_str());
|
|
|
|
//LOG_DEBUG << "initial file name: " << p << endl;
|
|
|
|
p = processFilename(p, (filecount == 0) ? currentdir : currentdir, 0);
|
|
|
|
|
|
|
|
//LOG_DEBUG << "Converted filename: " << p << endl;
|
2019-11-14 17:32:11 +00:00
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
Poco::Path tp(p);
|
|
|
|
Poco::Path path = tp.makeAbsolute();
|
2019-11-14 05:56:50 +00:00
|
|
|
Poco::Path parent = path.parent();
|
2019-11-14 18:47:50 +00:00
|
|
|
std::string dir = parent.toString();
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-14 05:56:50 +00:00
|
|
|
try
|
|
|
|
{
|
2019-11-14 18:47:50 +00:00
|
|
|
|
|
|
|
if (filecount == 0)
|
|
|
|
{
|
|
|
|
// is this the first file in the compilation, or a PUT/USE?
|
|
|
|
// if first, change CWD to location of file
|
2019-11-16 06:27:43 +00:00
|
|
|
//LOG_DEBUG << "Changing directory to: " << dir << endl;
|
2019-11-15 11:40:35 +00:00
|
|
|
if (chdir(dir.c_str())) {} // change directory to where the file is
|
2019-11-14 18:47:50 +00:00
|
|
|
}
|
2019-11-13 23:45:39 +00:00
|
|
|
|
2019-11-14 15:28:42 +00:00
|
|
|
p1 = path.toString();
|
|
|
|
|
2019-11-14 18:47:50 +00:00
|
|
|
newfilename = p1;
|
2019-11-14 15:28:42 +00:00
|
|
|
//LOG_DEBUG << "initial file name: " << p1 << endl;
|
2019-11-13 23:45:39 +00:00
|
|
|
|
2019-11-14 05:56:50 +00:00
|
|
|
valid = true;
|
|
|
|
Poco::File fn(p1);
|
2019-11-11 23:56:03 +00:00
|
|
|
if (!fn.exists())
|
|
|
|
{
|
2019-11-14 05:56:50 +00:00
|
|
|
fn = Poco::File(p1 + ".s");
|
2019-11-11 23:56:03 +00:00
|
|
|
if (!fn.exists())
|
|
|
|
{
|
2019-11-14 05:56:50 +00:00
|
|
|
fn = Poco::File(p1 + ".S");
|
2019-11-11 23:56:03 +00:00
|
|
|
if (!fn.exists())
|
|
|
|
{
|
2019-11-14 05:56:50 +00:00
|
|
|
fn = Poco::File(p1 + ".mac");
|
|
|
|
if (!fn.exists())
|
|
|
|
{
|
2019-11-14 15:28:42 +00:00
|
|
|
fn = Poco::File(p1);
|
2019-11-14 05:56:50 +00:00
|
|
|
valid = false;
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-14 05:56:50 +00:00
|
|
|
p1 = fn.path();
|
2019-11-14 15:28:42 +00:00
|
|
|
//LOG_DEBUG << "File name: " << p1 << endl;
|
|
|
|
|
2019-11-14 18:47:50 +00:00
|
|
|
int ecode = -3;
|
2019-11-14 17:32:11 +00:00
|
|
|
valid = false;
|
2019-11-14 15:28:42 +00:00
|
|
|
if (fn.exists())
|
|
|
|
{
|
2019-11-14 18:47:50 +00:00
|
|
|
ecode = -2;
|
2019-11-14 17:32:11 +00:00
|
|
|
valid = true;
|
2019-11-14 15:28:42 +00:00
|
|
|
//LOG_DEBUG << "File exists: " << p1 << endl;
|
|
|
|
if (fn.isLink())
|
|
|
|
{
|
|
|
|
//LOG_DEBUG << "File is a link: " << p1 << endl;
|
|
|
|
}
|
|
|
|
if ((fn.isDirectory()) || (!fn.canRead()))
|
|
|
|
{
|
2019-11-19 16:38:49 +00:00
|
|
|
LOG_DEBUG << "File is a directory: " << p1 << endl;
|
2019-11-14 15:28:42 +00:00
|
|
|
valid = false;
|
|
|
|
}
|
|
|
|
}
|
2019-11-19 16:38:49 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("file does not exist |%s|\n", p1.c_str());
|
|
|
|
}
|
2019-11-14 15:28:42 +00:00
|
|
|
|
2019-11-14 18:47:50 +00:00
|
|
|
newfilename = p1;
|
2019-11-14 15:28:42 +00:00
|
|
|
if (!valid)
|
|
|
|
{
|
2019-11-14 17:32:11 +00:00
|
|
|
//fprintf(stderr, "Unable to access file: %s\n", p1.c_str());
|
2019-11-14 15:28:42 +00:00
|
|
|
|
|
|
|
errorct = 1;
|
2019-11-14 17:32:11 +00:00
|
|
|
return (ecode);
|
2019-11-14 15:28:42 +00:00
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-14 05:56:50 +00:00
|
|
|
if (valid)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-14 17:32:11 +00:00
|
|
|
|
2019-11-14 15:28:42 +00:00
|
|
|
if (filecount == 0)
|
|
|
|
{
|
|
|
|
}
|
2019-11-14 17:32:11 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for (auto itr = filenames.begin(); itr != filenames.end(); ++itr)
|
|
|
|
{
|
|
|
|
if (*itr == p1)
|
|
|
|
{
|
|
|
|
return (-9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-14 15:28:42 +00:00
|
|
|
filecount++;
|
2019-11-14 17:32:11 +00:00
|
|
|
filenames.push_back(p1);
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-14 05:56:50 +00:00
|
|
|
std::ifstream f(p1);
|
|
|
|
if (f.is_open())
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-14 05:56:50 +00:00
|
|
|
//printf("file is open\n");
|
|
|
|
line = "";
|
|
|
|
|
|
|
|
while ((!done) && (f.good()) && (!f.eof()))
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-14 05:56:50 +00:00
|
|
|
c = f.get();
|
|
|
|
if (c == 0x8D) // merlin line ending
|
|
|
|
{
|
|
|
|
c = 0x0A; // convert to linux
|
|
|
|
}
|
|
|
|
if (c == 0x8A) // possible merlin line ending
|
|
|
|
{
|
|
|
|
c = 0x00; // ignore
|
|
|
|
}
|
|
|
|
c &= 0x7F;
|
|
|
|
int x;
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 0x0D:
|
|
|
|
break;
|
|
|
|
case 0x09:
|
|
|
|
line += " ";
|
|
|
|
break;
|
|
|
|
case 0x0A:
|
|
|
|
linect++;
|
|
|
|
x = doline(linect, line);
|
|
|
|
if (x < 0)
|
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
line = "";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if ((c >= ' ') && (c < 0x7F))
|
|
|
|
{
|
|
|
|
line += c;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//printf("garbage %08X\n",c);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-14 05:56:50 +00:00
|
|
|
if ( (f.eof()))
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-14 05:56:50 +00:00
|
|
|
res = 0;
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-14 05:56:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "File <%s> does not exist.\n\n", p.c_str());
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-14 15:28:42 +00:00
|
|
|
catch (...)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-15 01:04:35 +00:00
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CLASS
|
2019-11-13 01:03:51 +00:00
|
|
|
#define CLASS TMerlinConverter
|
|
|
|
CLASS::CLASS() : TFileProcessor()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
CLASS::~CLASS()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void CLASS::init(void)
|
|
|
|
{
|
2019-11-17 05:03:19 +00:00
|
|
|
TFileProcessor::init();
|
2019-11-13 01:03:51 +00:00
|
|
|
std::string s;
|
|
|
|
lines.clear();
|
|
|
|
|
2019-11-14 15:28:42 +00:00
|
|
|
syntax = SYNTAX_MERLIN;
|
2019-11-13 01:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CLASS::doline(int lineno, std::string line)
|
|
|
|
{
|
2019-11-15 11:40:35 +00:00
|
|
|
UNUSED(lineno);
|
|
|
|
|
2019-11-13 01:03:51 +00:00
|
|
|
MerlinLine l(line);
|
|
|
|
lines.push_back(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLASS::process(void)
|
|
|
|
{
|
|
|
|
|
2019-12-03 16:44:50 +00:00
|
|
|
uint32_t ct = (uint32_t)lines.size();
|
2019-11-13 01:03:51 +00:00
|
|
|
|
2019-11-19 06:29:06 +00:00
|
|
|
uint32_t len, t, pos;
|
|
|
|
|
2019-11-13 01:03:51 +00:00
|
|
|
for (uint32_t lineno = 0; lineno < ct; lineno++)
|
|
|
|
{
|
2019-11-13 14:54:48 +00:00
|
|
|
MerlinLine &line = lines.at(lineno);
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-13 04:32:10 +00:00
|
|
|
pos = 0;
|
2019-11-13 01:03:51 +00:00
|
|
|
len = 0;
|
2019-11-13 04:32:10 +00:00
|
|
|
if ((line.lable.length() == 0)
|
|
|
|
&& (line.opcode.length() == 0)
|
|
|
|
&& (line.operand.length() == 0))
|
2019-11-13 01:03:51 +00:00
|
|
|
{
|
2019-11-13 04:32:10 +00:00
|
|
|
if (line.comment.length() > 0)
|
|
|
|
{
|
|
|
|
char c = line.comment[0];
|
|
|
|
if ((c == '*') || (c == '/'))
|
|
|
|
{
|
|
|
|
printf("%s", line.comment.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t = tabs[2];
|
|
|
|
while (len < t)
|
|
|
|
{
|
|
|
|
len += printf(" ");
|
|
|
|
}
|
|
|
|
printf("%s", line.comment.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n");
|
2019-11-13 01:03:51 +00:00
|
|
|
}
|
2019-11-13 04:32:10 +00:00
|
|
|
else
|
2019-11-13 01:03:51 +00:00
|
|
|
{
|
2019-11-13 04:32:10 +00:00
|
|
|
t = tabs[pos++];
|
|
|
|
len = printf("%s ", line.printlable.c_str());
|
|
|
|
while (len < t)
|
|
|
|
{
|
|
|
|
len += printf(" ");
|
|
|
|
}
|
2019-11-13 01:03:51 +00:00
|
|
|
|
2019-11-13 04:32:10 +00:00
|
|
|
t = tabs[pos++];
|
|
|
|
len += printf("%s ", line.opcode.c_str());
|
|
|
|
while (len < t)
|
|
|
|
{
|
|
|
|
len += printf(" ");
|
|
|
|
}
|
2019-11-13 01:03:51 +00:00
|
|
|
|
2019-11-13 04:32:10 +00:00
|
|
|
t = tabs[pos++];
|
|
|
|
len += printf("%s ", line.operand.c_str());
|
|
|
|
while (len < t)
|
|
|
|
{
|
|
|
|
len += printf(" ");
|
|
|
|
}
|
2019-11-13 01:03:51 +00:00
|
|
|
|
2019-11-13 04:32:10 +00:00
|
|
|
t = tabs[pos++];
|
|
|
|
len += printf("%s", line.comment.c_str());
|
|
|
|
while (len < t)
|
|
|
|
{
|
|
|
|
len += printf(" ");
|
|
|
|
}
|
|
|
|
len += printf("\n");
|
|
|
|
}
|
2019-11-13 01:03:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLASS::complete(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#undef CLASS
|
2019-11-11 23:56:03 +00:00
|
|
|
#define CLASS T65816Asm
|
|
|
|
|
2019-11-13 01:03:51 +00:00
|
|
|
CLASS::CLASS() : TFileProcessor()
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
|
|
|
lines.clear();
|
2019-11-13 01:03:51 +00:00
|
|
|
psuedoops = new TPsuedoOp();
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
2019-11-13 01:03:51 +00:00
|
|
|
//#define OPHANDLER(ACB) std::bind(ACB, this, std::placeholders::_1, std::placeholders::_2)
|
2019-11-11 23:56:03 +00:00
|
|
|
|
|
|
|
CLASS::~CLASS()
|
|
|
|
{
|
2019-11-13 01:03:51 +00:00
|
|
|
if (psuedoops != NULL)
|
|
|
|
{
|
|
|
|
delete(psuedoops);
|
|
|
|
psuedoops = NULL;
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLASS::pushopcode(std::string op, uint8_t opcode, uint16_t flags, TOpCallback cb)
|
|
|
|
{
|
|
|
|
TSymbol sym;
|
|
|
|
|
|
|
|
sym.name = op;
|
|
|
|
sym.opcode = opcode;
|
|
|
|
sym.namelc = Poco::toLower(op);
|
|
|
|
sym.stype = flags;
|
|
|
|
sym.value = 0;
|
|
|
|
sym.cb = cb;
|
|
|
|
std::pair<std::string, TSymbol> p(Poco::toUpper(op), sym);
|
|
|
|
|
|
|
|
opcodes.insert(p);
|
|
|
|
}
|
|
|
|
|
2019-11-19 06:29:06 +00:00
|
|
|
TSymbol * CLASS::addSymbol(std::string symname, uint32_t val, bool replace)
|
2019-11-13 01:03:51 +00:00
|
|
|
{
|
|
|
|
TSymbol *res = NULL;
|
|
|
|
TSymbol *fnd = NULL;
|
|
|
|
|
2019-11-18 19:34:20 +00:00
|
|
|
std::string sym = symname;
|
|
|
|
if (!casesen)
|
|
|
|
{
|
|
|
|
sym = Poco::toUpper(sym);
|
|
|
|
}
|
|
|
|
|
|
|
|
//printf("addSymbol: |%s|\n",sym.c_str());
|
2019-11-17 16:02:55 +00:00
|
|
|
if (sym.length() > 0)
|
2019-11-13 01:03:51 +00:00
|
|
|
{
|
2019-11-17 16:02:55 +00:00
|
|
|
TSymbol s;
|
|
|
|
s.name = sym;
|
|
|
|
s.opcode = 0;
|
|
|
|
s.namelc = Poco::toLower(sym);
|
|
|
|
s.stype = 0;
|
|
|
|
s.value = val;
|
|
|
|
s.used = false;
|
|
|
|
s.cb = NULL;
|
2019-11-18 19:34:20 +00:00
|
|
|
std::pair<std::string, TSymbol> p(sym, s);
|
2019-11-13 01:03:51 +00:00
|
|
|
|
2019-11-17 16:02:55 +00:00
|
|
|
if (sym[0] == ':')
|
|
|
|
{
|
|
|
|
//local symbol
|
|
|
|
if (currentsym == NULL)
|
|
|
|
{
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fnd = findSymbol(sym);
|
|
|
|
if ((fnd != NULL) && (!replace))
|
|
|
|
{
|
|
|
|
goto out;
|
|
|
|
}
|
2019-11-13 01:03:51 +00:00
|
|
|
|
2019-11-17 16:02:55 +00:00
|
|
|
if (fnd != NULL)
|
|
|
|
{
|
|
|
|
fnd->value = val;
|
|
|
|
res = fnd;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (currentsym != NULL)
|
|
|
|
{
|
|
|
|
currentsym->locals.insert(p);
|
|
|
|
}
|
|
|
|
res = findSymbol(sym);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fnd = findSymbol(sym);
|
|
|
|
|
|
|
|
if ((fnd != NULL) && (!replace))
|
|
|
|
{
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fnd != NULL)
|
|
|
|
{
|
|
|
|
//printf("replacing symbol: %s %08X\n",sym.c_str(),val);
|
|
|
|
fnd->value = val;
|
|
|
|
res = fnd;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbols.insert(p);
|
|
|
|
res = findSymbol(sym);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
2019-11-13 01:03:51 +00:00
|
|
|
return (res);
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-21 05:50:00 +00:00
|
|
|
|
|
|
|
TMacro * CLASS::findMacro(std::string symname)
|
|
|
|
{
|
|
|
|
TMacro *res = NULL;
|
|
|
|
|
|
|
|
std::string sym = symname;
|
|
|
|
if (!casesen)
|
|
|
|
{
|
|
|
|
sym = Poco::toUpper(sym);
|
|
|
|
}
|
|
|
|
if (symname.length() > 0)
|
|
|
|
{
|
|
|
|
//printf("finding: %s\n",symname.c_str());
|
|
|
|
auto itr = macros.find(sym);
|
|
|
|
if (itr != macros.end())
|
|
|
|
{
|
|
|
|
res = &itr->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
2019-11-19 06:29:06 +00:00
|
|
|
TSymbol * CLASS::findSymbol(std::string symname)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
|
|
|
TSymbol *res = NULL;
|
|
|
|
|
2019-11-18 19:34:20 +00:00
|
|
|
std::string sym = symname;
|
2019-11-18 14:07:44 +00:00
|
|
|
if (!casesen)
|
|
|
|
{
|
2019-11-18 19:34:20 +00:00
|
|
|
sym = Poco::toUpper(sym);
|
2019-11-18 14:07:44 +00:00
|
|
|
}
|
2019-11-17 16:02:55 +00:00
|
|
|
if (symname.length() > 0)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-17 16:02:55 +00:00
|
|
|
if (symname[0] == ':')
|
|
|
|
{
|
|
|
|
if (currentsym == NULL)
|
|
|
|
{
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-18 14:07:44 +00:00
|
|
|
auto itr = currentsym->locals.find(sym);
|
2019-11-17 16:02:55 +00:00
|
|
|
if (itr != currentsym->locals.end())
|
|
|
|
{
|
|
|
|
res = &itr->second;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//printf("finding: %s\n",symname.c_str());
|
2019-11-18 14:07:44 +00:00
|
|
|
auto itr = symbols.find(sym);
|
2019-11-17 16:02:55 +00:00
|
|
|
if (itr != symbols.end())
|
|
|
|
{
|
|
|
|
//printf("Found: %s 0x%08X\n",itr->second.name.c_str(),itr->second.value);
|
|
|
|
res = &itr->second;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-17 16:02:55 +00:00
|
|
|
out:
|
2019-11-11 23:56:03 +00:00
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
2019-11-21 16:47:03 +00:00
|
|
|
TSymbol * CLASS::addVariable(std::string symname, std::string val, TVariable &vars, bool replace)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
|
|
|
TSymbol *res = NULL;
|
|
|
|
TSymbol *fnd = NULL;
|
|
|
|
|
2019-11-18 19:34:20 +00:00
|
|
|
std::string sym = symname;
|
2019-11-18 14:07:44 +00:00
|
|
|
if (!casesen)
|
|
|
|
{
|
2019-11-18 19:34:20 +00:00
|
|
|
sym = Poco::toUpper(sym);
|
2019-11-18 14:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-11-13 01:03:51 +00:00
|
|
|
//printf("addvariable\n");
|
2019-11-21 12:53:10 +00:00
|
|
|
fnd = findVariable(sym, vars);
|
2019-11-11 23:56:03 +00:00
|
|
|
|
|
|
|
if ((fnd != NULL) && (!replace))
|
|
|
|
{
|
|
|
|
return (NULL); // it is a duplicate
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fnd != NULL)
|
|
|
|
{
|
2019-11-12 08:15:47 +00:00
|
|
|
//printf("replacing symbol: %s %08X\n",sym.c_str(),val);
|
2019-11-19 19:27:17 +00:00
|
|
|
fnd->var_text = val;
|
2019-11-11 23:56:03 +00:00
|
|
|
return (fnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
TSymbol s;
|
|
|
|
s.name = sym;
|
|
|
|
s.opcode = 0;
|
|
|
|
s.namelc = Poco::toLower(sym);
|
|
|
|
s.stype = 0;
|
2019-11-13 01:03:51 +00:00
|
|
|
s.value = 0;
|
2019-11-19 19:27:17 +00:00
|
|
|
s.var_text = val;
|
2019-11-12 18:13:15 +00:00
|
|
|
s.used = false;
|
2019-11-11 23:56:03 +00:00
|
|
|
s.cb = NULL;
|
2019-11-14 05:39:35 +00:00
|
|
|
|
|
|
|
//printf("addvariable: %s %s\n", s.name.c_str(), s.text.c_str());
|
|
|
|
|
2019-11-18 14:07:44 +00:00
|
|
|
std::pair<std::string, TSymbol> p(sym, s);
|
2019-11-21 16:47:03 +00:00
|
|
|
vars.vars.insert(p);
|
2019-11-21 12:53:10 +00:00
|
|
|
res = findVariable(sym, vars);
|
2019-11-13 01:03:51 +00:00
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
2019-11-21 16:47:03 +00:00
|
|
|
TSymbol * CLASS::findVariable(std::string symname, TVariable &vars)
|
2019-11-13 01:03:51 +00:00
|
|
|
{
|
|
|
|
TSymbol *res = NULL;
|
|
|
|
|
2019-11-22 17:33:24 +00:00
|
|
|
if (!casesen)
|
|
|
|
{
|
|
|
|
symname = Poco::toUpper(symname);
|
|
|
|
}
|
|
|
|
|
2019-11-21 16:47:03 +00:00
|
|
|
if ((expand_macrostack.size() > 0) && (vars.id != expand_macro.variables.id))
|
|
|
|
{
|
|
|
|
res = findVariable(symname, expand_macro.variables);
|
|
|
|
if (res != NULL)
|
|
|
|
{
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-13 01:03:51 +00:00
|
|
|
//printf("finding: %s\n",symname.c_str());
|
2019-11-21 16:47:03 +00:00
|
|
|
auto itr = vars.vars.find(symname);
|
|
|
|
if (itr != vars.vars.end())
|
2019-11-13 01:03:51 +00:00
|
|
|
{
|
|
|
|
//printf("Found: %s 0x%08X\n",itr->second.name.c_str(),itr->second.value);
|
|
|
|
res = &itr->second;
|
|
|
|
|
|
|
|
return (res);
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
2019-11-21 16:47:03 +00:00
|
|
|
void CLASS::showVariables(TVariable &vars)
|
2019-11-13 01:03:51 +00:00
|
|
|
{
|
2019-11-21 16:47:03 +00:00
|
|
|
if (vars.vars.size() > 0)
|
2019-11-13 01:03:51 +00:00
|
|
|
{
|
2019-11-13 23:45:39 +00:00
|
|
|
printf("\nVariables:\n");
|
2019-11-13 01:03:51 +00:00
|
|
|
|
2019-11-21 16:47:03 +00:00
|
|
|
for (auto itr = vars.vars.begin(); itr != vars.vars.end(); ++itr)
|
2019-11-13 23:45:39 +00:00
|
|
|
{
|
2019-11-19 19:27:17 +00:00
|
|
|
printf("%-16s %s\n", itr->first.c_str(), itr->second.var_text.c_str());
|
2019-11-13 23:45:39 +00:00
|
|
|
}
|
2019-11-15 05:21:03 +00:00
|
|
|
printf("\n");
|
2019-11-13 23:45:39 +00:00
|
|
|
}
|
2019-11-13 01:03:51 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 08:15:47 +00:00
|
|
|
// set alpha to true to print table sorted by name or
|
|
|
|
// false to print by value;
|
|
|
|
void CLASS::showSymbolTable(bool alpha)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-14 15:28:42 +00:00
|
|
|
if (symbols.size() > 0)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-14 15:28:42 +00:00
|
|
|
std::map<std::string, uint32_t> alphamap;
|
|
|
|
std::map<uint32_t, std::string> nummap;
|
2019-11-12 08:15:47 +00:00
|
|
|
|
2019-11-15 07:35:04 +00:00
|
|
|
int columns = getInt("asm.symcolumns", 3);
|
2019-11-14 15:28:42 +00:00
|
|
|
int column = columns;
|
|
|
|
|
|
|
|
for (auto itr = symbols.begin(); itr != symbols.end(); itr++)
|
|
|
|
{
|
|
|
|
TSymbol ptr = itr->second;
|
|
|
|
alphamap.insert(pair<std::string, uint32_t>(ptr.name, ptr.value));
|
|
|
|
nummap.insert(pair<uint32_t, std::string>(ptr.value, ptr.name));
|
|
|
|
}
|
2019-11-12 08:15:47 +00:00
|
|
|
|
2019-11-14 15:28:42 +00:00
|
|
|
if (alpha)
|
2019-11-12 08:15:47 +00:00
|
|
|
{
|
2019-11-14 15:28:42 +00:00
|
|
|
printf("\n\nSymbol table sorted alphabetically:\n\n");
|
|
|
|
|
|
|
|
for (auto itr = alphamap.begin(); itr != alphamap.end(); ++itr)
|
2019-11-13 23:45:39 +00:00
|
|
|
{
|
2019-11-15 01:04:35 +00:00
|
|
|
printf("%-16s 0x%08X ", itr->first.c_str(), itr->second);
|
2019-11-14 15:28:42 +00:00
|
|
|
if ( !--column )
|
|
|
|
{
|
|
|
|
printf("\n");
|
|
|
|
column = columns;
|
|
|
|
}
|
2019-11-13 23:45:39 +00:00
|
|
|
}
|
2019-11-12 08:15:47 +00:00
|
|
|
}
|
2019-11-14 15:28:42 +00:00
|
|
|
else
|
2019-11-12 08:15:47 +00:00
|
|
|
{
|
2019-11-14 15:28:42 +00:00
|
|
|
printf("\n\nSymbol table sorted numerically:\n\n");
|
|
|
|
for (auto itr = nummap.begin(); itr != nummap.end(); ++itr)
|
2019-11-13 23:45:39 +00:00
|
|
|
{
|
2019-11-15 01:04:35 +00:00
|
|
|
printf("0x%08X %-16s ", itr->first, itr->second.c_str());
|
2019-11-14 15:28:42 +00:00
|
|
|
if ( !--column )
|
|
|
|
{
|
|
|
|
printf("\n");
|
|
|
|
column = columns;
|
|
|
|
}
|
2019-11-13 23:45:39 +00:00
|
|
|
}
|
2019-11-12 08:15:47 +00:00
|
|
|
}
|
2019-11-15 07:35:04 +00:00
|
|
|
if (column > 0)
|
2019-11-15 05:21:03 +00:00
|
|
|
{
|
|
|
|
printf("\n");
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-21 12:53:10 +00:00
|
|
|
// set alpha to true to print table sorted by name or
|
|
|
|
// false to print by value;
|
|
|
|
void CLASS::showMacros(bool alpha)
|
|
|
|
{
|
|
|
|
if (macros.size() > 0)
|
|
|
|
{
|
|
|
|
std::map<std::string, uint32_t> alphamap;
|
|
|
|
|
|
|
|
int columns = getInt("asm.symcolumns", 3);
|
|
|
|
int column = columns;
|
|
|
|
|
|
|
|
for (auto itr = macros.begin(); itr != macros.end(); itr++)
|
|
|
|
{
|
|
|
|
TMacro ptr = itr->second;
|
|
|
|
alphamap.insert(pair<std::string, uint32_t>(ptr.name, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alpha)
|
|
|
|
{
|
|
|
|
printf("\n\nmacros sorted alphabetically:\n\n");
|
|
|
|
|
|
|
|
for (auto itr = alphamap.begin(); itr != alphamap.end(); ++itr)
|
|
|
|
{
|
|
|
|
printf("%-16s 0x%08X ", itr->first.c_str(), itr->second);
|
|
|
|
if ( !--column )
|
|
|
|
{
|
|
|
|
printf("\n");
|
|
|
|
column = columns;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (column > 0)
|
|
|
|
{
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
int CLASS::callOpCode(std::string op, MerlinLine &line)
|
|
|
|
{
|
|
|
|
int res = -1;
|
|
|
|
char c;
|
2019-11-16 18:48:01 +00:00
|
|
|
std::string s;
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-22 05:00:26 +00:00
|
|
|
// 'op' is always lowercase here
|
|
|
|
|
2019-11-22 02:14:30 +00:00
|
|
|
// 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
|
2019-11-22 05:00:26 +00:00
|
|
|
if (!((op == "mac") || (op == "eom") || (op == "<<<")))
|
2019-11-22 02:14:30 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
if (op.length() == 4) // check for 4 digit 'L' opcodes
|
|
|
|
{
|
2019-11-13 23:45:39 +00:00
|
|
|
c = op[3] & 0x7F;
|
|
|
|
if ((c >= 'a') && (c <= 'z'))
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
|
|
|
c = c - 0x20;
|
|
|
|
}
|
2019-11-13 23:45:39 +00:00
|
|
|
switch (c)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-13 23:45:39 +00:00
|
|
|
case 'L':
|
|
|
|
op = op.substr(0, 3);
|
|
|
|
line.flags |= FLAG_FORCELONG; // 3 byte address
|
|
|
|
break;
|
|
|
|
default: // any char but 'L' as in Merlin 16+
|
2019-11-16 18:48:01 +00:00
|
|
|
s = Poco::toUpper(op);
|
|
|
|
if ((s == "ELSE") || (s == "DEND"))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (c != 'D')
|
2019-11-13 23:45:39 +00:00
|
|
|
{
|
|
|
|
op = op.substr(0, 3);
|
|
|
|
line.flags |= FLAG_FORCEABS; // 2 byte address
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'Z':
|
|
|
|
op = op.substr(0, 3);
|
|
|
|
line.flags |= FLAG_FORCEDP; // one byte address
|
|
|
|
break;
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-13 23:45:39 +00:00
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-19 21:41:27 +00:00
|
|
|
if (line.addressmode == syn_imm)
|
2019-11-13 23:45:39 +00:00
|
|
|
{
|
2019-11-19 21:41:27 +00:00
|
|
|
//printf("immediate mode\n");
|
|
|
|
switch (line.expr_shift)
|
|
|
|
{
|
|
|
|
case '<':
|
2019-11-20 01:09:58 +00:00
|
|
|
//line.expr_value &= 0xFF;
|
2019-11-19 21:41:27 +00:00
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
line.expr_value >>= 8;
|
2019-11-20 01:09:58 +00:00
|
|
|
//line.expr_value &= 0xFFFF;
|
2019-11-19 21:41:27 +00:00
|
|
|
break;
|
|
|
|
case '^':
|
2019-11-20 01:09:58 +00:00
|
|
|
line.expr_value = (line.expr_value >> 16);
|
|
|
|
//line.expr_value = (line.expr_value >> 16) & 0xFFFF;
|
2019-11-19 21:41:27 +00:00
|
|
|
break;
|
|
|
|
case '|':
|
2019-11-21 05:50:00 +00:00
|
|
|
if (syntax == SYNTAX_MERLIN)
|
|
|
|
{
|
2019-11-20 18:20:43 +00:00
|
|
|
line.setError(errBadLabel);
|
2019-11-21 05:50:00 +00:00
|
|
|
line.expr_value = 0;
|
2019-11-20 18:20:43 +00:00
|
|
|
}
|
2019-11-19 21:41:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (line.expr_shift)
|
|
|
|
{
|
|
|
|
case '<':
|
|
|
|
line.flags |= FLAG_DP;
|
|
|
|
break;
|
|
|
|
case '>':
|
2019-11-20 01:09:58 +00:00
|
|
|
#if 0
|
2019-11-19 21:41:27 +00:00
|
|
|
if ((syntax & SYNTAX_MERLIN32) == SYNTAX_MERLIN32)
|
|
|
|
{
|
|
|
|
// bug in M32 or not, do what it does
|
|
|
|
line.flags |= FLAG_FORCEABS;
|
|
|
|
}
|
|
|
|
else
|
2019-11-20 01:09:58 +00:00
|
|
|
#endif
|
2019-11-19 21:41:27 +00:00
|
|
|
{
|
|
|
|
line.flags |= FLAG_FORCELONG;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '|':
|
2019-11-19 19:27:17 +00:00
|
|
|
line.flags |= FLAG_FORCEABS;
|
2019-11-19 21:41:27 +00:00
|
|
|
break;
|
|
|
|
case '^':
|
|
|
|
//line.flags |= FLAG_FORCELONG;
|
|
|
|
break;
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-17 16:02:55 +00:00
|
|
|
if (line.expr_value >= 0x100)
|
2019-11-17 04:39:09 +00:00
|
|
|
{
|
2019-11-17 16:02:55 +00:00
|
|
|
line.flags |= FLAG_FORCEABS;
|
2019-11-17 04:39:09 +00:00
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
|
|
|
|
auto itr = opcodes.find(Poco::toUpper(op));
|
|
|
|
if (itr != opcodes.end())
|
|
|
|
{
|
|
|
|
TSymbol s = itr->second;
|
|
|
|
if (s.cb != NULL)
|
|
|
|
{
|
|
|
|
res = s.cb(line, s);
|
|
|
|
if (res == -1)
|
|
|
|
{
|
|
|
|
res = -2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line.setError(errBadOpcode);
|
|
|
|
}
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
std::string regEx;
|
|
|
|
uint16_t addrMode;
|
|
|
|
std::string text;
|
2019-11-15 11:40:35 +00:00
|
|
|
//std::string expression;
|
2019-11-11 23:56:03 +00:00
|
|
|
} TaddrMode;
|
|
|
|
|
2019-11-12 03:51:26 +00:00
|
|
|
// these are the regular expressions that determine the addressing mode
|
|
|
|
// and extract the 'expr' part of the addr-mode
|
2019-11-12 08:15:47 +00:00
|
|
|
|
2019-11-12 18:13:15 +00:00
|
|
|
const TaddrMode addrRegEx[] =
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
|
|
|
{ "^(?'expr'.+)\\,[s,S]{1}$", syn_s, "e,s"}, // expr,s
|
|
|
|
{"^[(]{1}(?'expr'.+)[,]{1}[(S|s)]{1}[)]{1}[,]{1}[(Y|y)]{1}$", syn_sy, "(e,s),y"}, // (expr,s),y
|
2019-11-13 14:54:48 +00:00
|
|
|
{"^#{1}(.+)$", syn_imm, "immediate"}, //#expr,#^expr,#|expr,#<expr,#>expr
|
2019-11-11 23:56:03 +00:00
|
|
|
{"^[(]{1}(?'expr'.+)[,]{1}[x,X]{1}\\)$", syn_diix, "(e,x)"}, // (expr,x)
|
|
|
|
{"^[(]{1}(?'expr'.+)[\\)]{1}[\\,][(Y|y]{1}$", syn_diiy, "(e),y"}, //(expr),y
|
|
|
|
{"^[(]{1}(?'expr'.+)[\\)]{1}$", syn_di, "(e)"}, // (expr)
|
2019-11-12 18:13:15 +00:00
|
|
|
{"^\\[{1}(?'expr'.+)\\]{1}[,]{1}[(Y|y)]{1}$", syn_iyl, "[e],y"}, // [expr],y
|
2019-11-11 23:56:03 +00:00
|
|
|
{"^\\[(?'expr'.+)\\]$", syn_dil, "[e]"}, // [expr]
|
|
|
|
{"^(?'expr'.+)[,]{1}[(X|x)]{1}$", syn_absx, "e,x"}, // expr,x
|
|
|
|
{"^(?'expr'.+)[,]{1}[(Y|y)]{1}$", syn_absy, "e,y"}, // expr,y
|
|
|
|
{"^(?'expr'.+)[,]{1}(?'expr2'.+)$", syn_bm, "block"}, // block move expr,expr1
|
|
|
|
{"^(?'expr'.+)$", syn_abs, "absolute"}, // expr (MUST BE LAST)
|
|
|
|
{"", 0, ""}
|
|
|
|
};
|
|
|
|
|
2019-11-13 14:54:48 +00:00
|
|
|
// one or more of any character except ][,();
|
|
|
|
const std::string valExpression = "^([^\\]\\[,();]+)$";
|
2019-11-12 18:13:15 +00:00
|
|
|
|
2019-11-14 03:37:26 +00:00
|
|
|
// this one looks for ]variables
|
2019-11-14 05:39:35 +00:00
|
|
|
const std::string varExpression = "([]]{1}[:0-9A-Z_a-z]{1}[0-9A-Z_a-z]*)";
|
2019-11-14 03:37:26 +00:00
|
|
|
|
2019-11-12 03:51:26 +00:00
|
|
|
// opcode check. emitted opcodes are compared against this
|
|
|
|
// table, and if the XC status doesn't meet the requirements
|
|
|
|
// an error is thrown
|
|
|
|
|
|
|
|
// 0x00 = 6502
|
|
|
|
// 0x01 = 65C02
|
|
|
|
// 0x02 = 65816
|
|
|
|
uint8_t opCodeCompatibility[256] =
|
|
|
|
{
|
|
|
|
0x00, 0x00, 0x02, 0x02, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x02,
|
|
|
|
0x00, 0x00, 0x01, 0x02, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x02, 0x01, 0x00, 0x00, 0x02,
|
|
|
|
0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02,
|
|
|
|
0x00, 0x00, 0x01, 0x02, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x02, 0x01, 0x00, 0x00, 0x02,
|
|
|
|
0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02,
|
|
|
|
0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00, 0x02,
|
|
|
|
0x00, 0x00, 0x02, 0x02, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02,
|
|
|
|
0x00, 0x00, 0x01, 0x02, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x02, 0x01, 0x00, 0x00, 0x02,
|
|
|
|
0x01, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02,
|
|
|
|
0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x01, 0x02,
|
|
|
|
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02,
|
|
|
|
0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02,
|
|
|
|
0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02,
|
|
|
|
0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00, 0x02,
|
|
|
|
0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02,
|
|
|
|
0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00, 0x02
|
2019-11-11 23:56:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void CLASS::init(void)
|
|
|
|
{
|
2019-11-12 18:13:15 +00:00
|
|
|
uint8_t b = opCodeCompatibility[0];
|
|
|
|
if (b)
|
|
|
|
{
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
TFileProcessor::init();
|
|
|
|
lines.clear();
|
|
|
|
|
|
|
|
insertOpcodes();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLASS::initpass(void)
|
|
|
|
{
|
2019-11-12 08:15:47 +00:00
|
|
|
std::string s;
|
|
|
|
|
2019-11-12 18:13:15 +00:00
|
|
|
casesen = getBool("asm.casesen", true);
|
2019-11-12 08:15:47 +00:00
|
|
|
listing = getBool("asm.lst", true);
|
2019-11-13 01:03:51 +00:00
|
|
|
showmx = getBool("asm.showmx", false);
|
2019-11-18 14:07:44 +00:00
|
|
|
merlinerrors = getBool("asm.merlinerrors", true);
|
|
|
|
|
2019-11-13 01:03:51 +00:00
|
|
|
trackrep = getBool("asm.trackrep", false);
|
2019-11-19 17:59:03 +00:00
|
|
|
if (syntax == SYNTAX_MERLIN32)
|
|
|
|
{
|
|
|
|
trackrep = true; // can't turn this off in M32
|
|
|
|
}
|
|
|
|
else if (syntax == SYNTAX_MERLIN)
|
|
|
|
{
|
|
|
|
trackrep = false; // can't turn this ON in M16
|
|
|
|
}
|
|
|
|
else if (syntax == SYNTAX_QASM)
|
|
|
|
{
|
|
|
|
// we will allow this to be settable default off
|
|
|
|
trackrep = false;
|
|
|
|
trackrep = getBool("asm.trackrep", trackrep);
|
|
|
|
|
|
|
|
}
|
2019-11-19 17:22:27 +00:00
|
|
|
//merlincompat = getBool("asm.merlincompatible", true);
|
2019-11-13 23:45:39 +00:00
|
|
|
allowdup = getBool("asm.allowduplicate", true);
|
2019-11-13 01:03:51 +00:00
|
|
|
|
2019-11-12 03:51:26 +00:00
|
|
|
skiplist = false;
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-13 04:32:10 +00:00
|
|
|
PC.origin = 0x8000;
|
|
|
|
PC.currentpc = PC.origin;
|
2019-11-13 23:45:39 +00:00
|
|
|
PC.totalbytes = 0;
|
|
|
|
PC.orgsave = PC.origin;
|
2019-11-12 08:15:47 +00:00
|
|
|
|
|
|
|
s = getConfig("asm.cpu", "M65816");
|
|
|
|
s = Poco::trim(Poco::toUpper(s));
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
cpumode = MODE_65816;
|
2019-11-12 08:15:47 +00:00
|
|
|
|
|
|
|
if (s == "M65816")
|
|
|
|
{
|
|
|
|
cpumode = MODE_65816;
|
|
|
|
mx = 0x00;
|
|
|
|
}
|
|
|
|
else if (s == "M65C02")
|
|
|
|
{
|
|
|
|
cpumode = MODE_65C02;
|
|
|
|
mx = 0x03;
|
|
|
|
}
|
|
|
|
else if (s == "M6502")
|
|
|
|
{
|
|
|
|
cpumode = MODE_6502;
|
|
|
|
mx = 0x03;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Unknown CPU type in .ini\n");
|
2019-11-17 22:15:45 +00:00
|
|
|
mx = 0x00;
|
2019-11-12 08:15:47 +00:00
|
|
|
}
|
2019-11-17 22:15:45 +00:00
|
|
|
mx = getInt("asm.startmx", mx);;
|
|
|
|
|
2019-11-18 12:50:02 +00:00
|
|
|
|
2019-11-17 22:15:45 +00:00
|
|
|
savepath = getConfig("option.objfile", "");
|
2019-11-17 20:17:28 +00:00
|
|
|
|
2019-11-18 12:50:02 +00:00
|
|
|
lastcarry = false;
|
2019-11-12 08:15:47 +00:00
|
|
|
relocatable = false;
|
2019-11-19 17:59:03 +00:00
|
|
|
currentsym = NULL;
|
2019-11-19 19:27:17 +00:00
|
|
|
if ((syntax & SYNTAX_MERLIN32) == SYNTAX_MERLIN32)
|
2019-11-19 17:59:03 +00:00
|
|
|
{
|
|
|
|
// M32 allows locals that don't have a global above. this is the catchall for that
|
|
|
|
currentsym = &topSymbol; // this is the default symbol for :locals without a global above;
|
|
|
|
}
|
2019-11-17 22:15:45 +00:00
|
|
|
currentsymstr = "";
|
2019-11-11 23:56:03 +00:00
|
|
|
lineno = 0;
|
2019-11-12 03:51:26 +00:00
|
|
|
errorct = 0;
|
2019-11-11 23:56:03 +00:00
|
|
|
passcomplete = false;
|
2019-11-13 23:45:39 +00:00
|
|
|
dumstartaddr = 0;
|
|
|
|
dumstart = 0;
|
2019-11-17 03:33:22 +00:00
|
|
|
truncdata = 0;
|
2019-11-21 16:47:03 +00:00
|
|
|
variables.vars.clear(); // clear the variables for each pass
|
2019-11-16 00:15:58 +00:00
|
|
|
|
2019-11-21 05:50:00 +00:00
|
|
|
while (!macrostack.empty())
|
2019-11-13 04:32:10 +00:00
|
|
|
{
|
2019-11-21 05:50:00 +00:00
|
|
|
macrostack.pop();
|
2019-11-13 04:32:10 +00:00
|
|
|
}
|
2019-11-21 12:53:10 +00:00
|
|
|
while (!expand_macrostack.empty())
|
|
|
|
{
|
|
|
|
expand_macrostack.pop();
|
|
|
|
}
|
2019-11-16 00:15:58 +00:00
|
|
|
while (!LUPstack.empty())
|
|
|
|
{
|
|
|
|
LUPstack.pop();
|
|
|
|
}
|
2019-11-16 17:27:24 +00:00
|
|
|
while (!DOstack.empty())
|
|
|
|
{
|
|
|
|
DOstack.pop();
|
|
|
|
}
|
2019-11-16 19:14:51 +00:00
|
|
|
while (!LSTstack.empty())
|
|
|
|
{
|
|
|
|
LSTstack.pop();
|
|
|
|
}
|
2019-11-21 05:50:00 +00:00
|
|
|
while (!PCstack.empty())
|
|
|
|
{
|
|
|
|
PCstack.pop();
|
|
|
|
}
|
|
|
|
currentmacro.clear();
|
2019-11-21 12:53:10 +00:00
|
|
|
expand_macro.clear();
|
2019-11-16 00:15:58 +00:00
|
|
|
curLUP.clear();
|
2019-11-16 17:27:24 +00:00
|
|
|
curDO.clear();
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLASS::complete(void)
|
|
|
|
{
|
2019-11-12 08:15:47 +00:00
|
|
|
if (savepath != "")
|
|
|
|
{
|
|
|
|
if (errorct == 0)
|
|
|
|
{
|
2019-11-15 01:04:35 +00:00
|
|
|
std::string currentdir = Poco::Path::current();
|
|
|
|
|
|
|
|
savepath = processFilename(savepath, currentdir, 0);
|
|
|
|
printf("saving to file: %s\n", savepath.c_str());
|
|
|
|
|
2019-11-12 08:15:47 +00:00
|
|
|
std::ofstream f(savepath);
|
|
|
|
|
|
|
|
uint32_t lineno = 0;
|
2019-12-03 16:44:50 +00:00
|
|
|
uint32_t l = (uint32_t)lines.size();
|
2019-11-12 08:15:47 +00:00
|
|
|
while (lineno < l)
|
|
|
|
{
|
2019-11-13 23:45:39 +00:00
|
|
|
MerlinLine &line = lines.at(lineno++);
|
|
|
|
if ((line.outbytect > 0) && ((line.flags & FLAG_INDUM) == 0))
|
2019-11-12 08:15:47 +00:00
|
|
|
{
|
2019-11-13 14:54:48 +00:00
|
|
|
for (uint32_t i = 0; i < line.outbytect; i++)
|
2019-11-12 08:15:47 +00:00
|
|
|
{
|
2019-11-13 14:54:48 +00:00
|
|
|
f.put(line.outbytes[i]);
|
2019-11-12 08:15:47 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-18 12:50:02 +00:00
|
|
|
if ((line.datafillct > 0) && ((line.flags & FLAG_INDUM) == 0))
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < line.datafillct; i++)
|
|
|
|
{
|
|
|
|
f.put(line.datafillbyte & 0xFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-11-12 08:15:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("\nErrors in assembly. Output not SAVED.\n\n");
|
|
|
|
}
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-16 17:27:24 +00:00
|
|
|
printf("\n\nEnd qASM assembly, %d bytes, %u errors, %lu lines, %lu symbols.\n", PC.totalbytes, errorct, lines.size(), symbols.size());
|
2019-11-16 06:27:43 +00:00
|
|
|
|
|
|
|
TFileProcessor::complete();
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
if (listing)
|
|
|
|
{
|
2019-11-12 08:15:47 +00:00
|
|
|
showSymbolTable(true);
|
|
|
|
showSymbolTable(false);
|
2019-11-21 12:53:10 +00:00
|
|
|
showVariables(variables);
|
2019-11-22 05:00:26 +00:00
|
|
|
showMacros(true);
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-21 12:53:10 +00:00
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
2019-11-13 23:45:39 +00:00
|
|
|
int CLASS::evaluate(MerlinLine &line, std::string expr, int64_t &value)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
|
|
|
int res = -1;
|
|
|
|
int64_t result = 0;
|
|
|
|
|
|
|
|
if (expr.length() > 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
TEvaluator eval(*this);
|
2019-11-13 23:45:39 +00:00
|
|
|
line.eval_result = 0;
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-13 23:45:39 +00:00
|
|
|
res = eval.evaluate(expr, result, line.expr_shift);
|
2019-11-12 18:13:15 +00:00
|
|
|
if (res != 0)
|
|
|
|
{
|
2019-11-13 01:03:51 +00:00
|
|
|
if (isDebug() > 2)
|
2019-11-12 18:13:15 +00:00
|
|
|
{
|
|
|
|
int c = SetColor(CL_RED);
|
2019-11-15 07:35:04 +00:00
|
|
|
uint32_t rr = result & 0xFFFFFFFF;
|
|
|
|
printf("eval Error=%d %08X |%s|\n", res, rr, eval.badsymbol.c_str());
|
2019-11-12 18:13:15 +00:00
|
|
|
SetColor(c);
|
|
|
|
}
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
if (res == 0)
|
|
|
|
{
|
2019-11-13 23:45:39 +00:00
|
|
|
uint64_t v1 = (uint64_t) result;
|
2019-11-11 23:56:03 +00:00
|
|
|
value = result;
|
2019-11-13 23:45:39 +00:00
|
|
|
if ((listing) && (pass > 0) && (isDebug() > 2))
|
|
|
|
{
|
2019-11-15 07:35:04 +00:00
|
|
|
uint32_t rr = v1 & 0xFFFFFFFF;
|
|
|
|
printf("EV1=%08X '%c'\n", rr, line.expr_shift);
|
2019-11-13 23:45:39 +00:00
|
|
|
}
|
|
|
|
if (v1 >= 0x10000)
|
|
|
|
{
|
|
|
|
line.flags |= FLAG_BIGNUM;
|
|
|
|
}
|
|
|
|
if (v1 < 0x100)
|
|
|
|
{
|
|
|
|
line.flags |= FLAG_DP;
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = 0;
|
|
|
|
res = 0;
|
|
|
|
}
|
2019-11-13 23:45:39 +00:00
|
|
|
if (isDebug() >= 3)
|
2019-11-13 14:54:48 +00:00
|
|
|
{
|
2019-11-15 07:35:04 +00:00
|
|
|
uint32_t rr = value & 0xFFFFFFFF;
|
|
|
|
printf("Eval Result: %08X (status=%d)\n", rr, res);
|
2019-11-13 14:54:48 +00:00
|
|
|
}
|
2019-11-12 18:13:15 +00:00
|
|
|
return (res);
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 08:15:47 +00:00
|
|
|
int CLASS::getAddrMode(MerlinLine & line)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
|
|
|
int res = -1;
|
|
|
|
uint16_t mode = syn_none;
|
|
|
|
int idx, x;
|
|
|
|
std::string s, oper;
|
|
|
|
std::vector<std::string> groups;
|
|
|
|
|
|
|
|
oper = line.operand;
|
|
|
|
|
|
|
|
if ((line.opcode.length() == 0) || (line.operand.length() == 0))
|
|
|
|
{
|
|
|
|
return (syn_implied);
|
|
|
|
}
|
|
|
|
|
|
|
|
idx = 0;
|
2019-11-12 18:13:15 +00:00
|
|
|
RegularExpression valEx(valExpression, 0, true);
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
while (mode == syn_none)
|
|
|
|
{
|
|
|
|
s = addrRegEx[idx].regEx;
|
|
|
|
if (s == "")
|
|
|
|
{
|
|
|
|
mode = syn_err;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RegularExpression regex(s, 0, true);
|
|
|
|
groups.clear();
|
|
|
|
x = 0;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
x = regex.split(oper, 0, groups, 0);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
if (x > 0)
|
|
|
|
{
|
|
|
|
mode = addrRegEx[idx].addrMode;
|
|
|
|
line.addrtext = addrRegEx[idx].text;
|
|
|
|
//cout << "mode: " << line.addrtext << endl;
|
2019-11-12 03:51:26 +00:00
|
|
|
int ct = 0;
|
2019-11-11 23:56:03 +00:00
|
|
|
for (uint32_t i = 0; i < groups.size(); i++)
|
|
|
|
{
|
|
|
|
s = groups[i];
|
2019-11-12 03:51:26 +00:00
|
|
|
//printf("ct=%zu idx=%d group: |%s|\n", groups.size(), i, s.c_str());
|
|
|
|
|
|
|
|
if (s != "")
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-12 03:51:26 +00:00
|
|
|
if ((s != "^") && (s != "<") && (s != ">") && (s != "|"))
|
|
|
|
{
|
2019-11-12 18:13:15 +00:00
|
|
|
bool v = true;
|
2019-11-13 04:32:10 +00:00
|
|
|
if (mode == syn_abs)
|
2019-11-12 18:13:15 +00:00
|
|
|
{
|
2019-11-13 04:32:10 +00:00
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
v = valEx.match(s, 0, 0);
|
2019-11-18 12:50:02 +00:00
|
|
|
if (v)
|
|
|
|
{
|
|
|
|
if (pass == 0)
|
|
|
|
{
|
|
|
|
// can only check on pass 0, because if the A"
|
|
|
|
// symbol is defined later, we will generate different
|
|
|
|
// bytes on the next pass
|
|
|
|
|
2019-11-19 19:27:17 +00:00
|
|
|
if ((line.syntax & SYNTAX_MERLIN32) == SYNTAX_MERLIN32)
|
2019-11-18 12:50:02 +00:00
|
|
|
{
|
2019-11-19 17:59:03 +00:00
|
|
|
if (Poco::toUpper(oper) == "A") // check the whole operand, not just the expression
|
2019-11-18 12:50:02 +00:00
|
|
|
{
|
2019-11-19 17:59:03 +00:00
|
|
|
TSymbol *sym = findSymbol("A");
|
|
|
|
if (sym == NULL)
|
|
|
|
{
|
|
|
|
line.flags |= FLAG_FORCEIMPLIED;
|
|
|
|
mode = syn_implied; // if the label hasn't been defined yet, assume Immediate addressing
|
|
|
|
goto out;
|
|
|
|
}
|
2019-11-18 12:50:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (line.flags & FLAG_FORCEIMPLIED)
|
|
|
|
{
|
|
|
|
mode = syn_implied;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2019-11-13 04:32:10 +00:00
|
|
|
}
|
2019-11-12 18:13:15 +00:00
|
|
|
}
|
|
|
|
if (!v)
|
|
|
|
{
|
|
|
|
//printf("invalid expression |%s|\n", s.c_str());
|
|
|
|
mode = syn_none;
|
|
|
|
}
|
|
|
|
else if (ct == 1)
|
2019-11-12 03:51:26 +00:00
|
|
|
{
|
|
|
|
line.operand_expr = s;
|
|
|
|
}
|
|
|
|
else if (ct == 2)
|
|
|
|
{
|
|
|
|
line.operand_expr2 = s;
|
|
|
|
}
|
|
|
|
ct++;
|
|
|
|
//printf("line expression=|%s|\n", s.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// SGQ need to set a flag for a shift and process it after eval
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
idx++;
|
|
|
|
}
|
2019-11-18 12:50:02 +00:00
|
|
|
out:
|
2019-11-11 23:56:03 +00:00
|
|
|
if (mode == syn_none)
|
|
|
|
{
|
|
|
|
mode = syn_err;
|
|
|
|
}
|
|
|
|
res = mode;
|
|
|
|
//printf("syn_mode=%d\n", mode);
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
2019-11-12 08:15:47 +00:00
|
|
|
int CLASS::parseOperand(MerlinLine & line)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
int res = -1;
|
|
|
|
|
|
|
|
line.operand_expr = "";
|
|
|
|
int m = getAddrMode(line);
|
|
|
|
if (m >= 0)
|
|
|
|
{
|
|
|
|
res = m;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//errorOut(errBadAddressMode);
|
|
|
|
}
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
2019-11-19 19:27:17 +00:00
|
|
|
int CLASS::substituteVariables(MerlinLine & line, std::string &outop)
|
2019-11-14 03:37:26 +00:00
|
|
|
{
|
2019-11-19 19:27:17 +00:00
|
|
|
int res = 0;
|
2019-11-14 05:39:35 +00:00
|
|
|
int x;
|
|
|
|
std::string::size_type offset, slen;
|
2019-11-14 03:37:26 +00:00
|
|
|
std::string oper = line.operand;
|
2019-11-14 05:39:35 +00:00
|
|
|
std::string s;
|
2019-11-19 19:27:17 +00:00
|
|
|
std::string operin;
|
2019-11-14 05:39:35 +00:00
|
|
|
TSymbol *sym;
|
2019-11-14 05:56:50 +00:00
|
|
|
uint32_t len, off, ct;
|
2019-11-14 05:39:35 +00:00
|
|
|
|
2019-11-19 19:27:17 +00:00
|
|
|
bool done = false;
|
2019-11-19 20:06:08 +00:00
|
|
|
operin = oper;
|
|
|
|
ct = 0;
|
2019-11-19 19:27:17 +00:00
|
|
|
restart:
|
|
|
|
while (!done)
|
2019-11-14 03:37:26 +00:00
|
|
|
{
|
|
|
|
|
2019-11-19 19:27:17 +00:00
|
|
|
slen = oper.length();
|
|
|
|
if (slen > 0)
|
2019-11-14 05:39:35 +00:00
|
|
|
{
|
2019-11-19 19:27:17 +00:00
|
|
|
std::vector<std::string> groups;
|
2019-11-14 05:39:35 +00:00
|
|
|
|
2019-11-19 19:27:17 +00:00
|
|
|
offset = 0;
|
|
|
|
RegularExpression varEx(varExpression, 0, true);
|
|
|
|
Poco::RegularExpression::MatchVec mVec;
|
|
|
|
|
|
|
|
//printf("|%s|%s|\n", varExpression.c_str(), oper.c_str());
|
|
|
|
groups.clear();
|
|
|
|
while (offset < slen)
|
2019-11-14 05:39:35 +00:00
|
|
|
{
|
2019-11-19 19:27:17 +00:00
|
|
|
try
|
2019-11-14 05:39:35 +00:00
|
|
|
{
|
2019-11-19 19:27:17 +00:00
|
|
|
varEx.match(oper, offset, mVec, 0);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
offset = slen;
|
|
|
|
}
|
|
|
|
|
2019-12-03 16:44:50 +00:00
|
|
|
x = (int)mVec.size();
|
2019-11-19 19:27:17 +00:00
|
|
|
if (x > 0)
|
|
|
|
{
|
|
|
|
res = 0;
|
2019-12-03 16:44:50 +00:00
|
|
|
off = (uint32_t)mVec[0].offset;
|
|
|
|
len = (uint32_t)mVec[0].length;
|
2019-11-19 19:27:17 +00:00
|
|
|
s = oper.substr(off, len);
|
2019-11-22 17:33:24 +00:00
|
|
|
slen = s.length();
|
2019-11-22 02:14:30 +00:00
|
|
|
sym = NULL;
|
|
|
|
if (expand_macrostack.size() > 0)
|
|
|
|
{
|
|
|
|
sym = findVariable(s, expand_macro.variables);
|
|
|
|
}
|
|
|
|
if (sym == NULL)
|
|
|
|
{
|
|
|
|
sym = findVariable(s, variables);
|
|
|
|
}
|
2019-11-19 19:27:17 +00:00
|
|
|
if (sym != NULL)
|
2019-11-14 05:39:35 +00:00
|
|
|
{
|
2019-11-19 19:27:17 +00:00
|
|
|
//printf("match |%s|\n",sym->var_text.c_str());
|
|
|
|
|
|
|
|
if (sym->var_text != "")
|
|
|
|
{
|
|
|
|
oper = oper.replace(off, len, sym->var_text);
|
2019-11-22 17:33:24 +00:00
|
|
|
slen = oper.length();
|
2019-11-19 19:27:17 +00:00
|
|
|
ct++;
|
|
|
|
if (pass > 0)
|
|
|
|
{
|
|
|
|
//printf("%d |%s|\n", ct, s.c_str());
|
|
|
|
}
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-19 20:06:08 +00:00
|
|
|
done = true;
|
2019-11-14 05:39:35 +00:00
|
|
|
}
|
2019-11-19 19:27:17 +00:00
|
|
|
offset += len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
offset = slen;
|
2019-11-19 20:06:08 +00:00
|
|
|
done = true;
|
2019-11-14 05:39:35 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-14 03:37:26 +00:00
|
|
|
|
2019-11-19 19:27:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-19 20:06:08 +00:00
|
|
|
done = true;
|
2019-11-19 19:27:17 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-22 02:14:30 +00:00
|
|
|
//printf("inoper=|%s| outoper=|%s|\n",operin.c_str(),oper.c_str());
|
2019-11-19 20:06:08 +00:00
|
|
|
if (ct > 0)
|
2019-11-19 19:27:17 +00:00
|
|
|
{
|
2019-11-19 20:06:08 +00:00
|
|
|
outop = oper;
|
|
|
|
res = ct;
|
2019-11-14 03:37:26 +00:00
|
|
|
}
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
2019-11-22 03:20:59 +00:00
|
|
|
bool CLASS::doOFF(void)
|
|
|
|
{
|
2019-11-22 05:00:26 +00:00
|
|
|
bool res = curDO.doskip;
|
2019-11-22 03:20:59 +00:00
|
|
|
std::stack<TDOstruct> tmpstack;
|
|
|
|
TDOstruct doitem;
|
|
|
|
|
2019-12-03 16:44:50 +00:00
|
|
|
uint32_t ct = (uint32_t)DOstack.size();
|
2019-11-22 05:00:26 +00:00
|
|
|
if (ct > 0)
|
2019-11-22 03:20:59 +00:00
|
|
|
{
|
2019-11-22 05:00:26 +00:00
|
|
|
tmpstack = DOstack;
|
2019-11-22 03:20:59 +00:00
|
|
|
}
|
2019-11-22 05:00:26 +00:00
|
|
|
while (ct > 0)
|
2019-11-22 03:20:59 +00:00
|
|
|
{
|
2019-11-22 05:00:26 +00:00
|
|
|
doitem = tmpstack.top();
|
2019-11-22 03:20:59 +00:00
|
|
|
tmpstack.pop();
|
|
|
|
if (doitem.doskip)
|
|
|
|
{
|
2019-11-22 05:00:26 +00:00
|
|
|
res = true;
|
2019-11-22 03:20:59 +00:00
|
|
|
}
|
|
|
|
ct--;
|
|
|
|
}
|
2019-11-22 05:00:26 +00:00
|
|
|
//printf("DOOFF: %d\n",res);
|
|
|
|
return (res);
|
2019-11-22 03:20:59 +00:00
|
|
|
}
|
|
|
|
|
2019-11-16 18:48:01 +00:00
|
|
|
// this function determines if code generation is turned off (IF,DO,LUP,MAC, etc
|
2019-11-16 17:27:24 +00:00
|
|
|
bool CLASS::codeSkipped(void)
|
|
|
|
{
|
|
|
|
bool res = false;
|
|
|
|
|
2019-11-16 18:48:01 +00:00
|
|
|
res = (curLUP.lupskip) ? true : res;
|
2019-11-22 03:20:59 +00:00
|
|
|
res = doOFF() ? true : res;
|
2019-11-21 05:50:00 +00:00
|
|
|
res = currentmacro.running ? true : res;
|
2019-11-16 18:48:01 +00:00
|
|
|
|
|
|
|
//printf("codeskip: %d\n",res);
|
2019-11-16 17:27:24 +00:00
|
|
|
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
void CLASS::process(void)
|
|
|
|
{
|
2019-11-19 06:29:06 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
uint32_t ct = lines.size();
|
|
|
|
for (uint32_t lineno = 0; lineno < ct; lineno++)
|
|
|
|
{
|
|
|
|
//MerlinLine &line = lines.at(lineno);
|
|
|
|
//printf("|%s| |%s| |%s| |%s|\n", line.lable.c_str()
|
|
|
|
// , line.opcode.c_str(), line.operand.c_str(), line.comment.c_str());
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
uint32_t l;
|
2019-11-13 14:54:48 +00:00
|
|
|
int x;;
|
2019-11-11 23:56:03 +00:00
|
|
|
char c;
|
2019-11-14 05:39:35 +00:00
|
|
|
char buff[256];
|
2019-11-16 02:30:12 +00:00
|
|
|
MerlinLine errLine;
|
2019-11-22 03:20:59 +00:00
|
|
|
std::string op, realop, operand, ls;
|
2019-11-11 23:56:03 +00:00
|
|
|
|
|
|
|
pass = 0;
|
|
|
|
while (pass < 2)
|
|
|
|
{
|
|
|
|
initpass();
|
|
|
|
|
2019-12-03 16:44:50 +00:00
|
|
|
l = (uint32_t)lines.size();
|
2019-11-22 05:00:26 +00:00
|
|
|
bool passdone = false;
|
|
|
|
while ((!passdone) && (!passcomplete))
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-21 12:53:10 +00:00
|
|
|
|
|
|
|
MerlinLine *ml = NULL;
|
|
|
|
bool srcline = true;
|
|
|
|
if (expand_macro.running)
|
|
|
|
{
|
|
|
|
srcline = false;
|
|
|
|
if (expand_macro.currentline >= expand_macro.len)
|
|
|
|
{
|
|
|
|
// macro is complete
|
|
|
|
lineno = expand_macro.sourceline + 1;
|
|
|
|
if (expand_macrostack.size() > 0)
|
|
|
|
{
|
|
|
|
expand_macro = expand_macrostack.top();
|
|
|
|
expand_macrostack.pop();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
expand_macro.clear();
|
|
|
|
}
|
|
|
|
srcline = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ml = &expand_macro.lines[expand_macro.currentline];
|
|
|
|
lineno = expand_macro.sourceline;
|
|
|
|
expand_macro.currentline++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (srcline)
|
|
|
|
{
|
2019-11-22 05:00:26 +00:00
|
|
|
if (lineno >= l)
|
|
|
|
{
|
|
|
|
passdone = true;
|
|
|
|
goto passout;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ml = &lines[lineno];
|
|
|
|
}
|
2019-11-21 12:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MerlinLine &line = *ml;
|
|
|
|
|
|
|
|
//printf("lineno=%u %s\n", lineno, line.wholetext.c_str());
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-13 23:45:39 +00:00
|
|
|
line.eval_result = 0;
|
2019-11-13 14:54:48 +00:00
|
|
|
line.lineno = lineno + 1;
|
2019-11-17 03:33:22 +00:00
|
|
|
line.truncdata = truncdata;
|
2019-11-17 16:02:55 +00:00
|
|
|
memcpy(line.tabs, tabs, sizeof(tabs));
|
2019-11-13 14:54:48 +00:00
|
|
|
//printf("lineno: %d %d |%s|\n",lineno,l,line.operand.c_str());
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-13 14:54:48 +00:00
|
|
|
op = Poco::toLower(line.opcode);
|
2019-11-22 03:20:59 +00:00
|
|
|
realop = line.opcode;
|
2019-11-13 14:54:48 +00:00
|
|
|
operand = Poco::toLower(line.operand);
|
|
|
|
line.startpc = PC.currentpc;
|
|
|
|
line.linemx = mx;
|
|
|
|
line.bytect = 0;
|
|
|
|
line.showmx = showmx;
|
2019-11-19 17:59:03 +00:00
|
|
|
line.syntax = syntax;
|
2019-11-18 14:07:44 +00:00
|
|
|
line.merlinerrors = merlinerrors;
|
2019-11-11 23:56:03 +00:00
|
|
|
|
2019-11-22 05:00:26 +00:00
|
|
|
if ((line.lable != "") && (op != "mac"))
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-13 14:54:48 +00:00
|
|
|
std::string lable = Poco::trim(line.lable);
|
2019-11-13 01:03:51 +00:00
|
|
|
TSymbol *sym = NULL;
|
|
|
|
bool dupsym = false;
|
2019-11-13 14:54:48 +00:00
|
|
|
c = line.lable[0];
|
2019-11-11 23:56:03 +00:00
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case ']':
|
2019-11-14 05:39:35 +00:00
|
|
|
sprintf(buff, "$%X", PC.currentpc);
|
|
|
|
ls = buff;
|
2019-11-21 12:53:10 +00:00
|
|
|
sym = addVariable(line.lable, ls, variables, true);
|
2019-11-19 19:27:17 +00:00
|
|
|
//if (sym == NULL) { dupsym = true; }
|
2019-11-11 23:56:03 +00:00
|
|
|
break;
|
2019-11-17 16:02:55 +00:00
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
case ':':
|
|
|
|
default:
|
2019-11-14 05:39:35 +00:00
|
|
|
if (pass == 0)
|
|
|
|
{
|
|
|
|
sym = addSymbol(line.lable, PC.currentpc, false);
|
2019-11-17 16:02:55 +00:00
|
|
|
if (sym == NULL)
|
|
|
|
{
|
|
|
|
dupsym = true;
|
|
|
|
line.setError(errDupSymbol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c != ':')
|
|
|
|
{
|
|
|
|
currentsym = findSymbol(line.lable);
|
2019-11-17 22:15:45 +00:00
|
|
|
currentsymstr = line.lable;
|
2019-11-14 05:39:35 +00:00
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-11-13 01:03:51 +00:00
|
|
|
if (dupsym)
|
|
|
|
{
|
2019-11-13 14:54:48 +00:00
|
|
|
line.setError(errDupSymbol);
|
2019-11-13 01:03:51 +00:00
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-19 19:27:17 +00:00
|
|
|
std::string outop;
|
2019-11-21 12:53:10 +00:00
|
|
|
line.printoperand = line.operand;
|
|
|
|
|
2019-11-22 17:33:24 +00:00
|
|
|
x = 0;
|
|
|
|
if (macrostack.size() == 0)
|
|
|
|
{
|
|
|
|
x = substituteVariables(line, outop);
|
|
|
|
}
|
2019-11-19 20:06:08 +00:00
|
|
|
if (x > 0)
|
2019-11-19 19:27:17 +00:00
|
|
|
{
|
2019-11-22 02:14:30 +00:00
|
|
|
line.printoperand = outop;
|
2019-11-19 20:06:08 +00:00
|
|
|
line.operand = outop;
|
2019-11-19 19:27:17 +00:00
|
|
|
}
|
2019-11-13 14:54:48 +00:00
|
|
|
x = parseOperand(line);
|
2019-11-11 23:56:03 +00:00
|
|
|
if (x >= 0)
|
|
|
|
{
|
2019-11-13 14:54:48 +00:00
|
|
|
line.addressmode = x;
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-12 18:13:15 +00:00
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
int64_t value = -1;
|
2019-11-13 23:45:39 +00:00
|
|
|
x = evaluate(line, line.operand_expr, value);
|
2019-11-12 18:13:15 +00:00
|
|
|
|
2019-11-18 12:50:02 +00:00
|
|
|
line.eval_result = x;
|
2019-11-11 23:56:03 +00:00
|
|
|
if (x == 0)
|
|
|
|
{
|
|
|
|
value &= 0xFFFFFFFF;
|
2019-11-18 02:16:39 +00:00
|
|
|
line.expr_value = (uint32_t)value;
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-13 14:54:48 +00:00
|
|
|
line.expr_value = 0;
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
x = 0;
|
|
|
|
if (op.length() > 0)
|
|
|
|
{
|
2019-11-22 03:20:59 +00:00
|
|
|
bool skipop = false;
|
|
|
|
if (doOFF())
|
2019-11-21 05:50:00 +00:00
|
|
|
{
|
2019-11-22 03:20:59 +00:00
|
|
|
skipop = true;
|
|
|
|
if ((op == "fin") || (op == "else") || (op == "do") || (op == "if"))
|
2019-11-21 16:47:03 +00:00
|
|
|
{
|
2019-11-22 03:20:59 +00:00
|
|
|
skipop = false;
|
2019-11-21 16:47:03 +00:00
|
|
|
}
|
2019-11-22 02:14:30 +00:00
|
|
|
}
|
2019-11-22 03:20:59 +00:00
|
|
|
if (!skipop)
|
2019-11-22 02:14:30 +00:00
|
|
|
{
|
2019-11-22 03:20:59 +00:00
|
|
|
TMacro *mac = NULL;
|
|
|
|
bool inoperand = false;
|
2019-11-22 17:33:24 +00:00
|
|
|
if (macrostack.size() == 0)
|
2019-11-21 12:53:10 +00:00
|
|
|
{
|
2019-11-22 17:33:24 +00:00
|
|
|
mac = findMacro(realop);
|
|
|
|
if (mac == NULL)
|
2019-11-22 03:20:59 +00:00
|
|
|
{
|
2019-11-22 17:33:24 +00:00
|
|
|
if (op == ">>>") // specal merlin way of calling a macro
|
2019-11-22 03:20:59 +00:00
|
|
|
{
|
2019-11-22 17:33:24 +00:00
|
|
|
Poco::StringTokenizer tok(operand, ", ", Poco::StringTokenizer::TOK_TRIM |
|
|
|
|
Poco::StringTokenizer::TOK_IGNORE_EMPTY);
|
|
|
|
std::string s = "";
|
|
|
|
if (tok.count() > 0)
|
|
|
|
{
|
|
|
|
s = tok[0];
|
|
|
|
}
|
|
|
|
mac = findMacro(s);
|
|
|
|
inoperand = true;
|
2019-11-22 03:20:59 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-22 02:14:30 +00:00
|
|
|
}
|
2019-11-22 03:20:59 +00:00
|
|
|
if (mac == NULL)
|
2019-11-22 02:14:30 +00:00
|
|
|
{
|
2019-11-22 03:20:59 +00:00
|
|
|
x = callOpCode(op, line);
|
|
|
|
}
|
|
|
|
if (mac != NULL)
|
|
|
|
{
|
|
|
|
expand_macrostack.push(expand_macro);
|
|
|
|
expand_macro = *mac;
|
|
|
|
|
|
|
|
expand_macro.lines.clear();
|
|
|
|
//printf("mac start=%u end=%u\n", expand_macro.start, expand_macro.end);
|
|
|
|
for (uint32_t lc = expand_macro.start; lc < expand_macro.end; lc++)
|
2019-11-21 16:47:03 +00:00
|
|
|
{
|
2019-11-22 03:20:59 +00:00
|
|
|
//printf("pushing %s\n", lines[lc].wholetext.c_str());
|
|
|
|
MerlinLine nl(lines[lc].wholetext); // create a new clean line (without errors,data)
|
|
|
|
expand_macro.lines.push_back(nl);
|
2019-11-21 16:47:03 +00:00
|
|
|
}
|
2019-11-22 03:20:59 +00:00
|
|
|
expand_macro.running = true;
|
|
|
|
expand_macro.sourceline = lineno;
|
|
|
|
expand_macro.variables.vars.clear();
|
|
|
|
// set the variables for the macro here SGQ
|
2019-11-22 02:14:30 +00:00
|
|
|
|
2019-11-22 03:20:59 +00:00
|
|
|
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;
|
2019-11-22 02:14:30 +00:00
|
|
|
}
|
2019-11-21 05:50:00 +00:00
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-12 18:13:15 +00:00
|
|
|
|
2019-11-16 17:27:24 +00:00
|
|
|
if ((x > 0) && (codeSkipped())) // has a psuedo-op turned off code generation? (LUP, IF, etc)
|
|
|
|
{
|
|
|
|
x = 0;
|
2019-11-17 03:33:22 +00:00
|
|
|
line.outbytect = 0;
|
2019-11-16 17:27:24 +00:00
|
|
|
}
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
if (x > 0)
|
|
|
|
{
|
2019-11-13 23:45:39 +00:00
|
|
|
if (!PCstack.empty()) // are we inside a DUM section?
|
|
|
|
{
|
|
|
|
line.flags |= FLAG_INDUM;
|
|
|
|
}
|
2019-11-13 14:54:48 +00:00
|
|
|
if ((line.eval_result != 0) && (pass > 0))
|
2019-11-12 18:13:15 +00:00
|
|
|
{
|
2019-11-13 14:54:48 +00:00
|
|
|
line.setError(errBadOperand);
|
|
|
|
line.errorText = line.operand_expr;
|
2019-11-12 18:13:15 +00:00
|
|
|
}
|
2019-11-13 14:54:48 +00:00
|
|
|
line.bytect = x;
|
2019-11-13 04:32:10 +00:00
|
|
|
PC.currentpc += x;
|
|
|
|
PC.totalbytes += x;
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
if (pass == 0)
|
|
|
|
{
|
2019-11-13 14:54:48 +00:00
|
|
|
line.pass0bytect = line.bytect;
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
2019-11-13 23:45:39 +00:00
|
|
|
if (dumstart > 0) // starting a dummy section
|
2019-11-13 14:54:48 +00:00
|
|
|
{
|
|
|
|
PCstack.push(PC);
|
2019-11-13 23:45:39 +00:00
|
|
|
PC.origin = dumstartaddr;
|
|
|
|
PC.currentpc = PC.origin;
|
|
|
|
dumstart = 0;
|
|
|
|
dumstartaddr = 0;
|
2019-11-13 14:54:48 +00:00
|
|
|
}
|
2019-11-13 23:45:39 +00:00
|
|
|
if (dumstart < 0)
|
2019-11-13 14:54:48 +00:00
|
|
|
{
|
2019-11-13 23:45:39 +00:00
|
|
|
PC = PCstack.top();
|
2019-11-13 14:54:48 +00:00
|
|
|
PCstack.pop();
|
2019-11-13 23:45:39 +00:00
|
|
|
dumstart = 0;
|
|
|
|
dumstartaddr = 0;
|
2019-11-13 14:54:48 +00:00
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
|
|
|
|
if (pass == 1)
|
|
|
|
{
|
2019-11-13 14:54:48 +00:00
|
|
|
if ((line.pass0bytect != line.bytect) && (line.errorcode == 0))
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-21 12:53:10 +00:00
|
|
|
if (expand_macrostack.size() == 0) // if macro expanding, you can't make this check
|
|
|
|
{
|
|
|
|
line.setError(errBadByteCount);
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
2019-11-13 14:54:48 +00:00
|
|
|
if (line.errorcode != 0)
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-12 03:51:26 +00:00
|
|
|
errorct++;
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-13 14:54:48 +00:00
|
|
|
if (((!skiplist) && (listing) && (pass == 1)) || (line.errorcode != 0))
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-13 14:54:48 +00:00
|
|
|
line.print(lineno);
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
2019-11-12 03:51:26 +00:00
|
|
|
skiplist = false;
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
lineno++;
|
|
|
|
}
|
2019-11-22 05:00:26 +00:00
|
|
|
passout:
|
2019-11-16 02:30:12 +00:00
|
|
|
// end of file reached here, do some final checks
|
|
|
|
|
2019-11-16 17:27:24 +00:00
|
|
|
#if 0
|
2019-11-16 02:30:12 +00:00
|
|
|
if (LUPstack.size() > 0)
|
|
|
|
{
|
|
|
|
errLine.clear();
|
|
|
|
errLine.setError(errUnexpectedEOF);
|
|
|
|
errLine.print(lineno);
|
|
|
|
pass = 2;
|
|
|
|
}
|
2019-11-16 17:27:24 +00:00
|
|
|
#endif
|
2019-11-11 23:56:03 +00:00
|
|
|
pass++;
|
|
|
|
}
|
2019-11-19 06:29:06 +00:00
|
|
|
#endif
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CLASS::doline(int lineno, std::string line)
|
|
|
|
{
|
|
|
|
int res = 0;
|
2019-11-14 17:32:11 +00:00
|
|
|
int x;
|
2019-11-11 23:56:03 +00:00
|
|
|
std::string op;
|
|
|
|
|
2019-11-15 11:40:35 +00:00
|
|
|
UNUSED(lineno);
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
MerlinLine l(line);
|
|
|
|
|
|
|
|
op = Poco::toLower(l.opcode);
|
|
|
|
if (op == "merlin")
|
|
|
|
{
|
|
|
|
syntax = SYNTAX_MERLIN;
|
|
|
|
}
|
|
|
|
else if (op == "orca")
|
|
|
|
{
|
|
|
|
syntax = SYNTAX_ORCA;
|
|
|
|
}
|
|
|
|
l.syntax = syntax;
|
|
|
|
lines.push_back(l);
|
|
|
|
|
2019-11-16 02:30:12 +00:00
|
|
|
if ((op == "use") || (op == "put"))
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
2019-11-14 18:47:50 +00:00
|
|
|
std::string fn;
|
|
|
|
x = processfile(l.operand, fn);
|
2019-11-19 16:38:49 +00:00
|
|
|
//printf("processfile : %d\n",x);
|
2019-11-14 17:32:11 +00:00
|
|
|
if (x < 0)
|
|
|
|
{
|
|
|
|
switch (x)
|
|
|
|
{
|
|
|
|
case -9:
|
|
|
|
l.setError(errDuplicateFile);
|
|
|
|
break;
|
|
|
|
case -3:
|
|
|
|
l.setError(errFileNotFound);
|
|
|
|
break;
|
|
|
|
case -2:
|
|
|
|
l.setError(errFileNoAccess);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
l.setError(errFileNotFound);
|
|
|
|
break;
|
|
|
|
}
|
2019-11-14 18:47:50 +00:00
|
|
|
l.operand = fn;
|
2019-11-14 17:32:11 +00:00
|
|
|
l.print(0);
|
|
|
|
errorct++;
|
|
|
|
res = -1;
|
|
|
|
}
|
2019-11-11 23:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CLASS
|
|
|
|
|
|
|
|
#define CLASS T65816Link
|
|
|
|
|
2019-11-13 01:03:51 +00:00
|
|
|
CLASS::CLASS() : TFileProcessor()
|
2019-11-11 23:56:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CLASS::~CLASS()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLASS::init(void)
|
|
|
|
{
|
|
|
|
TFileProcessor::init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLASS::process(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
void CLASS::complete(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int CLASS::doline(int lineno, std::string line)
|
|
|
|
{
|
2019-11-15 11:40:35 +00:00
|
|
|
UNUSED(lineno);
|
|
|
|
UNUSED(line);
|
|
|
|
|
2019-11-11 23:56:03 +00:00
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CLASS
|