2004-08-06 08:46:59 +00:00
|
|
|
/* AMX Assembler
|
|
|
|
* Copyright (C)2004 David "BAILOPAN" Anderson
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event will the authors be held liable for any damages
|
|
|
|
* arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
|
|
* including commercial applications, and to alter it and redistribute it
|
|
|
|
* freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
* claim that you wrote the original software. If you use this software
|
|
|
|
* in a product, an acknowledgment in the product documentation would be
|
|
|
|
* appreciated but is not required.
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
* misrepresented as being the original software.
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "amxasm.h"
|
|
|
|
|
|
|
|
Compiler::Compiler()
|
|
|
|
{
|
|
|
|
curLine = -1;
|
|
|
|
cellsize = 4;
|
2004-08-08 10:15:08 +00:00
|
|
|
Output = 0;
|
|
|
|
stacksize = cellsize * 4096;
|
2004-08-09 05:23:32 +00:00
|
|
|
debug = false;
|
2004-08-11 14:31:26 +00:00
|
|
|
pack = false;
|
|
|
|
dopt = false;
|
2004-08-07 17:07:50 +00:00
|
|
|
Init();
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Compiler::~Compiler()
|
|
|
|
{
|
2004-08-08 10:15:08 +00:00
|
|
|
Clear();
|
2004-08-06 08:46:59 +00:00
|
|
|
delete CDefines;
|
|
|
|
delete CError;
|
|
|
|
delete CLabels;
|
|
|
|
delete CMacros;
|
|
|
|
delete CNatives;
|
|
|
|
delete CSymbols;
|
|
|
|
delete PROC;
|
|
|
|
delete DAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
Compiler::Compiler(std::string &f)
|
|
|
|
{
|
|
|
|
curLine = -1;
|
|
|
|
cellsize = 4;
|
2004-08-08 10:15:08 +00:00
|
|
|
Output = 0;
|
|
|
|
filename.assign(f);
|
|
|
|
stacksize = cellsize * 4096;
|
2004-08-09 05:23:32 +00:00
|
|
|
debug = false;
|
2004-08-11 14:31:26 +00:00
|
|
|
pack = false;
|
|
|
|
dopt = false;
|
2004-08-08 10:15:08 +00:00
|
|
|
Init();
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
|
2004-08-11 14:31:26 +00:00
|
|
|
bool Compiler::SetDOpt()
|
|
|
|
{
|
|
|
|
bool state = dopt;
|
|
|
|
|
|
|
|
dopt = dopt ? false : true;
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2004-08-09 05:23:32 +00:00
|
|
|
bool Compiler::SetDebug()
|
|
|
|
{
|
|
|
|
bool state = debug;
|
|
|
|
|
|
|
|
debug = debug ? false : true;
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2004-08-11 14:31:26 +00:00
|
|
|
bool Compiler::SetPack()
|
|
|
|
{
|
|
|
|
bool state = pack;
|
|
|
|
|
|
|
|
pack = pack ? false : true;
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2004-08-06 08:46:59 +00:00
|
|
|
void Compiler::Load(std::string &f)
|
|
|
|
{
|
|
|
|
filename.assign(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compiler::Init()
|
|
|
|
{
|
|
|
|
Compiler *c = this;
|
|
|
|
/* Load error handling */
|
|
|
|
CError = new ErrorMngr(c);
|
|
|
|
/* Load symbol management */
|
|
|
|
CSymbols = new SymbolList;
|
|
|
|
/* Load constant management */
|
|
|
|
CDefines = new DefineMngr;
|
|
|
|
/* Load macro management */
|
|
|
|
CMacros = new MacroList(this);
|
|
|
|
/* Load DAT management */
|
|
|
|
DAT = new DataMngr(cellsize);
|
|
|
|
/* Load Proc management */
|
2004-08-12 16:31:50 +00:00
|
|
|
PROC = new ProcMngr(CError);
|
2004-08-06 08:46:59 +00:00
|
|
|
/* Load Label management */
|
2004-08-09 08:43:27 +00:00
|
|
|
CLabels = new LabelMngr(CError);
|
2004-08-06 08:46:59 +00:00
|
|
|
/* Load Native management */
|
|
|
|
CNatives = new NativeMngr;
|
|
|
|
/* Load the default symbols + opcodes */
|
|
|
|
InitOpcodes();
|
|
|
|
}
|
|
|
|
|
2004-08-08 10:15:08 +00:00
|
|
|
int Compiler::CipCount()
|
|
|
|
{
|
|
|
|
std::vector<Asm *>::iterator i;
|
|
|
|
std::vector<int>::iterator j;
|
|
|
|
int cipc = 0;
|
|
|
|
|
|
|
|
for (i=CodeList.begin(); i!=CodeList.end(); i++)
|
|
|
|
{
|
|
|
|
cipc+=cellsize;
|
|
|
|
for (j=(*i)->params.begin(); j!=(*i)->params.end(); j++)
|
|
|
|
{
|
|
|
|
cipc+=cellsize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cipc;
|
|
|
|
}
|
|
|
|
|
2004-08-11 14:31:26 +00:00
|
|
|
void Compiler::WriteCell(FILE *fp, ucell *c, int repeat)
|
|
|
|
{
|
|
|
|
unsigned char T[5] = {0,0,0,0,0};
|
|
|
|
unsigned char code = 0;
|
|
|
|
int index = 0;
|
|
|
|
ucell p = (*c);
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (i=1; i<=repeat; i++)
|
|
|
|
{
|
|
|
|
if (pack)
|
|
|
|
{
|
|
|
|
for (index=0;index<5;index++)
|
|
|
|
{
|
|
|
|
T[index]=(unsigned char)(p & 0x7f);
|
|
|
|
p>>=7;
|
|
|
|
}
|
|
|
|
while (index>1 && T[index-1]==0 && (T[index-2] & 0x40)==0)
|
|
|
|
{
|
|
|
|
index--;
|
|
|
|
}
|
|
|
|
if (index==5 && T[index-1]==0x0f && (T[index-2] & 0x40)!=0)
|
|
|
|
{
|
|
|
|
index--;
|
|
|
|
}
|
|
|
|
while (index>1 && T[index-1]==0x7f && (T[index-2] & 0x40)!=0)
|
|
|
|
{
|
|
|
|
index--;
|
|
|
|
}
|
|
|
|
assert(index>0);
|
|
|
|
while (index-->0)
|
|
|
|
{
|
|
|
|
code=(unsigned char)((index==0)?T[index]:(T[index]|0x80));
|
|
|
|
fwrite((void*)&code, sizeof(unsigned char), 1, fp);
|
|
|
|
bitsOut += sizeof(unsigned char);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fwrite((void*)c, sizeof(ucell), 1, fp);
|
|
|
|
bitsOut += sizeof(ucell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-11 09:32:24 +00:00
|
|
|
bool Compiler::Compile(std::string &out)
|
2004-08-08 10:15:08 +00:00
|
|
|
{
|
|
|
|
if (CodeList.size() < 1 || !CError || CError->GetStatus() >= Err_Error)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-08-11 14:31:26 +00:00
|
|
|
bitsOut = 0;
|
2004-08-08 10:15:08 +00:00
|
|
|
int32_t fileSize = 0;
|
2004-08-09 05:23:32 +00:00
|
|
|
int16_t magic = (int16_t)AMX_MAGIC;
|
2004-08-08 10:15:08 +00:00
|
|
|
char file_version = CUR_FILE_VERSION;
|
|
|
|
char amx_version = MIN_AMX_VERSION;
|
|
|
|
int16_t flags = 0;
|
|
|
|
int16_t defsize = 8;
|
|
|
|
int32_t cod, dat, hea, stp, cip, publics, natives, libraries;
|
|
|
|
int32_t pubvars, tags, names;
|
|
|
|
int hdrEnd = sizeof(AMX_HEADER);
|
2004-08-11 14:31:26 +00:00
|
|
|
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
flags |= AMX_FLAG_DEBUG;
|
|
|
|
}
|
|
|
|
if (pack)
|
|
|
|
{
|
|
|
|
flags |= AMX_FLAG_COMPACT;
|
|
|
|
}
|
2004-08-08 10:15:08 +00:00
|
|
|
|
|
|
|
std::vector<ProcMngr::AsmProc *> ProcList;
|
|
|
|
std::vector<ProcMngr::AsmProc *>::iterator pl;
|
|
|
|
std::vector<NativeMngr::Native *> NativeList;
|
|
|
|
std::vector<NativeMngr::Native *>::iterator nl;
|
|
|
|
std::map<int,int> NameMap;
|
|
|
|
|
|
|
|
/* Tables */
|
|
|
|
std::vector<NameRecord> Nametbl;
|
|
|
|
std::vector<AddrTable> PublicsTable;
|
|
|
|
std::vector<AddrTable> NativesTable;
|
|
|
|
std::vector<AddrTable>::iterator ai;
|
|
|
|
std::vector<NameRecord>::iterator nt;
|
|
|
|
|
|
|
|
PROC->GetPublics(ProcList);
|
|
|
|
CNatives->GetNatives(NativeList);
|
|
|
|
|
|
|
|
/* The only way I see to do this is to build the nametable first.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Public table starts right after the header */
|
|
|
|
publics = hdrEnd;
|
|
|
|
for (pl = ProcList.begin(); pl != ProcList.end(); pl++)
|
|
|
|
{
|
|
|
|
NameRecord n;
|
|
|
|
AddrTable a;
|
|
|
|
n.Name = (*pl)->Symbol->sym.c_str();
|
|
|
|
a.addr = (*pl)->ASM->cip;
|
2004-08-09 05:23:32 +00:00
|
|
|
a.offset = (int)Nametbl.size();
|
2004-08-08 10:15:08 +00:00
|
|
|
Nametbl.push_back(n);
|
|
|
|
PublicsTable.push_back(a);
|
|
|
|
}
|
|
|
|
|
2004-08-09 05:23:32 +00:00
|
|
|
natives = publics + (int)(PublicsTable.size() * (sizeof(int32_t) * 2));
|
2004-08-08 10:15:08 +00:00
|
|
|
for (nl = NativeList.begin(); nl != NativeList.end(); nl++)
|
|
|
|
{
|
|
|
|
NameRecord n;
|
|
|
|
AddrTable a;
|
|
|
|
n.Name = (*nl)->S->sym.c_str();
|
|
|
|
a.addr = 0;
|
2004-08-09 05:23:32 +00:00
|
|
|
a.offset = (int)Nametbl.size();
|
2004-08-08 10:15:08 +00:00
|
|
|
Nametbl.push_back(n);
|
|
|
|
NativesTable.push_back(a);
|
|
|
|
}
|
|
|
|
|
2004-08-09 05:23:32 +00:00
|
|
|
libraries = natives + (int)(NativesTable.size() * (sizeof(int32_t) * 2));
|
2004-08-08 10:15:08 +00:00
|
|
|
pubvars = libraries;
|
|
|
|
tags = pubvars;
|
|
|
|
names = tags;
|
|
|
|
|
|
|
|
/* Fill out the tables */
|
|
|
|
int cOffset = names + sizeof(int16_t);
|
|
|
|
int16_t nameHdr = 0x1F;
|
|
|
|
for (ai = PublicsTable.begin(); ai != PublicsTable.end(); ai++)
|
|
|
|
{
|
|
|
|
int off = (*ai).offset;
|
|
|
|
NameMap[cOffset] = off;
|
|
|
|
(*ai).offset = cOffset;
|
2004-08-09 05:23:32 +00:00
|
|
|
cOffset += (int)strlen(Nametbl.at(off).Name) + 1;
|
2004-08-08 10:15:08 +00:00
|
|
|
}
|
|
|
|
for (ai = NativesTable.begin(); ai != NativesTable.end(); ai++)
|
|
|
|
{
|
|
|
|
int off = (*ai).offset;
|
|
|
|
NameMap[cOffset] = off;
|
|
|
|
(*ai).offset = cOffset;
|
2004-08-09 05:23:32 +00:00
|
|
|
cOffset += (int)strlen(Nametbl.at(off).Name) + 1;
|
2004-08-08 10:15:08 +00:00
|
|
|
}
|
|
|
|
|
2004-08-11 14:31:26 +00:00
|
|
|
bitsOut = cOffset;
|
2004-08-08 10:15:08 +00:00
|
|
|
cod = cOffset;
|
|
|
|
dat = cod + CipCount();
|
|
|
|
hea = dat + DAT->GetSize();
|
|
|
|
stp = hea + stacksize;
|
|
|
|
cip = -1;
|
|
|
|
fileSize = hea;
|
|
|
|
|
|
|
|
std::string amxname;
|
2004-08-11 09:32:24 +00:00
|
|
|
amxname.assign(out);
|
2004-08-11 10:01:56 +00:00
|
|
|
size_t pos = amxname.find(".asm");
|
2004-08-08 10:15:08 +00:00
|
|
|
if (pos != std::string::npos)
|
|
|
|
{
|
|
|
|
amxname.replace(pos, 4, ".amx");
|
|
|
|
} else {
|
|
|
|
amxname.append(".amx");
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE *fp = fopen(amxname.c_str(), "wb");
|
|
|
|
|
|
|
|
fwrite((void*)&fileSize, sizeof(int32_t), 1, fp);
|
|
|
|
fwrite((void*)&magic, sizeof(int16_t), 1, fp);
|
|
|
|
fwrite((void*)&file_version, sizeof(char), 1, fp);
|
|
|
|
fwrite((void*)&amx_version, sizeof(char), 1, fp);
|
|
|
|
fwrite((void*)&flags, sizeof(int16_t), 1, fp);
|
|
|
|
fwrite((void*)&defsize, sizeof(int16_t), 1, fp);
|
|
|
|
|
|
|
|
fwrite((void*)&cod, sizeof(int32_t), 1, fp);
|
|
|
|
fwrite((void*)&dat, sizeof(int32_t), 1, fp);
|
|
|
|
fwrite((void*)&hea, sizeof(int32_t), 1, fp);
|
|
|
|
fwrite((void*)&stp, sizeof(int32_t), 1, fp);
|
|
|
|
fwrite((void*)&cip, sizeof(int32_t), 1, fp);
|
|
|
|
fwrite((void*)&publics, sizeof(int32_t), 1, fp);
|
|
|
|
fwrite((void*)&natives, sizeof(int32_t), 1, fp);
|
|
|
|
fwrite((void*)&libraries, sizeof(int32_t), 1, fp);
|
|
|
|
fwrite((void*)&pubvars, sizeof(int32_t), 1, fp);
|
|
|
|
fwrite((void*)&tags, sizeof(int32_t), 1, fp);
|
|
|
|
fwrite((void*)&names, sizeof(int32_t), 1, fp);
|
|
|
|
|
|
|
|
for (ai = PublicsTable.begin(); ai != PublicsTable.end(); ai++)
|
|
|
|
{
|
|
|
|
fwrite((void*)&((*ai).addr), sizeof(int32_t), 1, fp);
|
|
|
|
fwrite((void*)&((*ai).offset), sizeof(int32_t), 1, fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ai = NativesTable.begin(); ai != NativesTable.end(); ai++)
|
|
|
|
{
|
|
|
|
fwrite((void*)&((*ai).addr), sizeof(int32_t), 1, fp);
|
|
|
|
fwrite((void*)&((*ai).offset), sizeof(int32_t), 1, fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
fwrite((void*)&(nameHdr), sizeof(int16_t), 1, fp);
|
|
|
|
|
|
|
|
for (ai = PublicsTable.begin(); ai != PublicsTable.end(); ai++)
|
|
|
|
{
|
|
|
|
int off = (*ai).offset;
|
|
|
|
int offs = NameMap[off];
|
|
|
|
const char *s = Nametbl.at(offs).Name;
|
|
|
|
fwrite(s, sizeof(char), strlen(s)+1, fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ai = NativesTable.begin(); ai != NativesTable.end(); ai++)
|
|
|
|
{
|
|
|
|
int off = (*ai).offset;
|
|
|
|
int offs = NameMap[off];
|
|
|
|
const char *s = Nametbl.at(offs).Name;
|
|
|
|
fwrite(s, sizeof(char), strlen(s)+1, fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the code */
|
|
|
|
|
|
|
|
std::vector<Asm *>::iterator ci;
|
|
|
|
std::vector<int>::iterator di;
|
2004-08-11 14:31:26 +00:00
|
|
|
ucell cop = 0;
|
2004-08-08 10:15:08 +00:00
|
|
|
for (ci = CodeList.begin(); ci != CodeList.end(); ci++)
|
|
|
|
{
|
|
|
|
cop = (*ci)->op;
|
2004-08-11 14:31:26 +00:00
|
|
|
WriteCell(fp, &cop, 1);
|
2004-08-08 10:15:08 +00:00
|
|
|
for (di = (*ci)->params.begin(); di != (*ci)->params.end(); di++)
|
|
|
|
{
|
|
|
|
cop = (*di);
|
2004-08-11 14:31:26 +00:00
|
|
|
WriteCell(fp, &cop, 1);
|
2004-08-08 10:15:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<DataMngr::Datum *> dm;
|
|
|
|
std::vector<DataMngr::Datum *>::iterator dmi;
|
|
|
|
DAT->GetData(dm);
|
|
|
|
|
2004-08-11 14:31:26 +00:00
|
|
|
ucell val = 0;
|
2004-08-08 10:15:08 +00:00
|
|
|
const char *s = 0;
|
|
|
|
for (dmi = dm.begin(); dmi != dm.end(); dmi++)
|
|
|
|
{
|
2004-08-09 05:23:32 +00:00
|
|
|
if ( (*dmi)->db )
|
2004-08-08 10:15:08 +00:00
|
|
|
{
|
2004-08-09 05:23:32 +00:00
|
|
|
if ( (*dmi)->e.GetType() == Val_Number )
|
|
|
|
{
|
|
|
|
val = (*dmi)->e.GetNumber();
|
|
|
|
fwrite((void *)&val, sizeof(int32_t), 1, fp);
|
|
|
|
} else {
|
|
|
|
s = (*dmi)->e.GetString();
|
|
|
|
for (int q = 0; q < (*dmi)->e.Size(); q++)
|
|
|
|
{
|
|
|
|
val = s[q];
|
2004-08-11 14:31:26 +00:00
|
|
|
WriteCell(fp, &val, 1);
|
2004-08-09 05:23:32 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-08 10:15:08 +00:00
|
|
|
} else {
|
2004-08-11 14:31:26 +00:00
|
|
|
if (DAT->IsOptimized())
|
|
|
|
break;
|
|
|
|
ucell c = (*dmi)->fill;
|
|
|
|
WriteCell(fp, &c, (*dmi)->e.GetNumber());
|
2004-08-08 10:15:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-11 14:31:26 +00:00
|
|
|
/* Was packing enabled? Re-output the actual size */
|
|
|
|
if (pack)
|
|
|
|
{
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
fwrite((void *)&bitsOut, sizeof(int32_t), 1, fp);
|
|
|
|
fseek(fp, 0, SEEK_END);
|
|
|
|
}
|
|
|
|
|
2004-08-08 10:15:08 +00:00
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compiler::Clear()
|
|
|
|
{
|
|
|
|
DAT->Clear();
|
|
|
|
CDefines->Clear();
|
|
|
|
CMacros->Clear();
|
|
|
|
CLabels->Clear();
|
|
|
|
CNatives->Clear();
|
|
|
|
PROC->Clear();
|
|
|
|
CSymbols->Clear();
|
|
|
|
}
|
|
|
|
|
2004-08-11 14:31:26 +00:00
|
|
|
/* Two pass parser.
|
|
|
|
* The first pass applies macros + defines + directives
|
|
|
|
* natives, and data.
|
|
|
|
* The second pass eats up everything else (code, publics)
|
|
|
|
*/
|
2004-08-06 08:46:59 +00:00
|
|
|
bool Compiler::Parse()
|
|
|
|
{
|
2004-08-11 14:31:26 +00:00
|
|
|
FILE *fp = 0;
|
2004-08-06 08:46:59 +00:00
|
|
|
char buffer[256] = {0};
|
2004-08-09 05:23:32 +00:00
|
|
|
std::stack<int> DefStack;
|
2004-08-06 08:46:59 +00:00
|
|
|
curLine = 0;
|
|
|
|
AsmSection sec = Asm_None;
|
2004-08-08 10:15:08 +00:00
|
|
|
lastCip = 0-cellsize;
|
2004-08-11 14:31:26 +00:00
|
|
|
int pass = 0;
|
|
|
|
Start:
|
|
|
|
fp = fopen(filename.c_str(), "rt");
|
|
|
|
curLine = 0;
|
|
|
|
sec = Asm_None;
|
|
|
|
lastCip = 0-cellsize;
|
|
|
|
|
|
|
|
if (!fp)
|
2004-08-06 08:46:59 +00:00
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_FileOpen, filename.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-08-11 14:31:26 +00:00
|
|
|
while (!feof(fp))
|
2004-08-06 08:46:59 +00:00
|
|
|
{
|
2004-08-11 14:31:26 +00:00
|
|
|
fgets(buffer, 255, fp);
|
2004-08-11 08:14:54 +00:00
|
|
|
curLine+=1;
|
2004-08-09 05:23:32 +00:00
|
|
|
|
2004-08-06 08:46:59 +00:00
|
|
|
/* Check for preprocessor directives */
|
|
|
|
if (buffer[0] == '#')
|
|
|
|
{
|
|
|
|
std::string procline(buffer);
|
2004-08-11 14:31:26 +00:00
|
|
|
if (procline.substr(0, 6).compare("#ifdef") == 0)
|
2004-08-09 05:23:32 +00:00
|
|
|
{
|
|
|
|
std::string def;
|
|
|
|
std::string temp;
|
|
|
|
std::string comp;
|
|
|
|
StringBreak(procline, def, temp);
|
|
|
|
StringBreak(temp, def, comp);
|
|
|
|
DefineMngr::Define *D = 0;
|
2004-08-11 14:31:26 +00:00
|
|
|
if ( (D = CDefines->FindDefine(def)) == NULL)
|
2004-08-09 05:23:32 +00:00
|
|
|
{
|
|
|
|
DefStack.push(0);
|
2004-08-11 14:31:26 +00:00
|
|
|
} else {
|
|
|
|
if (D->GetDefine()->compare("0") == 0)
|
|
|
|
{
|
|
|
|
DefStack.push(0);
|
|
|
|
} else {
|
|
|
|
DefStack.push(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (procline.substr(0, 7).compare("#ifndef") == 0) {
|
|
|
|
std::string def;
|
|
|
|
std::string temp;
|
|
|
|
std::string comp;
|
|
|
|
StringBreak(procline, def, temp);
|
|
|
|
StringBreak(temp, def, comp);
|
|
|
|
DefineMngr::Define *D = 0;
|
|
|
|
if ( (D = CDefines->FindDefine(def)) == NULL)
|
|
|
|
{
|
2004-08-09 05:23:32 +00:00
|
|
|
DefStack.push(1);
|
|
|
|
} else {
|
2004-08-11 14:31:26 +00:00
|
|
|
if (D->GetDefine()->compare("0") == 0)
|
|
|
|
{
|
|
|
|
DefStack.push(1);
|
|
|
|
} else {
|
|
|
|
DefStack.push(0);
|
|
|
|
}
|
2004-08-09 05:23:32 +00:00
|
|
|
}
|
|
|
|
} else if (procline.substr(0, 5).compare("#else") == 0) {
|
2004-08-11 14:31:26 +00:00
|
|
|
if (!DefStack.empty())
|
2004-08-09 05:23:32 +00:00
|
|
|
{
|
|
|
|
if (DefStack.top() == 1)
|
|
|
|
{
|
|
|
|
DefStack.pop();
|
|
|
|
DefStack.push(0);
|
|
|
|
} else if (DefStack.top() == 0) {
|
|
|
|
DefStack.pop();
|
|
|
|
DefStack.push(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CError->ErrorMsg(Err_Misplaced_Directive);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
} else if (procline.substr(0, 6).compare("#endif") == 0) {
|
2004-08-11 14:31:26 +00:00
|
|
|
if (!DefStack.empty())
|
2004-08-09 05:23:32 +00:00
|
|
|
{
|
|
|
|
DefStack.pop();
|
|
|
|
} else {
|
|
|
|
CError->ErrorMsg(Err_Misplaced_Directive);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
/* Check for previous operations */
|
|
|
|
if (DefStack.size())
|
|
|
|
{
|
|
|
|
if (DefStack.top() < 1)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2004-08-11 14:31:26 +00:00
|
|
|
// only process directives on pass one
|
|
|
|
if (pass == 0)
|
|
|
|
{
|
|
|
|
ProcessDirective(procline);
|
|
|
|
}
|
2004-08-09 05:23:32 +00:00
|
|
|
}
|
2004-08-06 08:46:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-08-09 05:23:32 +00:00
|
|
|
/* Check for previous operations */
|
|
|
|
if (DefStack.size())
|
|
|
|
{
|
|
|
|
if (DefStack.top() < 1)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-06 08:46:59 +00:00
|
|
|
/* Strip the line */
|
|
|
|
std::string line(buffer);
|
2004-08-09 10:07:33 +00:00
|
|
|
|
2004-08-06 08:46:59 +00:00
|
|
|
StripComments(line);
|
|
|
|
Strip(line);
|
2004-08-09 10:07:33 +00:00
|
|
|
|
2004-08-06 08:46:59 +00:00
|
|
|
if (line.size() < 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Check for section state changes */
|
|
|
|
if (line[0] == '.')
|
|
|
|
{
|
|
|
|
if (line.compare(".DATA") == 0)
|
|
|
|
{
|
|
|
|
sec = Asm_Data;
|
2004-08-11 14:31:26 +00:00
|
|
|
} else if (line.compare(".CODE") == 0) {;
|
2004-08-06 08:46:59 +00:00
|
|
|
sec = Asm_Code;
|
|
|
|
} else if (line.compare(".PUBLIC") == 0) {
|
|
|
|
sec = Asm_Public;
|
|
|
|
} else if (line.compare(".NATIVE") == 0) {
|
|
|
|
sec = Asm_Native;
|
|
|
|
} else {
|
|
|
|
sec = Asm_Invalid;
|
|
|
|
CError->ErrorMsg(Err_Invalid_Section, buffer);
|
|
|
|
}
|
2004-08-11 14:31:26 +00:00
|
|
|
if (pass == 1)
|
2004-08-11 08:14:54 +00:00
|
|
|
{
|
2004-08-11 14:31:26 +00:00
|
|
|
/* Update the labels */
|
|
|
|
CLabels->CompleteQueue(true);
|
|
|
|
while (!LabelStack.empty())
|
|
|
|
{
|
|
|
|
CLabels->EraseLabel(LabelStack.top());
|
|
|
|
CSymbols->EraseSymbol(LabelStack.top());
|
|
|
|
LabelStack.pop();
|
|
|
|
}
|
2004-08-11 08:14:54 +00:00
|
|
|
}
|
2004-08-06 08:46:59 +00:00
|
|
|
} else {
|
|
|
|
/* Do pre-processing */
|
|
|
|
CMacros->SearchAndReplace(line);
|
|
|
|
CDefines->SearchAndReplace(line);
|
|
|
|
|
|
|
|
/* See if we're not in a section */
|
|
|
|
if (sec == Asm_None)
|
|
|
|
{
|
|
|
|
if (line.size() > 0)
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Wandering_Stuff);
|
|
|
|
}
|
|
|
|
} else if (sec == Asm_Invalid) {
|
|
|
|
/* Just ignore it */
|
|
|
|
} else if (sec == Asm_Data) {
|
2004-08-11 14:31:26 +00:00
|
|
|
if (pass == 1)
|
|
|
|
continue;
|
2004-08-06 08:46:59 +00:00
|
|
|
/* Format is Symbol, [db|stat], Data */
|
|
|
|
std::string symbol;
|
|
|
|
std::string data;
|
|
|
|
std::string buf;
|
|
|
|
std::string fmt;
|
|
|
|
|
|
|
|
/* Do two splits - line into symbol into data */
|
|
|
|
StringBreak(line, symbol, buf);
|
|
|
|
StringBreak(buf, fmt, data);
|
|
|
|
|
|
|
|
/* Check if the symbol is already defined */
|
|
|
|
SymbolList::Symbol *S = NULL;
|
|
|
|
if ((S = CSymbols->FindSymbol(symbol)) != NULL)
|
|
|
|
{
|
2004-08-08 10:15:08 +00:00
|
|
|
CError->ErrorMsg(Err_Symbol_Reuse, symbol.c_str(), S->line);
|
2004-08-06 08:46:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fmt.compare("db") && fmt.compare("stat"))
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Invalid_Stor, fmt.c_str());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-08-09 05:23:32 +00:00
|
|
|
if (fmt.compare("db") == 0)
|
|
|
|
{
|
|
|
|
/* Add and evaluate the expression */
|
|
|
|
CExpr e(CError);
|
|
|
|
e.Set(data);
|
|
|
|
e.Evaluate();
|
|
|
|
|
|
|
|
/* Add into the DAT section */
|
|
|
|
DAT->Add(symbol, e, true);
|
|
|
|
} else if (fmt.compare("stat") == 0) {
|
|
|
|
CExpr e(CError);
|
|
|
|
|
|
|
|
if (data.find("fill") != std::string::npos)
|
|
|
|
{
|
|
|
|
std::string fill, amt;
|
|
|
|
StringBreak(data, amt, buf);
|
|
|
|
StringBreak(buf, data, fill);
|
|
|
|
CExpr t(CError);
|
|
|
|
t.Set(fill);
|
|
|
|
t.Evaluate();
|
2004-08-11 14:31:26 +00:00
|
|
|
e = EvalE(amt, Sym_None);
|
2004-08-11 08:14:54 +00:00
|
|
|
DAT->Add(symbol, e, false, t.GetNumber());
|
2004-08-09 05:23:32 +00:00
|
|
|
} else {
|
2004-08-11 14:31:26 +00:00
|
|
|
e = EvalE(data, Sym_None);
|
2004-08-09 05:23:32 +00:00
|
|
|
DAT->Add(symbol, e, false, 0);
|
|
|
|
}
|
|
|
|
}
|
2004-08-08 10:15:08 +00:00
|
|
|
CSymbols->AddSymbol(symbol, Sym_Dat, CurLine());
|
2004-08-06 08:46:59 +00:00
|
|
|
} else if (sec == Asm_Public) {
|
2004-08-11 14:31:26 +00:00
|
|
|
if (pass == 0)
|
|
|
|
continue;
|
2004-08-06 08:46:59 +00:00
|
|
|
if (!IsValidSymbol(line))
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Invalid_Symbol);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SymbolList::Symbol *S = NULL;
|
|
|
|
if ( (S = CSymbols->FindSymbol(line)) == NULL)
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Unknown_Symbol, line.c_str());
|
|
|
|
continue;
|
|
|
|
}
|
2004-08-08 10:15:08 +00:00
|
|
|
if ( (S->type != Sym_Proc) )
|
2004-08-06 08:46:59 +00:00
|
|
|
{
|
2004-08-08 10:15:08 +00:00
|
|
|
CError->ErrorMsg(Err_Symbol_Type, Sym_Proc, S->type);
|
2004-08-06 08:46:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!PROC->SetPublic(line))
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Unknown_Symbol, line.c_str());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if (sec == Asm_Native) {
|
2004-08-11 14:31:26 +00:00
|
|
|
if (pass == 1)
|
|
|
|
continue;
|
2004-08-06 08:46:59 +00:00
|
|
|
if (!IsValidSymbol(line))
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Invalid_Symbol);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SymbolList::Symbol *S = NULL;
|
|
|
|
if ( (S = CSymbols->FindSymbol(line)) != NULL)
|
|
|
|
{
|
2004-08-08 10:15:08 +00:00
|
|
|
CError->ErrorMsg(Err_Invalid_Symbol, line.c_str(), S->line);
|
2004-08-06 08:46:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-08-08 10:15:08 +00:00
|
|
|
S = CSymbols->AddSymbol(line, Sym_Native, CurLine());
|
2004-08-06 08:46:59 +00:00
|
|
|
CNatives->AddNative(S);
|
|
|
|
} else if (sec == Asm_Code) {
|
2004-08-11 14:31:26 +00:00
|
|
|
if (pass == 0)
|
|
|
|
continue;
|
2004-08-06 08:46:59 +00:00
|
|
|
std::string code;
|
|
|
|
std::string params;
|
|
|
|
SymbolList::Symbol *S;
|
|
|
|
|
|
|
|
StringBreak(line, code, params);
|
|
|
|
|
|
|
|
if (code.compare("PROC") == 0 || code.compare("proc") == 0)
|
|
|
|
{
|
|
|
|
/* Check if symbol is valid */
|
|
|
|
if (!IsValidSymbol(params))
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Invalid_Symbol);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Check if the symbol is already used */
|
|
|
|
if ( (S = CSymbols->FindSymbol(params)) != NULL)
|
|
|
|
{
|
2004-08-12 16:31:50 +00:00
|
|
|
if (S->type != Sym_Proc)
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Symbol_Reuse, params.c_str(), S->line);
|
|
|
|
continue;
|
|
|
|
}
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
/* Create instruction */
|
|
|
|
Asm *ASM = new Asm;
|
2004-08-08 10:15:08 +00:00
|
|
|
ASM->cip = lastCip + cellsize;
|
2004-08-06 08:46:59 +00:00
|
|
|
ASM->op = OpCodes["proc"];
|
2004-08-11 08:14:54 +00:00
|
|
|
ASM->line = curLine;
|
2004-08-08 10:15:08 +00:00
|
|
|
lastCip += cellsize;
|
2004-08-12 16:31:50 +00:00
|
|
|
if (S == NULL)
|
|
|
|
{
|
|
|
|
/* Add symbol */
|
|
|
|
S = CSymbols->AddSymbol(params, Sym_Proc, CurLine());
|
|
|
|
/* Add to PROC list */
|
|
|
|
PROC->AddProc(S, ASM);
|
|
|
|
} else {
|
|
|
|
ProcMngr::AsmProc *p = 0;
|
|
|
|
p = PROC->FindProc(params);
|
|
|
|
|
|
|
|
if (p == NULL || p->ASM != NULL)
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Symbol_Reuse, params.c_str(), S->line);
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
p->ASM = ASM;
|
|
|
|
}
|
|
|
|
}
|
2004-08-06 08:46:59 +00:00
|
|
|
/* Add to code list */
|
|
|
|
CodeList.push_back(ASM);
|
|
|
|
} else if (code.compare("ENDP") == 0) {
|
2004-08-11 08:14:54 +00:00
|
|
|
/* This is, in theory, not needed
|
|
|
|
* Nonetheless, we check labels here
|
|
|
|
*/
|
|
|
|
CLabels->CompleteQueue(true);
|
|
|
|
while (!LabelStack.empty())
|
|
|
|
{
|
|
|
|
CLabels->EraseLabel(LabelStack.top());
|
|
|
|
CSymbols->EraseSymbol(LabelStack.top());
|
|
|
|
LabelStack.pop();
|
|
|
|
}
|
2004-08-06 08:46:59 +00:00
|
|
|
} else if (params.size() < 1 && code[code.size()-1] == ':') {
|
|
|
|
/* Label! */
|
|
|
|
/* Check if symbol is valid */
|
2004-08-09 08:43:27 +00:00
|
|
|
code.erase(code.size()-1, 1);
|
2004-08-06 08:46:59 +00:00
|
|
|
if (!IsValidSymbol(code))
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Invalid_Symbol);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Check if the symbol is already used */
|
|
|
|
if ( (S = CSymbols->FindSymbol(code)) != NULL)
|
|
|
|
{
|
2004-08-09 08:43:27 +00:00
|
|
|
if (S->type == Sym_Label)
|
|
|
|
{
|
|
|
|
LabelMngr::Label *p = CLabels->FindLabel(code);
|
|
|
|
if (p == NULL)
|
2004-08-12 16:31:50 +00:00
|
|
|
{
|
2004-08-09 08:43:27 +00:00
|
|
|
CError->ErrorMsg(Err_Invalid_Symbol);
|
2004-08-12 16:31:50 +00:00
|
|
|
} else {
|
2004-08-09 08:43:27 +00:00
|
|
|
p->cip = lastCip+cellsize;
|
2004-08-12 16:31:50 +00:00
|
|
|
p->sym->line = CurLine();
|
|
|
|
}
|
2004-08-09 08:43:27 +00:00
|
|
|
} else {
|
|
|
|
CError->ErrorMsg(Err_Symbol_Reuse, code.c_str(), S->line);
|
|
|
|
}
|
2004-08-06 08:46:59 +00:00
|
|
|
continue;
|
2004-08-12 16:31:50 +00:00
|
|
|
} else {
|
|
|
|
if (code[0] == '_')
|
|
|
|
{
|
|
|
|
LabelStack.push(code);
|
|
|
|
}
|
|
|
|
S = CSymbols->AddSymbol(code, Sym_Label, CurLine());
|
|
|
|
CLabels->AddLabel(S, lastCip+cellsize);
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Check if there is a valid opcode */
|
|
|
|
int op = OpCodes[code];
|
|
|
|
int argPos;
|
|
|
|
if (op == OP_NONE)
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Opcode);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-08-09 05:23:32 +00:00
|
|
|
Asm *ASM = 0;
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
ASM = new Asm;
|
|
|
|
ASM->cip = lastCip+cellsize;
|
|
|
|
ASM->op = OP_LINE;
|
2004-08-11 08:14:54 +00:00
|
|
|
ASM->line = curLine;
|
2004-08-09 05:23:32 +00:00
|
|
|
ASM->params.push_back(curLine);
|
|
|
|
ASM->params.push_back(0);
|
|
|
|
CodeList.push_back(ASM);
|
|
|
|
lastCip+=cellsize*3;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASM = new Asm;
|
|
|
|
|
2004-08-09 08:43:27 +00:00
|
|
|
curAsm = ASM;
|
|
|
|
|
2004-08-06 08:46:59 +00:00
|
|
|
std::vector<std::string *> paramList;
|
|
|
|
|
|
|
|
if (params.size() > 0)
|
|
|
|
{
|
|
|
|
FindArguments(params, paramList, argPos, true);
|
2004-08-11 10:01:56 +00:00
|
|
|
if (argPos != (int)(params.size()-1))
|
2004-08-06 08:46:59 +00:00
|
|
|
{
|
2004-08-12 16:31:50 +00:00
|
|
|
assert(0);
|
2004-08-06 08:46:59 +00:00
|
|
|
CError->ErrorMsg(Err_Unexpected_Char, params[argPos]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-08 10:15:08 +00:00
|
|
|
ASM->cip = (lastCip+cellsize);
|
2004-08-07 17:07:50 +00:00
|
|
|
ASM->op = op;
|
2004-08-11 08:14:54 +00:00
|
|
|
ASM->line = curLine;
|
2004-08-08 10:15:08 +00:00
|
|
|
lastCip += cellsize;
|
2004-08-07 17:07:50 +00:00
|
|
|
|
2004-08-06 08:46:59 +00:00
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case OP_LOAD_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LOAD_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LOAD_S_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LOAD_S_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LREF_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LREF_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LREF_S_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LREF_S_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LOAD_I:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LODB_I:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_CONST_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_CONST_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_ADDR_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_ADDR_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_STOR_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_STOR_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_STOR_S_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_STOR_S_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SREF_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SREF_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SREF_S_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SREF_S_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_STOR_I:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_STRB_I:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LIDX:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LIDX_B:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_IDXADDR:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_IDXADDR_B:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_ALIGN_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_ALIGN_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LCTRL:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SCTRL:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_MOVE_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_MOVE_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_XCHG:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_PUSH_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_PUSH_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_PUSH_R:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_PUSH_C:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_PUSH:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_PUSH_S:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_POP_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_POP_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_STACK:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_HEAP:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_PROC:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_RET:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_RETN:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_CALL:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Proc);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_CALL_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JUMP:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JREL:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JZER:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JNZ:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JEQ:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JNEQ:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JLESS:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JLEQ:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JGRTR:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JGEQ:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JSLESS:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JSLEQ:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JSGRTR:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JSGEQ:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SHL:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SHR:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SSHR:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SHL_C_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SHL_C_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SHR_C_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SHR_C_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SMUL:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SDIV:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SDIV_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_UMUL:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_UDIV:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_UDIV_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_ADD:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SUB:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SUB_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_AND:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_OR:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_XOR:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_NOT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_NEG:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_INVERT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_ADD_C:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SMUL_C:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_ZERO_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_ZERO_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_ZERO:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_ZERO_S:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SIGN_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SIGN_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_EQ:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_NEQ:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LESS:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LEQ:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_GRTR:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_GEQ:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SLESS:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SLEQ:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SGRTR:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SGEQ:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_EQ_C_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_EQ_C_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_INC_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_INC_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_INC:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_INC_S:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_INC_I:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_DEC_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_DEC_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_DEC:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_DEC_S:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_DEC_I:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_MOVS:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_CMPS:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_FILL:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_HALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_BOUNDS:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SYSREQ_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SYSREQ_C:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Native);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_FILE:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
/* Not yet implemented */
|
|
|
|
assert(0);
|
|
|
|
/*CHK_PARAMS(3);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);*/
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_LINE:
|
|
|
|
{
|
2004-08-09 05:23:32 +00:00
|
|
|
CHK_PARAMS(2);
|
2004-08-07 17:07:50 +00:00
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SYMBOL:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
/* Not yet implemented */
|
|
|
|
assert(0);
|
|
|
|
/*CHK_PARAMS(3);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);*/
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SRANGE:
|
|
|
|
{
|
2004-08-09 05:23:32 +00:00
|
|
|
CHK_PARAMS(2);
|
2004-08-07 17:07:50 +00:00
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_JUMP_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SWITCH:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
/* Not yet implemented */
|
|
|
|
assert(0);
|
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Label);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_CASETBL:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
/* Not yet implemented */
|
|
|
|
assert(0);
|
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Native);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SWAP_PRI:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SWAP_ALT:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_PUSHADDR:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_NOP:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(0);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SYSREQ_D:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
case OP_SYMTAG:
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
CHK_PARAMS(1);
|
|
|
|
PUSH_PARAM(1, Sym_Dat);
|
|
|
|
break;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
2004-08-07 17:07:50 +00:00
|
|
|
} /* Switch */
|
|
|
|
CodeList.push_back(ASM);
|
|
|
|
} /* Asm_Code */
|
|
|
|
} /* Section If */
|
2004-08-08 10:15:08 +00:00
|
|
|
} /* Line processing */
|
|
|
|
} /* While */
|
|
|
|
|
2004-08-11 14:31:26 +00:00
|
|
|
// go for second pass
|
|
|
|
if (pass == 0)
|
|
|
|
{
|
|
|
|
pass = 1;
|
|
|
|
fclose(fp);
|
|
|
|
if (dopt)
|
|
|
|
DAT->Optimize();
|
|
|
|
goto Start;
|
|
|
|
}
|
|
|
|
|
2004-08-09 08:43:27 +00:00
|
|
|
/* We're not done! Check the label Queue */
|
|
|
|
CLabels->CompleteQueue();
|
2004-08-12 16:31:50 +00:00
|
|
|
|
|
|
|
/* and the procedure queue ... */
|
|
|
|
PROC->CompleteQueue();
|
2004-08-09 08:43:27 +00:00
|
|
|
|
2004-08-08 10:15:08 +00:00
|
|
|
CError->PrintReport();
|
2004-08-11 14:31:26 +00:00
|
|
|
|
2004-08-11 09:06:00 +00:00
|
|
|
if (CError->GetStatus() >= Err_Error)
|
2004-08-11 14:31:26 +00:00
|
|
|
{
|
2004-08-11 09:06:00 +00:00
|
|
|
return false;
|
2004-08-11 14:31:26 +00:00
|
|
|
}
|
2004-08-06 08:46:59 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compiler::InitOpcodes()
|
|
|
|
{
|
|
|
|
OpCodes["nop"] = 0;
|
|
|
|
OpCodes["load.pri"] = 1;
|
|
|
|
OpCodes["load.alt"] = 2;
|
|
|
|
OpCodes["load.s.pri"] = 3;
|
|
|
|
OpCodes["load.s.alt"] = 4;
|
|
|
|
OpCodes["lref.pri"] = 5;
|
|
|
|
OpCodes["lref.alt"] = 6;
|
|
|
|
OpCodes["lref.s.pri"] = 7;
|
|
|
|
OpCodes["lref.s.alt"] = 8;
|
|
|
|
OpCodes["load.i"] = 9;
|
|
|
|
OpCodes["lodb.i"] = 10;
|
|
|
|
OpCodes["const.pri"] = 11;
|
|
|
|
OpCodes["const.alt"] = 12;
|
|
|
|
OpCodes["addr.pri"] = 13;
|
|
|
|
OpCodes["addr.alt"] = 14;
|
|
|
|
OpCodes["stor.pri"] = 15;
|
|
|
|
OpCodes["stor.alt"] = 16;
|
|
|
|
OpCodes["stor.s.pri"] = 17;
|
|
|
|
OpCodes["stor.s.alt"] = 18;
|
|
|
|
OpCodes["sref.pri"] = 19;
|
|
|
|
OpCodes["sref.alt"] = 20;
|
|
|
|
OpCodes["sref.s.pri"] = 21;
|
|
|
|
OpCodes["sref.s.alt"] = 22;
|
|
|
|
OpCodes["stor.i"] = 23;
|
|
|
|
OpCodes["strb.i"] = 24;
|
|
|
|
OpCodes["lidx"] = 25;
|
|
|
|
OpCodes["lidx.b"] = 26;
|
|
|
|
OpCodes["idxaddr"] = 27;
|
|
|
|
OpCodes["idxaddr.b"] = 28;
|
|
|
|
OpCodes["align.pri"] = 29;
|
|
|
|
OpCodes["align.alt"] = 30;
|
|
|
|
OpCodes["lctrl"] = 31;
|
|
|
|
OpCodes["sctrl"] = 32;
|
|
|
|
OpCodes["move.pri"] = 33;
|
|
|
|
OpCodes["move.alt"] = 34;
|
|
|
|
OpCodes["xchg"] = 35;
|
|
|
|
OpCodes["push.pri"] = 36;
|
|
|
|
OpCodes["push.alt"] = 37;
|
|
|
|
OpCodes["push.r"] = 38;
|
|
|
|
OpCodes["push.c"] = 39;
|
|
|
|
OpCodes["push"] = 40;
|
|
|
|
OpCodes["push.s"] = 41;
|
|
|
|
OpCodes["pop.pri"] = 42;
|
|
|
|
OpCodes["pop.alt"] = 43;
|
|
|
|
OpCodes["stack"] = 44;
|
|
|
|
OpCodes["heap"] = 45;
|
|
|
|
OpCodes["proc"] = 46;
|
|
|
|
OpCodes["ret"] = 47;
|
|
|
|
OpCodes["retn"] = 48;
|
|
|
|
OpCodes["call"] = 49;
|
|
|
|
OpCodes["call.pri"] = 50;
|
|
|
|
OpCodes["jump"] = 51;
|
|
|
|
OpCodes["jrel"] = 52;
|
|
|
|
OpCodes["jzer"] = 53;
|
|
|
|
OpCodes["jnz"] = 54;
|
|
|
|
OpCodes["jeq"] = 55;
|
|
|
|
OpCodes["jneq"] = 56;
|
|
|
|
OpCodes["jless"] = 57;
|
|
|
|
OpCodes["jleq"] = 58;
|
|
|
|
OpCodes["jgrtr"] = 59;
|
|
|
|
OpCodes["jgeq"] = 60;
|
|
|
|
OpCodes["jsless"] = 61;
|
|
|
|
OpCodes["jsleq"] = 62;
|
|
|
|
OpCodes["jsgrtr"] = 63;
|
|
|
|
OpCodes["jsgeq"] = 64;
|
|
|
|
OpCodes["shl"] = 65;
|
|
|
|
OpCodes["shr"] = 66;
|
|
|
|
OpCodes["sshr"] = 67;
|
|
|
|
OpCodes["shl.c.pri"] = 68;
|
|
|
|
OpCodes["shl.c.alt"] = 69;
|
|
|
|
OpCodes["shr.c.pri"] = 70;
|
|
|
|
OpCodes["shr.c.alt"] = 71;
|
|
|
|
OpCodes["smul"] = 72;
|
|
|
|
OpCodes["sdiv"] = 73;
|
|
|
|
OpCodes["sdiv.alt"] = 74;
|
|
|
|
OpCodes["umul"] = 75;
|
|
|
|
OpCodes["udiv"] = 76;
|
|
|
|
OpCodes["udiv.alt"] = 77;
|
|
|
|
OpCodes["add"] = 78;
|
|
|
|
OpCodes["sub"] = 79;
|
|
|
|
OpCodes["sub.alt"] = 80;
|
|
|
|
OpCodes["and"] = 81;
|
|
|
|
OpCodes["or"] = 82;
|
|
|
|
OpCodes["xor"] = 83;
|
|
|
|
OpCodes["not"] = 84;
|
|
|
|
OpCodes["neg"] = 85;
|
|
|
|
OpCodes["invert"] = 86;
|
|
|
|
OpCodes["add.c"] = 87;
|
|
|
|
OpCodes["smul.c"] = 88;
|
|
|
|
OpCodes["zero.pri"] = 89;
|
|
|
|
OpCodes["zero.alt"] = 90;
|
|
|
|
OpCodes["zero"] = 91;
|
|
|
|
OpCodes["zero.s"] = 92;
|
|
|
|
OpCodes["sign.pri"] = 93;
|
|
|
|
OpCodes["sign.alt"] = 94;
|
|
|
|
OpCodes["eq"] = 95;
|
|
|
|
OpCodes["neq"] = 96;
|
|
|
|
OpCodes["less"] = 97;
|
|
|
|
OpCodes["leq"] = 98;
|
|
|
|
OpCodes["grtr"] = 99;
|
|
|
|
OpCodes["geq"] = 100;
|
|
|
|
OpCodes["sless"] = 101;
|
|
|
|
OpCodes["sleq"] = 102;
|
|
|
|
OpCodes["sgrtr"] = 103;
|
|
|
|
OpCodes["sgeq"] = 104;
|
|
|
|
OpCodes["eq.c.pri"] = 105;
|
|
|
|
OpCodes["eq.c.alt"] = 106;
|
|
|
|
OpCodes["inc.pri"] = 107;
|
|
|
|
OpCodes["inc.alt"] = 108;
|
|
|
|
OpCodes["inc"] = 109;
|
|
|
|
OpCodes["inc.s"] = 110;
|
|
|
|
OpCodes["inc.i"] = 111;
|
|
|
|
OpCodes["dec.pri"] = 112;
|
|
|
|
OpCodes["dec.alt"] = 113;
|
|
|
|
OpCodes["dec"] = 114;
|
|
|
|
OpCodes["dec.s"] = 115;
|
|
|
|
OpCodes["dec.i"] = 116;
|
|
|
|
OpCodes["movs"] = 117;
|
|
|
|
OpCodes["cmps"] = 118;
|
|
|
|
OpCodes["fill"] = 119;
|
|
|
|
OpCodes["halt"] = 120;
|
|
|
|
OpCodes["bounds"] = 121;
|
|
|
|
OpCodes["sysreq.pri"] = 122;
|
|
|
|
OpCodes["sysreq.c"] = 123;
|
|
|
|
OpCodes["file"] = 124;
|
|
|
|
OpCodes["line"] = 125;
|
|
|
|
OpCodes["symbol"] = 126;
|
|
|
|
OpCodes["srange"] = 127;
|
|
|
|
OpCodes["jump.pri"] = 128;
|
|
|
|
OpCodes["switch"] = 129;
|
|
|
|
OpCodes["casetbl"] = 130;
|
|
|
|
OpCodes["swap.pri"] = 131;
|
|
|
|
OpCodes["swap.alt"] = 132;
|
|
|
|
OpCodes["pushaddr"] = 133;
|
|
|
|
OpCodes["nop"] = 134;
|
|
|
|
OpCodes["sysreq.d"] = 135;
|
|
|
|
OpCodes["symtag"] = 136;
|
|
|
|
|
|
|
|
std::map<std::string,int>::iterator i;
|
|
|
|
for (i=OpCodes.begin(); i!=OpCodes.end(); i++)
|
|
|
|
{
|
|
|
|
CSymbols->AddSymbol((*i).first.c_str(), Sym_Reserved, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
CSymbols->AddSymbol("db", Sym_Reserved, 0);
|
|
|
|
CSymbols->AddSymbol("PROC", Sym_Reserved, 0);
|
|
|
|
CSymbols->AddSymbol("ENDP", Sym_Reserved, 0);
|
|
|
|
CSymbols->AddSymbol("stat", Sym_Reserved, 0);
|
2004-08-09 08:43:27 +00:00
|
|
|
|
|
|
|
char buf[24];
|
|
|
|
sprintf(buf, "%d", cellsize?cellsize:4);
|
|
|
|
std::string CellDef("CELL");
|
|
|
|
std::string Cell(buf);
|
|
|
|
CDefines->AddDefine(CellDef, Cell);
|
|
|
|
CSymbols->AddSymbol("CELL", Sym_Define, 0);
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char Compiler::OperChar(OpToken c)
|
|
|
|
{
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case Token_Or:
|
|
|
|
return '|';
|
|
|
|
break;
|
|
|
|
case Token_Xor:
|
|
|
|
return '^';
|
|
|
|
break;
|
|
|
|
case Token_And:
|
|
|
|
return '&';
|
|
|
|
break;
|
|
|
|
case Token_Shr:
|
|
|
|
return '>';
|
|
|
|
break;
|
|
|
|
case Token_Shl:
|
|
|
|
return '<';
|
|
|
|
break;
|
|
|
|
case Token_Mod:
|
|
|
|
return '%';
|
|
|
|
break;
|
|
|
|
case Token_Div:
|
|
|
|
return '/';
|
|
|
|
break;
|
|
|
|
case Token_Mul:
|
|
|
|
return '*';
|
|
|
|
break;
|
|
|
|
case Token_Sub:
|
|
|
|
return '-';
|
|
|
|
break;
|
|
|
|
case Token_Add:
|
|
|
|
return '+';
|
|
|
|
break;
|
|
|
|
case Token_Not:
|
|
|
|
return '~';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return Token_None;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OpToken Compiler::OperToken(char c)
|
|
|
|
{
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case '|':
|
|
|
|
return Token_Or;
|
|
|
|
break;
|
|
|
|
case '^':
|
|
|
|
return Token_Xor;
|
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
return Token_And;
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
return Token_Shr;
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
return Token_Shl;
|
|
|
|
break;
|
|
|
|
case '%':
|
|
|
|
return Token_Mod;
|
|
|
|
break;
|
|
|
|
case '/':
|
|
|
|
return Token_Div;
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
return Token_Mul;
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
return Token_Sub;
|
|
|
|
break;
|
|
|
|
case '+':
|
|
|
|
return Token_Add;
|
|
|
|
break;
|
|
|
|
case '~':
|
|
|
|
return Token_Not;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return Token_None;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
char OperToken(OpToken c);
|
|
|
|
|
|
|
|
/* Returns all the arguments in a list
|
|
|
|
* This takes literals and expressions into account
|
2004-08-07 17:07:50 +00:00
|
|
|
* In non-simple mode, It is assumed that the first ( is stripped!
|
2004-08-06 08:46:59 +00:00
|
|
|
*/
|
|
|
|
int Compiler::FindArguments(std::string &text, std::vector<std::string*> &List, int &end, bool simple)
|
|
|
|
{
|
|
|
|
unsigned int i = 0, pos = 0;
|
|
|
|
char c = 0, d = 0, l = 0, size = 0;
|
|
|
|
std::stack<char> Stack;
|
|
|
|
end = -1;
|
|
|
|
|
|
|
|
for (i=0; i<text.size(); i++)
|
|
|
|
{
|
|
|
|
d = text[i];
|
|
|
|
|
|
|
|
/* Skip literal strings */
|
|
|
|
if (l)
|
|
|
|
{
|
|
|
|
if (d == l)
|
|
|
|
l = 0;
|
|
|
|
c = d;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
l = literal(d);
|
|
|
|
if (l)
|
|
|
|
{
|
|
|
|
c = d;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Stack.empty())
|
|
|
|
{
|
|
|
|
/* Check if an expression is ending or starting */
|
|
|
|
if (expr(d) == Stack.top())
|
|
|
|
{
|
|
|
|
Stack.pop();
|
|
|
|
if (Stack.size() == 0 && i == text.size()-1)
|
|
|
|
{
|
|
|
|
goto lCheck; //yeah yeah, I know this is bad
|
|
|
|
}
|
|
|
|
} else if (expr(d)) {
|
|
|
|
Stack.push(d);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Check if an expression or argument is starting */
|
2004-08-07 17:07:50 +00:00
|
|
|
if (expr(d) && (i!=text.size()-1) && (text[i] != ')' && !simple))
|
2004-08-06 08:46:59 +00:00
|
|
|
{
|
|
|
|
Stack.push(d);
|
|
|
|
} else {
|
|
|
|
/* Check to push another argument */
|
2004-08-07 17:07:50 +00:00
|
|
|
if (text[i] == ',' || (text[i] == ')' && !simple) || i==text.size()-1)
|
2004-08-06 08:46:59 +00:00
|
|
|
{
|
|
|
|
lCheck:
|
|
|
|
std::string *p = new std::string;
|
2004-08-07 17:07:50 +00:00
|
|
|
if (!simple)
|
|
|
|
{
|
|
|
|
p->assign(text.substr(pos,
|
|
|
|
(i==text.size()-1 && text[i]!=')')?
|
|
|
|
(i-pos+1):(i-pos)));
|
|
|
|
} else {
|
|
|
|
p->assign(text.substr(pos, i-pos+1));
|
|
|
|
}
|
2004-08-06 08:46:59 +00:00
|
|
|
Strip(*p);
|
|
|
|
pos = i+1;
|
|
|
|
if (p->size() < 1)
|
|
|
|
{
|
|
|
|
delete p;
|
|
|
|
} else {
|
|
|
|
List.push_back(p);
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
end = i;
|
|
|
|
if (text[i] == ')')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Stack.empty())
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_FatalTokenError);
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compiler::ProcessDirective(std::string &text)
|
|
|
|
{
|
|
|
|
Strip(text);
|
|
|
|
if (text[0] == '#')
|
|
|
|
text.erase(0, 1);
|
|
|
|
std::string directive;
|
|
|
|
std::string definition;
|
|
|
|
/* Split the directive */
|
|
|
|
StringBreak(text, directive, definition);
|
|
|
|
if (!directive.compare("macro"))
|
|
|
|
{
|
|
|
|
Strip(definition);
|
|
|
|
size_t argPos = definition.find('(', 0);
|
|
|
|
if (argPos == std::string::npos)
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_InvalidMacro, curLine);
|
|
|
|
} else {
|
|
|
|
/* Store the symbol, which is read up to the occurrence of ( */
|
|
|
|
std::string symbol;
|
|
|
|
symbol.assign(definition.substr(0, argPos-1));
|
|
|
|
/* Check if the symbol is already defined */
|
|
|
|
SymbolList::Symbol *S;
|
|
|
|
if ((S = CSymbols->FindSymbol(symbol)) != NULL)
|
|
|
|
{
|
2004-08-11 08:14:54 +00:00
|
|
|
CError->ErrorMsg(Err_SymbolRedef, S->sym.c_str(), S->line);
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
/* Store the argstring, which is the rest of the data */
|
|
|
|
std::string argstring;
|
|
|
|
argstring.assign(definition.substr(argPos+1, definition.size()-argPos+1));
|
|
|
|
/* Parse the arg string, storing the results and the offset to the end */
|
|
|
|
int bPos;
|
|
|
|
std::vector<std::string *> ArgList;
|
|
|
|
FindArguments(argstring, ArgList, bPos);
|
|
|
|
/* Store the rest in a function string (macro definition) */
|
|
|
|
std::string funcstring;
|
|
|
|
funcstring.assign(argstring.substr(bPos+1, argstring.size()-bPos+1));
|
|
|
|
/* Push the macro onto the Macro List */
|
|
|
|
Strip(funcstring);
|
|
|
|
Strip(symbol);
|
|
|
|
MacroList::Macro *m = CMacros->AddMacroBegin(symbol, funcstring);
|
|
|
|
std::vector<std::string *>::iterator i;
|
|
|
|
for (i=ArgList.begin(); i!=ArgList.end(); i++)
|
|
|
|
{
|
|
|
|
CMacros->AddMacroArgument(m, *(*i));
|
|
|
|
}
|
|
|
|
CMacros->AddMacroEnd(m);
|
|
|
|
/* Make sure to add the symbol */
|
2004-08-08 10:15:08 +00:00
|
|
|
CSymbols->AddSymbol(symbol, Sym_Macro, curLine);
|
2004-08-06 08:46:59 +00:00
|
|
|
//TODO: ClearList(ArgList);
|
|
|
|
}
|
2004-08-11 08:14:54 +00:00
|
|
|
} else if (!directive.compare("pragma")) {
|
|
|
|
std::string pragma;
|
|
|
|
std::string entry;
|
|
|
|
StringBreak(definition, pragma, entry);
|
|
|
|
if (pragma.compare("stacksize") == 0)
|
|
|
|
{
|
|
|
|
int stksz = atoi(entry.c_str());
|
|
|
|
if (stksz < 100)
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Invalid_Pragma);
|
|
|
|
} else {
|
|
|
|
stacksize = stksz;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CError->ErrorMsg(Err_Invalid_Pragma);
|
|
|
|
}
|
2004-08-06 08:46:59 +00:00
|
|
|
} else if (!directive.compare("define")) {
|
|
|
|
std::string symbol;
|
|
|
|
std::string def;
|
|
|
|
StringBreak(definition, symbol, def);
|
|
|
|
SymbolList::Symbol *S;
|
|
|
|
if ((S = CSymbols->FindSymbol(symbol)) != NULL)
|
|
|
|
{
|
2004-08-09 08:43:27 +00:00
|
|
|
CError->ErrorMsg(Err_SymbolRedef, S->sym.c_str(), S->line);
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
if (def.size() < 1)
|
|
|
|
def.assign("1");
|
2004-08-08 10:15:08 +00:00
|
|
|
CSymbols->AddSymbol(symbol, Sym_Define, curLine);
|
2004-08-06 08:46:59 +00:00
|
|
|
CDefines->AddDefine(symbol, def);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-11 14:31:26 +00:00
|
|
|
int Compiler::Eval(std::string &str, SymbolType sym)
|
|
|
|
{
|
|
|
|
CExpr e(CError);
|
|
|
|
|
|
|
|
e = EvalE(str, sym);
|
|
|
|
|
|
|
|
return e.GetNumber();
|
|
|
|
}
|
|
|
|
|
2004-08-06 08:46:59 +00:00
|
|
|
/* The evaluator works by storing expressions on a stack.
|
|
|
|
Each expression is an RPN-ordered pair of lists for ops and values
|
|
|
|
Every time the stack is popped, the expression is evaluated by searching
|
|
|
|
for the highest operators and evaluating them.
|
|
|
|
Note that string literals are not allowed here yet.
|
|
|
|
*/
|
2004-08-11 14:31:26 +00:00
|
|
|
CExpr Compiler::EvalE(std::string &str, SymbolType sym)
|
2004-08-06 08:46:59 +00:00
|
|
|
{
|
|
|
|
std::stack<rpn *> Stack;
|
|
|
|
std::string bpstr;
|
|
|
|
int i = 0;
|
|
|
|
rpn *r = new rpn;
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
Stack.push(r);
|
|
|
|
|
|
|
|
for (i=0; i<(int)str.size(); i++)
|
|
|
|
{
|
|
|
|
if (OperToken(str[i]) != Token_None)
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
if ((i == (int)(str.size() - 1))
|
|
|
|
|| ((OperToken(str[i]) != Token_Not && OperToken(str[i]) != Token_Sub)
|
|
|
|
&& i == 0))
|
2004-08-06 08:46:59 +00:00
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Unexpected_Char, str[i]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (str[i] == '<' && str[i+1] != '<')
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Unexpected_Char, str[i]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (str[i] == '>' && str[i+1] != '>')
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Unexpected_Char, str[i]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* Check to see if there are extra tokens */
|
2004-08-07 17:07:50 +00:00
|
|
|
if (pos < i || (pos == i && (OperToken(str[i]) == Token_Sub)))
|
2004-08-06 08:46:59 +00:00
|
|
|
{
|
|
|
|
bpstr.assign(str.substr(pos, i-pos));
|
2004-08-09 08:43:27 +00:00
|
|
|
Strip(bpstr);
|
2004-08-11 08:14:54 +00:00
|
|
|
CExpr e(CError);
|
2004-08-06 08:46:59 +00:00
|
|
|
e.Set(bpstr);
|
2004-08-11 08:14:54 +00:00
|
|
|
e.Evaluate(sym);
|
|
|
|
r->vals.push_back(e);
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
2004-08-11 09:06:00 +00:00
|
|
|
r->ops.push_back((char)str[i]);
|
2004-08-06 08:46:59 +00:00
|
|
|
if (str[i] == '>' || str[i] == '<')
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
pos = i+1;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
if (str[i] == '(')
|
|
|
|
{
|
|
|
|
if (pos < i)
|
|
|
|
{
|
|
|
|
bpstr.assign(str.substr(pos, i-pos));
|
2004-08-09 08:43:27 +00:00
|
|
|
Strip(bpstr);
|
2004-08-11 08:14:54 +00:00
|
|
|
CExpr e(CError);
|
2004-08-06 08:46:59 +00:00
|
|
|
e.Set(bpstr);
|
2004-08-11 08:14:54 +00:00
|
|
|
e.Evaluate(sym);
|
|
|
|
r->vals.push_back(e);
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
r = new rpn;
|
|
|
|
Stack.push(r);
|
|
|
|
pos = i+1;
|
|
|
|
continue;
|
|
|
|
} else if (str[i] == ')') {
|
|
|
|
if (pos < i)
|
|
|
|
{
|
|
|
|
bpstr.assign(str.substr(pos, i-pos));
|
2004-08-09 08:43:27 +00:00
|
|
|
Strip(bpstr);
|
2004-08-11 08:14:54 +00:00
|
|
|
CExpr e(CError);
|
2004-08-06 08:46:59 +00:00
|
|
|
e.Set(bpstr);
|
2004-08-11 08:14:54 +00:00
|
|
|
e.Evaluate(sym);
|
|
|
|
r->vals.push_back(e);
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
if (Stack.size() < 2)
|
|
|
|
{
|
2004-08-11 09:06:00 +00:00
|
|
|
while (!Stack.empty())
|
2004-08-09 08:43:27 +00:00
|
|
|
{
|
2004-08-11 09:06:00 +00:00
|
|
|
rpn *t = Stack.top();
|
|
|
|
if (t)
|
|
|
|
delete t;
|
|
|
|
t = 0;
|
2004-08-09 08:43:27 +00:00
|
|
|
Stack.pop();
|
|
|
|
}
|
2004-08-06 08:46:59 +00:00
|
|
|
CError->ErrorMsg(Err_Unmatched_Token, str[i]);
|
|
|
|
return 0;
|
2004-08-11 09:06:00 +00:00
|
|
|
} else {
|
|
|
|
CExpr t;
|
|
|
|
t = EvalRpn(r, sym);
|
|
|
|
delete r;
|
|
|
|
r = 0;
|
|
|
|
Stack.pop();
|
|
|
|
r = Stack.top();
|
|
|
|
r->vals.push_back(t);
|
|
|
|
pos = i + 1;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
} else if (i == (int)(str.size() - 1)) {
|
|
|
|
if (pos < i)
|
|
|
|
{
|
2004-08-07 17:07:50 +00:00
|
|
|
bpstr.assign(str.substr(pos));
|
2004-08-06 08:46:59 +00:00
|
|
|
} else if (pos == i) {
|
|
|
|
bpstr.assign(str.substr(pos, 1));
|
|
|
|
}
|
|
|
|
if (pos < i || pos == i)
|
|
|
|
{
|
2004-08-09 08:43:27 +00:00
|
|
|
Strip(bpstr);
|
2004-08-11 08:14:54 +00:00
|
|
|
CExpr e(CError);
|
2004-08-06 08:46:59 +00:00
|
|
|
e.Set(bpstr);
|
2004-08-11 08:14:54 +00:00
|
|
|
e.Evaluate(sym);
|
|
|
|
r->vals.push_back(e);
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Stack.size() != 1)
|
|
|
|
{
|
2004-08-11 09:06:00 +00:00
|
|
|
rpn *t = 0;
|
2004-08-07 17:07:50 +00:00
|
|
|
while (!Stack.empty())
|
|
|
|
{
|
2004-08-11 09:06:00 +00:00
|
|
|
t = Stack.top();
|
|
|
|
if (t)
|
|
|
|
delete t;
|
|
|
|
t = 0;
|
2004-08-07 17:07:50 +00:00
|
|
|
Stack.pop();
|
|
|
|
}
|
2004-08-06 08:46:59 +00:00
|
|
|
CError->ErrorMsg(Err_Unmatched_Token, '(');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stack.pop();
|
2004-08-11 08:14:54 +00:00
|
|
|
CExpr final;
|
|
|
|
final = EvalRpn(r, sym);
|
2004-08-06 08:46:59 +00:00
|
|
|
|
2004-08-11 09:06:00 +00:00
|
|
|
delete r;
|
|
|
|
r = 0;
|
|
|
|
|
2004-08-11 14:31:26 +00:00
|
|
|
return final;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
|
2004-08-11 08:14:54 +00:00
|
|
|
CExpr Compiler::EvalRpn(rpn *r, SymbolType sym)
|
2004-08-06 08:46:59 +00:00
|
|
|
{
|
|
|
|
int i = 0, j = 0;
|
2004-08-11 08:14:54 +00:00
|
|
|
CExpr er, el;
|
|
|
|
std::vector<CExpr>::iterator Q;
|
2004-08-06 08:46:59 +00:00
|
|
|
std::vector<char>::iterator R;
|
|
|
|
|
|
|
|
while (r->ops.size())
|
|
|
|
{
|
|
|
|
for (i=1; i<Tokens_Total; i++)
|
|
|
|
{
|
|
|
|
char c = OperChar((OpToken)i);
|
|
|
|
for (j=0; j<(int)r->ops.size(); j++)
|
|
|
|
{
|
|
|
|
if (r->ops[j] == c)
|
|
|
|
{
|
|
|
|
if ((int)r->vals.size() <= j)
|
|
|
|
assert(0);// Can't have more ops than values
|
2004-08-11 08:14:54 +00:00
|
|
|
el = r->vals[j];
|
2004-08-06 08:46:59 +00:00
|
|
|
if (i != Token_Not)
|
|
|
|
{
|
|
|
|
if ((int)r->vals.size() <= j+1)
|
2004-08-07 17:07:50 +00:00
|
|
|
{
|
2004-08-06 08:46:59 +00:00
|
|
|
assert(0);
|
2004-08-07 17:07:50 +00:00
|
|
|
}
|
2004-08-11 08:14:54 +00:00
|
|
|
er = r->vals[j+1];
|
|
|
|
el.Oper((OpToken)i, er);
|
|
|
|
} else {
|
|
|
|
el.Not();
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
R = r->ops.begin();
|
|
|
|
Q = r->vals.begin();
|
|
|
|
if (i != Token_Not)
|
|
|
|
{
|
|
|
|
R += j;
|
|
|
|
Q += j;
|
|
|
|
r->ops.erase(R);
|
2004-08-11 08:14:54 +00:00
|
|
|
r->vals[j+1] = el;
|
2004-08-06 08:46:59 +00:00
|
|
|
r->vals.erase(Q);
|
|
|
|
j--;
|
|
|
|
} else {
|
|
|
|
R += j;
|
|
|
|
r->ops.erase(R);
|
2004-08-11 08:14:54 +00:00
|
|
|
r->vals[j] = el;
|
2004-08-06 08:46:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return r->vals[0];
|
2004-08-07 17:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DestroyArgList(std::vector<std::string *> &List)
|
|
|
|
{
|
|
|
|
std::vector<std::string *>::iterator i;
|
|
|
|
|
|
|
|
for (i=List.begin(); i!=List.end(); i++)
|
|
|
|
{
|
|
|
|
if ( (*i) )
|
|
|
|
delete (*i);
|
|
|
|
}
|
|
|
|
|
|
|
|
List.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compiler::PrintCodeList()
|
|
|
|
{
|
|
|
|
std::vector<Asm *>::iterator i;
|
|
|
|
std::vector<int>::iterator j;
|
|
|
|
|
|
|
|
for (i=CodeList.begin(); i!=CodeList.end(); i++)
|
|
|
|
{
|
|
|
|
printf("OP: %d [%d]\n", (*i)->op, (*i)->cip);
|
|
|
|
for (j=(*i)->params.begin(); j!=(*i)->params.end(); j++)
|
|
|
|
{
|
|
|
|
printf("\tParameter: %d\n", (*j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 08:43:27 +00:00
|
|
|
|
|
|
|
int Compiler::DerefSymbol(std::string &str, SymbolType sym)
|
|
|
|
{
|
|
|
|
int val = 0;
|
|
|
|
|
|
|
|
SymbolList::Symbol *S = NULL;
|
|
|
|
if ( ((S = CSymbols->FindSymbol(str)) == NULL) )
|
|
|
|
{
|
|
|
|
if (sym == Sym_Label)
|
|
|
|
{
|
|
|
|
S = CSymbols->AddSymbol(str, Sym_Label, -1);
|
2004-08-12 16:31:50 +00:00
|
|
|
} else if (sym == Sym_Proc) {
|
|
|
|
S = CSymbols->AddSymbol(str, Sym_Proc, -1);
|
2004-08-09 08:43:27 +00:00
|
|
|
} else {
|
|
|
|
CError->ErrorMsg(Err_Unknown_Symbol, str.c_str());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sym != Sym_Dat && S->type != sym)
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Invalid_Symbol);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
switch (S->type)
|
|
|
|
{
|
|
|
|
case Sym_Proc:
|
|
|
|
{
|
2004-08-12 16:31:50 +00:00
|
|
|
ProcMngr::AsmProc *p = 0;
|
|
|
|
|
|
|
|
if ( ((p = PROC->FindProc(str)) == NULL) || p->ASM == NULL)
|
2004-08-09 08:43:27 +00:00
|
|
|
{
|
2004-08-12 16:31:50 +00:00
|
|
|
/* Labels we handle differently.
|
|
|
|
Add it to the label queue
|
|
|
|
*/
|
|
|
|
p = PROC->AddProc(S, NULL);
|
|
|
|
PROC->QueueProc(str, CurAsm());
|
|
|
|
val = ProcMngr::ncip;
|
|
|
|
} else {
|
|
|
|
val = p->ASM->cip;
|
2004-08-09 08:43:27 +00:00
|
|
|
}
|
|
|
|
break;
|
2004-08-12 16:31:50 +00:00
|
|
|
}
|
2004-08-09 08:43:27 +00:00
|
|
|
case Sym_Native:
|
|
|
|
{
|
|
|
|
val = CNatives->GetNativeId(str);
|
|
|
|
if (val == NativeMngr::ncip)
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Invalid_Symbol);
|
|
|
|
return 0;
|
2004-08-12 16:31:50 +00:00
|
|
|
}
|
2004-08-09 08:43:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Sym_Dat:
|
|
|
|
{
|
|
|
|
val = DAT->GetOffset(str);
|
|
|
|
if (val == DataMngr::nof)
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Invalid_Symbol);
|
|
|
|
return 0;
|
2004-08-12 16:31:50 +00:00
|
|
|
}
|
2004-08-09 08:43:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Sym_Label:
|
|
|
|
{
|
2004-08-12 16:31:50 +00:00
|
|
|
LabelMngr::Label *L = 0;
|
|
|
|
|
|
|
|
if ( (L = CLabels->FindLabel(str)) == NULL )
|
2004-08-09 08:43:27 +00:00
|
|
|
{
|
|
|
|
/* Labels we handle differently.
|
|
|
|
Add it to the label queue
|
|
|
|
*/
|
2004-08-12 16:31:50 +00:00
|
|
|
L = CLabels->AddLabel(S, LabelMngr::ncip);
|
2004-08-09 08:43:27 +00:00
|
|
|
CLabels->QueueLabel(str, CurAsm());
|
2004-08-12 16:31:50 +00:00
|
|
|
LabelStack.push(str);
|
2004-08-09 08:43:27 +00:00
|
|
|
}
|
2004-08-12 16:31:50 +00:00
|
|
|
|
|
|
|
val = L->cip;
|
2004-08-09 08:43:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
CError->ErrorMsg(Err_Invalid_Symbol);
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
2004-08-11 08:14:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Compiler::IsSymbol(std::string &str)
|
|
|
|
{
|
|
|
|
SymbolList::Symbol *S = 0;
|
|
|
|
|
|
|
|
if ( (S = CSymbols->FindSymbol(str)) == NULL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2004-08-11 09:06:00 +00:00
|
|
|
|
|
|
|
rpn::~rpn()
|
|
|
|
{
|
|
|
|
// ops.clear();
|
|
|
|
// vals.clear();
|
2004-08-11 10:01:56 +00:00
|
|
|
}
|