Commit 352a77c8 by James A. Morrison

Make-lang.in (TREE_BE_LIBS): Remove.


treelang:
2004-08-01  James A. Morrison  <phython@gcc.gnu.org>

        * Make-lang.in (TREE_BE_LIBS): Remove.
        (tree1): Depend on BACKEND and LIBDEPS.  Use BACKEND and LIBS instead
        of TREE_BE_LIBS.
        * parse.y: Add variable_defs_opt before statements_opt.
        Use tree_code_get_type instead of get_type_for_numeric_type.
        Reformat long lines.
        (parameters_opt): New rule.
        (function_prototype): Use parameters_opt.
        (return): Remove calls to print_token in error cases.  Use VOID_TYPE.
        (check_type_match): Use VOID_TYPE.
        * lex.l (update_lineno_charno): Ensure INPUT_LINE starts at 1.
        * tree1.c: Include version.h and cgraph.h
        (treelang_parse_file): Call cgraph_finalize_compilation_unit and
        cgraph_optimize.
        * treelang.h (item): Remove extraneous GTY.
        * treetree.h (get_type_for_numeric_type): Remove.
        * treetree.c: Include tree-dump.h, tree-iterator.h, tree-gimple.h,
        function.h, and cgraph.h.  Don't include rtl.h
        (keep_level_p): Remove.
        (tree_push_atomic_type_decl): Remove.
         (get_type_for_numeric_type): Remove.
        (tree_code_get_numeric_type): Remove.
        (global_bindings_p): Make static.
        (getdecls): Likewise.
        (insert_block): Likewise.
        (tree_code_if_start): Create a COND_EXPR and add it to the tree
        instead of creating rtl.
        (tree_code_if_else): Create a BIND_EXPR if any variables were created
        in the if statement.
        (tree_code_end_if): Likewise.
        (tree_code_create_function_prototype): Use tree_code_get_type.
        Don't use SET_DECL_ASSEMBLER_NAME.
        (tree_code_create_function_initial): Set DECL_ARTIFICIAL and
        DECL_IGNORING_P on RESULT_DECL.  Use tree_code_get_type.  Don't call
        layout_decl on RESULT_DECL.  Don't call rtl expand functions.
        (tree_code_create_function_wrapup): Don't call rtl expand functions.
        Create a BIND_EXPR for each function.  Dump original and gimplified
        copies of the function tree.  Gimplify function.
        (tree_code_create_variable): Use tree_code_get_type.  Don't call
        layout_decl or expand_decl.  Fold CONVERT_EXPRs.
        (tree_code_generate_return): Fold CONVERT_EXPRs and MODIFY_EXPRs.
        Add RETURN_EXPR to the current statement list.  Don't call rtl expand
        functions.
        (tree_code_output_expression_statement): Append CODE to current
        statement list.
        (tree_code_get_expression): Fold expressions.  Build a pointer to
        a FUNCTION_TYPE intead of the called functions return type.
        (struct binding_level): Add statement list STMTS.
        (getstmtlist): New Function.
        (pushlevel): Make static.  Allocate an empty statement list.
        (poplevel): Make static.  Don't clear BLOCK_NODE's BLOCK_VARS.
        Don't use DECL_ASSEMBLER_NAME.
        (tree_push_type_decl): Set TYPE_NAME of TYPE_NODE to ID.
        (treelang_init_decl_processing): Define basic types after unused types.
        Don't call tree_push_atomic_type_decl.
        (builtin_function): Don't call make_decl_rtl.
        (treelang_expand_function). New Function.

testsuite/treelang:
        * compile/vars_def.tree: New File.
        * compile/badreturn.tree: New File.

