[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnet/cscc/bf bf_codegen.tc,NONE,1.1 bf_defs.
From: |
Gopal.V <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnet/cscc/bf bf_codegen.tc,NONE,1.1 bf_defs.tc,NONE,1.1 bf_grammar.y,NONE,1.1 bf_internal.h,NONE,1.1 bf_optimize.c,NONE,1.1 bf_rename.h,NONE,1.1 bf_scanner.l,NONE,1.1 Makefile.am,NONE,1.1 |
Date: |
Sat, 17 May 2003 08:47:48 -0400 |
Update of /cvsroot/dotgnu-pnet/pnet/cscc/bf
In directory subversions:/tmp/cvs-serv2629/cscc/bf
Added Files:
bf_codegen.tc bf_defs.tc bf_grammar.y bf_internal.h
bf_optimize.c bf_rename.h bf_scanner.l Makefile.am
Log Message:
initial check in of the bf.net compiler
--- NEW FILE ---
%{
/*
* bf_codegen.tc - IL code generator
*
* Copyright (C) 2001 Southern Storm Software, Pty Ltd.
*
* Contributed by Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
%}
%output "bf_codegen.c"
%decls %{
extern int maxArraySize;
%}
%{
int maxArraySize=8000;
%}
ILNode_GenDiscard(ILNode_BFProgram)
{
const char * size=
CCStringListGetValue(extension_flags,num_extension_flags,
"max-array-size");
if(size)
{
int value;
sscanf(size,"%u",&value);
if(value >= 8) /* minimum 8 , right ? */
{
maxArraySize = value;
}
}
fprintf(info->asmOutput,
".class public bf extends [mscorlib] System.Object \n"
"{\n"
".method static public void main() il managed\n"
"{\n"
"\t.entrypoint\n"
"\t.locals (int8[] bfarray, int32 bfarrayloc)\n"
"\n");
ILGenWordInsn(info,IL_OP_LDC_I4 , maxArraySize);
ILGenAdjust(info,1);
ILGenArrayNew(info, ILType_Int8);
ILGenSimple(info,IL_OP_STLOC_0);
ILGenAdjust(info,-1);
ILGenWordInsn(info,IL_OP_LDC_I4 , maxArraySize/2);
ILGenAdjust(info,1);
ILGenSimple(info,IL_OP_STLOC_1);
ILGenAdjust(info,-1);
ILNode_GenDiscard(node->body,info);
ILGenSimple(info,IL_OP_RET);
fprintf(info->asmOutput, "\t.maxstack %ld\n", info->maxStackHeight);
fprintf(info->asmOutput,"}\n"
"}\n");
}
ILNode_GenDiscard(ILNode_BFLoop)
{
ILLabel label1 = ILLabel_Undefined;
ILLabel label2 = ILLabel_Undefined;
ILGenLabel(info, &label1);
ILGenSimple(info,IL_OP_LDLOC_0);
ILGenSimple(info,IL_OP_LDLOC_1);
ILGenSimple(info,IL_OP_LDELEM_I1);
ILGenJump(info,IL_OP_BRFALSE,&label2);
ILNode_GenDiscard(node->body,info);
ILGenJump(info,IL_OP_BR,&label1);
ILGenLabel(info, &label2);
}
ILNode_GenDiscard(ILNode_BFRead)
{
ILLabel label1 = ILLabel_Undefined;
ILGenSimple(info,IL_OP_LDLOC_0);
ILGenSimple(info,IL_OP_LDLOC_1);
ILGenCallByName(info,"int32 [.library] System.Console::Read()");
ILGenAdjust(info,3);
ILGenSimple(info,IL_OP_DUP);
ILGenSimple(info,IL_OP_LDC_I4_0);
ILGenAdjust(info,2);
ILGenJump(info,IL_OP_BGE,&label1);
ILGenAdjust(info,-2);
/* result is -1 */
ILGenSimple(info,IL_OP_LDC_I4_1);
ILGenAdjust(info,1);
ILGenSimple(info,IL_OP_ADD);
ILGenAdjust(info,-1);
ILGenLabel(info,&label1);
ILGenSimple(info,IL_OP_STELEM_I1);
ILGenAdjust(info, -3);
}
ILNode_GenDiscard(ILNode_BFWrite)
{
ILGenSimple(info,IL_OP_LDLOC_0);
ILGenSimple(info,IL_OP_LDLOC_1);
ILGenAdjust(info,2);
ILGenSimple(info,IL_OP_LDELEM_I1);
ILGenAdjust(info,-1);
ILGenCallByName(info,"void [.library] System.Console::Write(char)");
ILGenAdjust(info,-1);
}
ILNode_GenDiscard(ILNode_BFArith)
{
if(!node->count)return;
ILGenSimple(info,IL_OP_LDLOC_0);
ILGenSimple(info,IL_OP_LDLOC_1);
ILGenAdjust(info,2);
ILGenSimple(info,IL_OP_LDLOC_0);
ILGenSimple(info,IL_OP_LDLOC_1);
ILGenAdjust(info,2);
ILGenSimple(info,IL_OP_LDELEM_I1);
ILGenAdjust(info,-1);
if(node->count > 0)
{
ILGenShortInsn(info,IL_OP_LDC_I4_S,node->count);
ILGenAdjust(info,1);
ILGenSimple(info,IL_OP_ADD);
ILGenAdjust(info,-1);
}
else
{
ILGenShortInsn(info,IL_OP_LDC_I4_S,-(node->count));
ILGenAdjust(info,1);
ILGenSimple(info,IL_OP_SUB);
ILGenAdjust(info,-1);
}
ILGenSimple(info,IL_OP_STELEM_I1);
ILGenAdjust(info,-3);
}
ILNode_GenDiscard(ILNode_BFMove)
{
if(!node->count)return;
ILGenSimple(info,IL_OP_LDLOC_1);
if(node->count > 0)
{
ILGenShortInsn(info,IL_OP_LDC_I4_S, node->count);
ILGenAdjust(info,2);
ILGenSimple(info,IL_OP_ADD);
}
else
{
ILGenShortInsn(info,IL_OP_LDC_I4_S, -(node->count));
ILGenAdjust(info,2);
ILGenSimple(info,IL_OP_SUB);
}
ILGenAdjust(info,-1);
ILGenSimple(info,IL_OP_STLOC_1);
ILGenAdjust(info,-1);
}
--- NEW FILE ---
%{
/*
* bf_defs.tc - TreeCC nodes for BF
*
* Copyright (C) 2001 Southern Storm Software, Pty Ltd.
*
* Contributed by Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
%}
%include %readonly "../../codegen/cg_all.tc"
%header "bf_defs.h"
%output "bf_nodes.c"
%decls %{
#include "../codegen/cg_nodes.h"
#include "il_utils.h"
%}
%node ILNode_BF ILNode_Dummy
%node ILNode_BFBody ILNode_BF =
{
ILNode *body;
}
%node ILNode_BFProgram ILNode_BFBody
%node ILNode_BFLoop ILNode_BFBody
%node ILNode_BFRead ILNode_BF
%node ILNode_BFWrite ILNode_BF
%node ILNode_BFOpt ILNode_BF =
{
signed int count;
}
%node ILNode_BFArith ILNode_BFOpt
%node ILNode_BFMove ILNode_BFOpt
%{
#include "bf_internal.h"
%}
%include "bf_codegen.tc"
--- NEW FILE ---
%{
/*
* bf_grammar.y - BF grammar
*
* Copyright (C) 2001 Southern Storm Software, Pty Ltd.
*
* Contributed by Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
%}
%token LOOP_START LOOP_END
%token PREV NEXT
%token PLUS MINUS
%token READ WRITE
%type <node> Instruction InstructionList
%type <node> Arith Move IO Loop
%{
#include <stdio.h>
#include "il_system.h"
#include "il_opcodes.h"
#include "il_meta.h"
#include "il_utils.h"
#include "bf_rename.h"
#include "bf_internal.h"
int yydebug;
/*
* Global code generator object.
*/
ILGenInfo BFCodeGen;
/*
* Imports from the lexical analyser.
*/
extern int yylex();
#ifdef YYTEXT_POINTER
extern char *bf_text;
#else
extern char bf_text[];
#endif
static void yyerror(char *msg)
{
CCPluginParseError(msg, bf_text);
}
%}
%union {
ILNode *node;
};
%start CompilationUnit
%%
CompilationUnit
: /* empty */ {
CCError("input file is empty");
}
|
InstructionList {
CCParseTree = ILNode_BFProgram_create($1);
}
;
InstructionList
:Instruction {
$$ = ILNode_List_create();
ILNode_List_Add($$,$1);
}
| InstructionList Instruction {
$$ = $1;
ILNode_List_Add($$,$2);
}
;
Loop
: LOOP_START InstructionList LOOP_END {
$$ = ILNode_BFLoop_create($2);
}
;
Arith
: PLUS {
$$ = ILNode_BFArith_create(1);
}
| MINUS{
$$ = ILNode_BFArith_create(-1);
}
;
IO
: READ{
$$ = ILNode_BFRead_create();
}
| WRITE{
$$ = ILNode_BFWrite_create();
}
;
Move
: NEXT {
$$ = ILNode_BFMove_create(1);
}
| PREV {
$$ = ILNode_BFMove_create(-1);
}
Instruction
: Arith
| Move
| IO
| Loop
;
%%
--- NEW FILE ---
/*
* bf_internal.h - common include files for BF operations
*
* Copyright (C) 2001 Southern Storm Software, Pty Ltd.
*
* Contributed by Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _CSCC_BF_INTERNAL_H
#define _CSCC_BF_INTERNAL_H
#include <cscc/common/cc_main.h>
#include <cscc/bf/bf_defs.h>
ILNode * BFOptimize(ILGenInfo *info, ILNode *tree);
#endif /* _CSCC_BF_INTERNAL_H */
--- NEW FILE ---
/*
* bf_optimize.c - BF optimiser
*
* Copyright (C) 2001 Southern Storm Software, Pty Ltd.
*
* Contributed by Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "bf_internal.h"
ILNode * BFOptimize(ILGenInfo *info, ILNode *tree)
{
ILNode * newList;
ILNode * list;
ILNode * item=NULL;
ILNode * lastItem = NULL;
ILNode_ListIter iter;
if(!yyisa(tree,ILNode_BFBody))
{
return tree;
}
list = ((ILNode_BFBody*)tree)->body;
if(!yyisa(list,ILNode_List)) return tree;
newList=ILNode_List_create();
ILNode_ListIter_Init(&iter,list);
while((item = ILNode_ListIter_Next(&iter)) !=NULL)
{
if(lastItem == NULL)
{
ILNode_List_Add(newList,item);
lastItem = item;
}
else
{
if(yyisa(lastItem,ILNode_BFOpt))
{
if(yykind(lastItem) == yykind(item))
{
((ILNode_BFOpt*)lastItem)->count+=
((ILNode_BFOpt*)item)->count;
}
}
else if(yyisa(item, ILNode_BFBody))
{
lastItem = NULL;
item = BFOptimize(info, item);
ILNode_List_Add(newList, item);
}
else
{
ILNode_List_Add(newList, item);
lastItem = item;
}
}
}
((ILNode_BFBody*)tree)->body=newList;
return tree;
}
--- NEW FILE ---
/*
* bf_rename.h - lex & yacc renaming of functions
*
* Copyright (C) 2001 Southern Storm Software, Pty Ltd.
*
* Contributed by Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _CSCC_BF_RENAME_H
#define _CSCC_BF_RENAME_H
/*
* This list was extracted from the GNU automake documentation,
* and is supposed to be reasonably complete for all known
* yacc/lex implementations.
*/
#define yymaxdepth bf_maxdepth
#define yyparse bf_parse
#define yylex bf_lex
#define yyerror bf_error
#define yylval bf_lval
#define yychar bf_char
#define yydebug bf_debug
#define yypact bf_pact
#define yyr1 bf_r1
#define yyr2 bf_r2
#define yydef bf_def
#define yychk bf_chk
#define yypgo bf_pgo
#define yyact bf_act
#define yyexca bf_exca
#define yyerrflag bf_errflag
#define yynerrs bf_nerrs
#define yyps bf_ps
#define yypv bf_pv
#define yys bf_s
#define yy_yys bf_yys
#define yystate bf_state
#define yytmp bf_tmp
#define yyv bf_v
#define yy_yyv bf_yyv
#define yyval bf_val
#define yylloc bf_lloc
#define yyreds bf_reds
#define yytoks bf_toks
#define yylhs bf_yylhs
#define yylen bf_yylen
#define yydefred bf_yydefred
#define yydgoto bf_yydgoto
#define yysindex bf_yysindex
#define yyrindex bf_yyrindex
#define yygindex bf_yygindex
#define yytable bf_yytable
#define yycheck bf_yycheck
#define yyname bf_yyname
#define yyrule bf_yyrule
#endif /* _CSCC_BF_RENAME_H */
--- NEW FILE ---
%{
/*
* bf_scanner.l - BF Scanner
*
* Copyright (C) 2001 Southern Storm Software, Pty Ltd.
*
* Contributed by Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
%}
%{
/* Rename the lex/yacc symbols to support multiple parsers */
#include "bf_rename.h"
#include "bf_internal.h"
#include <stdio.h>
#include "bf_grammar.h"
/*
* Get the next line of input from the C# pre-processor.
*/
#define YY_INPUT(buf,result,maxSize) \
{ \
result = CCPluginInput((buf), (maxSize)); \
}
#define RETURNTOK(x) return (x)
%}
%option outfile="lex.yy.c"
%option prefix="bf_"
%option noyywrap
%option nounput
%%
"[" { RETURNTOK(LOOP_START); }
"]" { RETURNTOK(LOOP_END); }
"," { RETURNTOK(READ); }
"." { RETURNTOK(WRITE); }
"<" { RETURNTOK(PREV); }
">" { RETURNTOK(NEXT); }
"+" { RETURNTOK(PLUS); }
"-" { RETURNTOK(MINUS); }
\n ;
. ;
%%
--- NEW FILE ---
noinst_LIBRARIES = libILBf.a
TREECC_INPUTS = bf_defs.tc \
bf_codegen.tc
TREECC_SRCOUT = bf_nodes.c bf_codegen.c
TREECC_OUTPUT = $(TREECC_SRCOUT) bf_defs.h
libILBf_a_SOURCES = $(TREECC_SRCOUT)\
bf_grammar.y \
bf_scanner.l \
bf_optimize.c
AM_YFLAGS = -d
AM_CFLAGS = -I$(top_srcdir) -I$(top_builddir) -I$(top_srcdir)/include
STAMP = stamp-treecc
BUILT_SOURCES = $(STAMP)
libILBf_a_DEPENDENCIES = $(STAMP)
$(STAMP): $(TREECC_INPUTS) ../../codegen/$(STAMP)
$(TREECC) $(srcdir)/bf_defs.tc && touch $@
CLEANFILES = bf_grammar.c bf_scanner.c bf_grammar.h $(TREECC_OUTPUT) $(STAMP)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnet/cscc/bf bf_codegen.tc,NONE,1.1 bf_defs.tc,NONE,1.1 bf_grammar.y,NONE,1.1 bf_internal.h,NONE,1.1 bf_optimize.c,NONE,1.1 bf_rename.h,NONE,1.1 bf_scanner.l,NONE,1.1 Makefile.am,NONE,1.1,
Gopal.V <address@hidden> <=