mirror of
https://github.com/marketideas/qasm.git
synced 2025-07-16 03:24:05 +00:00
test
This commit is contained in:
123
asm.cpp
123
asm.cpp
@@ -30,7 +30,7 @@ void CLASS::print(uint32_t lineno)
|
|||||||
static bool checked = false;
|
static bool checked = false;
|
||||||
static bool nc1 = false;
|
static bool nc1 = false;
|
||||||
bool nc = false;
|
bool nc = false;
|
||||||
uint8_t commentcol=tabs[2];
|
uint8_t commentcol = tabs[2];
|
||||||
|
|
||||||
uint32_t b = 4; // how many bytes show on the first line
|
uint32_t b = 4; // how many bytes show on the first line
|
||||||
|
|
||||||
@@ -194,17 +194,17 @@ void CLASS::print(uint32_t lineno)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pcol += printf("%s ",printlable.c_str());
|
pcol += printf("%s ", printlable.c_str());
|
||||||
while (pcol < tabs[0])
|
while (pcol < tabs[0])
|
||||||
{
|
{
|
||||||
pcol += printf(" ");
|
pcol += printf(" ");
|
||||||
}
|
}
|
||||||
pcol+=printf("%s ",opcode.c_str());
|
pcol += printf("%s ", opcode.c_str());
|
||||||
while (pcol < tabs[1])
|
while (pcol < tabs[1])
|
||||||
{
|
{
|
||||||
pcol += printf(" ");
|
pcol += printf(" ");
|
||||||
}
|
}
|
||||||
pcol+=printf("%s ",operand.c_str());
|
pcol += printf("%s ", operand.c_str());
|
||||||
//pcol += printf("%-12s %-8s %-10s ", printlable.c_str(), opcode.c_str(), operand.c_str());
|
//pcol += printf("%-12s %-8s %-10s ", printlable.c_str(), opcode.c_str(), operand.c_str());
|
||||||
}
|
}
|
||||||
if ((errorcode > 0) && (!merlinstyle))
|
if ((errorcode > 0) && (!merlinstyle))
|
||||||
@@ -945,21 +945,8 @@ TSymbol *CLASS::addSymbol(std::string sym, uint32_t val, bool replace)
|
|||||||
TSymbol *res = NULL;
|
TSymbol *res = NULL;
|
||||||
TSymbol *fnd = NULL;
|
TSymbol *fnd = NULL;
|
||||||
|
|
||||||
fnd = findSymbol(sym);
|
if (sym.length() > 0)
|
||||||
|
|
||||||
if ((fnd != NULL) && (!replace))
|
|
||||||
{
|
{
|
||||||
return (NULL); // it is a duplicate
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fnd != NULL)
|
|
||||||
{
|
|
||||||
//printf("replacing symbol: %s %08X\n",sym.c_str(),val);
|
|
||||||
fnd->value = val;
|
|
||||||
return (fnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
//printf("addSymbol |%s|\n",sym.c_str());
|
|
||||||
TSymbol s;
|
TSymbol s;
|
||||||
s.name = sym;
|
s.name = sym;
|
||||||
s.opcode = 0;
|
s.opcode = 0;
|
||||||
@@ -969,8 +956,58 @@ TSymbol *CLASS::addSymbol(std::string sym, uint32_t val, bool replace)
|
|||||||
s.used = false;
|
s.used = false;
|
||||||
s.cb = NULL;
|
s.cb = NULL;
|
||||||
std::pair<std::string, TSymbol> p(Poco::toUpper(sym), s);
|
std::pair<std::string, TSymbol> p(Poco::toUpper(sym), s);
|
||||||
|
|
||||||
|
if (sym[0] == ':')
|
||||||
|
{
|
||||||
|
//local symbol
|
||||||
|
if (currentsym == NULL)
|
||||||
|
{
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fnd = findSymbol(sym);
|
||||||
|
if ((fnd != NULL) && (!replace))
|
||||||
|
{
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
symbols.insert(p);
|
||||||
res = findSymbol(sym);
|
res = findSymbol(sym);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out:
|
||||||
return (res);
|
return (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -978,15 +1015,37 @@ TSymbol *CLASS::findSymbol(std::string symname)
|
|||||||
{
|
{
|
||||||
TSymbol *res = NULL;
|
TSymbol *res = NULL;
|
||||||
|
|
||||||
|
if (symname.length() > 0)
|
||||||
|
{
|
||||||
|
if (symname[0] == ':')
|
||||||
|
{
|
||||||
|
if (currentsym == NULL)
|
||||||
|
{
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto itr = currentsym->locals.find(Poco::toUpper(symname));
|
||||||
|
if (itr != currentsym->locals.end())
|
||||||
|
{
|
||||||
|
res = &itr->second;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
//printf("finding: %s\n",symname.c_str());
|
//printf("finding: %s\n",symname.c_str());
|
||||||
auto itr = symbols.find(Poco::toUpper(symname));
|
auto itr = symbols.find(Poco::toUpper(symname));
|
||||||
if (itr != symbols.end())
|
if (itr != symbols.end())
|
||||||
{
|
{
|
||||||
//printf("Found: %s 0x%08X\n",itr->second.name.c_str(),itr->second.value);
|
//printf("Found: %s 0x%08X\n",itr->second.name.c_str(),itr->second.value);
|
||||||
res = &itr->second;
|
res = &itr->second;
|
||||||
|
goto out;
|
||||||
return (res);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out:
|
||||||
return (res);
|
return (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1166,9 +1225,9 @@ int CLASS::callOpCode(std::string op, MerlinLine &line)
|
|||||||
line.flags |= FLAG_FORCELONG;
|
line.flags |= FLAG_FORCELONG;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (line.expr_value>=0x100)
|
if (line.expr_value >= 0x100)
|
||||||
{
|
{
|
||||||
line.flags|=FLAG_FORCEABS;
|
line.flags |= FLAG_FORCEABS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1321,6 +1380,7 @@ void CLASS::initpass(void)
|
|||||||
}
|
}
|
||||||
relocatable = false;
|
relocatable = false;
|
||||||
currentsym = NULL;
|
currentsym = NULL;
|
||||||
|
currentsymstr="";
|
||||||
lineno = 0;
|
lineno = 0;
|
||||||
errorct = 0;
|
errorct = 0;
|
||||||
passcomplete = false;
|
passcomplete = false;
|
||||||
@@ -1359,9 +1419,9 @@ void CLASS::complete(void)
|
|||||||
std::string currentdir = Poco::Path::current();
|
std::string currentdir = Poco::Path::current();
|
||||||
|
|
||||||
savepath = processFilename(savepath, currentdir, 0);
|
savepath = processFilename(savepath, currentdir, 0);
|
||||||
if (isDebug()>=1)
|
if (isDebug() >= 1)
|
||||||
{
|
{
|
||||||
savepath+="1"; // append this to the end to help with testing against other assemblers
|
savepath += "1"; // append this to the end to help with testing against other assemblers
|
||||||
}
|
}
|
||||||
printf("saving to file: %s\n", savepath.c_str());
|
printf("saving to file: %s\n", savepath.c_str());
|
||||||
|
|
||||||
@@ -1664,7 +1724,7 @@ void CLASS::process(void)
|
|||||||
line.eval_result = 0;
|
line.eval_result = 0;
|
||||||
line.lineno = lineno + 1;
|
line.lineno = lineno + 1;
|
||||||
line.truncdata = truncdata;
|
line.truncdata = truncdata;
|
||||||
memcpy(line.tabs,tabs,sizeof(tabs));
|
memcpy(line.tabs, tabs, sizeof(tabs));
|
||||||
//printf("lineno: %d %d |%s|\n",lineno,l,line.operand.c_str());
|
//printf("lineno: %d %d |%s|\n",lineno,l,line.operand.c_str());
|
||||||
|
|
||||||
op = Poco::toLower(line.opcode);
|
op = Poco::toLower(line.opcode);
|
||||||
@@ -1688,13 +1748,22 @@ void CLASS::process(void)
|
|||||||
sym = addVariable(line.lable, ls, true);
|
sym = addVariable(line.lable, ls, true);
|
||||||
if (sym == NULL) { dupsym = true; }
|
if (sym == NULL) { dupsym = true; }
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ':':
|
case ':':
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
if (pass == 0)
|
if (pass == 0)
|
||||||
{
|
{
|
||||||
sym = addSymbol(line.lable, PC.currentpc, false);
|
sym = addSymbol(line.lable, PC.currentpc, false);
|
||||||
if (sym == NULL) { dupsym = true; }
|
if (sym == NULL)
|
||||||
|
{
|
||||||
|
dupsym = true;
|
||||||
|
line.setError(errDupSymbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (c != ':')
|
||||||
|
{
|
||||||
|
currentsym = findSymbol(line.lable);
|
||||||
|
currentsymstr=line.lable;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
1
asm.h
1
asm.h
@@ -347,6 +347,7 @@ public:
|
|||||||
|
|
||||||
std::string savepath;
|
std::string savepath;
|
||||||
TSymbol *currentsym;
|
TSymbol *currentsym;
|
||||||
|
std::string currentsymstr;
|
||||||
std::vector<MerlinLine> lines;
|
std::vector<MerlinLine> lines;
|
||||||
Poco::HashMap<std::string, TSymbol>opcodes;
|
Poco::HashMap<std::string, TSymbol>opcodes;
|
||||||
Poco::HashMap<std::string, TSymbol> macros;
|
Poco::HashMap<std::string, TSymbol> macros;
|
||||||
|
4
eval.cpp
4
eval.cpp
@@ -225,9 +225,9 @@ std::deque<Token> CLASS::shuntingYard(const std::deque<Token>& tokens)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//printf("symbol find |%s|\n",token.str.c_str());
|
|
||||||
|
|
||||||
sym = assembler.findSymbol(token.str);
|
sym = assembler.findSymbol(token.str);
|
||||||
|
//printf("symbol find |%s| %p\n",token.str.c_str(),sym);
|
||||||
|
|
||||||
if (sym != NULL)
|
if (sym != NULL)
|
||||||
{
|
{
|
||||||
sym->used = true;
|
sym->used = true;
|
||||||
|
Reference in New Issue
Block a user