From-SVN: r85684
parent c30ff96b
2004-07-31 James A. Morrison <phython@gcc.gnu.org>
* compile/vars_def.tree: New File.
* compile/badreturn.tree: New File.
2004-01-18 James A. Morrison <ja2morri@uwaterloo.ca>
* compile/compile.exp: New File.
......
......@@ -27,6 +27,7 @@
int add(int, int);
int subtract(int, int);
int first_nonzero(int, int);
extern int printf(char *template, ...);
int
main (int argc, char *argv[])
......
// { dg-do compile }
external_definition void bar ();
external_definition int gar (int arg0);
bar
{
return 0; // { dg-warning "return" }
}
gar
{
return; // { dg-error "return" }
}
# Tests for treelang; run from gcc/treelang/Make-lang.in => gcc/Makefile
# Copyright (C) 2004 by The Free Software Foundation
# 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, 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, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
# In other words, you are welcome to use, share and improve this program.
# You are forbidden to forbid anyone else to use, share and improve
# what you give them. Help stamp out software-hoarding!
# Treelang tests that only need to compile.
# Load support procs.
load_lib treelang-dg.exp
dg-init
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.tree]] "" ""
dg-finish
// { dg-do compile }
// { dg-options "-funit-at-a-time" }
external_definition int add (int arga, int argb);
external_definition char sub (char argc, char argd);
add
{
return arga + argb + +3;
}
sub
{
return argd - argc + +2;
}
// { dg-final { scan-assembler "add" } }
// { dg-final { scan-assembler "sub" } }
// { dg-do compile }
external_definition int main(int argc);
main {
automatic int v1;
automatic int v2;
v1 = argc;
v2 = 3;
return v2;
}
// { dg-do compile }
external_definition void boring (int arg0);
external_definition char condition (char arg1, char arg2);
external_definition int first_nonzero (int arg5, int arg6);
boring
{
arg0 = +5 + +3; // Force 3 and 5 to be signed numbers.
arg0 = arg0 + +3;
}
condition
{
if (arg1)
{
automatic int i;
return arg1;
}
else
{
return 0;
}
}
first_nonzero
{
if (arg5)
{
return arg5;
}
else
{
automatic int j;
j = arg6;
return j;
}
return arg6;
}
2004-07-31 James A. Morrison <phython@gcc.gnu.org>
* Make-lang.in (TREE_BE_LIBS): Remove.
(tree1): Depend on BACKEND and LIBDEPS. Use BACKEND and LIBS instead
of TREE_BE_LIBS.
* parse.y: Add variable_defs_opt before statements_opt.
Use tree_code_get_type instead of get_type_for_numeric_type.
Reformat long lines.
(parameters_opt): New rule.
(function_prototype): Use parameters_opt.
(return): Remove calls to print_token in error cases. Use VOID_TYPE.
(check_type_match): Use VOID_TYPE.
* lex.l (update_lineno_charno): Ensure INPUT_LINE starts at 1.
* tree1.c: Include version.h and cgraph.h
(treelang_parse_file): Call cgraph_finalize_compilation_unit and
cgraph_optimize.
* treelang.h (item): Remove extraneous GTY.
* treetree.h (get_type_for_numeric_type): Remove.
* treetree.c: Include tree-dump.h, tree-iterator.h, tree-gimple.h,
function.h, and cgraph.h. Don't include rtl.h
(keep_level_p): Remove.
(tree_push_atomic_type_decl): Remove.
(get_type_for_numeric_type): Remove.
(tree_code_get_numeric_type): Remove.
(global_bindings_p): Make static.
(getdecls): Likewise.
(insert_block): Likewise.
(tree_code_if_start): Create a COND_EXPR and add it to the tree
instead of creating rtl.
(tree_code_if_else): Create a BIND_EXPR if any variables were created
in the if statement.
(tree_code_end_if): Likewise.
(tree_code_create_function_prototype): Use tree_code_get_type.
Don't use SET_DECL_ASSEMBLER_NAME.
(tree_code_create_function_initial): Set DECL_ARTIFICIAL and
DECL_IGNORING_P on RESULT_DECL. Use tree_code_get_type. Don't call
layout_decl on RESULT_DECL. Don't call rtl expand functions.
(tree_code_create_function_wrapup): Don't call rtl expand functions.
Create a BIND_EXPR for each function. Dump original and gimplified
copies of the function tree. Gimplify function.
(tree_code_create_variable): Use tree_code_get_type. Don't call
layout_decl or expand_decl. Fold CONVERT_EXPRs.
(tree_code_generate_return): Fold CONVERT_EXPRs and MODIFY_EXPRs.
Add RETURN_EXPR to the current statement list. Don't call rtl expand
functions.
(tree_code_output_expression_statement): Append CODE to current
statement list.
(tree_code_get_expression): Fold expressions. Build a pointer to
a FUNCTION_TYPE intead of the called functions return type.
(struct binding_level): Add statement list STMTS.
(getstmtlist): New Function.
(pushlevel): Make static. Allocate an empty statement list.
(poplevel): Make static. Don't clear BLOCK_NODE's BLOCK_VARS.
Don't use DECL_ASSEMBLER_NAME.
(tree_push_type_decl): Set TYPE_NAME of TYPE_NODE to ID.
(treelang_init_decl_processing): Define basic types after unused types.
Don't call tree_push_atomic_type_decl.
(builtin_function): Don't call make_decl_rtl.
(treelang_expand_function). New Function.
2004-07-11 Joseph S. Myers <jsm@polyomino.org.uk>
* treetree.c (set_block): Remove.
......
......@@ -45,10 +45,6 @@
TREELANGSED = sed
TREELANGSEDFLAGS = -n
# back end compiler libraries etc
TREE_BE_LIBS = $(BACKEND) $(LIBIBERTY) $(INTLIBS) $(LIBS) $(LIBDEPS)
GCC_EXTRAS = -B./ -B$(build_tooldir)/bin/ -isystem $(build_tooldir)/include
# ./xgcc is the just built compiler. See GCC_FOR_TARGET in the GCC Makefile.in.
......@@ -83,11 +79,11 @@ treelang.done: tree1$(exeext)
# core compiler
tree1$(exeext): treelang/tree1.o treelang/treetree.o treelang/tree-convert.o \
treelang/lex.o treelang/parse.o \
$(TREE_BE_LIBS) attribs.o
$(BACKEND) $(LIBSDEPS) attribs.o
$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \
treelang/tree1.o treelang/treetree.o treelang/tree-convert.o \
treelang/lex.o treelang/parse.o \
$(TREE_BE_LIBS) attribs.o
$(BACKEND) $(LIBS) attribs.o
#
# Compiling object files from source files.
......
......@@ -4,7 +4,7 @@
---------------------------------------------------------------------
Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003
Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003, 2004
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
......@@ -233,6 +233,9 @@ update_lineno_charno (void)
int yyl;
((struct prod_token_parm_item *)yylval)->tp.tok.location = input_location;
((struct prod_token_parm_item *)yylval)->tp.tok.charno = next_tree_charno;
if (input_line == 0)
input_line = 1;
for ( yyl = 0; yyl < yyleng; ++yyl )
{
if ( yytext[yyl] == '\n' )
......
......@@ -5,7 +5,8 @@
---------------------------------------------------------------------
Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004
Free Software Foundation, Inc.
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
......@@ -254,7 +255,7 @@ typename NAME {
;
function_prototype:
storage typename NAME LEFT_PARENTHESIS parameters RIGHT_PARENTHESIS SEMICOLON {
storage typename NAME LEFT_PARENTHESIS parameters_opt RIGHT_PARENTHESIS SEMICOLON {
struct prod_token_parm_item* tok;
struct prod_token_parm_item *prod;
struct prod_token_parm_item *type;
......@@ -450,6 +451,14 @@ INT {
}
;
parameters_opt:
/* Nothing to do. */ {
$$ = 0;
}
| parameters {
$$ = $1;
}
parameters:
parameter {
/* Nothing to do. */
......@@ -496,7 +505,7 @@ IF LEFT_PARENTHESIS expression RIGHT_PARENTHESIS {
ensure_not_void (NUMERIC_TYPE (exp), exp->tp.pro.main_token);
tree_code_if_start (exp->tp.pro.code, tok->tp.tok.location);
}
LEFT_BRACE statements_opt RIGHT_BRACE {
LEFT_BRACE variable_defs_opt statements_opt RIGHT_BRACE {
/* Just let the statements flow. */
}
ELSE {
......@@ -504,7 +513,7 @@ ELSE {
tok = $1;
tree_code_if_else (tok->tp.tok.location);
}
LEFT_BRACE statements_opt RIGHT_BRACE {
LEFT_BRACE variable_defs_opt statements_opt RIGHT_BRACE {
struct prod_token_parm_item* tok;
tok = $12;
tree_code_if_end (tok->tp.tok.location);
......@@ -518,25 +527,23 @@ tl_RETURN expression_opt {
struct prod_token_parm_item* ret_tok;
ret_tok = $1;
type_prod = EXPRESSION_TYPE (current_function);
if (NUMERIC_TYPE (type_prod) == VOID)
if (NUMERIC_TYPE (type_prod) == VOID_TYPE)
if ($2 == NULL)
tree_code_generate_return (type_prod->tp.pro.code, NULL);
else
{
fprintf (stderr, "%s:%i:%i: Redundant expression in return\n",
ret_tok->tp.tok.location.file,
ret_tok->tp.tok.location.line, ret_tok->tp.tok.charno);
print_token (stderr, 0, ret_tok);
ret_tok->tp.tok.location.file,
ret_tok->tp.tok.location.line, ret_tok->tp.tok.charno);
errorcount++;
tree_code_generate_return (type_prod->tp.pro.code, NULL);
}
}
else
if ($2 == NULL)
{
fprintf (stderr, "%s:%i:%i: Expression missing in return\n",
ret_tok->tp.tok.location.file,
ret_tok->tp.tok.location.line, ret_tok->tp.tok.charno);
print_token (stderr, 0, ret_tok);
ret_tok->tp.tok.location.file,
ret_tok->tp.tok.location.line, ret_tok->tp.tok.charno);
errorcount++;
}
else
......@@ -687,7 +694,7 @@ NAME LEFT_PARENTHESIS expressions_with_commas RIGHT_PARENTHESIS {
abort ();
parms = tree_code_add_parameter (parms, var->tp.pro.code, exp->tp.pro.code);
}
type = get_type_for_numeric_type (NUMERIC_TYPE (prod));
type = tree_code_get_type (NUMERIC_TYPE (prod));
prod->tp.pro.code = tree_code_get_expression
(EXP_FUNCTION_INVOCATION, type, proto->tp.pro.code, parms, NULL);
$$ = prod;
......@@ -734,7 +741,7 @@ NAME {
prod = make_production (PROD_VARIABLE_REFERENCE_EXPRESSION, tok);
NUMERIC_TYPE (prod) = NUMERIC_TYPE (symbol_table_entry);
type = get_type_for_numeric_type (NUMERIC_TYPE (prod));
type = tree_code_get_type (NUMERIC_TYPE (prod));
if (!NUMERIC_TYPE (prod))
YYERROR;
OP1 (prod) = $1;
......@@ -832,7 +839,7 @@ reverse_prod_list (struct prod_token_parm_item *old_first)
static void
ensure_not_void (unsigned int type, struct prod_token_parm_item* name)
{
if (type == VOID)
if (type == VOID_TYPE)
{
fprintf (stderr, "%s:%i:%i: Type must not be void in this context\n",
name->tp.tok.location.file,
......@@ -877,7 +884,7 @@ check_type_match (int type_num, struct prod_token_parm_item *exp)
case UNSIGNED_CHAR:
return 1;
case VOID:
case VOID_TYPE:
abort ();
default:
......@@ -885,7 +892,7 @@ check_type_match (int type_num, struct prod_token_parm_item *exp)
}
break;
case VOID:
case VOID_TYPE:
abort ();
default:
......@@ -903,7 +910,8 @@ make_integer_constant (struct prod_token_parm_item* value)
struct prod_token_parm_item *prod;
tok = value;
prod = make_production (PROD_INTEGER_CONSTANT, tok);
if ((tok->tp.tok.chars[0] == (unsigned char)'-')|| (tok->tp.tok.chars[0] == (unsigned char)'+'))
if ((tok->tp.tok.chars[0] == (unsigned char)'-')
|| (tok->tp.tok.chars[0] == (unsigned char)'+'))
NUMERIC_TYPE (prod) = SIGNED_INT;
else
NUMERIC_TYPE (prod) = UNSIGNED_INT;
......@@ -930,7 +938,7 @@ make_plus_expression (struct prod_token_parm_item* tok,
prod = make_production (PROD_PLUS_EXPRESSION, tok);
NUMERIC_TYPE (prod) = type_code;
type = get_type_for_numeric_type (NUMERIC_TYPE (prod));
type = tree_code_get_type (type_code);
if (!type)
abort ();
OP1 (prod) = op1;
......
......@@ -3,7 +3,8 @@
TREELANG Compiler almost main (tree1)
Called by GCC's toplev.c
Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003, 2004
Free Software Foundation, Inc.
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
......@@ -37,9 +38,11 @@
#include "tm.h"
#include "flags.h"
#include "toplev.h"
#include "version.h"
#include "ggc.h"
#include "tree.h"
#include "cgraph.h"
#include "diagnostic.h"
#include "treelang.h"
......@@ -141,7 +144,7 @@ bool
treelang_init (void)
{
input_filename = main_input_filename;
input_line = 0;
input_line = 1;
/* Init decls etc. */
......@@ -185,6 +188,8 @@ treelang_parse_file (int debug_flag ATTRIBUTE_UNUSED)
{
treelang_debug ();
yyparse ();
cgraph_finalize_compilation_unit ();
cgraph_optimize ();
}
/* Allocate SIZE bytes and clear them. Not to be used for strings
......
......@@ -2,7 +2,8 @@
TREELANG Compiler common definitions (treelang.h)
Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003, 2004
Free Software Foundation, Inc.
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
......@@ -48,7 +49,7 @@ extern FILE* yyin;
struct token_part;
struct production_part;
struct prod_token_parm_item;
typedef struct GTY(()) prod_token_parm_item item;
typedef struct prod_token_parm_item item;
/* A token from the input file. */
......
......@@ -3,7 +3,8 @@
TREELANG Compiler definitions for interfacing to treetree.c
(compiler back end interface).
Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003, 2004
Free Software Foundation, Inc.
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
......@@ -55,7 +56,6 @@ tree tree_code_create_variable (unsigned int storage_class,
location_t loc);
void tree_code_output_expression_statement (tree code,
location_t loc);
tree get_type_for_numeric_type (unsigned int numeric_type);
void tree_code_if_start (tree exp, location_t loc);
void tree_code_if_else (location_t loc);
void tree_code_if_end (location_t loc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment