Commit 97af71b3 authored by johnvg@science.ru.nl's avatar johnvg@science.ru.nl

remove inlining abc code from .abc files in the backend (use :== code in system modules instead)

parent 4a22c31f
......@@ -13,7 +13,6 @@
# include "sizes.h"
# include "set_scope_numbers.h"
# include "scanner.h" /* InitScanner, ScanInitIdentStringTable */
# include "checker.h" /* scc_dependency_list, ClearOpenDefinitionModules, AddOpenDefinitionModule */
# include "comsupport.h" /* CurrentModule */
# include "buildtree.h" /* TupleSymbol, ApplySymbol */
......@@ -2353,9 +2352,6 @@ BEDeclareRuleType (int functionIndex, int moduleIndex, CleanString name)
Assert (functions [functionIndex].symb_kind == erroneous_symb);
newSymbDef = ConvertAllocType (SymbDefS);
if (module->bem_isSystemModule) /* for inline code */
PutStringInHashTable (ConvertCleanString (name), FirstSystemModuleTable + moduleIndex, newSymbDef);
newSymbDef->sdef_kind = NEWDEFINITION;
newSymbDef->sdef_exported = False;
newSymbDef->sdef_module = module->bem_name;
......@@ -3296,9 +3292,6 @@ BEInit (int argc)
CurrentExt = "";
InitStorage ();
/* +++ remove symbol table from backend */
ScanInitIdentStringTable ();
InitScanner (); /* for inlining */
#if SA_RECOGNIZES_ABORT_AND_UNDEF
StdMiscId = NULL;
......
......@@ -6,7 +6,6 @@
# include "sizes.h"
# include "buildtree.h"
# include "checker.h"
# include "scanner.h"
SymbolP TrueSymbol, FalseSymbol, TupleSymbol,
SelectSymbols [MaxNodeArity], ApplySymbol, IfSymbol,
......
......@@ -9,7 +9,6 @@
#include "syntaxtr.t"
#include "comsupport.h"
#include "sizes.h"
#include "scanner.h"
#include "buildtree.h"
#include "comparser.h"
#include "statesgen.h"
......@@ -42,37 +41,6 @@ void GenDependencyList (void)
);
}
void ReadInlineCode (void)
{
DefModList d_mod;
for_l (d_mod,OpenDefinitionModules,mod_next){
DefMod def_mod;
def_mod=d_mod->mod_body;
if (def_mod->dm_system_module){
int i,n_function_symbols;
Symbol function_symbol_a;
n_function_symbols=def_mod->dm_n_function_symbols;
function_symbol_a=def_mod->dm_function_symbol_a;
for (i=0; i<n_function_symbols; ++i)
if (function_symbol_a[i].symb_kind==definition){
SymbDef sdef;
sdef=function_symbol_a[i].symb_def;
if (sdef->sdef_kind==SYSRULE &&
(sdef->sdef_mark & (SDEF_USED_STRICTLY_MASK | SDEF_DEFRULE_ABC_CODE))==SDEF_USED_STRICTLY_MASK)
break;
}
if (i<n_function_symbols && d_mod->mod_body->dm_name!=CurrentModule)
/* Get the inline instructions of all the rules that are defined in this module */
ScanInlineFile (d_mod->mod_body->dm_name,FirstSystemModuleTable+def_mod->dm_module_n);
}
}
}
char *StdBoolId;
SymbDef AndSymbDef,OrSymbDef;
......
......@@ -3,7 +3,6 @@
#include "types.t"
#include "syntaxtr.t"
#include "comsupport.h"
#include "scanner.h"
#include "checksupport.h"
#include "settings.h"
#include "buildtree.h"
......
......@@ -1223,8 +1223,6 @@ void CodeGeneration (ImpMod imod, char *fname)
GenSystemImports();
FileComment();
ReadInlineCode();
CreateStackFrames();
ImportSymbols (imod->im_size_dcl_mfts_a,imod->im_dcl_mfts_a);
......
......@@ -24,7 +24,6 @@
#include "codegen2.h"
#include "codegen3.h"
#include "instructions.h"
#include "scanner.h"
#include "buildtree.h"
#include "pattern_match.h"
#if SHARE_UPDATE_CODE
......
......@@ -2616,9 +2616,7 @@ static void FillSymbol (Node node,SymbDef sdef,int *asp_p,int *bsp_p,NodeId upda
*bsp_p-=b_size;
if (! (sdef->sdef_kind==SYSRULE &&
( (sdef->sdef_mark & SDEF_DEFRULE_INSTRUCTIONS)!=0 && sdef->sdef_instructions!=NULL && *sdef->sdef_instructions!='\0' && *sdef->sdef_instructions!='.')
|| (sdef->sdef_mark & SDEF_DEFRULE_ABC_CODE)!=0 && sdef->sdef_abc_code!=NULL && sdef->sdef_abc_code->instr_this[0]!='.')
)
(sdef->sdef_mark & SDEF_DEFRULE_ABC_CODE)!=0 && sdef->sdef_abc_code!=NULL && sdef->sdef_abc_code->instr_this[0]!='.'))
{
cleanup_stack (asp_p,bsp_p,a_size,b_size,&code_gen_node_ids_p->a_node_ids,&code_gen_node_ids_p->b_node_ids,
&code_gen_node_ids_p->free_node_ids,code_gen_node_ids_p->moved_node_ids_l,
......@@ -2643,9 +2641,7 @@ static void FillSymbol (Node node,SymbDef sdef,int *asp_p,int *bsp_p,NodeId upda
*bsp_p-=b_size;
if (! (sdef->sdef_kind==SYSRULE &&
( (sdef->sdef_mark & SDEF_DEFRULE_INSTRUCTIONS)!=0 && sdef->sdef_instructions!=NULL && *sdef->sdef_instructions!='\0' && *sdef->sdef_instructions!='.')
|| (sdef->sdef_mark & SDEF_DEFRULE_ABC_CODE)!=0 && sdef->sdef_abc_code!=NULL && sdef->sdef_abc_code->instr_this[0]!='.')
)
(sdef->sdef_mark & SDEF_DEFRULE_ABC_CODE)!=0 && sdef->sdef_abc_code!=NULL && sdef->sdef_abc_code->instr_this[0]!='.'))
{
cleanup_stack (asp_p,bsp_p,a_size+1,b_size,&code_gen_node_ids_p->a_node_ids,&code_gen_node_ids_p->b_node_ids,
&code_gen_node_ids_p->free_node_ids,code_gen_node_ids_p->moved_node_ids_l,
......@@ -2668,9 +2664,7 @@ static void FillSymbol (Node node,SymbDef sdef,int *asp_p,int *bsp_p,NodeId upda
*bsp_p-=b_size;
if (! (sdef->sdef_kind==SYSRULE &&
( (sdef->sdef_mark & SDEF_DEFRULE_INSTRUCTIONS)!=0 && sdef->sdef_instructions!=NULL && *sdef->sdef_instructions!='\0' && *sdef->sdef_instructions!='.')
|| (sdef->sdef_mark & SDEF_DEFRULE_ABC_CODE)!=0 && sdef->sdef_abc_code!=NULL && sdef->sdef_abc_code->instr_this[0]!='.')
)
(sdef->sdef_mark & SDEF_DEFRULE_ABC_CODE)!=0 && sdef->sdef_abc_code!=NULL && sdef->sdef_abc_code->instr_this[0]!='.'))
{
cleanup_stack (asp_p,bsp_p,a_size,b_size,&code_gen_node_ids_p->a_node_ids,&code_gen_node_ids_p->b_node_ids,
&code_gen_node_ids_p->free_node_ids,code_gen_node_ids_p->moved_node_ids_l,
......@@ -4998,9 +4992,7 @@ static void FillUniqueNodeWithNode (NodeP update_node,int *asp_p,int *bsp_p,Code
*bsp_p-=b_size;
if (! (sdef->sdef_kind==SYSRULE &&
( (sdef->sdef_mark & SDEF_DEFRULE_INSTRUCTIONS)!=0 && sdef->sdef_instructions!=NULL && *sdef->sdef_instructions!='\0' && *sdef->sdef_instructions!='.')
|| (sdef->sdef_mark & SDEF_DEFRULE_ABC_CODE)!=0 && sdef->sdef_abc_code!=NULL && sdef->sdef_abc_code->instr_this[0]!='.')
)
(sdef->sdef_mark & SDEF_DEFRULE_ABC_CODE)!=0 && sdef->sdef_abc_code!=NULL && sdef->sdef_abc_code->instr_this[0]!='.'))
{
cleanup_stack (asp_p,bsp_p,a_size,b_size,&code_gen_node_ids_p->a_node_ids,&code_gen_node_ids_p->b_node_ids,
&code_gen_node_ids_p->free_node_ids,code_gen_node_ids_p->moved_node_ids_l,
......
......@@ -6,7 +6,6 @@
# include "syntaxtr.t"
# include "comsupport.h"
# include "scanner.h"
# include "sizes.h"
# include "checker.h"
# include "statesgen.h"
......@@ -20,8 +19,6 @@ InitParser (void)
{
int i;
ScanInitialise ();
for (i = 0; i < MaxNodeArity; i++)
{ SelectSymbols [i] = NULL;
TupleTypeSymbols [i] = NULL;
......
......@@ -22,7 +22,6 @@
#include "settings.h"
#include "syntaxtr.t"
#include "comsupport.h"
#include "scanner.h"
#include "buildtree.h"
#include "comparser.h"
#include "checker.h"
......@@ -454,7 +453,6 @@ void InitCompiler (void)
CurrentExt = "";
InitStorage ();
InitScanner ();
InitParser ();
InitChecker ();
InitStatesGen ();
......
......@@ -1332,55 +1332,12 @@ static void CallFunction2 (Label label, SymbDef def, Bool isjsr, StateS root_sta
label->lab_pref = s_pref;
if (def->sdef_kind==SYSRULE){
char *instr;
if (def->sdef_mark & SDEF_DEFRULE_ABC_CODE){
GenABCInstructions (def->sdef_abc_code);
if (!isjsr)
GenRtn (aout, bout, root_state);
return;
}
if (def->sdef_mark & SDEF_DEFRULE_INSTRUCTIONS)
instr = def->sdef_instructions;
else
instr = NULL;
if (instr && *instr!='\0'){
char *tail;
for (; *instr != '\0'; instr = tail){
for (tail = instr; *tail != '\n'; tail++)
;
*tail = '\0';
FPrintF (OutFile, "\n%s", instr);
*tail++ = '\n';
}
if (!isjsr)
GenRtn (aout, bout, root_state);
} else {
if ((def->sdef_mark & SDEF_WARNED_NO_INLINE_CODE)==0 && instr==NULL){
char *previous_module = CurrentModule;
char *previous_ext = CurrentExt;
CurrentModule = def->sdef_module;
CurrentExt = GetFileExtension (abcFile);
StaticMessage (False, "%D", "no inline code for this function", def);
CurrentModule = previous_module;
CurrentExt = previous_ext;
def->sdef_mark |= SDEF_WARNED_NO_INLINE_CODE;
}
GenDStackLayout (ain, bin, fun_args);
if (isjsr){
GenJsr (label);
GenOStackLayoutOfState (aout, bout, root_state);
} else
GenJmp (label);
}
return;
}
if (def->sdef_kind==IMPRULE){
if ((def->sdef_mark & SDEF_INLINE_IS_CONSTRUCTOR)!=0){
......
......@@ -10,7 +10,6 @@
#include "comsupport.h"
#include "statesgen.h"
#include "checker.h"
#include "scanner.h"
#include "buildtree.h"
#include "codegen_types.h"
#include "optimisations.h"
......
extern void PutStringInHashTable (char *string, TableKind tabkind, SymbDefP sys_rule_def);
extern void InitScanner (void);
extern void ScanInitialise (void);
extern void ScanInitIdentStringTable (void);
extern void ScanInlineFile (char *fname,TableKind table_kind);
/*
Ronny Wichers Schreur
University of Nijmegen
*/
# include <stdio.h>
# include <string.h>
# include <ctype.h>
# include <limits.h>
# undef H
# include "compiledefines.h"
# include "types.t"
#if defined (applec) || (defined (__MWERKS__) && !defined (_WINDOWS_)) || defined (__MRC__)
# define __ppc__
#endif
# include "system.h"
# include "syntaxtr.t"
# include "comsupport.h"
# include "scanner.h"
# include "sizes.h"
STRUCT(ident,Ident){
char * ident_name;
struct symbol_def * ident_sys_rule_def;
struct ident * ident_next;
unsigned char ident_table; /* TableKind */
unsigned char ident_mark;
};
#define INLINE_MASK 8
typedef struct ident_string *IdentStringP;
struct ident_string {
IdentStringP left;
IdentStringP right;
Ident ident;
char *string;
};
static IdentP
NewIdentInTable (TableKind tableKind, char *name)
{
IdentP ident;
ident = CompAllocType (struct ident);
ident->ident_table = tableKind;
ident->ident_name = name;
ident->ident_next = NULL;
ident->ident_sys_rule_def = NULL;
ident->ident_mark = 0;
return (ident);
}
#define CompAllocString(size) ((char*)CompAlloc(size))
static char *
AllocString (char *string, short length)
{
int i;
char *s, *newString;
s = newString = CompAllocString (length+1);
for (i = 0; i < length; i++)
*s++ = *string++;
*s = '\0';
return (newString);
} /* AllocString */
# define kIdentStringTableSizeBits 10
# define kIdentStringTableSize ((1 << kIdentStringTableSizeBits) - 1)
static IdentStringP *gIdentStringTable;
static IdentStringP
StringInTable (char *string, short length)
{
int i;
unsigned long hash;
IdentStringP identString, *identStringPtr;
char *s;
hash = 0;
s = string;
for (i = 0; i < length; i++)
{
hash <<= 2;
hash += *s++;
}
/* Compute (hash % kIdentStringTableSize) */
while (hash >= (kIdentStringTableSize<<1))
hash = (hash & kIdentStringTableSize) + (hash >> kIdentStringTableSizeBits);
if (hash >= kIdentStringTableSize)
hash -= kIdentStringTableSize;
identStringPtr = &gIdentStringTable [hash];
while ((identString = *identStringPtr) != NIL)
{
int compare;
compare = strncmp (identString->string, string, length);
if (compare == 0 && (compare = ((unsigned char *)identString->string) [length]) == 0)
/* found it */
break;
else if (compare > 0)
identStringPtr = &identString->left;
else /* if (compare < 0) */
identStringPtr = &identString->right;
}
if (identString == NIL)
{
identString = CompAllocType (struct ident_string);
identString->left = NIL;
identString->right = NIL;
identString->ident = NIL;
identString->string = AllocString (string, length);
*identStringPtr = identString;
}
return (identString);
} /* StringInTable */
static IdentP
PutIdentStringInTable (IdentStringP identString, TableKind tableKind)
{
IdentP ident;
for (ident = identString->ident; ident != NIL; ident = ident->ident_next)
if (ident->ident_table == tableKind)
break;
if (ident == NIL)
{
ident = NewIdentInTable (tableKind, identString->string);
ident->ident_next = identString->ident;
identString->ident = ident;
}
return (ident);
} /* PutIdentStringInTable */
void PutStringInHashTable (char *string, TableKind tableKind, SymbDefP sys_rule_def)
{
IdentStringP identString;
IdentP newIdent;
identString = StringInTable (string, strlen (string));
newIdent = PutIdentStringInTable (identString, tableKind);
newIdent->ident_sys_rule_def = sys_rule_def;
} /* PutStringInHashTable */
static IdentP RetrieveFromSymbolTable (char *string,TableKind table_kind)
{
char *s;
unsigned long hash;
IdentStringP identString;
IdentP ident;
hash = 0;
for (s = string; *s != '\0'; s++){
hash <<= 2;
hash += *s;
}
/* Compute (hash % 1023) */
while (hash >= 2046)
hash = (hash & 1023) + (hash >> 10);
if (hash >= 1023)
hash -= 1023;
identString = gIdentStringTable [hash];
while (identString != NIL){
int compare;
compare = strcmp (identString->string, string);
if (compare == 0)
/* found it */
break;
else if (compare > 0)
identString = identString->left;
else /* if (compare < 0) */
identString = identString->right;
}
if (identString != NIL){
for (ident = identString->ident; ident != NIL; ident = ident->ident_next)
if (ident->ident_table == table_kind)
break;
} else
ident = NIL;
return ident;
}
/*
+-----------------------------------------------------------------------+
| ReadInlineCode scans all the imported SYSTEM modules and stores the |
| the encountered inline instructions in the symbol table. |
+-----------------------------------------------------------------------+
*/
char NextLine[LineLength];
/* has a command been read? */
static char *IsCommand (char *com, char *p)
{
while (*com++ == *p++)
if (*com == '\0')
return (p);
return ((char *) NIL);
}
/* scan a file for .inline-.end command pairs */
char *InlineCodeBuffer;
unsigned InlineBufferIndex, InlineBufferStart;
void ScanInlineFile (char *fname,TableKind system_module_table_kind)
{
register char *tail, *instr, *importingModule, *importingExtension;
IdentP instrid;
int nrinstr;
File f;
importingModule = CurrentModule;
importingExtension = CurrentExt;
CurrentModule = fname;
CurrentExt = GetFileExtension (abcFile);
if (! (f = FOpen (fname, abcFile, "r")))
{ CurrentModule = importingModule;
CurrentExt = importingExtension;
return;
}
# if defined (POWER)
setvbuf ((void*) f, NULL, _IOFBF, 8192);
# endif
CurrentLine = 0;
CurrentPhase = NULL;
for (;;){
if (! FGetS (NextLine, LineLength, f))
break;
for (tail = NextLine; isspace (*tail); tail++)
;
/* if not at .inline reenter loop from top */
if ((tail = IsCommand (".inline", tail)) == NIL)
continue;
/* get the function name */
while (*tail == ' ' || *tail == '\t')
tail++;
/* terminate it with a '\0' */
for (instr = tail; ! isspace (*tail); tail++)
;
if (instr == tail)
continue;
*tail = '\0';
if (! (instrid = RetrieveFromSymbolTable (instr,system_module_table_kind)))
continue;
if (instrid->ident_sys_rule_def==NULL || (instrid->ident_sys_rule_def->sdef_mark & SDEF_DEFRULE_ABC_CODE)!=0)
continue;
if ((instrid->ident_mark & INLINE_MASK) != 0)
{
StaticMessage (True, "%s", "multiple .inline directives", instr);
continue;
}
instrid->ident_mark |= INLINE_MASK;
/* Open the buffer for the next instructions */
InlineBufferIndex = InlineBufferStart;
for (nrinstr = 0; nrinstr <= MaxInlineInstr;){
if (! FGetS (NextLine, LineLength, f)){
StaticMessage (False, "%s", "%s no .end found in this file", instrid->ident_name,fname);
break;
}
for (tail = NextLine; *tail == ' ' || *tail == '\t'; tail++)
;
if (IsCommand (".end", tail))
break;
if (*tail != '\n' && *tail != '\0'){
instr = NextLine;
/* Copy this instruction into the buffer */
do
{ if (InlineBufferIndex < InlineBuffSize-2)
InlineCodeBuffer [InlineBufferIndex++] = *instr++;
else
DoFatalError ("too many inline instructions");
} while (*instr != '\n' && *instr != '\0');
/* close the instruction with a newline character */
InlineCodeBuffer [InlineBufferIndex++] = '\n';
nrinstr++;
}
}
if (nrinstr > MaxInlineInstr){
StaticMessage (False, "%s", "%s file contains too many instructions", instrid->ident_name,fname);
}
/* save the list of inline instructions */
instrid->ident_sys_rule_def->sdef_mark |= SDEF_DEFRULE_INSTRUCTIONS;
instrid->ident_sys_rule_def->sdef_instructions = &InlineCodeBuffer [InlineBufferStart];
InlineBufferStart = InlineBufferIndex+1;
/* close the list with the NULL character */
InlineCodeBuffer [InlineBufferIndex] = '\0';
}
FClose (f);
CurrentModule = importingModule;
CurrentExt = importingExtension;
}
void
ScanInitIdentStringTable (void)
{
int i;
gIdentStringTable = (struct ident_string**)CompAlloc (kIdentStringTableSize * sizeof (struct ident_string));
for (i = 0; i < kIdentStringTableSize; i++)
gIdentStringTable [i] = NIL;
}
void
ScanInitialise (void)
{
ScanInitIdentStringTable();
} /* ScanInitialise */
void
InitScanner (void)
{