From 8b60d8eb3679337b9036988d2898558d5ef49117 Mon Sep 17 00:00:00 2001 From: Adrian Thurston Date: Sun, 7 Nov 2021 17:10:14 -0800 Subject: moved HostLang type and makeCodeGen funcs to here from colm --- src/Makefile.am | 2 +- src/allocgen.cc | 32 ++++++++++++++++---------------- src/host-asm/main.cc | 1 + src/host-c/main.cc | 1 + src/host-crack/main.cc | 1 + src/host-csharp/main.cc | 1 + src/host-d/main.cc | 1 + src/host-go/main.cc | 1 + src/host-java/main.cc | 1 + src/host-js/main.cc | 1 + src/host-julia/main.cc | 1 + src/host-ocaml/main.cc | 1 + src/host-ruby/main.cc | 1 + src/host-rust/main.cc | 1 + src/inputdata.cc | 1 + src/inputdata.h | 6 +++++- src/nragel.h | 27 +++++++++++++++++++++++++++ src/parsedata.cc | 6 +++--- src/parsedata.h | 5 +++-- 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 +#include +#include #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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include 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 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 #include 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 #include #include @@ -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 #include +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 #include "compare.h" #include "vector.h" -#include #include "parsetree.h" +#include "nragel.h" +#include +#include #include -- cgit v1.2.1