common.cc (ragel-7.0.0.10) | : | common.cc (ragel-7.0.0.11) | ||
---|---|---|---|---|
/* | /* | |||
* Copyright 2006-2007 Adrian Thurston <thurston@colm.net> | * Copyright 2006-2018 Adrian Thurston <thurston@colm.net> | |||
* | * | |||
* Permission is hereby granted, free of charge, to any person obtaining a copy | * Permission is hereby granted, free of charge, to any person obtaining a copy | |||
* of this software and associated documentation files (the "Software"), to | * of this software and associated documentation files (the "Software"), to | |||
* deal in the Software without restriction, including without limitation the | * deal in the Software without restriction, including without limitation the | |||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |||
* sell copies of the Software, and to permit persons to whom the Software is | * sell copies of the Software, and to permit persons to whom the Software is | |||
* furnished to do so, subject to the following conditions: | * furnished to do so, subject to the following conditions: | |||
* | * | |||
* The above copyright notice and this permission notice shall be included in al l | * The above copyright notice and this permission notice shall be included in al l | |||
* copies or substantial portions of the Software. | * copies or substantial portions of the Software. | |||
skipping to change at line 30 | skipping to change at line 30 | |||
* SOFTWARE. | * SOFTWARE. | |||
*/ | */ | |||
#include "pcheck.h" | #include "pcheck.h" | |||
#include "common.h" | #include "common.h" | |||
#include "stdlib.h" | #include "stdlib.h" | |||
#include <string.h> | #include <string.h> | |||
#include <assert.h> | #include <assert.h> | |||
#include "ragel.h" | #include "ragel.h" | |||
/* | ||||
* C | ||||
*/ | ||||
const char *c_defaultOutFn( const char *inputFileName ) | ||||
{ | ||||
const char *ext = findFileExtension( inputFileName ); | ||||
if ( ext != 0 && strcmp( ext, ".rh" ) == 0 ) | ||||
return fileNameFromStem( inputFileName, ".h" ); | ||||
else | ||||
return fileNameFromStem( inputFileName, ".c" ); | ||||
} | ||||
HostType hostTypesC[] = | HostType hostTypesC[] = | |||
{ | { | |||
{ "char", 0, "char", true, true, false, CHAR_MIN, CHAR_ MAX, 0, 0, sizeof(char) }, | { "char", 0, "char", true, true, false, CHAR_MIN, CHAR_ MAX, 0, 0, sizeof(char) }, | |||
{ "unsigned", "char", "uchar", false, true, false, 0, 0, 0, UCHAR_MAX, sizeof(unsigned char) }, | { "unsigned", "char", "uchar", false, true, false, 0, 0, 0, UCHAR_MAX, sizeof(unsigned char) }, | |||
{ "short", 0, "short", true, true, false, SHRT_MIN, SHRT_ MAX, 0, 0, sizeof(short) }, | { "short", 0, "short", true, true, false, SHRT_MIN, SHRT_ MAX, 0, 0, sizeof(short) }, | |||
{ "unsigned", "short", "ushort", false, true, false, 0, 0, 0, USHRT_MAX, sizeof(unsigned short) }, | { "unsigned", "short", "ushort", false, true, false, 0, 0, 0, USHRT_MAX, sizeof(unsigned short) }, | |||
{ "int", 0, "int", true, true, false, INT_MIN, INT_M AX, 0, 0, sizeof(int) }, | { "int", 0, "int", true, true, false, INT_MIN, INT_M AX, 0, 0, sizeof(int) }, | |||
{ "unsigned", "int", "uint", false, true, false, 0, 0, 0, UINT_MAX, sizeof(unsigned int) }, | { "unsigned", "int", "uint", false, true, false, 0, 0, 0, UINT_MAX, sizeof(unsigned int) }, | |||
{ "long", 0, "long", true, true, false, LONG_MIN, LONG_ MAX, 0, 0, sizeof(long) }, | { "long", 0, "long", true, true, false, LONG_MIN, LONG_ MAX, 0, 0, sizeof(long) }, | |||
{ "unsigned", "long", "ulong", false, true, false, 0, 0, 0, ULONG_MAX, sizeof(unsigned long) }, | { "unsigned", "long", "ulong", false, true, false, 0, 0, 0, ULONG_MAX, sizeof(unsigned long) }, | |||
}; | }; | |||
const HostLang hostLangC = { | const HostLang hostLangC = { | |||
"C", | "C", | |||
"-C", | "-C", | |||
HostLang::C, | (HostLang::Lang)-1, | |||
hostTypesC, 8, | hostTypesC, 8, | |||
hostTypesC+0, | hostTypesC+0, | |||
true, | true, | |||
false, | false, | |||
"c" | "c", | |||
&c_defaultOutFn, | ||||
&makeCodeGen, | ||||
Direct, | ||||
GotoFeature | ||||
}; | ||||
/* | ||||
* ASM | ||||
*/ | ||||
const char *asm_defaultOutFn( const char *inputFileName ) | ||||
{ | ||||
return fileNameFromStem( inputFileName, ".s" ); | ||||
} | ||||
HostType hostTypesAsm[] = | ||||
{ | ||||
{ "char", 0, "char", true, true, false, CHAR_MIN, CHAR_ | ||||
MAX, 0, 0, sizeof(char) }, | ||||
{ "unsigned", "char", "uchar", false, true, false, 0, 0, | ||||
0, UCHAR_MAX, sizeof(unsigned char) }, | ||||
{ "short", 0, "short", true, true, false, SHRT_MIN, SHRT_ | ||||
MAX, 0, 0, sizeof(short) }, | ||||
{ "unsigned", "short", "ushort", false, true, false, 0, 0, | ||||
0, USHRT_MAX, sizeof(unsigned short) }, | ||||
{ "int", 0, "int", true, true, false, INT_MIN, INT_M | ||||
AX, 0, 0, sizeof(int) }, | ||||
{ "unsigned", "int", "uint", false, true, false, 0, 0, | ||||
0, UINT_MAX, sizeof(unsigned int) }, | ||||
{ "long", 0, "long", true, true, false, LONG_MIN, LONG_ | ||||
MAX, 0, 0, sizeof(long) }, | ||||
{ "unsigned", "long", "ulong", false, true, false, 0, 0, | ||||
0, ULONG_MAX, sizeof(unsigned long) }, | ||||
}; | }; | |||
const HostLang hostLangAsm = { | const HostLang hostLangAsm = { | |||
"ASM", | "ASM", | |||
"--asm", | "--asm", | |||
HostLang::Asm, | (HostLang::Lang)-1, | |||
hostTypesC, 8, | hostTypesAsm, 8, | |||
hostTypesC+0, | hostTypesAsm+0, | |||
true, | true, | |||
false, | false, | |||
"no-lang" | "no-lang", | |||
&asm_defaultOutFn, | ||||
&asm_makeCodeGen, | ||||
Direct, | ||||
GotoFeature | ||||
}; | }; | |||
const HostLang *hostLangs[] = { | const HostLang *hostLangs[] = { | |||
&hostLangC, | &hostLangC, | |||
&hostLangAsm, | ||||
}; | }; | |||
const int numHostLangs = sizeof(hostLangs)/sizeof(hostLangs[0]); | const int numHostLangs = sizeof(hostLangs)/sizeof(hostLangs[0]); | |||
HostType *findAlphType( const HostLang *hostLang, const char *s1 ) | HostType *findAlphType( const HostLang *hostLang, const char *s1 ) | |||
{ | { | |||
for ( int i = 0; i < hostLang->numHostTypes; i++ ) { | for ( int i = 0; i < hostLang->numHostTypes; i++ ) { | |||
if ( strcmp( s1, hostLang->hostTypes[i].data1 ) == 0 && | if ( strcmp( s1, hostLang->hostTypes[i].data1 ) == 0 && | |||
hostLang->hostTypes[i].data2 == 0 ) | hostLang->hostTypes[i].data2 == 0 ) | |||
{ | { | |||
End of changes. 7 change blocks. | ||||
8 lines changed or deleted | 56 lines changed or added |