this version is broken, working on RegEx to see if we can go faster

This commit is contained in:
Shawn Quick 2023-02-12 22:05:28 -08:00
parent 51231c9336
commit 855add4427
14 changed files with 372 additions and 112 deletions

View File

@ -1,35 +1,9 @@
{
"version": 4,
"env": {
"def_include": [
"${workspaceRoot}/libpal/include",
"${workspaceRoot}/libpal/include/pal",
"${workspaceRoot}/nufxlib",
"${workspaceRoot}/diskimg",
"${workspaceRoot}/libhfs",
"${workspaceRoot}"
]
},
"configurations": [
{
"name": "CMake",
"configurationProvider": "ms-vscode.cmake-tools",
"includePath": [
"${def_include}"
],
"browse": {
"path": [
"${def_include}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db"
},
//"compilerPath": "/usr/bin/clang++",
//"compilerArgs": [
// "-Wall"
//],
"compileCommands": "${workspaceFolder}/compile_commands.json",
//"intelliSenseMode": "linux-clang-x64",
"name": "cmake",
"configurationProvider": "ms-vscode.cmake-tools"
}
]
],
"version": 4
}

44
.vscode/launch.json vendored
View File

@ -1,44 +0,0 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "DEBUG",
"type": "cppdbg",
"request": "launch",
// Resolved by CMake Tools:
"program": "${workspaceFolder}/build/qasm",
"args": [
//"${workspaceFolder}/testdata/3006-pea.S",
"${workspaceFolder}/test.s",
"-d",
"-d",
"-d",
"-l",
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
//"externalConsole": true,
"environment": [
{
// add the directory where our target was built to the PATHs
// it gets resolved by CMake Tools:
"name": "PATH",
"value": "${env:PATH}:${workspaceFolder}/build"
},
{
"name": "OTHER_VALUE",
"value": "Something something"
}
],
//"console": "externalTerminal",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

View File

@ -12,7 +12,6 @@ project(QAsm)
set(APPVERSION "4.0.10")
set(LIBRARY_NAME pal)
set(FIND_LIBRARY_USE_LIB64_PATHS TRUE)
#message("root: ${PROJECT_ROOT}")
@ -42,6 +41,7 @@ set(SOURCE
${PROJECT_ROOT}/psuedo.cpp
${PROJECT_ROOT}/qoptions.cpp
${PROJECT_ROOT}/cider.cpp
${PROJECT_ROOT}/shell.cpp
${PROJECT_ROOT}/util.cpp
)
@ -89,6 +89,8 @@ target_link_libraries (
${PROJECT_NAME}
${LIBRARY_NAME}
pthread
readline
history
${CIDERLIBS}
${Poco_LIBRARIES}
)

18
asm.cpp
View File

@ -318,6 +318,7 @@ void CLASS::clear()
{
shiftchar=0;
wholetext = "";
operparams.clear();
lable = "";
printlable = "";
opcode = "";
@ -1625,6 +1626,7 @@ int CLASS::callOpCode(std::string op, MerlinLine &line)
}
}
#if 0
if (line.addressmode == syn_imm) //page 83 merlin16 manual
{
//printf("immediate mode\n");
@ -1703,6 +1705,7 @@ int CLASS::callOpCode(std::string op, MerlinLine &line)
{
line.flags |= FLAG_FORCEABS;
}
#endif
auto itr = opcodes.find(Poco::toUpper(op));
if (itr != opcodes.end())
@ -1997,6 +2000,14 @@ void CLASS::complete(void)
}
int CLASS::split_params(string param_string, std::vector<TOperParam> &params)
{
int res=-1;
printf("split: |%s|\n",param_string.c_str());
TOperParam p(param_string);
return(res);
}
int CLASS::evaluate(MerlinLine &line, std::string expr, int64_t &value)
{
int res = -1;
@ -2011,7 +2022,7 @@ int CLASS::evaluate(MerlinLine &line, std::string expr, int64_t &value)
if (line.addressmode==syn_data)
{
printf("\n<data>\n");
//printf("\n<data>\n");
value=0;
int l=line.operand_expr.length();
int i=0;
@ -2023,10 +2034,13 @@ int CLASS::evaluate(MerlinLine &line, std::string expr, int64_t &value)
}
res=0;
}
else if (line.addressmode==syn_params)
//else if ((line.addressmode==syn_params) || (line.addressmode=syn_data))
else if ((line.addressmode==syn_params))
{
// if this is a parameter list, don't eval here, because it will
// fail
split_params(expr,line.operparams);
res=0;
}
else

