Commit e8645a40 by Tom Tromey Committed by Tom Tromey

MAINTAINERS: Update for treelang deletion.

.	* MAINTAINERS: Update for treelang deletion.
gcc
2008-03-05  Tom Tromey  <tromey@redhat.com>

	* treelang: Delete.
	* doc/standards.texi (Standards): Don't mention treelang.
	* doc/invoke.texi (Overall Options): Don't mention treelang.
	* doc/install.texi (Prerequisites): Don't mention bison or
	treelang.
	(Configuration): Don't mention treelang.
	(Building): Likewise.
	* doc/frontends.texi (G++ and GCC): Don't mention treelang.
gcc/testsuite
	* lib/treelang-dg.exp, lib/treelang.exp: Delete.
	* treelang: Delete.
gcc/testsuite/treelang
Removed
gcc/treelang
Removed

From-SVN: r132976
parent 3825be8c
2008-03-06 Tom Tromey <tromey@redhat.com>
* MAINTAINERS: Update for treelang deletion.
2008-03-03 James E. Wilson <wilson@tuliptree.org>
* MAINTAINERS: Update my email address.
......
......@@ -130,8 +130,6 @@ java Andrew Haley aph@redhat.com
java Tom Tromey tromey@redhat.com
objective-c/c++ Mike Stump mrs@apple.com
objective-c/c++ Stan Shebs stanshebs@earthlink.net
treelang Tim Josling tej@melbpc.org.au
treelang James A. Morrison phython@gcc.gnu.org
Various Maintainers
......@@ -338,6 +336,7 @@ Andreas Jaeger aj@suse.de
Harsha Jagasia harsha.jagasia@amd.com
Fariborz Jahanian fjahanian@apple.com
Phillip Jordan phillip.m.jordan@gmail.com
Tim Josling tej@melbpc.org.au
Klaus Kaempf kkaempf@progis.de
Victor Kaplansky victork@il.ibm.com
Brendan Kehoe brendan@zen.org
......@@ -385,6 +384,7 @@ Lee Millward lee.millward@gmail.com
Alan Modra amodra@bigpond.net.au
Alexander Monakov amonakov@ispras.ru
Catherine Moore clm@redhat.com
James A. Morrison phython@gcc.gnu.org
Dirk Mueller dmueller@suse.de
Adam Nemet anemet@caviumnetworks.com
Thomas Neumann tneumann@users.sourceforge.net
......
2008-03-06 Tom Tromey <tromey@redhat.com>
* treelang: Delete.
* doc/standards.texi (Standards): Don't mention treelang.
* doc/invoke.texi (Overall Options): Don't mention treelang.
* doc/install.texi (Prerequisites): Don't mention bison or
treelang.
(Configuration): Don't mention treelang.
(Building): Likewise.
* doc/frontends.texi (G++ and GCC): Don't mention treelang.
2008-03-06 Paolo Bonzini <bonzini@gnu.org>
* simplify-rtx.c (simplify_subreg): Remove useless shifts from
......
@c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
@c 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
@c 1999, 2000, 2001, 2002, 2004, 2008 Free Software Foundation, Inc.
@c This is part of the GCC manual.
@c For copying conditions, see the file gcc.texi.
......@@ -14,7 +14,6 @@
@cindex Java
@cindex Objective-C
@cindex Objective-C++
@cindex treelang
GCC stands for ``GNU Compiler Collection''. GCC is an integrated
distribution of compilers for several major programming languages. These
languages currently include C, C++, Objective-C, Objective-C++, Java,
......
......@@ -372,16 +372,6 @@ Necessary to run @samp{make check} for @file{fixinc}.
Necessary to regenerate the top level @file{Makefile.in} file from
@file{Makefile.tpl} and @file{Makefile.def}.
@item GNU Bison version 1.28 (or later)
Necessary when modifying @file{*.y} files. Necessary to build the
@code{treelang} front end (which is not enabled by default) from a
checkout of the SVN repository; the generated files are not in the
repository. They are included in releases.
Berkeley @command{yacc} (@command{byacc}) has been reported to work
as well.
@item Flex version 2.5.4 (or later)
Necessary when modifying @file{*.l} files.
......@@ -1161,11 +1151,11 @@ grep language= */config-lang.in
@end smallexample
Currently, you can use any of the following:
@code{all}, @code{ada}, @code{c}, @code{c++}, @code{fortran}, @code{java},
@code{objc}, @code{obj-c++}, @code{treelang}.
@code{objc}, @code{obj-c++}.
Building the Ada compiler has special requirements, see below.
If you do not pass this flag, or specify the option @code{all}, then all
default languages available in the @file{gcc} sub-tree will be configured.
Ada, Objective-C++, and treelang are not default languages; the rest are.
Ada and Objective-C++ are not default languages; the rest are.
Re-defining @code{LANGUAGES} when calling @samp{make} @strong{does not}
work anymore, as those language sub-directories might not have been
configured!
......@@ -1707,18 +1697,13 @@ that type mismatches occur, this could be the cause.
The solution is not to use such a directory for building GCC@.
When building from SVN or snapshots and enabling the @code{treelang}
front end, or if you modify @file{*.y} files, you need the Bison parser
generator installed. If you do not modify @file{*.y} files, releases
contain the Bison-generated files and you do not need Bison installed
to build them. Note that most front ends now use hand-written parsers,
which can be modified with no need for Bison.
Similarly, when building from SVN or snapshots, or if you modify
@file{*.l} files, you need the Flex lexical analyzer generator installed.
There is still one Flex-based lexical analyzer (part of the build
machinery, not of GCC itself) that is used even if you only build the
C front end.
@file{*.l} files, you need the Flex lexical analyzer generator
installed. If you do not modify @file{*.l} files, releases contain
the Flex-generated files and you do not need Flex installed to build
them. There is still one Flex-based lexical analyzer (part of the
build machinery, not of GCC itself) that is used even if you only
build the C front end.
When building from SVN or snapshots, or if you modify Texinfo
documentation, you need version 4.4 or later of Texinfo installed if you
......
......@@ -1001,7 +1001,6 @@ assembler assembler-with-cpp
ada
f95 f95-cpp-input
java
treelang
@end smallexample
@item -x none
......
@c Copyright (C) 2000, 2001, 2002, 2004, 2006, 2007 Free Software Foundation,
@c Copyright (C) 2000, 2001, 2002, 2004, 2006, 2007, 2008 Free Software Foundation,
@c Inc.
@c This is part of the GCC manual.
@c For copying conditions, see the file gcc.texi.
......@@ -219,14 +219,6 @@ and
have additional useful information.
@end itemize
@section Treelang language
@cindex treelang
There is no standard for treelang, which is a sample language front end
for GCC@. Its only purpose is as a sample for people wishing to write a
new language for GCC@. The language is documented in
@file{gcc/treelang/treelang.texi} which can be turned into info or
HTML format.
@xref{Top, GNAT Reference Manual, About This Guide, gnat_rm,
GNAT Reference Manual}, for information on standard
conformance and compatibility of the Ada compiler.
......
2008-03-06 Tom Tromey <tromey@redhat.com>
* lib/treelang-dg.exp, lib/treelang.exp: Delete.
* treelang: Delete.
2008-03-05 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/specs/pack33.ads: New test.
# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2007
# 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 Free Software Foundation; either version 3 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 GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.
load_lib gcc-dg.exp
# Define gcc callbacks for dg.exp.
proc treelang-dg-test { prog do_what extra_tool_flags } {
return [gcc-dg-test-1 treelang_target_compile $prog $do_what $extra_tool_flags]
}
proc treelang-dg-prune { system text } {
return [gcc-dg-prune $system $text]
}
# Utility routines.
# Modified dg-runtest that can cycle through a list of optimization options
# as c-torture does.
proc treelang-dg-runtest { testcases default-extra-flags } {
return [gcc-dg-runtest $testcases ${default-extra-flags}]
}
# Copyright (C) 1992, 1993, 1994, 1996, 1997, 2000, 2001, 2002, 2004,
# 2007 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 Free Software Foundation; either version 3 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 GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.
# This file was written by Rob Savoye (rob@cygnus.com)
# Currently maintained by James A. Morrison (ja2morri@uwaterloo.ca)
# Having this file here magically tells dejagnu that the treelang
# directory is worthy of testing
# This file is basically gcc.exp with gcc replaced with treelang.
# This file is loaded by the tool init file (eg: unix.exp). It provides
# default definitions for treelang_start, etc. and other supporting cast
# members.
# These globals are used by treelang_start if no compiler arguments are
# provided. They are also used by the various testsuites to define the
# environment: where to find stdio.h, libc.a, etc.
load_lib libgloss.exp
load_lib prune.exp
load_lib gcc-defs.exp
load_lib target-libpath.exp
#
# TREELANG_UNDER_TEST is the compiler under test.
#
#
# default_treelang_version -- extract and print the version number of the compiler
#
proc default_treelang_version { } {
global TREELANG_UNDER_TEST
treelang_init
# ignore any arguments after the command
set compiler [lindex $TREELANG_UNDER_TEST 0]
if ![is_remote host] {
set compiler_name [which $compiler]
} else {
set compiler_name $compiler
}
# verify that the compiler exists
if { $compiler_name != 0 } then {
set tmp [remote_exec host "$compiler -v"]
set status [lindex $tmp 0]
set output [lindex $tmp 1]
regexp " version \[^\n\r\]*" $output version
if { $status == 0 && [info exists version] } then {
clone_output "$compiler_name $version\n"
} else {
clone_output "Couldn't determine version of $compiler_name: $output\n"
}
} else {
# compiler does not exist (this should have already been detected)
warning "$compiler does not exist"
}
}
# treelang_init -- called at the start of each .exp script.
#
# There currently isn't much to do, but always using it allows us to
# make some enhancements without having to go back and rewrite the scripts.
#
set treelang_initialized 0
proc treelang_init { args } {
global tmpdir
global libdir
global gluefile wrap_flags
global treelang_initialized
global TREELANG_UNDER_TEST
global TOOL_EXECUTABLE
global treelang_libgcc_s_path
# We set LC_ALL and LANG to C so that we get the same error messages as expected.
setenv LC_ALL C
setenv LANG C
if { $treelang_initialized == 1 } { return; }
if ![info exists TREELANG_UNDER_TEST] then {
if [info exists TOOL_EXECUTABLE] {
set TREELANG_UNDER_TEST $TOOL_EXECUTABLE
} else {
set TREELANG_UNDER_TEST [find_gcc]
}
}
if ![info exists tmpdir] then {
set tmpdir /tmp
}
treelang_maybe_build_wrapper "${tmpdir}/treelang-testglue.o"
set treelang_libgcc_s_path \
[gcc-set-multilib-library-path $TREELANG_UNDER_TEST]
}
proc treelang_target_compile { source dest type options } {
global rootme
global tmpdir
global gluefile wrap_flags
global srcdir
global TREELANG_UNDER_TEST
global TOOL_OPTIONS
global ld_library_path
global treelang_libgcc_s_path
set ld_library_path ".:${treelang_libgcc_s_path}"
set_ld_library_path_env_vars
if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
lappend options "libs=${gluefile}"
lappend options "ldflags=$wrap_flags"
}
# TOOL_OPTIONS must come first, so that it doesn't override testcase
# specific options.
if [info exists TOOL_OPTIONS] {
set options [concat "{additional_flags=$TOOL_OPTIONS}" $options]
}
# If we have built libtreelang along with the compiler (which usually
# _is not_ the case on Mac OS X systems), point the test harness
# at it (and associated headers).
return [target_compile $source $dest $type $options]
}
#
# treelang_pass -- utility to record a testcase passed
#
proc treelang_pass { testcase cflags } {
if { "$cflags" == "" } {
pass "$testcase"
} else {
pass "$testcase, $cflags"
}
}
#
# treelang_fail -- utility to record a testcase failed
#
proc treelang_fail { testcase cflags } {
if { "$cflags" == "" } {
fail "$testcase"
} else {
fail "$testcase, $cflags"
}
}
#
# treelang_finish -- called at the end of every .exp script that calls treelang_init
#
# The purpose of this proc is to hide all quirks of the testing environment
# from the testsuites. It also exists to undo anything that treelang_init did
# (that needs undoing).
#
proc treelang_finish { } {
# The testing harness apparently requires this.
global errorInfo
if [info exists errorInfo] then {
unset errorInfo
}
# Might as well reset these (keeps our caller from wondering whether
# s/he has to or not).
global prms_id bug_id
set prms_id 0
set bug_id 0
}
proc treelang_exit { } {
global gluefile
if [info exists gluefile] {
file_on_build delete $gluefile
unset gluefile
}
}
# If this is an older version of dejagnu (without runtest_file_p),
# provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
# This can be deleted after next dejagnu release.
if { [info procs runtest_file_p] == "" } then {
proc runtest_file_p { runtests testcase } {
if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
return 1
} else {
return 0
}
}
return 1
}
}
# Provide a definition of this if missing (delete after next dejagnu release).
if { [info procs prune_warnings] == "" } then {
proc prune_warnings { text } {
return $text
}
}
# Utility used by mike-gcc.exp and c-torture.exp.
# Check the compiler(/assembler/linker) output for text indicating that
# the testcase should be marked as "unsupported".
#
# When dealing with a large number of tests, it's difficult to weed out the
# ones that are too big for a particular cpu (eg: 16 bit with a small amount
# of memory). There are various ways to deal with this. Here's one.
# Fortunately, all of the cases where this is likely to happen will be using
# gld so we can tell what the error text will look like.
proc ${tool}_check_unsupported_p { output } {
if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $output] {
return "memory full"
}
return ""
}
# Prune messages from treelang that aren't useful.
proc prune_treelang_output { text } {
#send_user "Before:$text\n"
regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
# It would be nice to avoid passing anything to treelang that would cause it to
# issue these messages (since ignoring them seems like a hack on our part),
# but that's too difficult in the general case. For example, sometimes
# you need to use -B to point treelang at crt0.o, but there are some targets
# that don't have crt0.o.
regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
#send_user "After:$text\n"
return $text
}
2005-08-06 James A. Morrison <phython@gcc.gnu.org>
* treetests.exp: Remove.
* a01gcco01runpgm: Move to...
* output/output-1.out: here.
* a01gcci01.c: Move to...
* output/output-1.c: here.
* a01gcci01.tree: Move to...
* output/output-1.tree: here.
* output/output.exp: New.
2005-07-23 James A. Morrison <phython@gcc.gnu.org>
* compile/var_defs.tree: Remove extra lines.
2005-07-19 James A. Morrison <phython@gcc.gnu.org>
* compile/var_defs.tree: Remove duplicate variable.
* compile/var_defs-2.tree: Add duplicate variable test.
2005-03-22 James A. Morrison <phython@gcc.gnu.org>
* compile/memory.tree: New test.
2005-02-26 James A. Morrison <phython@gcc.gnu.org>
* compile/var_defs: Add uninitialized variables.
2005-02-26 James A. Morrison <phython@gcc.gnu.org>
* compile/extrafunc.tree, compile/extravar.tree: New tests.
2005-02-26 James A. Morrison <phython@gcc.gnu.org>
* compile/unsigned.tree: New test.
2005-02-24 James A. Morrison <phython@gcc.gnu.org>
PR other/19896
* execute/execute.exp: New file.
* execute/funccall.tree, execute/funccall-2.tree, execute/initial.tree,
execute/main.tree, execute/static.tree: New tests.
2005-02-24 James A. Morrison <phython@gcc.gnu.org>
PR other/19897
* compile/exit.tree, compile/extref.tree, compile/function-1.tree,
compile/syntax-1.tree: New tests.
2004-10-02 James A. Morrison <phython@gcc.gnu.org>
* compile/autofunc.tree: New File.
* compile/badchar.tree: New File.
* compile/externvar.tree: New File.
* compile/mismatch.tree: New File.
* compile/noproto.tree: New File.
* compile/novar.tree: New File.
* compile/var_defs.tree: Add duplicate variable.
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.
* compile/tabs.tree: Test whether the front end
compiles code with tabs in it.
2003-02-25 Tim Josling <tej@melbpc.org.au>
* treetests.exp (run3): set options to force aggressive GC, to
ensure GC is all set up correct,
2002-05-07 Tim Josling <tej@melbpc.org.au>
* Makefile.in: Fix copyright
* a01gcci01.c: Ditto
* a01gcci01.tree: Ditto
* treetests.exp: Ditto
2002-04-13 Tim Josling <tej@melbpc.org.au>
* treetree.c (tree_code_create_function_initial)
Remove duplicate call to layout_decl
2001-12-02 Tim Josling <tej@melbpc.org.au>
* Make-lang.in
Ensure directory is built during install (installdirs dependency)
* lex.l
Work around poisoned malloc (undef IN_GCC)
Remove fake definition of tree.
* parse.y
Work around poisoned malloc (undef IN_GCC)
* tree1.c
New front end interface.
(top level) New structure lang_hooks.
(tree_post_options) Remove.
errorcount now a macro so do not define it.
current_nesting_level => work_nesting_level due to clash.
* treelang.h
errorcount now a macro so do not reference it.
* treetree.c
Replace NULL_PTR by NULL.
(tree_code_get_expression) Mark op3 unused.
Do not init builtins.
2001-06-11 Tim Josling <tej@melbpc.org.au>
* treelang.exp (global) remove COBOL specific code.
2001-05-24 Tim Josling <tej@melbpc.org.au>
Created this directory and its tests. All derived from the cobol
test swamp which was also all written by me.
# Copyright (C) 2001, 2002, 2007 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
# Free Software Foundation; either version 3, 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 GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.
#
# 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!
#
#
all:
clean:
-rm -f *.o *.diff *~ *.bad core *.x
distclean: clean
-rm -f Makefile config.status
// { dg-do compile }
automatic int bar (); // { dg-error "automatic" }
bar () {
return -12;
}
// { dg-do compile }
static int bar = 1*; // { dg-error "Unrecognized" }
// { 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, 2007 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 3, 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 GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.
#
# 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 }
external_reference void exit (int code);
static int foo ();
foo
{
automatic int bar = +1;
bar = bar + +1;
exit (0); // Calling external references is currently broken.
return bar;
}
// { dg-do compile }
external_reference int bar = 0; // { dg-error "initial" }
static char barf = 1;
// { dg-do compile }
// { dg-options "-O2 -fdump-tree-optimized -Wunused-function" }
// Check to see that unused functions get removed at -O2 and
// above.
static int foo (int bar);
static int baz (int aaa);
external_definition int ext (int bbb);
foo
{
return bar;
}
baz // { dg-warning "defined but not used" }
{
return foo (aaa);
}
ext
{
return foo (bbb);
}
// { dg-final { scan-tree-dump-not "baz" "optimized" } }
// { dg-final { cleanup-tree-dump "optimized" } }
// { dg-do compile }
// { dg-options "-fdump-tree-optimized -O1 -Wunused-variable" }
external_definition int bar (int aaa, int ddd);
static int foo = -3; // { dg-warning "defined but not used" }
bar
{
automatic int ccc;
return aaa + ddd + +3;
}
// { dg-final { scan-tree-dump-not "ccc" "optimized" } }
// { dg-final { cleanup-tree-dump "optimized" } }
// { dg-do compile }
external_reference void abort ();
static int foo (int a);
foo
{
return a;
}
// { 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 }
static int foo ();
static int bar (int a);
foo
{
return 1;
}
bar
{
a = a + foo ();
return a;
}
// { dg-do compile }
static int bar ();
static void barf ();
bar {
barf (1); // { dg-error "mismatch" "barf" }
return -12;
}
// { dg-do compile }
foo // { dg-error "foo" "prototype" }
{
x = 3;
}
static void bar ();
bar {
x = 3; // { dg-error "x" "not defined" }
}
// { dg-do compile }
external_reference void exit(int); // { dg-error "(parse|syntax) error" }
static int foo (int a);
foo
{
return a;
}
// { 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 }
// { dg-options "-fdump-tree-gimple" }
external_reference void abort ();
external_reference void exit (int status);
external_definition int main (int argc, int argv);
main
{
automatic unsigned int bar = 2147483649;
automatic unsigned int baz = 2147483649;
if (bar == baz) {
abort ();
} else {
exit (0);
}
return +1;
}
// { dg-final { scan-tree-dump-not "\\\(int\\\)" "gimple" } }
// { dg-final { cleanup-tree-dump "gimple" } }
// { dg-do compile }
external_definition int first_nonzero (int arg5, int arg6);
first_nonzero
{
automatic int y;
automatic int y; // { dg-error "Duplicate" }
if (arg5)
{
return arg5;
}
else
{
automatic int j;
j = arg6;
return j;
}
return arg6;
}
// { dg-do compile }
// { dg-options "-Wuninitialized -O" }
external_definition void boring (int arg0);
external_definition char condition (char arg1, char arg2);
boring
{
arg0 = +5 + +3; // Force 3 and 5 to be signed numbers.
arg0 = arg0 + +3;
}
condition
{
if (arg1)
{
automatic int i; // { dg-warning "was declared here" }
return i + 1; // { dg-warning "uninitialized" }
}
else
{
automatic int j; // { dg-warning "was declared here" }
return j; // { dg-warning "uninitialized" }
}
}
# Tests for treelang; run from gcc/treelang/Make-lang.in => gcc/Makefile
# Copyright (C) 2004, 2007 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 3, 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 GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.
#
# 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 run }
external_definition int main (int argc);
static int foo (int bba);
foo
{
automatic int bar;
bar = bba + +1;
return bar;
}
main
{
automatic int aaa = +3;
aaa = foo (argc);
if (aaa == +2)
{
return +0;
}
else
{
return +1;
}
}
// { dg-do run }
// Tests whether initializtion works properly.
external_reference void abort ();
external_reference void exit (int code);
external_definition int main ();
static int foo ();
foo
{
automatic int bar;
bar = +1;
bar = bar + +1;
return bar;
}
main
{
automatic int aaa;
aaa = foo ();
if (aaa == +2)
{
exit (0);
}
else
{
abort ();
}
return 0;
}
// { dg-do run }
// Tests whether initializtion works properly.
external_reference void abort ();
external_reference void exit (int code);
external_definition int main ();
main
{
automatic int aaa = +3;
if (aaa == +3)
{
exit (0);
}
else
{
abort ();
}
return 0;
}
// { dg-do run }
external_definition int main (int argc);
main
{
if (argc == 1)
{
return 0;
}
else
{
return argc;
}
}
// { dg-do run }
external_reference void abort ();
external_reference void exit (int code);
external_definition int main (int argc, int argv);
static int foo ();
foo
{
static int bar = +1;
bar = bar + +1;
return bar;
}
main
{
automatic int aaa = +3;
aaa = foo ();
aaa = foo ();
if (aaa == 3)
{
exit (0);
}
else
{
abort ();
}
return 0;
}
/* Driver for treelang test pgm */
/*
Copyright (C) 2001, 2002, 2007 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
Free Software Foundation; either version 3, 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 GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>.
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!
*/
int add(int, int);
int subtract(int, int);
int first_nonzero(int, int);
extern int printf(char *template, ...);
int
main (int argc, char *argv[])
{
printf("2:%d\n", add(1,1));
printf("7:%d\n", add(3,4));
printf("-1:%d\n", subtract(3,4));
printf("1:%d\n", subtract(2,1));
printf("3:%d\n", first_nonzero(0,3));
printf("0:%d\n", first_nonzero(0,0));
printf("1:%d\n", first_nonzero(1,0));
printf("15:%d\n", double_plus_one(7));
return 0;
}
2:2
7:7
-1:-1
1:1
3:3
0:0
1:1
15:15
// -*- c -*- c mode in emacs
// Copyright (C) 2001, 2002, 2007 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
// Free Software Foundation; either version 3, 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 GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
//
// 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!
external_definition int add(int arg1, int arg2);
external_definition int subtract(int arg3, int arg4);
external_definition int first_nonzero(int arg5, int arg6);
external_definition int double_plus_one(int arg7);
add
{
return arg1 + arg2;
}
subtract
{
return arg3 - arg4;
}
double_plus_one
{
automatic int aaa;
aaa=add(arg7, arg7);
aaa=add(aaa, aaa);
aaa=subtract(subtract(aaa, arg7), arg7) + 1;
return aaa;
}
first_nonzero
{
if (arg5)
{
return arg5;
}
else
{
}
return arg6;
}
proc test_treelang_output { testname srcfiles infile resfile args } {
set comp_output [treelang_target_compile $srcfiles $testname executable $args]
if { [treelang_check_compile $testname $args $testname $comp_output] == 0 } {
return 0;
}
verbose "Expected output is in $resfile"
set id [open $resfile r]
set expected ""
append expected [read $id]
close $id
set output ""
set output [exec $testname $infile]
regsub -all "\r" "$output" "" output
regsub "\n*$" $expected "" expected
regsub "\n*$" $output "" output
regsub "^\n*" $expected "" expected
regsub "^\n*" $output "" output
regsub -all "\[ \t\]\[ \t\]*" $expected " " expected
regsub -all "\[ \t\]*\n\n*" $expected "\n" expected
regsub -all "\[ \t\]\[ \t\]*" $output " " output
regsub -all "\[ \t\]*\n\n*" $output "\n" output
verbose "expected is $expected"
verbose "actual is $output"
if { $expected == $output } {
pass $testname
} else {
fail $testname
}
exec rm $testname
}
global srcdir subdir
catch { lsort [glob -nocomplain ${srcdir}/${subdir}/*.out] } outfiles
verbose "Output files are $outfiles"
set prefix ""
foreach x $outfiles {
regsub "\\.out$" $x "" prefix
set bname [file tail $prefix]
if [file exists ${prefix}.inp] {
set inpfile ${prefix}.inp
} else {
set inpfile ""
}
verbose "inpfile is $inpfile"
set srcfiles [lsort [glob -nocomplain ${prefix}.{c,tree}]]
verbose "source files are $srcfiles"
test_treelang_output "treelang/$bname" $srcfiles $inpfile $x ""
}
# Local Variables:
# tcl-indent-level:4
# End:
This is a sample language front end for GCC.
This is a replacement for 'toy' which had potential copyright issues,
but more importantly it did not exercise very much of GCC. The intent
of this language is that it should provide a cookbook of language
elements that you can use in any language front end.
To this end, treelang is essentially an implementation of a subset of
the GCC back end 'tree' interface in syntax.
Thanks to Richard Kenner, Joachim Nadler and many others for helping
me to understand enough of GCC to do this.
Please note, the documentation is not a good model to use for GCC
front end documentation.
Tim Josling
19 June 2002
# Top level configure fragment for GNU C++.
# Copyright (C) 1994, 1995, 1997, 1998, 2000, 2001, 2002, 2007 Free Software Foundation, Inc.
# This file is part of GCC.
# GCC 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 3, or (at your option)
# any later version.
# GCC 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 GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.
# Configure looks for the existence of this file to auto-config each language.
# We define several parameters used by configure:
#
# language - name of language as it would appear in $(LANGUAGES)
# compilers - value to add to $(COMPILERS)
# diff_excludes - files to ignore when building diffs between two versions.
language="treelang"
compilers="tree1\$(exeext)"
diff_excludes="-x lex.c -x parse.c -x parse.h"
headers=
build_by_default="no"
gtfiles="\$(srcdir)/treelang/tree1.c \$(srcdir)/treelang/treetree.c \$(srcdir)/treelang/treelang.h"
/* Definitions for specs for TREELANG
The format of the specs file is documented in gcc.c
Copyright (C) 1995, 96-98, 1999, 2000, 2001, 2002, 2007 Free Software Foundation, Inc.
This file is part of GCC.
GCC 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 3, or (at your option)
any later version.
GCC 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; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
/*
This is the contribution to the `default_compilers' array in GCC.c for
treelang.
This file must compile with 'traditional', so no ANSI string concatenations
*/
{".tree", "@treelang", NULL, 0, 0},
{".TREE", "@treelang", NULL, 0, 0},
{".tre", "@treelang", NULL, 0, 0},
{".TRE", "@treelang", NULL, 0, 0},
{"@treelang",
"%{!E:tree1 %i %(cc1_options) %{J*} %{I*}\
%{!fsyntax-only:%(invoke_as)}}", NULL , 0, 0
},
; Options for the treelang front end.
; Copyright (C) 2003, 2007 Free Software Foundation, Inc.
;
; This file is part of GCC.
;
; GCC 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 3, or (at your option) any later
; version.
;
; GCC 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 GCC; see the file COPYING3. If not see
; <http://www.gnu.org/licenses/>.
; See the GCC internals manual for a description of this file's format.
; Please try to keep this file in ASCII collating order.
Language
Treelang
flexer-trace
Treelang
Trace lexical analysis
fparser-trace
Treelang
Trace the parsing process
v
Treelang
y
Treelang
; This comment is to ensure we retain the blank line above.
/* -*- c -*- = mode for emacs editor
TREELANG lexical analysis
---------------------------------------------------------------------
Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2007, 2008 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
Free Software Foundation; either version 3, 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; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>.
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!
---------------------------------------------------------------------
Written by Tim Josling 1999-2001, based in part on other parts of
the GCC compiler. */
%{
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "input.h"
#include "tree.h"
/* Token defs. */
#include "treelang.h"
#include "parse.h"
#include "treetree.h"
#include "toplev.h"
extern int option_lexer_trace;
int yylex (void);
void update_yylval (int a);
static int next_tree_charno = 1;
static int lineno = 1;
static void update_lineno_charno (void);
static void dump_lex_value (int lexret);
#define SAVE_RETURN(a) {update_yylval (a); if (option_lexer_trace)\
{fprintf (stderr, "\nlexer returning"); dump_lex_value (a);} return a;}
#define NOT_RETURN(a) {update_yylval (a); if (option_lexer_trace)\
{fprintf (stderr, "\nlexer swallowing"); dump_lex_value (a);}}
%}
%option nostack
%option nounput
%option noyywrap
%option pointer
%option nodefault
%%
{
/* ??? Should really allocate only what we need. */
yylval = my_malloc (sizeof (struct prod_token_parm_item));
LINEMAP_POSITION_FOR_COLUMN (input_location, line_table,
next_tree_charno);
((struct prod_token_parm_item *)yylval)->tp.tok.location = input_location;
((struct prod_token_parm_item *)yylval)->tp.tok.charno = next_tree_charno;
}
[ \n\t]+ {
update_lineno_charno ();
NOT_RETURN (WHITESPACE);
}
"//".* {
/* Comment. */
update_lineno_charno ();
NOT_RETURN (COMMENT);
}
"{" {
update_lineno_charno ();
SAVE_RETURN (LEFT_BRACE);
}
"}" {
update_lineno_charno ();
SAVE_RETURN (RIGHT_BRACE);
}
"(" {
update_lineno_charno ();
SAVE_RETURN (LEFT_PARENTHESIS);
}
")" {
update_lineno_charno ();
SAVE_RETURN (RIGHT_PARENTHESIS);
}
"," {
update_lineno_charno ();
SAVE_RETURN (COMMA);
}
";" {
update_lineno_charno ();
SAVE_RETURN (SEMICOLON);
}
"+" {
update_lineno_charno ();
SAVE_RETURN (tl_PLUS);
}
"-" {
update_lineno_charno ();
SAVE_RETURN (tl_MINUS);
}
"=" {
update_lineno_charno ();
SAVE_RETURN (ASSIGN);
}
"==" {
update_lineno_charno ();
SAVE_RETURN (EQUALS);
}
[+-]?[0-9]+ {
update_lineno_charno ();
SAVE_RETURN (INTEGER);
}
"external_reference" {
update_lineno_charno ();
SAVE_RETURN (EXTERNAL_REFERENCE);
}
"external_definition" {
update_lineno_charno ();
SAVE_RETURN (EXTERNAL_DEFINITION);
}
"static" {
update_lineno_charno ();
SAVE_RETURN (STATIC);
}
"automatic" {
update_lineno_charno ();
SAVE_RETURN (AUTOMATIC);
}
"int" {
update_lineno_charno ();
SAVE_RETURN (INT);
}
"char" {
update_lineno_charno ();
SAVE_RETURN (CHAR);
}
"void" {
update_lineno_charno ();
SAVE_RETURN (VOID);
}
"unsigned" {
update_lineno_charno ();
SAVE_RETURN (UNSIGNED);
}
"return" {
update_lineno_charno ();
SAVE_RETURN (tl_RETURN);
}
"if" {
update_lineno_charno ();
SAVE_RETURN (IF);
}
"else" {
update_lineno_charno ();
SAVE_RETURN (ELSE);
}
[A-Za-z_]+[A-Za-z_0-9]* {
update_lineno_charno ();
update_yylval (NAME);
if (option_lexer_trace)
{
fprintf (stderr, "\nlexer returning");
dump_lex_value (NAME);
}
return NAME;
}
[^\n] {
update_lineno_charno ();
error ("%HUnrecognized character %qc.",
&((struct prod_token_parm_item *)yylval)->tp.tok.location,
yytext[0]);
}
%%
/*
Update line number (1-) and character number (1-). Call this
before processing the token. */
static void
update_lineno_charno (void)
{
/* Update the values we send to caller in case we sometimes don't
tell them about all the 'tokens' eg comments etc. */
int yyl;
LINEMAP_POSITION_FOR_COLUMN (input_location, line_table,
next_tree_charno);
((struct prod_token_parm_item *)yylval)->tp.tok.location = input_location;
((struct prod_token_parm_item *)yylval)->tp.tok.charno = next_tree_charno;
for ( yyl = 0; yyl < yyleng; ++yyl )
{
if ( yytext[yyl] == '\n' )
{
source_location s = linemap_line_start (line_table, ++lineno,
80);
input_location = s;
next_tree_charno = 1;
}
else
next_tree_charno++;
}
}
/* Fill in the fields of yylval - the value of the token. The token
type is A. */
void
update_yylval (int a)
{
struct prod_token_parm_item * tok;
tok = yylval;
tok->category = token_category;
tok->type = a;
tok->tp.tok.length = yyleng;
/* Have to copy yytext as it is just a ptr into the buffer at the
moment. */
tok->tp.tok.chars = (const unsigned char *) get_string (yytext, yyleng);
}
/* Trace the value LEXRET and the position and token details being
returned by the lexical analyser. */
static void
dump_lex_value (int lexret)
{
int ix;
fprintf (stderr, " %d l:%d c:%d ln:%d text=", lexret,
LOCATION_LINE (((struct prod_token_parm_item *)
yylval)->tp.tok.location),
((struct prod_token_parm_item *) yylval)->tp.tok.charno,
((struct prod_token_parm_item *) yylval)->tp.tok.length);
for (ix = 0; ix < yyleng; ix++)
{
fprintf (stderr, "%c", yytext[ix]);
}
fprintf (stderr, " in hex:");
for (ix = 0; ix < yyleng; ix++)
{
fprintf (stderr, " %2.2x", yytext[ix]);
}
fprintf (stderr, "\n");
}
/* Specific flags and argument handling of the Treelang front-end.
Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
This file is part of GCC.
GCC 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 3, or (at your option)
any later version.
GCC 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 GNU CC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "gcc.h"
#include "coretypes.h"
#include "tm.h"
void
lang_specific_driver (int *in_argc, const char *const **in_argv,
int *in_added_libraries ATTRIBUTE_UNUSED)
{
int argc = *in_argc, i;
const char *const *argv = *in_argv;
for (i = 1; i < argc; ++i)
{
if (!strcmp (argv[i], "-fversion")) /* Really --version!! */
{
printf ("\
GNU Treelang (GCC %s)\n\
Copyright (C) 2006 Free Software Foundation, Inc.\n\
\n\
GNU Treelang comes with NO WARRANTY, to the extent permitted by law.\n\
You may redistribute copies of GNU Treelang\n\
under the terms of the GNU General Public License.\n\
For more information about these matters, see the file named COPYING\n\
", version_string);
exit (0);
}
}
}
/* Called before linking. Returns 0 on success and -1 on failure. */
int
lang_specific_pre_link (void) /* Not used for Treelang. */
{
return 0;
}
/* Number of extra output files that lang_specific_pre_link may generate. */
int lang_specific_extra_outfiles = 0; /* Not used for Treelang. */
/* Language-level data type conversion for Treelang.
This is a very slightly modified copy of c-convert.c.
Copyright (C) 1987, 1988, 1991, 1998, 2002, 2003, 2007
Free Software Foundation, Inc.
This file is part of GCC.
GCC 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 3, or (at your option) any later
version.
GCC 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 GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
/* This file contains the functions for converting C expressions
to different data types. The only entry point is `convert'.
Every language front end must have a `convert' function
but what kind of conversions it does will depend on the language. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "diagnostic.h"
#include "tree.h"
#include "flags.h"
#include "convert.h"
#include "toplev.h"
#include "langhooks.h"
/* Change of width--truncation and extension of integers or reals--
is represented with NOP_EXPR. Proper functioning of many things
assumes that no other conversions can be NOP_EXPRs.
Conversion between integer and pointer is represented with CONVERT_EXPR.
Converting integer to real uses FLOAT_EXPR
and real to integer uses FIX_TRUNC_EXPR.
Here is a list of all the functions that assume that widening and
narrowing is always done with a NOP_EXPR:
In convert.c, convert_to_integer.
In c-typeck.c, build_binary_op (boolean ops), and
c_common_truthvalue_conversion.
In expr.c: expand_expr, for operands of a MULT_EXPR.
In fold-const.c: fold.
In tree.c: get_narrower and get_unwidened. */
/* Create an expression whose value is that of EXPR,
converted to type TYPE. The TREE_TYPE of the value
is always TYPE. This function implements all reasonable
conversions; callers should filter out those that are
not permitted by the language being compiled. */
tree
convert (tree type, tree expr)
{
tree e = expr;
enum tree_code code = TREE_CODE (type);
if (type == TREE_TYPE (expr)
|| TREE_CODE (expr) == ERROR_MARK
|| code == ERROR_MARK || TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
return expr;
if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr)))
return fold_build1 (NOP_EXPR, type, expr);
if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
return error_mark_node;
if (TREE_CODE (TREE_TYPE (expr)) == VOID_TYPE)
{
error ("void value not ignored as it ought to be");
return error_mark_node;
}
if (code == VOID_TYPE)
return build1 (CONVERT_EXPR, type, e);
if (code == INTEGER_TYPE || code == ENUMERAL_TYPE)
return fold (convert_to_integer (type, e));
if (code == BOOLEAN_TYPE)
{
tree t = expr;
/* If it returns a NOP_EXPR, we must fold it here to avoid
infinite recursion between fold () and convert (). */
if (TREE_CODE (t) == NOP_EXPR)
return fold_build1 (NOP_EXPR, type, TREE_OPERAND (t, 0));
else
return fold_build1 (NOP_EXPR, type, t);
}
if (code == POINTER_TYPE || code == REFERENCE_TYPE)
return fold (convert_to_pointer (type, e));
if (code == REAL_TYPE)
return fold (convert_to_real (type, e));
if (code == COMPLEX_TYPE)
return fold (convert_to_complex (type, e));
if (code == VECTOR_TYPE)
return fold (convert_to_vector (type, e));
error ("conversion to non-scalar type requested");
return error_mark_node;
}
/* TREELANG Compiler almost main (tree1)
Called by GCC's toplev.c
Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
2007, 2008 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 Free Software Foundation; either version 3 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; see the file COPYING3. If not, see
<http://www.gnu.org/licenses/>.
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!
---------------------------------------------------------------------------
Written by Tim Josling 1999, 2000, 2001, based in part on other
parts of the GCC compiler. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#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"
#include "treetree.h"
#include "opts.h"
#include "options.h"
extern int yyparse (void);
/* Linked list of symbols - all must be unique in treelang. */
static GTY(()) struct prod_token_parm_item *symbol_table = NULL;
/* Language for usage for messages. */
const char *const language_string = "TREELANG - sample front end for GCC ";
/* Local prototypes. */
void version (void);
/* Global variables. */
extern struct cbl_tree_struct_parse_tree_top* parse_tree_top;
/*
Options.
*/
/* Trace the parser. */
unsigned int option_parser_trace = 0;
/* Trace the lexical analysis. */
unsigned int option_lexer_trace = 0;
/* Warning levels. */
/* Local variables. */
/* This is 1 if we have output the version string. */
static int version_done = 0;
/* Variable nesting level. */
static unsigned int work_nesting_level = 0;
/* Prepare to handle switches. */
unsigned int
treelang_init_options (unsigned int argc ATTRIBUTE_UNUSED,
const char **argv ATTRIBUTE_UNUSED)
{
return CL_Treelang;
}
/* Process a switch - called by opts.c. */
int
treelang_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED,
int value)
{
enum opt_code code = (enum opt_code) scode;
switch (code)
{
case OPT_v:
if (!version_done)
{
fputs (language_string, stdout);
fputs (pkgversion_string, stdout);
fputs (version_string, stdout);
fputs ("\n", stdout);
version_done = 1;
}
break;
case OPT_y:
option_lexer_trace = 1;
option_parser_trace = 1;
break;
case OPT_fparser_trace:
option_parser_trace = value;
break;
case OPT_flexer_trace:
option_lexer_trace = value;
break;
default:
gcc_unreachable ();
}
return 1;
}
/* Language dependent parser setup. */
bool
treelang_init (void)
{
linemap_add (line_table, LC_ENTER, false, main_input_filename, 1);
/* This error will not happen from GCC as it will always create a
fake input file. */
if (!input_filename || input_filename[0] == ' ' || !input_filename[0])
{
if (!version_done)
{
fprintf (stderr, "No input file specified, try --help for help\n");
exit (1);
}
return false;
}
yyin = fopen (input_filename, "r");
if (!yyin)
{
fprintf (stderr, "Unable to open input file %s\n", input_filename);
exit (1);
}
linemap_add (line_table, LC_RENAME, false, "<built-in>", 1);
linemap_line_start (line_table, 0, 1);
/* Init decls, etc. */
treelang_init_decl_processing ();
return true;
}
/* Language dependent wrapup. */
void
treelang_finish (void)
{
fclose (yyin);
}
/* Parse a file. Debug flag doesn't seem to work. */
void
treelang_parse_file (int debug_flag ATTRIBUTE_UNUSED)
{
source_location s;
linemap_add (line_table, LC_RENAME, false, main_input_filename, 1);
s = linemap_line_start (line_table, 1, 80);
input_location = s;
treelang_debug ();
yyparse ();
cgraph_finalize_compilation_unit ();
linemap_add (line_table, LC_LEAVE, false, NULL, 0);
cgraph_optimize ();
}
/* Allocate SIZE bytes and clear them. Not to be used for strings
which must go in stringpool. */
void *
my_malloc (size_t size)
{
void *mem;
mem = ggc_alloc (size);
if (!mem)
{
fprintf (stderr, "\nOut of memory\n");
abort ();
}
memset (mem, 0, size);
return mem;
}
/* Look up a name in PROD->SYMBOL_TABLE_NAME in the symbol table;
return the symbol table entry from the symbol table if found there,
else 0. */
struct prod_token_parm_item*
lookup_tree_name (struct prod_token_parm_item *prod)
{
struct prod_token_parm_item *this;
struct prod_token_parm_item *this_tok;
struct prod_token_parm_item *tok;
sanity_check (prod);
tok = SYMBOL_TABLE_NAME (prod);
sanity_check (tok);
for (this = symbol_table; this; this = this->tp.pro.next)
{
sanity_check (this);
this_tok = this->tp.pro.main_token;
sanity_check (this_tok);
if (tok->tp.tok.length != this_tok->tp.tok.length)
continue;
if (memcmp (tok->tp.tok.chars, this_tok->tp.tok.chars,
this_tok->tp.tok.length))
continue;
if (option_parser_trace)
fprintf (stderr, "Found symbol %s (%i:%i) as %i \n",
tok->tp.tok.chars, LOCATION_LINE (tok->tp.tok.location),
tok->tp.tok.charno, NUMERIC_TYPE (this));
return this;
}
if (option_parser_trace)
fprintf (stderr, "Not found symbol %s (%i:%i) as %i \n",
tok->tp.tok.chars, LOCATION_LINE (tok->tp.tok.location),
tok->tp.tok.charno, tok->type);
return NULL;
}
/* Insert name PROD into the symbol table. Return 1 if duplicate, 0 if OK. */
int
insert_tree_name (struct prod_token_parm_item *prod)
{
struct prod_token_parm_item *tok;
tok = SYMBOL_TABLE_NAME (prod);
sanity_check (prod);
if (lookup_tree_name (prod))
{
error ("%HDuplicate name %q.*s.", &tok->tp.tok.location,
tok->tp.tok.length, tok->tp.tok.chars);
return 1;
}
prod->tp.pro.next = symbol_table;
NESTING_LEVEL (prod) = work_nesting_level;
symbol_table = prod;
return 0;
}
/* Create a struct productions of type TYPE, main token MAIN_TOK. */
struct prod_token_parm_item *
make_production (int type, struct prod_token_parm_item *main_tok)
{
struct prod_token_parm_item *prod;
prod = my_malloc (sizeof (struct prod_token_parm_item));
prod->category = production_category;
prod->type = type;
prod->tp.pro.main_token = main_tok;
return prod;
}
/* Abort if ITEM is not a valid structure, based on 'category'. */
void
sanity_check (struct prod_token_parm_item *item)
{
switch (item->category)
{
case token_category:
case production_category:
case parameter_category:
break;
default:
gcc_unreachable ();
}
}
/* New garbage collection regime see gty.texi. */
#include "gt-treelang-tree1.h"
/*#include "gt-treelang-treelang.h"*/
#include "gtype-treelang.h"
/* TREELANG Compiler common definitions (treelang.h)
Copyright (C) 1986, 87, 89, 92-96, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
2007 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
Free Software Foundation; either version 3, 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; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>.
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!
---------------------------------------------------------------------------
Written by Tim Josling 1999, 2000, 2001, based in part on other
parts of the GCC compiler. */
#include "input.h"
/* Parse structure type. */
enum category_enum
{ /* These values less likely to be there by chance unlike 0/1,
make checks more meaningful */
token_category = 111,
production_category = 222,
parameter_category = 333
};
/* Input file FILE. */
extern FILE* yyin;
/* Forward references to satisfy mutually recursive definitions. */
struct token_part;
struct production_part;
struct prod_token_parm_item;
typedef struct prod_token_parm_item item;
/* A token from the input file. */
struct token_part GTY(())
{
location_t location;
unsigned int charno;
unsigned int length; /* The value. */
const unsigned char *chars;
};
/* Definitions for fields in production. */
#define NESTING_LEVEL(a) a->tp.pro.info[0] /* Level used for variable definitions. */
/* Numeric type used in type definitions and expressions. */
#define NUMERIC_TYPE(a) a->tp.pro.info[1]
#define SUB_COUNT 5
#define SYMBOL_TABLE_NAME(a) (a->tp.pro.sub[0]) /* Name token. */
#define EXPRESSION_TYPE(a) (a->tp.pro.sub[1]) /* Type identifier. */
#define OP1(a) (a->tp.pro.sub[2]) /* Exp operand1. */
#define PARAMETERS(a) (a->tp.pro.sub[2]) /* Function parameters. */
#define VARIABLE(a) (a->tp.pro.sub[2]) /* Parameter variable ptr. */
#define VAR_INIT(a) (a->tp.pro.sub[2]) /* Variable init. */
#define OP2(a) (a->tp.pro.sub[3]) /* Exp operand2. */
/* Function parameters linked via struct tree_parameter_list. */
#define FIRST_PARMS(a) (a->tp.pro.sub[3])
#define OP3(a) (a->tp.pro.sub[4]) /* Exp operand3. */
#define STORAGE_CLASS_TOKEN(a) (a->tp.pro.sub[4]) /* Storage class token. */
#define STORAGE_CLASS(a) a->tp.pro.flag1 /* Values in treetree.h. */
struct production_part GTY(())
{
struct prod_token_parm_item *main_token; /* Main token for error msgs; variable name token. */
unsigned int info[2]; /* Extra information. */
struct prod_token_parm_item *sub[SUB_COUNT]; /* Sub productions or tokens. */
tree code; /* Back end hook for this item. */
struct prod_token_parm_item *next; /* Next in chains of various types. */
unsigned int flag1:2;
unsigned int flag2:1;
unsigned int flag3:1;
unsigned int flag4:1;
unsigned int flag5:1;
unsigned int flag6:1;
unsigned int flag7:1;
};
/* Storage modes. */
#define STATIC_STORAGE 0
#define AUTOMATIC_STORAGE 1
#define EXTERNAL_REFERENCE_STORAGE 2
#define EXTERNAL_DEFINITION_STORAGE 3
/* Numeric types. */
#define SIGNED_CHAR 1
#define UNSIGNED_CHAR 2
#define SIGNED_INT 3
#define UNSIGNED_INT 4
#define VOID_TYPE 5
/* Expression types. */
#define EXP_PLUS 0 /* Addition expression. */
#define EXP_REFERENCE 1 /* Variable reference. */
#define EXP_ASSIGN 2 /* Assignment. */
#define EXP_FUNCTION_INVOCATION 3 /* Call function. */
#define EXP_MINUS 4 /* Subtraction. */
#define EXP_EQUALS 5 /* Equality test. */
/* Parameter list passed to back end. */
struct parameter_part GTY(())
{
struct prod_token_parm_item *next; /* Next entry. */
const unsigned char *variable_name; /* Name. */
tree * GTY ((skip)) where_to_put_var_tree; /* Where to save decl. */
};
/* A production or a token. */
struct prod_token_parm_item GTY(())
{
enum category_enum category; /* Token or production. */
unsigned int type; /* Token or production type. */
union t_or_p
{
struct token_part GTY((tag ("token_category"))) tok;
struct production_part GTY((tag ("production_category"))) pro;
struct parameter_part GTY((tag ("parameter_category"))) par;
} GTY((desc ("((item *)&%1)->category"))) tp;
};
/* For parser. Alternatively you can define it using %union (bison) or
union. */
#define YYSTYPE void *
void *my_malloc (size_t size);
int insert_tree_name (struct prod_token_parm_item *prod);
struct prod_token_parm_item *lookup_tree_name (struct prod_token_parm_item *prod);
struct prod_token_parm_item *make_production (int type, struct prod_token_parm_item *main_tok);
void mark_production_used (struct prod_token_parm_item *pp);
void mark_token_used (struct prod_token_parm_item *tt);
void treelang_debug (void);
void sanity_check (struct prod_token_parm_item *item);
/* 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,
2004, 2005, 2007 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
Free Software Foundation; either version 3, 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; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>.
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!
---------------------------------------------------------------------------
Written by Tim Josling 1999, 2000, 2001, based in part on other
parts of the GCC compiler. */
tree tree_code_init_parameters (void);
tree tree_code_add_parameter (tree list, tree proto_exp, tree exp);
tree tree_code_get_integer_value (const unsigned char *chars, unsigned int length);
void tree_code_generate_return (tree type, tree exp);
void tree_ggc_storage_always_used (void *m);
tree tree_code_get_expression (unsigned int exp_type, tree type, tree op1,
tree op2, tree op3, location_t loc);
tree tree_code_get_numeric_type (unsigned int size1, unsigned int sign1);
void tree_code_create_function_initial (tree prev_saved,
location_t loc);
void tree_code_create_function_wrapup (location_t loc);
tree tree_code_create_function_prototype (const unsigned char *chars,
unsigned int storage_class,
unsigned int ret_type,
struct prod_token_parm_item* parms,
location_t loc);
tree tree_code_create_variable (unsigned int storage_class,
const unsigned char *chars,
unsigned int length,
unsigned int expression_type,
tree init,
location_t loc);
void tree_code_output_expression_statement (tree code,
location_t loc);
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);
tree tree_code_get_type (int type_num);
void treelang_init_decl_processing (void);
void treelang_finish (void);
bool treelang_init (void);
unsigned int treelang_init_options (unsigned int, const char **);
int treelang_handle_option (size_t scode, const char *arg, int value);
void treelang_parse_file (int debug_flag);
void push_var_level (void);
void pop_var_level (void);
const char* get_string (const char *s, size_t l);
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