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 ### Language
* Missing warnings for all kind of abuses * Missing warnings for all kind of abuses
* no goto or C label support, but keyword protected
### Linker ### Linker
@ -104,6 +105,7 @@ The compiler is command line driven, and creates an executable .prg file.
* -bc : create byte code for all functions * -bc : create byte code for all functions
* -n : create pure native code for all functions (now default) * -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 (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 * -O1 or -O : default optimizations
* -O0 : disable optimizations * -O0 : disable optimizations
* -O2 : more aggressive speed optimizations including auto inline of small functions * -O2 : more aggressive speed optimizations including auto inline of small functions

View File

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

View File

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

View File

@ -27,6 +27,7 @@ enum Token
TK_DEFAULT, TK_DEFAULT,
TK_BREAK, TK_BREAK,
TK_RETURN, TK_RETURN,
TK_GOTO,
TK_SHORT, TK_SHORT,
TK_LONG, TK_LONG,
TK_CONTINUE, 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__"), "1");
compiler->AddDefine(Ident::Unique("__STDC_VERSION__"), "199901L"); compiler->AddDefine(Ident::Unique("__STDC_VERSION__"), "199901L");
bool defining = false;
for (int i = 1; i < argc; i++) for (int i = 1; i < argc; i++)
{ {
const char* arg = argv[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] == '=') if (arg[1] == 'i' && arg[2] == '=')
{ {
@ -230,6 +249,10 @@ int main2(int argc, const char** argv)
else if (arg[2] == 'b') else if (arg[2] == 'b')
trace = 1; trace = 1;
} }
else if (arg[1] == 'D' && !arg[2])
{
defining = true;
}
else if (arg[1] == 'd') else if (arg[1] == 'd')
{ {
char def[100]; char def[100];