summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2021-11-07 17:09:50 -0800
committerAdrian Thurston <thurston@colm.net>2021-11-07 17:09:50 -0800
commitc7c7742f7038694cb20ce5bee33679d42f065d94 (patch)
tree99a341b00df38a9ad11ddba7eb5a748b5dddf21a
parent6877df322fe8bbcf05212dd6bf333ba4d6564c4f (diff)
downloadcolm-c7c7742f7038694cb20ce5bee33679d42f065d94.tar.gz
moved HostLang type and makeCodeGen funcs to ragel
-rw-r--r--src/libfsm/Makefile.am18
-rw-r--r--src/libfsm/allocgen.cc92
-rw-r--r--src/libfsm/codegen.cc2
-rw-r--r--src/libfsm/common.h25
-rw-r--r--src/libfsm/fsmgraph.h4
-rw-r--r--src/libfsm/gendata.cc2
-rw-r--r--src/libfsm/gendata.h16
7 files changed, 22 insertions, 137 deletions
diff --git a/src/libfsm/Makefile.am b/src/libfsm/Makefile.am
index 4174548a..42d009ee 100644
--- a/src/libfsm/Makefile.am
+++ b/src/libfsm/Makefile.am
@@ -6,7 +6,15 @@ lib_LTLIBRARIES = libfsm.la
libfsminclude_HEADERS = \
action.h fsmgraph.h common.h \
- gendata.h redfsm.h dot.h asm.h ragel.h
+ gendata.h redfsm.h dot.h asm.h ragel.h \
+ binary.h bingoto.h binbreak.h binvar.h \
+ flat.h flatgoto.h flatbreak.h flatvar.h \
+ switch.h switchgoto.h switchbreak.h switchvar.h \
+ goto.h gotoloop.h gotoexp.h \
+ parsedata.h idbase.h codegen.h \
+ tables.h \
+ actloop.h actexp.h \
+ ipgoto.h
# nodist_pkginclude_HEADERS = config.h
@@ -16,14 +24,6 @@ libfsminclude_HEADERS = \
libfsm_la_CPPFLAGS = -I$(top_srcdir)/src/aapl
dist_libfsm_la_SOURCES = \
- parsedata.h idbase.h codegen.h \
- actloop.h actexp.h \
- tables.h \
- binary.h bingoto.h binbreak.h binvar.h \
- flat.h flatgoto.h flatbreak.h flatvar.h \
- switch.h switchgoto.h switchbreak.h switchvar.h \
- goto.h gotoloop.h gotoexp.h \
- ipgoto.h asm.h \
idbase.cc fsmstate.cc fsmbase.cc fsmattach.cc fsmmin.cc fsmgraph.cc \
fsmap.cc fsmcond.cc fsmnfa.cc common.cc redfsm.cc gendata.cc \
allocgen.cc codegen.cc \
diff --git a/src/libfsm/allocgen.cc b/src/libfsm/allocgen.cc
index 02278bfa..991cf62d 100644
--- a/src/libfsm/allocgen.cc
+++ b/src/libfsm/allocgen.cc
@@ -42,95 +42,3 @@
#include "ipgoto.h"
#include "asm.h"
-CodeGenData *makeCodeGenAsm( const HostLang *hostLang, const CodeGenArgs &args )
-{
- return new AsmCodeGen( args );
-}
-
-/* Invoked by the parser when a ragel definition is opened. */
-CodeGenData *makeCodeGen( const HostLang *hostLang, const CodeGenArgs &args )
-{
- FsmGbl *id = args.id;
- CodeGenData *codeGen = 0;
- BackendFeature feature = hostLang->feature;
- if ( args.forceVar )
- feature = VarFeature;
-
- switch ( args.codeStyle ) {
- case GenBinaryLoop:
- if ( feature == GotoFeature )
- codeGen = new BinGotoLoop( args );
- else if ( feature == BreakFeature )
- codeGen = new BinBreakLoop( args );
- else
- codeGen = new BinVarLoop( args );
- break;
-
- case GenBinaryExp:
- if ( feature == GotoFeature )
- codeGen = new BinGotoExp( args );
- else if ( feature == BreakFeature )
- codeGen = new BinBreakExp( args );
- else
- codeGen = new BinVarExp( args );
- break;
-
- case GenFlatLoop:
- if ( feature == GotoFeature )
- codeGen = new FlatGotoLoop( args );
- else if ( feature == BreakFeature )
- codeGen = new FlatBreakLoop( args );
- else
- codeGen = new FlatVarLoop( args );
- break;
-
- case GenFlatExp:
- if ( feature == GotoFeature )
- codeGen = new FlatGotoExp( args );
- else if ( feature == BreakFeature )
- codeGen = new FlatBreakExp( args );
- else
- codeGen = new FlatVarExp( args );
- break;
- case GenSwitchLoop:
- if ( feature == GotoFeature )
- codeGen = new SwitchGotoLoop( args );
- else if ( feature == BreakFeature )
- codeGen = new SwitchBreakLoop( args );
- else
- codeGen = new SwitchVarLoop( args );
- break;
-
- case GenSwitchExp:
- if ( feature == GotoFeature )
- codeGen = new SwitchGotoExp( args );
- else if ( feature == BreakFeature )
- codeGen = new SwitchBreakExp( args );
- else
- codeGen = new SwitchVarExp( args );
- break;
-
-
- case GenGotoLoop:
- if ( feature == GotoFeature )
- codeGen = new GotoLoop(args);
- else
- id->error() << "unsupported lang/style combination" << endp;
- break;
- case GenGotoExp:
- if ( feature == GotoFeature )
- codeGen = new GotoExp(args);
- else
- id->error() << "unsupported lang/style combination" << endp;
- break;
-
- case GenIpGoto:
- if ( feature == GotoFeature )
- codeGen = new IpGoto(args);
- else
- id->error() << "unsupported lang/style combination" << endp;
- break;
- }
-
- return codeGen;
-}
diff --git a/src/libfsm/codegen.cc b/src/libfsm/codegen.cc
index ac06aaf8..21edb5ac 100644
--- a/src/libfsm/codegen.cc
+++ b/src/libfsm/codegen.cc
@@ -361,7 +361,7 @@ CodeGen::CodeGen( const CodeGenArgs &args )
new_recs( "new_recs" ),
alt( "_alt" ),
tableData( 0 ),
- backend( args.id->hostLang->backend ),
+ backend( args.backend ),
stringTables( args.id->stringTables ),
nfaTargs( "nfa_targs", *this ),
diff --git a/src/libfsm/common.h b/src/libfsm/common.h
index 2be2bb55..964a3908 100644
--- a/src/libfsm/common.h
+++ b/src/libfsm/common.h
@@ -32,7 +32,6 @@ struct colm_location;
struct InputData;
struct CodeGenData;
-struct HostLang;
struct CodeGenArgs;
enum RagelBackend
@@ -220,23 +219,6 @@ struct HostType
typedef void (*GenLineDirectiveT)( std::ostream &out, bool nld, int line, const char *file );
typedef const char *(*DefaultOutFnT)( const char *inputFileName );
-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;
-};
void genLineDirectiveC( std::ostream &out, bool nld, int line, const char *file );
void genLineDirectiveAsm( std::ostream &out, bool nld, int line, const char *file );
@@ -259,10 +241,10 @@ struct KeyOps
bool explicitUnsigned;
Key minKey, maxKey;
- void setAlphType( const HostLang *hostLang, const HostType *alphType )
+ void setAlphType( bool explicitUnsigned, const HostType *alphType )
{
isSigned = alphType->isSigned;
- explicitUnsigned = hostLang->explicitUnsigned;
+ this->explicitUnsigned = explicitUnsigned;
if ( isSigned ) {
minKey = (long) alphType->sMinVal;
@@ -488,7 +470,4 @@ enum RagelFrontend
ReduceBased
};
-CodeGenData *makeCodeGen( const HostLang *hostLang, const CodeGenArgs &args );
-CodeGenData *makeCodeGenAsm( const HostLang *hostLang, const CodeGenArgs &args );
-
#endif
diff --git a/src/libfsm/fsmgraph.h b/src/libfsm/fsmgraph.h
index aee6f718..de55b0c1 100644
--- a/src/libfsm/fsmgraph.h
+++ b/src/libfsm/fsmgraph.h
@@ -1016,12 +1016,11 @@ struct CondData
struct FsmGbl
{
- FsmGbl( const HostLang *hostLang )
+ FsmGbl()
:
printStatistics(false),
errorCount(0),
displayPrintables(false),
- hostLang(hostLang),
stringTables(false),
checkPriorInteraction(0),
wantDupsRemoved(true),
@@ -1060,7 +1059,6 @@ struct FsmGbl
void abortCompile( int code );
bool displayPrintables;
- const HostLang *hostLang;
bool stringTables;
bool checkPriorInteraction;
bool wantDupsRemoved;
diff --git a/src/libfsm/gendata.cc b/src/libfsm/gendata.cc
index 355ed12c..8226ae60 100644
--- a/src/libfsm/gendata.cc
+++ b/src/libfsm/gendata.cc
@@ -862,7 +862,7 @@ void Reducer::makeMachine()
resolveTargetStates();
}
-void Reducer::make( const HostLang *hostLang, const HostType *alphType )
+void Reducer::make()
{
/* Getkey expression. */
if ( fsmCtx->getKeyExpr != 0 ) {
diff --git a/src/libfsm/gendata.h b/src/libfsm/gendata.h
index 1ad63429..17b5b26b 100644
--- a/src/libfsm/gendata.h
+++ b/src/libfsm/gendata.h
@@ -298,7 +298,7 @@ public:
void makeExports();
void makeGenInlineList( GenInlineList *outList, InlineList *inList );
void analyzeMachine();
- void make( const HostLang *hostLang, const HostType *alphType );
+ void make();
/*
* Collecting the machine.
@@ -348,7 +348,8 @@ struct CodeGenArgs
CodeGenArgs( FsmGbl *id, Reducer *red, HostType *alphType,
int machineId, std::string sourceFileName,
std::string fsmName, std::ostream &out,
- CodeStyle codeStyle )
+ CodeStyle codeStyle, GenLineDirectiveT genLineDirective,
+ RagelBackend backend )
:
id(id),
red(red),
@@ -359,8 +360,10 @@ struct CodeGenArgs
out(out),
codeStyle(codeStyle),
lineDirectives(true),
+ genLineDirective(genLineDirective),
forceVar(false),
- loopLabels(false)
+ loopLabels(false),
+ backend(backend)
{}
FsmGbl *id;
@@ -375,6 +378,7 @@ struct CodeGenArgs
GenLineDirectiveT genLineDirective;
bool forceVar;
bool loopLabels;
+ RagelBackend backend;
};
struct CodeGenData
@@ -396,7 +400,7 @@ struct CodeGenData
lineDirectives(args.lineDirectives),
cleared(false),
referencesCollected(false),
- genLineDirective(args.id->hostLang->genLineDirective)
+ genLineDirective(args.genLineDirective)
{
}
@@ -459,10 +463,6 @@ struct CodeGenData
GenLineDirectiveT genLineDirective;
};
-/* 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 AvlMap<char *, CodeGenData*, CmpStr> CodeGenMap;
typedef AvlMapEl<char *, CodeGenData*> CodeGenMapEl;