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$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE_AMXCOMPILER_H
|
|
|
|
#define _INCLUDE_AMXCOMPILER_H
|
|
|
|
|
2004-08-07 17:07:50 +00:00
|
|
|
#define CHK_PARAMS(d) \
|
|
|
|
if (paramList.size() > d) \
|
|
|
|
{ \
|
|
|
|
CError->ErrorMsg(Warning_Param_Count, paramList.size(), d); \
|
|
|
|
} else if (paramList.size() < d) { \
|
|
|
|
CError->ErrorMsg(Err_Param_Count, paramList.size(), d); \
|
|
|
|
delete ASM; \
|
|
|
|
ASM = 0; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PUSH_PARAM(n,sym) \
|
|
|
|
if (paramList.size() >= n) \
|
|
|
|
{ \
|
|
|
|
ASM->params.push_back(Eval(*(paramList[n-1]), sym)); \
|
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
|
|
|
class rpn
|
|
|
|
{
|
|
|
|
public:
|
2004-08-11 09:42:15 +00:00
|
|
|
~rpn();
|
2004-08-06 08:46:59 +00:00
|
|
|
//TODO: use linked lists, but not std::list
|
|
|
|
std::vector<char> ops;
|
2004-08-11 08:14:54 +00:00
|
|
|
std::vector<CExpr> vals;
|
2004-08-06 08:46:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Compiler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Compiler();
|
|
|
|
~Compiler();
|
|
|
|
Compiler(std::string &f);
|
|
|
|
void Load(std::string &f);
|
|
|
|
bool Parse();
|
2004-08-11 09:42:15 +00:00
|
|
|
bool Compile(std::string &out);
|
2004-08-06 08:46:59 +00:00
|
|
|
int CurLine() { return curLine; }
|
|
|
|
ErrorMngr *ErrorHandler() { return CError; }
|
2004-08-07 17:07:50 +00:00
|
|
|
void PrintCodeList();
|
2004-08-06 08:46:59 +00:00
|
|
|
public:
|
|
|
|
int FindArguments(std::string &text, std::vector<std::string*> &List, int &end, bool simple = false);
|
2004-08-08 10:15:08 +00:00
|
|
|
void Clear();
|
|
|
|
int CipCount();
|
2004-08-09 05:23:32 +00:00
|
|
|
int CurCip() { return lastCip; }
|
2004-08-09 08:43:27 +00:00
|
|
|
Asm *CurAsm() { return curAsm; }
|
2004-08-09 05:23:32 +00:00
|
|
|
bool SetDebug();
|
2004-08-11 14:31:26 +00:00
|
|
|
bool SetPack();
|
|
|
|
bool SetDOpt();
|
2004-08-09 08:43:27 +00:00
|
|
|
int DerefSymbol(std::string &str, SymbolType sym = Sym_None);
|
2004-08-11 14:31:26 +00:00
|
|
|
bool IsSymbol(std::string &str);
|
|
|
|
private:
|
2004-08-06 08:46:59 +00:00
|
|
|
void ProcessDirective(std::string &text);
|
|
|
|
void Init();
|
|
|
|
void InitOpcodes();
|
|
|
|
int Eval(std::string &str, SymbolType sym = Sym_None);
|
2004-08-11 14:31:26 +00:00
|
|
|
CExpr EvalE(std::string &str, SymbolType sym = Sym_None);
|
2004-08-11 08:14:54 +00:00
|
|
|
CExpr EvalRpn(rpn *r, SymbolType sym);
|
2004-08-06 08:46:59 +00:00
|
|
|
OpToken OperToken(char c);
|
|
|
|
char OperChar(OpToken c);
|
2004-08-11 14:31:26 +00:00
|
|
|
void WriteCell(FILE *fp, ucell *c, int repeat);
|
2004-08-06 08:46:59 +00:00
|
|
|
private:
|
|
|
|
std::vector<Asm *> CodeList;
|
|
|
|
std::map<std::string,int> OpCodes;
|
2004-08-08 10:15:08 +00:00
|
|
|
char *Output;
|
2004-08-06 08:46:59 +00:00
|
|
|
ErrorMngr *CError;
|
|
|
|
SymbolList *CSymbols;
|
|
|
|
DefineMngr *CDefines;
|
|
|
|
MacroList *CMacros;
|
|
|
|
DataMngr *DAT;
|
|
|
|
ProcMngr *PROC;
|
|
|
|
LabelMngr *CLabels;
|
|
|
|
NativeMngr *CNatives;
|
|
|
|
std::string filename;
|
|
|
|
int curLine;
|
|
|
|
int lastCip;
|
|
|
|
int cellsize;
|
2004-08-08 10:15:08 +00:00
|
|
|
int stacksize;
|
2004-08-09 05:23:32 +00:00
|
|
|
bool debug;
|
2004-08-11 14:31:26 +00:00
|
|
|
bool pack;
|
|
|
|
bool dopt;
|
|
|
|
int bitsOut;
|
2004-08-09 08:43:27 +00:00
|
|
|
Asm *curAsm;
|
2004-08-06 08:46:59 +00:00
|
|
|
};
|
|
|
|
|
2004-08-11 08:14:54 +00:00
|
|
|
#endif //_INCLUDE_AMXCOMPILER_H
|