summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2021-11-07 17:10:14 -0800
committerAdrian Thurston <thurston@colm.net>2021-11-07 17:10:14 -0800
commit8b60d8eb3679337b9036988d2898558d5ef49117 (patch)
tree7e05ca84fbb85bb4220c5d0c8937358782aeee65
parent6e3af69137f6fbe000ce2d8dca33cef764722a40 (diff)
downloadragel-8b60d8eb3679337b9036988d2898558d5ef49117.tar.gz
moved HostLang type and makeCodeGen funcs to here from colm
-rw-r--r--src/Makefile.am2
-rw-r--r--src/allocgen.cc32
-rw-r--r--src/host-asm/main.cc1
-rw-r--r--src/host-c/main.cc1
-rw-r--r--src/host-crack/main.cc1
-rw-r--r--src/host-csharp/main.cc1
-rw-r--r--src/host-d/main.cc1
-rw-r--r--src/host-go/main.cc1
-rw-r--r--src/host-java/main.cc1
-rw-r--r--src/host-js/main.cc1
-rw-r--r--src/host-julia/main.cc1
-rw-r--r--src/host-ocaml/main.cc1
-rw-r--r--src/host-ruby/main.cc1
-rw-r--r--src/host-rust/main.cc1
-rw-r--r--src/inputdata.cc1
-rw-r--r--src/inputdata.h6
-rw-r--r--src/nragel.h27
-rw-r--r--src/parsedata.cc6
-rw-r--r--src/parsedata.h5
19 files changed, 68 insertions, 23 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8052c13a..02cd02f0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -19,7 +19,7 @@ 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 \
- ncommon.cc
+ ncommon.cc allocgen.cc
libragel_la_LDFLAGS = -no-undefined
libragel_la_LIBADD = $(LIBFSM_LA) $(LIBCOLM_LA)
diff --git a/src/allocgen.cc b/src/allocgen.cc
index fee37940..38514a76 100644
--- a/src/allocgen.cc
+++ b/src/allocgen.cc
@@ -20,29 +20,29 @@
* SOFTWARE.
*/
-#include "ragel.h"
+#include <libfsm/ragel.h>
+#include <libfsm/fsmgraph.h>
+#include <libfsm/gendata.h>
#include "parsedata.h"
-#include "fsmgraph.h"
-#include "gendata.h"
#include "inputdata.h"
#include "version.h"
/*
* Code generators.
*/
-#include "bingoto.h"
-#include "binbreak.h"
-#include "binvar.h"
-#include "flatgoto.h"
-#include "flatbreak.h"
-#include "flatvar.h"
-#include "switchgoto.h"
-#include "switchbreak.h"
-#include "switchvar.h"
-#include "gotoloop.h"
-#include "gotoexp.h"
-#include "ipgoto.h"
-#include "asm.h"
+#include <libfsm/bingoto.h>
+#include <libfsm/binbreak.h>
+#include <libfsm/binvar.h>
+#include <libfsm/flatgoto.h>
+#include <libfsm/flatbreak.h>
+#include <libfsm/flatvar.h>
+#include <libfsm/switchgoto.h>
+#include <libfsm/switchbreak.h>
+#include <libfsm/switchvar.h>
+#include <libfsm/gotoloop.h>
+#include <libfsm/gotoexp.h>
+#include <libfsm/ipgoto.h>
+#include <libfsm/asm.h>
CodeGenData *makeCodeGenAsm( const HostLang *hostLang, const CodeGenArgs &args )
{
diff --git a/src/host-asm/main.cc b/src/host-asm/main.cc
index 1c486100..1fa6c6b1 100644
--- a/src/host-asm/main.cc
+++ b/src/host-asm/main.cc
@@ -21,6 +21,7 @@
*/
#include "inputdata.h"
+#include "nragel.h"
#include <libfsm/asm.h>
extern struct colm_sections rlparseAsm;
diff --git a/src/host-c/main.cc b/src/host-c/main.cc
index 8d7a7514..0bb40644 100644
--- a/src/host-c/main.cc
+++ b/src/host-c/main.cc
@@ -21,6 +21,7 @@
*/
#include "inputdata.h"
+#include "nragel.h"
extern struct colm_sections rlparseC;
extern struct colm_sections rlhcC;
diff --git a/src/host-crack/main.cc b/src/host-crack/main.cc
index dd45fd1b..54eacd09 100644
--- a/src/host-crack/main.cc
+++ b/src/host-crack/main.cc
@@ -21,6 +21,7 @@
*/
#include "inputdata.h"
+#include "nragel.h"
extern struct colm_sections rlparseCrack;
extern struct colm_sections rlhcCrack;
diff --git a/src/host-csharp/main.cc b/src/host-csharp/main.cc
index 330e6b37..548df374 100644
--- a/src/host-csharp/main.cc
+++ b/src/host-csharp/main.cc
@@ -21,6 +21,7 @@
*/
#include "inputdata.h"
+#include "nragel.h"
extern struct colm_sections rlparseCSharp;
extern struct colm_sections rlhcCSharp;
diff --git a/src/host-d/main.cc b/src/host-d/main.cc
index 6841f2e9..7ec6fb22 100644
--- a/src/host-d/main.cc
+++ b/src/host-d/main.cc
@@ -21,6 +21,7 @@
*/
#include "inputdata.h"
+#include "nragel.h"
extern struct colm_sections rlparseD;
extern struct colm_sections rlhcD;
diff --git a/src/host-go/main.cc b/src/host-go/main.cc
index 99fb50d7..792927df 100644
--- a/src/host-go/main.cc
+++ b/src/host-go/main.cc
@@ -21,6 +21,7 @@
*/
#include "inputdata.h"
+#include "nragel.h"
extern struct colm_sections rlparseGo;
extern struct colm_sections rlhcGo;
diff --git a/src/host-java/main.cc b/src/host-java/main.cc
index 9899a053..f70d2cf9 100644
--- a/src/host-java/main.cc
+++ b/src/host-java/main.cc
@@ -21,6 +21,7 @@
*/
#include "inputdata.h"
+#include "nragel.h"
extern struct colm_sections rlparseJava;
extern struct colm_sections rlhcJava;
diff --git a/src/host-js/main.cc b/src/host-js/main.cc
index e52c02df..54ad7e15 100644
--- a/src/host-js/main.cc
+++ b/src/host-js/main.cc
@@ -21,6 +21,7 @@
*/
#include "inputdata.h"
+#include "nragel.h"
extern struct colm_sections rlparseJs;
extern struct colm_sections rlhcJs;
diff --git a/src/host-julia/main.cc b/src/host-julia/main.cc
index f06d7493..9fae58d4 100644
--- a/src/host-julia/main.cc
+++ b/src/host-julia/main.cc
@@ -21,6 +21,7 @@
*/
#include "inputdata.h"
+#include "nragel.h"
extern struct colm_sections rlparseJulia;
extern struct colm_sections rlhcJulia;
diff --git a/src/host-ocaml/main.cc b/src/host-ocaml/main.cc
index 36f3d030..b8de16e4 100644
--- a/src/host-ocaml/main.cc
+++ b/src/host-ocaml/main.cc
@@ -21,6 +21,7 @@
*/
#include "inputdata.h"
+#include "nragel.h"
extern struct colm_sections rlparseOCaml;
extern struct colm_sections rlhcOCaml;
diff --git a/src/host-ruby/main.cc b/src/host-ruby/main.cc
index 0398cafd..19fc4d37 100644
--- a/src/host-ruby/main.cc
+++ b/src/host-ruby/main.cc
@@ -21,6 +21,7 @@
*/
#include "inputdata.h"
+#include "nragel.h"
extern struct colm_sections rlparseRuby;
extern struct colm_sections rlhcRuby;
diff --git a/src/host-rust/main.cc b/src/host-rust/main.cc
index 6f4bedd0..106d3566 100644
--- a/src/host-rust/main.cc
+++ b/src/host-rust/main.cc
@@ -21,6 +21,7 @@
*/
#include "inputdata.h"
+#include "nragel.h"
extern struct colm_sections rlparseRust;
extern struct colm_sections rlhcRust;
diff --git a/src/inputdata.cc b/src/inputdata.cc
index 7805c9c2..2f58e706 100644
--- a/src/inputdata.cc
+++ b/src/inputdata.cc
@@ -29,6 +29,7 @@
#include "reducer.h"
#include "version.h"
#include "pcheck.h"
+#include "nragel.h"
#include <libfsm/dot.h>
#include <colm/colm.h>
diff --git a/src/inputdata.h b/src/inputdata.h
index 6793acd1..52096afe 100644
--- a/src/inputdata.h
+++ b/src/inputdata.h
@@ -23,6 +23,7 @@
#ifndef _INPUT_DATA
#define _INPUT_DATA
+#include "nragel.h"
#include <libfsm/gendata.h>
#include <iostream>
#include <sstream>
@@ -173,7 +174,8 @@ struct InputData
InputData( const HostLang *hostLang,
struct colm_sections *frontendSections, struct colm_sections *rlhcSections )
:
- FsmGbl(hostLang),
+ FsmGbl(),
+ hostLang(hostLang),
frontendSections(frontendSections),
rlhcSections(rlhcSections),
inputFileName(0),
@@ -214,6 +216,8 @@ struct InputData
~InputData();
+ const HostLang *hostLang;
+
void usage();
void version();
void showFrontends();
diff --git a/src/nragel.h b/src/nragel.h
index f8c7f4ad..11bca028 100644
--- a/src/nragel.h
+++ b/src/nragel.h
@@ -4,8 +4,35 @@
#include <libfsm/common.h>
#include <libfsm/ragel.h>
+struct HostLang;
+
HostType *findAlphType( const HostLang *hostLang, const char *s1 );
HostType *findAlphType( const HostLang *hostLang, const char *s1, const char *s2 );
HostType *findAlphTypeInternal( const HostLang *hostLang, const char *s1 );
+CodeGenData *makeCodeGen( const HostLang *hostLang, const CodeGenArgs &args );
+CodeGenData *makeCodeGenAsm( const HostLang *hostLang, const CodeGenArgs &args );
+
+/* Selects and constructs the codegen based on the output options. */
+CodeGenData *makeCodeGen( const HostLang *hostLang, const CodeGenArgs &args );
+CodeGenData *asm_makeCodeGen( const HostLang *hostLang, const CodeGenArgs &args );
+
+typedef CodeGenData *(*MakeCodeGenT)( const HostLang *hostLang, const CodeGenArgs &args );
+
+struct HostLang
+{
+ HostType *hostTypes;
+ int numHostTypes;
+ int defaultAlphType;
+ bool explicitUnsigned;
+ bool loopLabels;
+
+ RagelBackend backend;
+ BackendFeature feature;
+
+ MakeCodeGenT makeCodeGen;
+ DefaultOutFnT defaultOutFn;
+ GenLineDirectiveT genLineDirective;
+};
+
#endif
diff --git a/src/parsedata.cc b/src/parsedata.cc
index 07474582..f18d8af3 100644
--- a/src/parsedata.cc
+++ b/src/parsedata.cc
@@ -1022,7 +1022,7 @@ void ParseData::initKeyOps( const HostLang *hostLang )
{
/* Signedness and bounds. */
alphType = alphTypeSet ? userAlphType : &hostLang->hostTypes[hostLang->defaultAlphType];
- fsmCtx->keyOps->setAlphType( hostLang, alphType );
+ fsmCtx->keyOps->setAlphType( hostLang->explicitUnsigned, alphType );
if ( lowerNum != 0 ) {
/* If ranges are given then interpret the alphabet type. */
@@ -1450,9 +1450,9 @@ void ParseData::generateReduced( const char *inputFileName, CodeStyle codeStyle,
std::ostream &out, const HostLang *hostLang )
{
Reducer *red = new Reducer( this->id, fsmCtx, sectionGraph, sectionName, machineId );
- red->make( hostLang, alphType );
+ red->make();
- CodeGenArgs args( this->id, red, alphType, machineId, inputFileName, sectionName, out, codeStyle );
+ CodeGenArgs args( this->id, red, alphType, machineId, inputFileName, sectionName, out, codeStyle, hostLang->genLineDirective, hostLang->backend );
args.lineDirectives = !id->noLineDirectives;
args.forceVar = id->forceVar;
diff --git a/src/parsedata.h b/src/parsedata.h
index 109f36e6..798e9388 100644
--- a/src/parsedata.h
+++ b/src/parsedata.h
@@ -33,11 +33,12 @@
#include "bstmap.h"
#include "vector.h"
#include "dlist.h"
-#include <libfsm/fsmgraph.h>
#include "compare.h"
#include "vector.h"
-#include <libfsm/common.h>
#include "parsetree.h"
+#include "nragel.h"
+#include <libfsm/fsmgraph.h>
+#include <libfsm/common.h>
#include <libfsm/action.h>