diff options
-rw-r--r-- | backendC/CleanCompilerSources/backend.c | 15 | ||||
-rw-r--r-- | backendC/CleanCompilerSources/backend.h | 3 | ||||
-rw-r--r-- | backendC/CleanCompilerSources/codegen.c | 2 | ||||
-rw-r--r-- | backendC/CleanCompilerSources/instructions.c | 51 | ||||
-rw-r--r-- | backendC/CleanCompilerSources/instructions.h | 1 | ||||
-rw-r--r-- | backendC/CleanCompilerSources/syntaxtr.t | 6 |
6 files changed, 78 insertions, 0 deletions
diff --git a/backendC/CleanCompilerSources/backend.c b/backendC/CleanCompilerSources/backend.c index 6308b8d..fcbd1ec 100644 --- a/backendC/CleanCompilerSources/backend.c +++ b/backendC/CleanCompilerSources/backend.c @@ -413,6 +413,7 @@ BEDeclareIclModule (CleanString name, CleanString modificationTime, int nFunctio iclModule->im_imported_objs = NULL; iclModule->im_imported_libs = NULL; # endif + iclModule->im_foreign_exports=NULL; CurrentModule = cName; @@ -3057,6 +3058,20 @@ BEDefineImportedObjsAndLibs (BEStringListP objs, BEStringListP libs) gBEState.be_icl.beicl_module->im_imported_libs = libs; } /* BEDefineRules */ +void BEInsertForeignExport (BESymbolP symbol_p) +{ + ImpMod icl_mod_p; + struct foreign_export_list *foreign_export_list_p; + + foreign_export_list_p=ConvertAllocType (struct foreign_export_list); + + icl_mod_p=gBEState.be_icl.beicl_module; + + foreign_export_list_p->fe_symbol_p=symbol_p; + foreign_export_list_p->fe_next=icl_mod_p->im_foreign_exports; + icl_mod_p->im_foreign_exports=foreign_export_list_p; +} + BEStringListP BEString (CleanString cleanString) { diff --git a/backendC/CleanCompilerSources/backend.h b/backendC/CleanCompilerSources/backend.h index e0ecc0d..f16e6c1 100644 --- a/backendC/CleanCompilerSources/backend.h +++ b/backendC/CleanCompilerSources/backend.h @@ -532,6 +532,9 @@ Clean (BEExportFunction :: Int BackEnd -> BackEnd) void BEDefineImportedObjsAndLibs (BEStringListP objs, BEStringListP libs); Clean (BEDefineImportedObjsAndLibs :: BEStringListP BEStringListP BackEnd -> BackEnd) +void BEInsertForeignExport (BESymbolP symbol_p); +Clean (BEInsertForeignExport :: BESymbolP BackEnd -> BackEnd) + void BESetMainDclModuleN (int main_dcl_module_n_parameter); Clean (BESetMainDclModuleN :: Int BackEnd -> BackEnd) diff --git a/backendC/CleanCompilerSources/codegen.c b/backendC/CleanCompilerSources/codegen.c index 2505f5f..5109a41 100644 --- a/backendC/CleanCompilerSources/codegen.c +++ b/backendC/CleanCompilerSources/codegen.c @@ -1242,6 +1242,8 @@ void CodeGeneration (ImpMod imod, char *fname) GenerateCodeForConstructorsAndRecords (imod->im_symbols); + GenerateForeignExports (imod->im_foreign_exports); + if (imod->im_start) GenStart (imod->im_start); ExitOnInterrupt (); diff --git a/backendC/CleanCompilerSources/instructions.c b/backendC/CleanCompilerSources/instructions.c index 9c03346..d13edbb 100644 --- a/backendC/CleanCompilerSources/instructions.c +++ b/backendC/CleanCompilerSources/instructions.c @@ -22,6 +22,8 @@ #include "statesgen.h" #include "version.h" +#define for_l(v,l,n) for(v=(l);v!=NULL;v=v->n) + #define BINARY_ABC 0 #undef MEMORY_PROFILING_WITH_N_STRING @@ -3522,6 +3524,55 @@ void GenSystemImports (void) } } +static void print_foreign_export_type (TypeNode type) +{ + if (!type->type_node_is_var){ + Symbol symbol_p; + + symbol_p=type->type_node_symbol; + + if (symbol_p->symb_kind==int_type){ + FPrintF (OutFile,"I"); + return; + } else if (symbol_p->symb_kind==tuple_type){ + TypeArgs type_arg_p; + + for_l (type_arg_p,type->type_node_arguments,type_arg_next) + print_foreign_export_type (type_arg_p->type_arg_node); + + return; + } + } + + error_in_function ("print_foreign_export_type"); +} + +void GenerateForeignExports (struct foreign_export_list *foreign_export_list) +{ + struct foreign_export_list *foreign_export_p; + + for_l (foreign_export_p,foreign_export_list,fe_next){ + SymbDef function_sdef; + TypeAlt *rule_type_p; + TypeArgs type_arg_p; + + function_sdef=foreign_export_p->fe_symbol_p->symb_def; + + FPrintF (OutFile,"\n\tcentry %s e_%s_s%s \"",function_sdef->sdef_ident->ident_name,CurrentModule,function_sdef->sdef_ident->ident_name); + + rule_type_p=function_sdef->sdef_rule->rule_type; + + for_l (type_arg_p,rule_type_p->type_alt_lhs->type_node_arguments,type_arg_next) + print_foreign_export_type (type_arg_p->type_arg_node); + + FPrintF (OutFile,":"); + + print_foreign_export_type (rule_type_p->type_alt_rhs); + + FPrintF (OutFile,"\""); + } +} + void GenParameters (Bool input, Parameters params, int asp, int bsp) { int is_first_parameter; diff --git a/backendC/CleanCompilerSources/instructions.h b/backendC/CleanCompilerSources/instructions.h index 25c2400..e42914b 100644 --- a/backendC/CleanCompilerSources/instructions.h +++ b/backendC/CleanCompilerSources/instructions.h @@ -183,6 +183,7 @@ void GenDepend (char *modname); #endif void GenEndInfo (void); void GenSystemImports (void); +void GenerateForeignExports (struct foreign_export_list *foreign_export_p); void GenStart (SymbDef startsymb); void InitFileInfo (ImpMod imod); diff --git a/backendC/CleanCompilerSources/syntaxtr.t b/backendC/CleanCompilerSources/syntaxtr.t index 233ac3c..0583ea8 100644 --- a/backendC/CleanCompilerSources/syntaxtr.t +++ b/backendC/CleanCompilerSources/syntaxtr.t @@ -815,6 +815,11 @@ struct string_list { }; #endif +struct foreign_export_list { + SymbolP fe_symbol_p; + struct foreign_export_list *fe_next; +}; + #if CLEAN2 typedef char * ModuleFileTime; #else @@ -838,6 +843,7 @@ typedef struct { struct string_list * im_imported_objs; struct string_list * im_imported_libs; #endif + struct foreign_export_list * im_foreign_exports; #if WRITE_DCL_MODIFICATION_TIME ModuleFileTime im_modification_time; #endif |