Permalink
Browse files

Initial addition of Backend Code

IF, DO, DO WHILE, CYCLE, EXIT, FUNXTION, RESULT, SUBROUTINE, RETURN ans GOTO
constructs should all work.
The majority of expressions also work.
Don't even bother trying derived types, arrays, modules or calls.
  • Loading branch information...
1 parent 4d7a642 commit 0c5a32c0564b090aefe650c464c4c9fecb31b270 paul_brook committed Jun 29, 2002
Showing with 4,863 additions and 0 deletions.
  1. +226 −0 Make-lang.in
  2. +18 −0 config-lang.in
  3. +120 −0 convert.c
  4. +1,207 −0 support.c
  5. +12 −0 test.f90
  6. +16 −0 testprog.c
  7. +103 −0 trans-const.c
  8. +27 −0 trans-const.h
  9. +642 −0 trans-decl.c
  10. +385 −0 trans-expr.c
  11. +93 −0 trans-io.c
  12. +507 −0 trans-stmt.c
  13. +64 −0 trans-stmt.h
  14. +761 −0 trans-types.c
  15. +78 −0 trans-types.h
  16. +482 −0 trans.c
  17. +122 −0 trans.h
View
@@ -0,0 +1,226 @@
+# -*- makefile -*-
+# Top level makefile fragment for GNU g95, the GNU Fortran 95 compiler.
+# Copyright (C) 2002 Free Software Foundation, Inc.
+# Contributed by Paul Brook and Steven Bosscher
+
+#This file is part of G95.
+
+#G95 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.
+
+#G95 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 G95; see the file COPYING. If not, write to
+#the Free Software Foundation, 59 Temple Place - Suite 330,
+#Boston, MA 02111-1307, USA.
+
+# This file provides the language dependent support in the main Makefile.
+# Each language makefile fragment must provide the following targets:
+#
+# foo.all.build, foo.all.cross, foo.start.encap, foo.rest.encap,
+# foo.info, foo.dvi,
+# foo.install-normal, foo.install-common, foo.install-info, foo.install-man,
+# foo.uninstall, foo.distdir,
+# foo.mostlyclean, foo.clean, foo.distclean, foo.extraclean,
+# foo.maintainer-clean, foo.stage1, foo.stage2, foo.stage3, foo.stage4
+#
+# where `foo' is the name of the language.
+#
+# It should also provide rules for:
+#
+# - making any compiler driver (eg: g95)
+# - the compiler proper (eg: f951)
+# - define the names for selecting the language in LANGUAGES.
+# $(srcdir) must be set to the gcc/ source directory (*not* gcc/f95/).
+
+#^L
+# Actual name to use when installing a native compiler.
+G95_INSTALL_NAME = `echo g95|sed '$(program_transform_name)'`
+
+# Actual name to use when installing a cross-compiler.
+G95_CROSS_NAME = `echo g95|sed '$(program_transform_cross_name)'`
+
+# Some versions of `touch' (such as the version on Solaris 2.8)
+# do not correctly set the timestamp due to buggy versions of `utime'
+# in the kernel. So, we use `echo' instead.
+STAMP = echo timestamp >
+
+# this is in addition to th warning flags defined by default
+f95-warn = -Wno-write-strings
+
+G95_GENERATED =
+
+G95_EXES = f951$(exeext)
+
+G95_PARSER_SOURCE = /g95
+
+G95_PARSER_OBJS = f95/arith.o f95/array.o f95/check.o f95/decl.o f95/error.o \
+ f95/expr.o f95/format.o f95/interface.o f95/intrinsic.o f95/io.o \
+ f95/iresolve.o f95/match.o f95/matchexp.o f95/misc.o f95/module.o \
+ f95/parse.o f95/primary.o f95/resolve.o f95/scanner.o f95/select.o \
+ f95/simplify.o f95/st.o f95/symbol.o
+
+G95_OBJS = $(G95_PARSER_OBJS) \
+ f95/f95-lang.o f95/support.o f95/convert.o f95/trans.o \
+ f95/trans-decl.o f95/trans-types.o f95/trans-const.o f95/trans-expr.o \
+ f95/trans-stmt.o f95/trans-io.o
+
+G95_ADDITIONAL_OBJS = c-semantics.o c-pretty-print.o \
+ tree-cfg.o tree-dfa.o tree-optimize.o tree-ssa.o \
+ tree-ssa-pre.o tree-simple.o
+
+# G95 uses GMP for its internal arithmetics.
+G95_LIBS = $(LIBS) -lgmp
+
+#
+# Define the names for selecting g95 in LANGUAGES.
+
+# Tell GNU make to ignore files by these names if they exist.
+
+.PHONY: f95 f95.clean f95.mostlyclean f95.distclean f95.extraclean f95.maintainer-clean testf95
+
+F95 f95: f951$(exeext) f95/testprog$(exeext)
+
+testf95: $(srcdir)/f95/testprog
+ f95/testprog > $(srcdir)/f95/test.out
+ diff -q f95/test.out f95/correct.out
+
+#test program
+f95/testprog$(exeext): f95/testprog.o f95/test.o
+ $(CC) $(ALL_CFLAGS) $(LDFLAGS) f95/testprog.o f95/test.o -o $@
+
+f95/test.f90:
+ touch $@
+
+f95/test.s: $(srcdir)/f95/test.f90 ./f951$(exeext)
+ ./f951$(exeext) $(srcdir)/f95/test.f90 -o $@
+
+f95/test.o: f95/test.s
+ $(CC) $(ALL_CFLAGS) $(INCLUDES) -o $@ -c $<
+
+# The actual 'compiler' is called f951
+f951$(exeext): $(G95_OBJS) $(G95_ADDITIONAL_OBJS) \
+ $(BACKEND) $(LIBDEPS)
+ $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \
+ $(G95_OBJS) $(G95_ADDITIONAL_OBJS) $(BACKEND) $(G95_LIBS)
+
+gt-f95-f95-lang.h gtype-f95.h gt-f95-trans-decl.c: s-gtype; @true
+
+#
+# Compiling object files from source files.
+
+# Object file makes
+#f95/g95.o: $(srcdir)/g95.c $(CONFIG_H) $(TREE_H) flags.h
+# $(GCC_FOR_TARGET) -o $@ -c $(ALL_CFLAGS) $(INCLUDES) $<
+
+
+# Generated files
+# The files from lex and yacc are put into the source directory
+# in case someone wants to build but does not have lex/yacc.
+# We have a hand-crafted scanner/parser, so we don't generate
+# any files.
+
+force:
+
+$(INTL_TARGETS):
+
+#
+# Build hooks:
+
+f95.all.build: f95
+f95.all.cross:
+ _error_not_here_yet - havent even thought about it - it may even work
+
+f95.start.encap:
+f95.rest.encap:
+
+f95.info:
+f95.dvi:
+f95.generated-manpages:
+
+#
+# Install hooks:
+
+# Nothing to do here.
+f95.install-normal:
+
+f95.install-common: installdirs
+
+f95.install-info:
+
+f95.install-man:
+
+f95.uninstall:
+
+#
+# Clean hooks:
+# A lot of the ancillary files are deleted by the main makefile.
+# We just have to delete files specific to us.
+
+f95.mostlyclean:
+ -rm -f f951$(exeext)
+ -rm -f f95/*.o
+
+
+f95.clean: f95.mostlyclean
+
+f95.distclean:
+ -rm -f f95/config.status f95/Makefile
+ -rm -f f95/*.output
+
+f95.extraclean:
+
+f95.maintainer-clean:
+
+
+#
+# Stage hooks:
+# The toplevel makefile has already created stage?/f95 at this point.
+
+f95.stage1: stage1-start
+ -mv f95/*$(objext) stage1/f95
+f95.stage2: stage2-start
+ -mv f95/*$(objext) stage2/f95
+f95.stage3: stage3-start
+ -mv f95/*$(objext) stage3/f95
+f95.stage4: stage4-start
+ -mv f95/*$(objext) stage4/f95
+#
+# Maintenance hooks:
+
+# This target creates the files that can be rebuilt, but go in the
+# distribution anyway. It then copies the files to the distdir directory.
+f95.distdir:
+ not here yet
+
+#tests
+
+check: check-f95
+
+check-f95:
+
+# copy the output files from the current test to source ie say the new results are OK
+check-f95-fix: force
+
+# Dependencies for source files.
+# Can't be bothered doing these properly... Fix later :-)
+
+# Everything depends on g95.h
+$(G95_PARSER_OBJS): f95/g95.h
+
+f95/f95-lang.o: f95/g95.h
+f95/support.o: f95/g95.h
+f95/convert.o: f95/g95.h
+f95/trans.o: f95/g95.h f95/trans.h f95/trans-stmt.h
+f95/trans-decl.o: f95/g95.h
+f95/trans-types.o: f95/g95.h
+f95/trans-const.o: f95/g95.h f95/trans.h
+f95/trans-expr.o: f95/g95.h f95/trans.h
+f95/trans-stmt.o: f95/g95.h f95/trans.h f95/trans-stmt.h
+f95/trans-io.o: f95/g95.h f95/trans.h f95/trans-stmt.h
View
@@ -0,0 +1,18 @@
+# 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)
+# stagestuff - files to add to $(STAGESTUFF)
+# diff_excludes - files to ignore when building diffs between two versions.
+
+language="f95"
+
+compilers="f951\$(exeext)"
+
+stagestuff=
+
+gtfiles="\$(srcdir)/f95/f95-lang.c \$(srcdir)/f95/support.c \$(srcdir)/f95/trans-types.h \$(srcdir)/f95/trans-decl.c \$(srcdir)/f95/trans-types.c"
+
+#outputs=g95/Makefile
+
View
120 convert.c
@@ -0,0 +1,120 @@
+/* Language-level data type conversion for GNU C.
+ Copyright (C) 1987, 1988, 1991, 1998, 2002 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 2, 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 COPYING. If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA. */
+
+
+/* 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. */
+
+/* copied from the f77 frontend I think */
+
+/* copied from c-convert.c without significant modification*/
+/* 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.
+*/
+
+#include "config.h"
+#include "system.h"
+#include "tree.h"
+#include "flags.h"
+#include "convert.h"
+#include "c-common.h"
+#include "toplev.h"
+#include "g95-support.h"
+
+/*
+ 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. */
+
+/* Subroutines of `convert'. */
+
+
+
+/* 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 (type, expr)
+ tree type, 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 0
+ /* This is incorrect. A truncation can't be stripped this way.
+ Extensions will be stripped by the use of get_unwidened. */
+ if (TREE_CODE (expr) == NOP_EXPR)
+ return convert (type, TREE_OPERAND (expr, 0));
+#endif
+ if (code == INTEGER_TYPE || code == ENUMERAL_TYPE)
+ return fold (convert_to_integer (type, e));
+ if (code == BOOLEAN_TYPE)
+ {
+ tree t = g95_truthvalue_conversion (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;
+}
Oops, something went wrong.

0 comments on commit 0c5a32c

Please sign in to comment.