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 *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);
} }
@@ -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;
@@ -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
View File

@@ -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;

View File

@@ -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;