Add -D for gcc compliant defines

This commit is contained in:
drmortalwombat 2024-06-24 18:14:07 +02:00
parent 9678814654
commit a71c433fc4
5 changed files with 35 additions and 1 deletions

View File

@ -28,6 +28,7 @@ There are still several open areas, but most targets have been reached. The cur
### Language
* Missing warnings for all kind of abuses
* no goto or C label support, but keyword protected
### Linker
@ -104,6 +105,7 @@ The compiler is command line driven, and creates an executable .prg file.
* -bc : create byte code for all functions
* -n : create pure native code for all functions (now default)
* -d : define a symbol (e.g. NOFLOAT or NOLONG to avoid float/long code in printf)
* -D : define a symbol in a gcc compliant way (e.g. -D NAME=VALUE)
* -O1 or -O : default optimizations
* -O0 : disable optimizations
* -O2 : more aggressive speed optimizations including auto inline of small functions

View File

@ -9320,6 +9320,11 @@ Expression* Parser::ParseStatement(void)
exp->mLeft = ParseParenthesisExpression();
ConsumeToken(TK_SEMICOLON);
break;
case TK_GOTO:
mErrors->Error(mScanner->mLocation, EERR_UNIMPLEMENTED, "'goto' not implemented");
mScanner->NextToken();
exp = new Expression(mScanner->mLocation, EX_VOID);
break;
default:
exp = CleanupExpression(ParseListExpression(true));

View File

@ -29,6 +29,7 @@ const char* TokenNames[] =
"'default'",
"'break'",
"'return'",
"'goto'",
"'short'",
"'long'",
"'continue'",
@ -1702,6 +1703,8 @@ void Scanner::NextRawToken(void)
mToken = TK_CONTINUE;
else if (!strcmp(tkident, "return"))
mToken = TK_RETURN;
else if (!strcmp(tkident, "goto"))
mToken = TK_GOTO;
else if (!strcmp(tkident, "void"))
mToken = TK_VOID;
else if (!strcmp(tkident, "struct"))

View File

@ -27,6 +27,7 @@ enum Token
TK_DEFAULT,
TK_BREAK,
TK_RETURN,
TK_GOTO,
TK_SHORT,
TK_LONG,
TK_CONTINUE,

View File

@ -134,10 +134,29 @@ int main2(int argc, const char** argv)
compiler->AddDefine(Ident::Unique("__STDC__"), "1");
compiler->AddDefine(Ident::Unique("__STDC_VERSION__"), "199901L");
bool defining = false;
for (int i = 1; i < argc; i++)
{
const char* arg = argv[i];
if (arg[0] == '-')
if (defining)
{
defining = false;
char def[100];
int i = 0;
while (arg[i] && arg[i] != '=')
{
def[i] = arg[i];
i++;
}
def[i] = 0;
if (arg[i] == '=')
compiler->AddDefine(Ident::Unique(def), _strdup(arg + i + 1));
else
compiler->AddDefine(Ident::Unique(def), "");
}
else if (arg[0] == '-')
{
if (arg[1] == 'i' && arg[2] == '=')
{
@ -230,6 +249,10 @@ int main2(int argc, const char** argv)
else if (arg[2] == 'b')
trace = 1;
}
else if (arg[1] == 'D' && !arg[2])
{
defining = true;
}
else if (arg[1] == 'd')
{
char def[100];