summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2021-11-07 15:09:53 -0800
committerAdrian Thurston <thurston@colm.net>2021-11-07 15:09:53 -0800
commitee588e7fb921afbad8c6b171f69ebd1161f66850 (patch)
tree3d4ab4266b3f79a05be5fc047e4246a645dd4f5f
parent8f4f87b3aa48cccfc7f7c9badf0f6dbef7c8f3df (diff)
downloadragel-ee588e7fb921afbad8c6b171f69ebd1161f66850.tar.gz
moved C and ASM host types here from colm
-rw-r--r--src/Makefile.am3
-rw-r--r--src/common.cc74
-rw-r--r--src/host-asm/main.cc35
-rw-r--r--src/host-c/main.cc3
-rw-r--r--src/main.cc1
-rw-r--r--src/ncommon.cc70
6 files changed, 111 insertions, 75 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index c4fe531c..8052c13a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,7 +18,8 @@ libragel_la_CPPFLAGS = -I$(top_srcdir)/aapl -I$(top_srcdir)/colm/include -DBINDI
dist_libragel_la_SOURCES = \
parsedata.h parsetree.h inputdata.h pcheck.h reducer.h rlscan.h load.h \
- parsetree.cc longest.cc parsedata.cc inputdata.cc load.cc reducer.cc
+ parsetree.cc longest.cc parsedata.cc inputdata.cc load.cc reducer.cc \
+ ncommon.cc
libragel_la_LDFLAGS = -no-undefined
libragel_la_LIBADD = $(LIBFSM_LA) $(LIBCOLM_LA)
diff --git a/src/common.cc b/src/common.cc
index 027b945c..b36dcace 100644
--- a/src/common.cc
+++ b/src/common.cc
@@ -27,80 +27,6 @@
#include <assert.h>
#include "ragel.h"
-/*
- * C
- */
-
-const char *defaultOutFnC( 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[] =
-{
- { "char", 0, "char", (CHAR_MIN != 0), true, false, SCHAR_MIN, SCHAR_MAX, 0, UCHAR_MAX, sizeof(char) },
- { "signed", "char", "char", true, true, false, SCHAR_MIN, SCHAR_MAX, 0, 0, sizeof(signed 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) },
- { "signed", "short", "short", true, true, false, SHRT_MIN, SHRT_MAX, 0, 0, sizeof(signed short) },
- { "unsigned", "short", "ushort", false, true, false, 0, 0, 0, USHRT_MAX, sizeof(unsigned short) },
- { "int", 0, "int", true, true, false, INT_MIN, INT_MAX, 0, 0, sizeof(int) },
- { "signed", "int", "int", true, true, false, INT_MIN, INT_MAX, 0, 0, sizeof(signed 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) },
- { "signed", "long", "long", true, true, false, LONG_MIN, LONG_MAX, 0, 0, sizeof(signed long) },
- { "unsigned", "long", "ulong", false, true, false, 0, 0, 0, ULONG_MAX, sizeof(unsigned long) },
-};
-
-const HostLang hostLangC = {
- hostTypesC,
- 12,
- 0,
- true,
- false, /* loopLabels */
- Direct,
- GotoFeature,
- &makeCodeGen,
- &defaultOutFnC,
- &genLineDirectiveC
-};
-
-/*
- * ASM
- */
-const char *defaultOutFnAsm( 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_MAX, 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 = {
- hostTypesAsm,
- 8,
- 0,
- true,
- false, /* loopLabels */
- Direct,
- GotoFeature,
- &makeCodeGenAsm,
- &defaultOutFnC,
- &genLineDirectiveAsm
-};
HostType *findAlphType( const HostLang *hostLang, const char *s1 )
{
diff --git a/src/host-asm/main.cc b/src/host-asm/main.cc
index c5523737..1c486100 100644
--- a/src/host-asm/main.cc
+++ b/src/host-asm/main.cc
@@ -25,6 +25,41 @@
extern struct colm_sections rlparseAsm;
+extern "C" const HostLang hostLangAsm;
+
+/*
+ * ASM
+ */
+const char *defaultOutFnAsm( 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_MAX, 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) },
+};
+
+extern "C" const HostLang hostLangAsm = {
+ hostTypesAsm,
+ 8,
+ 0,
+ true,
+ false, /* loopLabels */
+ Direct,
+ GotoFeature,
+ &makeCodeGenAsm,
+ &defaultOutFnAsm,
+ &genLineDirectiveAsm
+};
+
int main( int argc, const char **argv )
{
InputData id( &hostLangAsm, &rlparseAsm, 0 );
diff --git a/src/host-c/main.cc b/src/host-c/main.cc
index 20c7e6da..8d7a7514 100644
--- a/src/host-c/main.cc
+++ b/src/host-c/main.cc
@@ -25,6 +25,9 @@
extern struct colm_sections rlparseC;
extern struct colm_sections rlhcC;
+extern const char *defaultOutFnC( const char *inputFileName );
+extern HostType hostTypesC[];
+
const HostLang hostLangC_translated =
{
hostTypesC,
diff --git a/src/main.cc b/src/main.cc
index e9c5db39..4768b4a8 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -23,6 +23,7 @@
#include "inputdata.h"
extern struct colm_sections rlparseC;
+extern "C" const HostLang hostLangC;
int main( int argc, const char **argv )
{
diff --git a/src/ncommon.cc b/src/ncommon.cc
new file mode 100644
index 00000000..ae959efd
--- /dev/null
+++ b/src/ncommon.cc
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2006-2018 Adrian Thurston <thurston@colm.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * 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
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "stdlib.h"
+#include <string.h>
+#include <assert.h>
+#include <libfsm/common.h>
+#include <libfsm/ragel.h>
+
+/*
+ * C
+ */
+
+const char *defaultOutFnC( 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[] =
+{
+ { "char", 0, "char", (CHAR_MIN != 0), true, false, SCHAR_MIN, SCHAR_MAX, 0, UCHAR_MAX, sizeof(char) },
+ { "signed", "char", "char", true, true, false, SCHAR_MIN, SCHAR_MAX, 0, 0, sizeof(signed 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) },
+ { "signed", "short", "short", true, true, false, SHRT_MIN, SHRT_MAX, 0, 0, sizeof(signed short) },
+ { "unsigned", "short", "ushort", false, true, false, 0, 0, 0, USHRT_MAX, sizeof(unsigned short) },
+ { "int", 0, "int", true, true, false, INT_MIN, INT_MAX, 0, 0, sizeof(int) },
+ { "signed", "int", "int", true, true, false, INT_MIN, INT_MAX, 0, 0, sizeof(signed 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) },
+ { "signed", "long", "long", true, true, false, LONG_MIN, LONG_MAX, 0, 0, sizeof(signed long) },
+ { "unsigned", "long", "ulong", false, true, false, 0, 0, 0, ULONG_MAX, sizeof(unsigned long) },
+};
+
+extern "C" const HostLang hostLangC = {
+ hostTypesC,
+ 12,
+ 0,
+ true,
+ false, /* loopLabels */
+ Direct,
+ GotoFeature,
+ &makeCodeGen,
+ &defaultOutFnC,
+ &genLineDirectiveC
+};
+