This commit is contained in:
marketideas
2019-11-17 08:02:55 -08:00
parent 9009f5a222
commit 18c6987d34
3 changed files with 113 additions and 43 deletions

105
asm.cpp
View File

@ -945,21 +945,8 @@ TSymbol *CLASS::addSymbol(std::string sym, uint32_t val, bool replace)
TSymbol *res = NULL;
TSymbol *fnd = NULL;
fnd = findSymbol(sym);
if ((fnd != NULL) && (!replace))
if (sym.length() > 0)
{
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;
s.name = sym;
s.opcode = 0;
@ -969,8 +956,58 @@ TSymbol *CLASS::addSymbol(std::string sym, uint32_t val, bool replace)
s.used = false;
s.cb = NULL;
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);
res = findSymbol(sym);
}
}
out:
return (res);
}
@ -978,15 +1015,37 @@ TSymbol *CLASS::findSymbol(std::string symname)
{
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());
auto itr = symbols.find(Poco::toUpper(symname));
if (itr != symbols.end())
{
//printf("Found: %s 0x%08X\n",itr->second.name.c_str(),itr->second.value);
res = &itr->second;
return (res);
goto out;
}
}
}
out:
return (res);
}
@ -1321,6 +1380,7 @@ void CLASS::initpass(void)
}
relocatable = false;
currentsym = NULL;
currentsymstr="";
lineno = 0;
errorct = 0;
passcomplete = false;
@ -1688,13 +1748,22 @@ void CLASS::process(void)
sym = addVariable(line.lable, ls, true);
if (sym == NULL) { dupsym = true; }
break;
case ':':
break;
default:
if (pass == 0)
{
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;
}

1
asm.h
View File

@ -347,6 +347,7 @@ public:
std::string savepath;
TSymbol *currentsym;
std::string currentsymstr;
std::vector<MerlinLine> lines;
Poco::HashMap<std::string, TSymbol>opcodes;
Poco::HashMap<std::string, TSymbol> macros;

View File

@ -225,9 +225,9 @@ std::deque<Token> CLASS::shuntingYard(const std::deque<Token>& tokens)
}
else
{
//printf("symbol find |%s|\n",token.str.c_str());
sym = assembler.findSymbol(token.str);
//printf("symbol find |%s| %p\n",token.str.c_str(),sym);
if (sym != NULL)
{
sym->used = true;