180
asm.h
View File

@ -7,6 +7,7 @@
#define OPHANDLER(ACB) std::bind(ACB, this, std::placeholders::_1, std::placeholders::_2)
#define DEF_VAL 0
#define FLAG_FORCELONG 0x01
#define FLAG_FORCEABS 0x02
@ -112,7 +113,184 @@ extern uint8_t opCodeCompatibility[256];
#endif
class TOperParam
{
public:
std::string splitString;
//const string splitHex="^[$]?(?'hex'[A-Za-z0-9]+)(?'sep'[[:blank:],;]*)$";
//const string splitNum="^(?'number'[0-9]+)(?'sep'[[:blank:],;]*)$";
//const string splitBin="^[%]?(?'binary'[01]+)(?'sep'[[:blank:],;]*)$";
//const string splitLabel="^[#|<>^]?(?'label'[A-Za-z:]?[A-Za-z0-9_]*)[:]?(?'sep'[[:blank:],;]*)$";
//const string splitVariable="^[#|<>\\^]?[\\]]{1}(?'variable'[A-Za-z:]?[A-Za-z0-9_]*)[:]?(?'sep'[[:blank:],;]*)$";
//Poco::RegularExpression splitStringRegEx;
//Poco::RegularExpression splitStringRegEx(&splitString,0,true);
#if 0
/(?x) # ignore pattern whitespace
(?(DEFINE)
(?<dstring> (?'open'[!0-9\\,]{1})(?'str'.*?)(?'close'\k'open'))
(?<number> \d+ )
(?<value>
\s* (?:
(?&dstring)
| (?&number)
| (?&list)
) \s*
)
(?<list> \\ (?&value) (?: [,;]* (?&value) )* \\ )
)
^(?&value)$/gm
----
/[;,[:space:]]*(?'dstring'(?'delim'[^0-9,\\[:space:]])(?'str'.*?(?=\2))(?'close'\2)(?>[;,[:space:]]+))/gm // merlin delimited string
/[;,[:space:]]*(?'binarystr'(?'delim'[%])(?'val'[0-1+?)(?'close'\2)(?>[;,[:space:]]+))/gm // binary value %01001
/[;,[:space:]]*(?'decimalstr'(?'val'[0-9*?)(?'close'\2)(?>[;,[:space:]]+))/gm // integer
/[;,[:space:]]*(?'delim'[\$])(?'hexval'[0-9a-zA-Z]+?)(?'end'[;,[:space:]]+)/gm // hex
/[;,[:space:]]*(?'delim'[\%])(?'binval'[0-9a-zA-Z]+?)(?'end'[;,[:space:]]+)/gm // binary %1001
(?'stringval'[;,[:space:]]*(?'dstring'(?'delim'[^0-9,\\[:space:]])(?'str'.*?(?=(?P=delim)))(?'close'(?P=delim)(?>[;,[:space:]]+))))
/(?x) # ignore pattern whitespace
(?(DEFINE)
(?<stringitem>(?'s_delim'[^0-9\/[:space:]])(?'strout'.*?(?=(?P=s_delim)))(?'e_delim'(?P=s_delim)))
(?<number> (?'numout'[\#]?[<>|\^]?\d+ ))
(?<binary>([\#]?[<>|\^]?%[01]+))
(?<hex>(?'hexout'[\#]?[<>|\^]?\$[A-Fa-f0-9]+))
(?<hex1>(?'hexlist'[A-Fa-f0-9]+))
(?<label>(?'labelout'[\#]?[<>|]?[A-Za-z_][A-Z-a-z0-9]*))
(?<value>
(
(?&binary)
| (?&number)
| (?&hex)
| (?&hex1)
| (?&stringitem)
| (?&label)
| (?&list)
)
)
(?<list> \/ ((?&value) (?: [,;]+ (?&value) )*) \/ )
)
^((?&value))$/gm
/(?x) # ignore pattern whitespace
(?(DEFINE)
(?<stringitem>(?'s_delim'[^0-9\/[:space:]])(?'strout'.*?(?=(?P=s_delim)))(?'e_delim'(?P=s_delim)))
(?'separator' ([,;]))
(?<number> (?'numout'[\#]?[<>|\^]?\d+ ))
(?<binary>[\#]?[<>|\^]?%[01]+)
(?<hex>(?'hexout'[\#]?[<>|\^]?\$[A-Fa-f0-9]+))
(?<hex1>(?'hexlist'[A-Fa-f0-9]+))
(?<label>(?'labelout'[\#]?[<>|]?[A-Za-z_][A-Z-a-z0-9]*))
(?<sexprx>(?'sexpr'[\(][#]?[<>|]?[\S]+[\)]))
(?<lexprx>(?'lexpr'[\[][#]?[<>|]?[\S]+[\]]))
(?<value>
(?&separator)
| (?&binary)
| (?&number)
| (?&hex)
| (?&hex1)
| (?&sexprx)
| (?&lexprx)
| (?&stringitem)
| (?&label)
)
(?<list> \/ ((?&value) (?: [,;]+ (?&value) )*) \/ )
)
((?&value))/gm
/(?x) # ignore pattern whitespace
(?(DEFINE)
(?<stringitem>(?'s_delim'[^0-9\/[:space:]])(?'strout'.*?(?=(?P=s_delim)))(?'e_delim'(?P=s_delim)))
(?'separator' ([\\,;[:blank:]]))
(?<number> (?'numout'[\#]?[<>|\^]?\d+ ))
(?<binary>[\#]?[<>|\^]?%[01]+)
(?<hex>(?'hexout'[\#]?[<>|\^]?\$[A-Fa-f0-9]+))
(?<hex1>(?'hexlist'[A-Fa-f0-9]+))
(?<label>(?'labelout'[\#]?[<>|]?[A-Za-z_][A-Z-a-z0-9]*))
(?<sexprx>(?'sexpr'[\(][#]?[<>|]?[\S]+[\)]))
(?<lexprx>(?'lexpr'[\[][#]?[<>|]?[\S]+[\]]))
(?<value>
(?&separator)
| (?&binary)
| (?&number)
| (?&hex)
| (?&hex1)
| (?&sexprx)
| (?&lexprx)
| (?&stringitem)
| (?&label)
)
(?<list> \/ ((?&value) (?: [,;]+ (?&value) )*) \/ )
)
(?&separator){1}(?'output'(?&value))/gm
#endif
std::vector<string> tokens;
string expr;
uint64_t value;
int32_t error;
TOperParam() //: splitStringRegEx(splitString)
{
splitString="^(?'open'[[:punct:]]{1})(?'string'.*?)(?'close'\\1)(?'sep'[[:blank:],;]{1})(?'therest'.*?$)";
tokens.clear();
expr="";
value=DEF_VAL;
error=-1;
}
TOperParam(string ex) : TOperParam()
{
expr=ex;
parse(expr);
}
int parse(string ex)
{
int res=-1;
string orig=trim(ex);
std::vector<string> strs;
int x;
tokens.clear();
strs.clear();
//Poco::RegularExpression split(splitString);
Poco::RegularExpression splitEx(splitString, 0, true);
x = 0;
try
{
x = splitEx.split(orig, strs, 0);
}
catch (Poco::Exception &e)
{
x = 0;
}
if (x>0)
{
for (int i=0;i<x;i++)
{
printf("split: |%s|\n",strs[i].c_str());
}
}
if (res<=0)
{
tokens.clear();
error=-1;
}
return(res);
}
};
class TOriginSection
{
@ -298,6 +476,7 @@ public:
//uint32_t syntax;
ConfigOptions *qoptions;
std::vector<TOperParam> operparams;
std::string wholetext;
std::string lable;
std::string printlable;
@ -604,6 +783,7 @@ public:
void showVariables(TVariable &vars);
int evaluate(MerlinLine &line, std::string expr, int64_t &value);
int split_params(string param_string, std::vector<TOperParam> &params);
int substituteVariables(MerlinLine & line, std::string &outop);

View File

@ -2,8 +2,6 @@
#define CLASS TEvaluator
#define DEF_VAL 0
std::ostream& operator<<(std::ostream& os, const Token& token)
{
os << token.str;
@ -781,6 +779,12 @@ out:
if (stack.size() > 0)
{
v = stack.back();
switch(shift.shiftchar)
{
case '^': v>>=16;break;
case '<': break;
case '>': v>>=8;break;
}
if (isDebug() > 0)
{
printf("eval: expression: |%s| %08lX\n", expr.c_str(),v);

View File

@ -192,8 +192,10 @@ int CLASS::doMVN(MerlinLine &line, TSymbol &sym)
op = 0x44; // MVP
}
TEvaluator eval(*this);
int64_t value = -1;
int x = evaluate(line, line.operand_expr2, value);
printf("oper1=|%s| oper2=|%s|\n",line.operand_expr.c_str(),line.operand_expr2.c_str());
int x = eval.evaluate(line.operand_expr2, value);
if (x == 0)
{
value &= 0xFFFFFFFF;
@ -212,14 +214,13 @@ int CLASS::doMVN(MerlinLine &line, TSymbol &sym)
setOpcode(line, op);
// these bytes are the two bank registers
if (qoptions.isMerlin32() && (v<256))
//if (((line.syntax & SYNTAX_MERLIN32) == SYNTAX_MERLIN32) && (v<256))
{
// merlin32 uses the low byte of the two operands
line.outbytes.push_back((v) & 0xFF);
line.outbytes.push_back((line.expr_value) & 0xFF);
}
else
//if (qoptions.isMerlin32() && (v<256))
//{
// merlin32 uses the low byte of the two operands
// line.outbytes.push_back((v) & 0xFF);
// line.outbytes.push_back((line.expr_value) & 0xFF);
//}
//else
{
// merlin16 uses the high byte (bank) as the opcode
line.outbytes.push_back((v>>16) & 0xFF);
@ -320,10 +321,6 @@ int CLASS::doAddress(MerlinLine &line, TSymbol &sym)
res = 1 + sym.stype;
if (pass > 0)
{
//if (isMerlin816())
//{
//}
//switch(line.expr_shift)
switch(line.shiftchar)
{
case '^':

View File

@ -403,7 +403,7 @@ int CLASS::doDATA(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
//printf("error %d\n",r);
if (a.pass > 0)
{
line.setError(errBadEvaluation);
// SGQ line.setError(errBadEvaluation);
}
}
//eval_value = (uint64_t)doShift((uint32_t)eval_value);

View File

@ -2,6 +2,7 @@
ConfigOptions qoptions;
extern void runShell(void);
//#define XX printf
//#undef printf
int myprintf(const char *format, ...)
@ -46,7 +47,7 @@ programOption PAL::appOptions[] =
{ "list", "l", "force assembly listing ('lst' opcodes will be ignored)", "", false, true},
{ "no-list", "nl", "force assembly listing off ('lst' opcodes will be ignored)", "", false, true},
{ "symbols", "sym", "show symbol table after assembly", "", false, true},
{ "shell", "", "enter the shell", "", false, true},
{ "color", "c", "colorize the output", "", false, true},
{ "settings", "s", "show the working settings/options", "", false, true},
@ -111,6 +112,7 @@ int CLASS::runCommandLineApp(void)
string language="";
string syn;
bool settings;
bool shell;
int res = -1;
qoptions.init();
@ -119,6 +121,9 @@ int CLASS::runCommandLineApp(void)
startdirectory = Poco::Path::current();
appPath=utils->getAppPath();
settings=getBool("option.settings",false);
shell=getBool("option.shell",false);
#if 0
if (isDebug()>0)
{
printf("num args: %ld\n",commandargs.size());
@ -127,20 +132,24 @@ int CLASS::runCommandLineApp(void)
printf("commandarg[%ld] |%s|\n",i,commandargs[i].c_str());
}
}
//string help=getConfig("option.help","0");
//printf("help=|%s|\n",help.c_str());
//if(help!="0")
//{
// displayHelp();
// printf("help!\n");
// return(-4);
//}
if ((commandargs.size() == 0) && (!settings))
#endif
if ((commandargs.size()==0))
{
displayHelp();
return (res);
}
if (settings)
{
}
else if (shell)
{
runShell();
return(0);
}
else
{
displayHelp();
return (res);
}
}
//printf("apppath: |%s|\n",appPath.c_str());
qoptions.ReadFile(Poco::Path::config()+"/parms.json",false);
qoptions.ReadFile(appPath+"/parms.json",true);
@ -176,7 +185,7 @@ int CLASS::runCommandLineApp(void)
if (isDebug()>0)
{
printf("SYNTAX: |%s|\n",language.c_str());
//printf("SYNTAX: |%s|\n",language.c_str());
}
try

3
qasm.h
View File

@ -9,6 +9,9 @@
#include <stdarg.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <functional>
#include <iostream>

37
shell.cpp Normal file
View File

@ -0,0 +1,37 @@
#include <qasm.h>
void runShell(void)
{
char *cmdline;
string cmd,orig;
string cmd1;
bool done=false;
const char *prompt="qasm: ";
using_history();
printf("\nWelcome to qAsm shell.\n\n");
while(!done)
{
cmdline=readline(prompt);
if (cmdline!=NULL)
{
cmd=cmdline;
free(cmdline);
cmd=trim(cmd);
orig=cmd;
cmd1=cmd;
cmd=toUpper(cmd);
if ((cmd=="QUIT") || (cmd=="EXIT"))
{
done=true;
}
else
{
add_history(orig.c_str());
system(orig.c_str());
}
//printf("\n");
}
}
}

27
src/tomerlin.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/bash
export NEWDIR=./QASMOUT
rm -rf $NEWDIR
mkdir -p $NEWDIR
mkdir -p $NEWDIR/ASM
mkdir -p $NEWDIR/LINK
mkdir -p $NEWDIR/INTCMD
mkdir -p $NEWDIR/MACS
mkdir -p $NEWDIR/TOOLS
mkdir -p $NEWDIR/EDIT
mkdir -p $NEWDIR/SHELL
mkdir -p $NEWDIR/MACROS
mkdir -p $NEWDIR/EXE
mkdir -p $NEWDIR/QASYSTEM
mkdir -p $NEWDIR/DATA
X=`find . -name "*.s"`
for F in $X ; do
export UP=`echo $F | tr '[:lower:]' '[:upper:]'`
UP=${NEWDIR}/${UP}
#echo $F $UP
#qasm -x format-merlin $F
qasm -x format-merlin ${F} >${UP}
done

66
test.s
View File

@ -1,6 +1,62 @@
org $1234
ABS nop
DFB $FF,#<ABS,#>ABS
lst off
xc off
xc
xc
ZP equ $00
org $2000
lda <$fff0 ;zp
lda >$fff0 ;ABS (lo word)
lda ^$fff0 ;ABS (hi word)
lda |$fff0 ;ABS (long in 65816 mode)
lda <$FFF0+$FFFF
lda <$fff0+24 ;zp
lda >$fff0+24 ;ABS (lo word)
lda ^$fff0+24 ;ABS (hi word)
lda |$fff0+24 ;ABS (long in 65816 mode)
ldal $fff0+24 ;ABS (long in 65816 mode)
lda: $fff0+24 ;ABS (long in 65816 mode)
lda: $00
mx %11
lda #<$fff0 ;zp
lda #>$fff0 ;ABS (lo word)
lda #^$fff0 ;ABS (hi word)
lda #<$FFF0+$FFFF
lda #>$FFF0+$FFFF
lda #^$FFF0+$FFFF
mx %00
lda #<$fff0 ;zp
lda #>$fff0 ;ABS (lo word)
lda #^$fff0 ;ABS (hi word)
lda #<$FFF0+$FFFF
lda #>$FFF0+$FFFF
lda #^$FFF0+$FFFF
ora ($00)
lda ($00)
bit: $FFFE,X
ror: $FFFE,X
ora #ZP
]DPNOP equ $80
lda ]DPNOP
jsr DPCODE
rts
ABS
org $0080
DPCODE nop
lda DPCODE
lda |DPCODE
lda >DPCODE
DFB $FF,#<ABS,#>ABS
dfb 'string';D7;\slash\
dfb 'string',D7,\slash\
lst
chk
lst off

View File

@ -2,6 +2,7 @@
; See the LICENSE.txt file for distribution terms (Apache 2.0).
;
; Assembler: Merlin 32
lst off
xc off
xc
xc