1 // go-gcc.cc -- Go frontend to gcc IR.
2 // Copyright (C) 2011-2013 Free Software Foundation, Inc.
3 // Contributed by Ian Lance Taylor, Google.
5 // This file is part of GCC.
7 // GCC is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3, or (at your option) any later
12 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 // You should have received a copy of the GNU General Public License
18 // along with GCC; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 #include "go-system.h"
23 // This has to be included outside of extern "C", so we have to
24 // include it here before tree.h includes it later.
28 #include "tree-iterator.h"
40 // A class wrapping a tree.
61 // In gcc, types, expressions, and statements are all trees.
62 class Btype
: public Gcc_tree
70 class Bexpression
: public Gcc_tree
78 class Bstatement
: public Gcc_tree
86 class Bfunction
: public Gcc_tree
94 class Bblock
: public Gcc_tree
102 class Bvariable
: public Gcc_tree
110 class Blabel
: public Gcc_tree
118 // This file implements the interface between the Go frontend proper
119 // and the gcc IR. This implements specific instantiations of
120 // abstract classes defined by the Go frontend proper. The Go
121 // frontend proper class methods of these classes to generate the
122 // backend representation.
124 class Gcc_backend
: public Backend
131 { return this->make_type(error_mark_node
); }
135 { return this->make_type(void_type_node
); }
139 { return this->make_type(boolean_type_node
); }
142 integer_type(bool, int);
151 pointer_type(Btype
*);
154 function_type(const Btyped_identifier
&,
155 const std::vector
<Btyped_identifier
>&,
156 const std::vector
<Btyped_identifier
>&,
160 struct_type(const std::vector
<Btyped_identifier
>&);
163 array_type(Btype
*, Bexpression
*);
166 placeholder_pointer_type(const std::string
&, Location
, bool);
169 set_placeholder_pointer_type(Btype
*, Btype
*);
172 set_placeholder_function_type(Btype
*, Btype
*);
175 placeholder_struct_type(const std::string
&, Location
);
178 set_placeholder_struct_type(Btype
* placeholder
,
179 const std::vector
<Btyped_identifier
>&);
182 placeholder_array_type(const std::string
&, Location
);
185 set_placeholder_array_type(Btype
*, Btype
*, Bexpression
*);
188 named_type(const std::string
&, Btype
*, Location
);
191 circular_pointer_type(Btype
*, bool);
194 is_circular_pointer_type(Btype
*);
200 type_alignment(Btype
*);
203 type_field_alignment(Btype
*);
206 type_field_offset(Btype
*, size_t index
);
211 zero_expression(Btype
*);
215 { return this->make_expression(error_mark_node
); }
218 var_expression(Bvariable
* var
, Location
);
221 indirect_expression(Bexpression
* expr
, bool known_valid
, Location
);
224 integer_constant_expression(Btype
* btype
, mpz_t val
);
227 float_constant_expression(Btype
* btype
, mpfr_t val
);
230 complex_constant_expression(Btype
* btype
, mpfr_t real
, mpfr_t imag
);
233 convert_expression(Btype
* type
, Bexpression
* expr
, Location
);
239 { return this->make_statement(error_mark_node
); }
242 expression_statement(Bexpression
*);
245 init_statement(Bvariable
* var
, Bexpression
* init
);
248 assignment_statement(Bexpression
* lhs
, Bexpression
* rhs
, Location
);
251 return_statement(Bfunction
*, const std::vector
<Bexpression
*>&,
255 if_statement(Bexpression
* condition
, Bblock
* then_block
, Bblock
* else_block
,
259 switch_statement(Bexpression
* value
,
260 const std::vector
<std::vector
<Bexpression
*> >& cases
,
261 const std::vector
<Bstatement
*>& statements
,
265 compound_statement(Bstatement
*, Bstatement
*);
268 statement_list(const std::vector
<Bstatement
*>&);
273 block(Bfunction
*, Bblock
*, const std::vector
<Bvariable
*>&,
277 block_add_statements(Bblock
*, const std::vector
<Bstatement
*>&);
280 block_statement(Bblock
*);
286 { return new Bvariable(error_mark_node
); }
289 global_variable(const std::string
& package_name
,
290 const std::string
& pkgpath
,
291 const std::string
& name
,
295 bool in_unique_section
,
299 global_variable_set_init(Bvariable
*, Bexpression
*);
302 local_variable(Bfunction
*, const std::string
&, Btype
*, bool,
306 parameter_variable(Bfunction
*, const std::string
&, Btype
*, bool,
310 temporary_variable(Bfunction
*, Bblock
*, Btype
*, Bexpression
*, bool,
311 Location
, Bstatement
**);
314 immutable_struct(const std::string
&, bool, bool, Btype
*, Location
);
317 immutable_struct_set_init(Bvariable
*, const std::string
&, bool, bool, Btype
*,
318 Location
, Bexpression
*);
321 immutable_struct_reference(const std::string
&, Btype
*, Location
);
326 label(Bfunction
*, const std::string
& name
, Location
);
329 label_definition_statement(Blabel
*);
332 goto_statement(Blabel
*, Location
);
335 label_address(Blabel
*, Location
);
338 // Make a Bexpression from a tree.
340 make_expression(tree t
)
341 { return new Bexpression(t
); }
343 // Make a Bstatement from a tree.
345 make_statement(tree t
)
346 { return new Bstatement(t
); }
348 // Make a Btype from a tree.
351 { return new Btype(t
); }
354 fill_in_struct(Btype
*, const std::vector
<Btyped_identifier
>&);
357 fill_in_array(Btype
*, Btype
*, Bexpression
*);
360 non_zero_size_type(tree
);
363 // A helper function.
366 get_identifier_from_string(const std::string
& str
)
368 return get_identifier_with_length(str
.data(), str
.length());
371 // Get an unnamed integer type.
374 Gcc_backend::integer_type(bool is_unsigned
, int bits
)
379 if (bits
== INT_TYPE_SIZE
)
380 type
= unsigned_type_node
;
381 else if (bits
== CHAR_TYPE_SIZE
)
382 type
= unsigned_char_type_node
;
383 else if (bits
== SHORT_TYPE_SIZE
)
384 type
= short_unsigned_type_node
;
385 else if (bits
== LONG_TYPE_SIZE
)
386 type
= long_unsigned_type_node
;
387 else if (bits
== LONG_LONG_TYPE_SIZE
)
388 type
= long_long_unsigned_type_node
;
390 type
= make_unsigned_type(bits
);
394 if (bits
== INT_TYPE_SIZE
)
395 type
= integer_type_node
;
396 else if (bits
== CHAR_TYPE_SIZE
)
397 type
= signed_char_type_node
;
398 else if (bits
== SHORT_TYPE_SIZE
)
399 type
= short_integer_type_node
;
400 else if (bits
== LONG_TYPE_SIZE
)
401 type
= long_integer_type_node
;
402 else if (bits
== LONG_LONG_TYPE_SIZE
)
403 type
= long_long_integer_type_node
;
405 type
= make_signed_type(bits
);
407 return this->make_type(type
);
410 // Get an unnamed float type.
413 Gcc_backend::float_type(int bits
)
416 if (bits
== FLOAT_TYPE_SIZE
)
417 type
= float_type_node
;
418 else if (bits
== DOUBLE_TYPE_SIZE
)
419 type
= double_type_node
;
420 else if (bits
== LONG_DOUBLE_TYPE_SIZE
)
421 type
= long_double_type_node
;
424 type
= make_node(REAL_TYPE
);
425 TYPE_PRECISION(type
) = bits
;
428 return this->make_type(type
);
431 // Get an unnamed complex type.
434 Gcc_backend::complex_type(int bits
)
437 if (bits
== FLOAT_TYPE_SIZE
* 2)
438 type
= complex_float_type_node
;
439 else if (bits
== DOUBLE_TYPE_SIZE
* 2)
440 type
= complex_double_type_node
;
441 else if (bits
== LONG_DOUBLE_TYPE_SIZE
* 2)
442 type
= complex_long_double_type_node
;
445 type
= make_node(REAL_TYPE
);
446 TYPE_PRECISION(type
) = bits
/ 2;
448 type
= build_complex_type(type
);
450 return this->make_type(type
);
453 // Get a pointer type.
456 Gcc_backend::pointer_type(Btype
* to_type
)
458 tree to_type_tree
= to_type
->get_tree();
459 if (to_type_tree
== error_mark_node
)
460 return this->error_type();
461 tree type
= build_pointer_type(to_type_tree
);
462 return this->make_type(type
);
465 // Make a function type.
468 Gcc_backend::function_type(const Btyped_identifier
& receiver
,
469 const std::vector
<Btyped_identifier
>& parameters
,
470 const std::vector
<Btyped_identifier
>& results
,
473 tree args
= NULL_TREE
;
475 if (receiver
.btype
!= NULL
)
477 tree t
= receiver
.btype
->get_tree();
478 if (t
== error_mark_node
)
479 return this->error_type();
480 *pp
= tree_cons(NULL_TREE
, t
, NULL_TREE
);
481 pp
= &TREE_CHAIN(*pp
);
484 for (std::vector
<Btyped_identifier
>::const_iterator p
= parameters
.begin();
485 p
!= parameters
.end();
488 tree t
= p
->btype
->get_tree();
489 if (t
== error_mark_node
)
490 return this->error_type();
491 *pp
= tree_cons(NULL_TREE
, t
, NULL_TREE
);
492 pp
= &TREE_CHAIN(*pp
);
495 // Varargs is handled entirely at the Go level. When converted to
496 // GENERIC functions are not varargs.
497 *pp
= void_list_node
;
501 result
= void_type_node
;
502 else if (results
.size() == 1)
503 result
= results
.front().btype
->get_tree();
506 result
= make_node(RECORD_TYPE
);
507 tree field_trees
= NULL_TREE
;
509 for (std::vector
<Btyped_identifier
>::const_iterator p
= results
.begin();
513 const std::string name
= (p
->name
.empty()
516 tree name_tree
= get_identifier_from_string(name
);
517 tree field_type_tree
= p
->btype
->get_tree();
518 if (field_type_tree
== error_mark_node
)
519 return this->error_type();
520 gcc_assert(TYPE_SIZE(field_type_tree
) != NULL_TREE
);
521 tree field
= build_decl(location
.gcc_location(), FIELD_DECL
,
522 name_tree
, field_type_tree
);
523 DECL_CONTEXT(field
) = result
;
525 pp
= &DECL_CHAIN(field
);
527 TYPE_FIELDS(result
) = field_trees
;
530 if (result
== error_mark_node
)
531 return this->error_type();
533 tree fntype
= build_function_type(result
, args
);
534 if (fntype
== error_mark_node
)
535 return this->error_type();
537 return this->make_type(build_pointer_type(fntype
));
540 // Make a struct type.
543 Gcc_backend::struct_type(const std::vector
<Btyped_identifier
>& fields
)
545 return this->fill_in_struct(this->make_type(make_node(RECORD_TYPE
)), fields
);
548 // Fill in the fields of a struct type.
551 Gcc_backend::fill_in_struct(Btype
* fill
,
552 const std::vector
<Btyped_identifier
>& fields
)
554 tree fill_tree
= fill
->get_tree();
555 tree field_trees
= NULL_TREE
;
556 tree
* pp
= &field_trees
;
557 for (std::vector
<Btyped_identifier
>::const_iterator p
= fields
.begin();
561 tree name_tree
= get_identifier_from_string(p
->name
);
562 tree type_tree
= p
->btype
->get_tree();
563 if (type_tree
== error_mark_node
)
564 return this->error_type();
565 tree field
= build_decl(p
->location
.gcc_location(), FIELD_DECL
, name_tree
,
567 DECL_CONTEXT(field
) = fill_tree
;
569 pp
= &DECL_CHAIN(field
);
571 TYPE_FIELDS(fill_tree
) = field_trees
;
572 layout_type(fill_tree
);
576 // Make an array type.
579 Gcc_backend::array_type(Btype
* element_btype
, Bexpression
* length
)
581 return this->fill_in_array(this->make_type(make_node(ARRAY_TYPE
)),
582 element_btype
, length
);
585 // Fill in an array type.
588 Gcc_backend::fill_in_array(Btype
* fill
, Btype
* element_type
,
591 tree element_type_tree
= element_type
->get_tree();
592 tree length_tree
= length
->get_tree();
593 if (element_type_tree
== error_mark_node
|| length_tree
== error_mark_node
)
594 return this->error_type();
596 gcc_assert(TYPE_SIZE(element_type_tree
) != NULL_TREE
);
598 length_tree
= fold_convert(sizetype
, length_tree
);
600 // build_index_type takes the maximum index, which is one less than
602 tree index_type_tree
= build_index_type(fold_build2(MINUS_EXPR
, sizetype
,
606 tree fill_tree
= fill
->get_tree();
607 TREE_TYPE(fill_tree
) = element_type_tree
;
608 TYPE_DOMAIN(fill_tree
) = index_type_tree
;
609 TYPE_ADDR_SPACE(fill_tree
) = TYPE_ADDR_SPACE(element_type_tree
);
610 layout_type(fill_tree
);
612 if (TYPE_STRUCTURAL_EQUALITY_P(element_type_tree
))
613 SET_TYPE_STRUCTURAL_EQUALITY(fill_tree
);
614 else if (TYPE_CANONICAL(element_type_tree
) != element_type_tree
615 || TYPE_CANONICAL(index_type_tree
) != index_type_tree
)
616 TYPE_CANONICAL(fill_tree
) =
617 build_array_type(TYPE_CANONICAL(element_type_tree
),
618 TYPE_CANONICAL(index_type_tree
));
623 // Create a placeholder for a pointer type.
626 Gcc_backend::placeholder_pointer_type(const std::string
& name
,
627 Location location
, bool)
629 tree ret
= build_distinct_type_copy(ptr_type_node
);
632 tree decl
= build_decl(location
.gcc_location(), TYPE_DECL
,
633 get_identifier_from_string(name
),
635 TYPE_NAME(ret
) = decl
;
637 return this->make_type(ret
);
640 // Set the real target type for a placeholder pointer type.
643 Gcc_backend::set_placeholder_pointer_type(Btype
* placeholder
,
646 tree pt
= placeholder
->get_tree();
647 if (pt
== error_mark_node
)
649 gcc_assert(TREE_CODE(pt
) == POINTER_TYPE
);
650 tree tt
= to_type
->get_tree();
651 if (tt
== error_mark_node
)
653 placeholder
->set_tree(error_mark_node
);
656 gcc_assert(TREE_CODE(tt
) == POINTER_TYPE
);
657 TREE_TYPE(pt
) = TREE_TYPE(tt
);
658 if (TYPE_NAME(pt
) != NULL_TREE
)
660 // Build the data structure gcc wants to see for a typedef.
661 tree copy
= build_variant_type_copy(pt
);
662 TYPE_NAME(copy
) = NULL_TREE
;
663 DECL_ORIGINAL_TYPE(TYPE_NAME(pt
)) = copy
;
668 // Set the real values for a placeholder function type.
671 Gcc_backend::set_placeholder_function_type(Btype
* placeholder
, Btype
* ft
)
673 return this->set_placeholder_pointer_type(placeholder
, ft
);
676 // Create a placeholder for a struct type.
679 Gcc_backend::placeholder_struct_type(const std::string
& name
,
682 tree ret
= make_node(RECORD_TYPE
);
685 tree decl
= build_decl(location
.gcc_location(), TYPE_DECL
,
686 get_identifier_from_string(name
),
688 TYPE_NAME(ret
) = decl
;
690 return this->make_type(ret
);
693 // Fill in the fields of a placeholder struct type.
696 Gcc_backend::set_placeholder_struct_type(
698 const std::vector
<Btyped_identifier
>& fields
)
700 tree t
= placeholder
->get_tree();
701 gcc_assert(TREE_CODE(t
) == RECORD_TYPE
&& TYPE_FIELDS(t
) == NULL_TREE
);
702 Btype
* r
= this->fill_in_struct(placeholder
, fields
);
704 if (TYPE_NAME(t
) != NULL_TREE
)
706 // Build the data structure gcc wants to see for a typedef.
707 tree copy
= build_distinct_type_copy(t
);
708 TYPE_NAME(copy
) = NULL_TREE
;
709 DECL_ORIGINAL_TYPE(TYPE_NAME(t
)) = copy
;
712 return r
->get_tree() != error_mark_node
;
715 // Create a placeholder for an array type.
718 Gcc_backend::placeholder_array_type(const std::string
& name
,
721 tree ret
= make_node(ARRAY_TYPE
);
722 tree decl
= build_decl(location
.gcc_location(), TYPE_DECL
,
723 get_identifier_from_string(name
),
725 TYPE_NAME(ret
) = decl
;
726 return this->make_type(ret
);
729 // Fill in the fields of a placeholder array type.
732 Gcc_backend::set_placeholder_array_type(Btype
* placeholder
,
733 Btype
* element_btype
,
736 tree t
= placeholder
->get_tree();
737 gcc_assert(TREE_CODE(t
) == ARRAY_TYPE
&& TREE_TYPE(t
) == NULL_TREE
);
738 Btype
* r
= this->fill_in_array(placeholder
, element_btype
, length
);
740 // Build the data structure gcc wants to see for a typedef.
741 tree copy
= build_distinct_type_copy(t
);
742 TYPE_NAME(copy
) = NULL_TREE
;
743 DECL_ORIGINAL_TYPE(TYPE_NAME(t
)) = copy
;
745 return r
->get_tree() != error_mark_node
;
748 // Return a named version of a type.
751 Gcc_backend::named_type(const std::string
& name
, Btype
* btype
,
754 tree type
= btype
->get_tree();
755 if (type
== error_mark_node
)
756 return this->error_type();
758 // The middle-end expects a basic type to have a name. In Go every
759 // basic type will have a name. The first time we see a basic type,
760 // give it whatever Go name we have at this point.
761 if (TYPE_NAME(type
) == NULL_TREE
762 && location
.gcc_location() == BUILTINS_LOCATION
763 && (TREE_CODE(type
) == INTEGER_TYPE
764 || TREE_CODE(type
) == REAL_TYPE
765 || TREE_CODE(type
) == COMPLEX_TYPE
766 || TREE_CODE(type
) == BOOLEAN_TYPE
))
768 tree decl
= build_decl(BUILTINS_LOCATION
, TYPE_DECL
,
769 get_identifier_from_string(name
),
771 TYPE_NAME(type
) = decl
;
772 return this->make_type(type
);
775 tree copy
= build_variant_type_copy(type
);
776 tree decl
= build_decl(location
.gcc_location(), TYPE_DECL
,
777 get_identifier_from_string(name
),
779 DECL_ORIGINAL_TYPE(decl
) = type
;
780 TYPE_NAME(copy
) = decl
;
781 return this->make_type(copy
);
784 // Return a pointer type used as a marker for a circular type.
787 Gcc_backend::circular_pointer_type(Btype
*, bool)
789 return this->make_type(ptr_type_node
);
792 // Return whether we might be looking at a circular type.
795 Gcc_backend::is_circular_pointer_type(Btype
* btype
)
797 return btype
->get_tree() == ptr_type_node
;
800 // Return the size of a type.
803 Gcc_backend::type_size(Btype
* btype
)
805 tree t
= btype
->get_tree();
806 if (t
== error_mark_node
)
808 t
= TYPE_SIZE_UNIT(t
);
809 gcc_assert(TREE_CODE(t
) == INTEGER_CST
);
810 gcc_assert(TREE_INT_CST_HIGH(t
) == 0);
811 unsigned HOST_WIDE_INT val_wide
= TREE_INT_CST_LOW(t
);
812 size_t ret
= static_cast<size_t>(val_wide
);
813 gcc_assert(ret
== val_wide
);
817 // Return the alignment of a type.
820 Gcc_backend::type_alignment(Btype
* btype
)
822 tree t
= btype
->get_tree();
823 if (t
== error_mark_node
)
825 return TYPE_ALIGN_UNIT(t
);
828 // Return the alignment of a struct field of type BTYPE.
831 Gcc_backend::type_field_alignment(Btype
* btype
)
833 tree t
= btype
->get_tree();
834 if (t
== error_mark_node
)
836 return go_field_alignment(t
);
839 // Return the offset of a field in a struct.
842 Gcc_backend::type_field_offset(Btype
* btype
, size_t index
)
844 tree struct_tree
= btype
->get_tree();
845 if (struct_tree
== error_mark_node
)
847 gcc_assert(TREE_CODE(struct_tree
) == RECORD_TYPE
);
848 tree field
= TYPE_FIELDS(struct_tree
);
849 for (; index
> 0; --index
)
851 field
= DECL_CHAIN(field
);
852 gcc_assert(field
!= NULL_TREE
);
854 HOST_WIDE_INT offset_wide
= int_byte_position(field
);
855 gcc_assert(offset_wide
>= 0);
856 size_t ret
= static_cast<size_t>(offset_wide
);
857 gcc_assert(ret
== static_cast<unsigned HOST_WIDE_INT
>(offset_wide
));
861 // Return the zero value for a type.
864 Gcc_backend::zero_expression(Btype
* btype
)
866 tree t
= btype
->get_tree();
868 if (t
== error_mark_node
)
869 ret
= error_mark_node
;
871 ret
= build_zero_cst(t
);
872 return tree_to_expr(ret
);
875 // An expression that references a variable.
878 Gcc_backend::var_expression(Bvariable
* var
, Location
)
880 tree ret
= var
->get_tree();
881 if (ret
== error_mark_node
)
882 return this->error_expression();
883 return tree_to_expr(ret
);
886 // An expression that indirectly references an expression.
889 Gcc_backend::indirect_expression(Bexpression
* expr
, bool known_valid
,
892 tree ret
= build_fold_indirect_ref_loc(location
.gcc_location(),
895 TREE_THIS_NOTRAP(ret
) = 1;
896 return tree_to_expr(ret
);
899 // Return a typed value as a constant integer.
902 Gcc_backend::integer_constant_expression(Btype
* btype
, mpz_t val
)
904 tree t
= btype
->get_tree();
905 if (t
== error_mark_node
)
906 return this->error_expression();
908 tree ret
= double_int_to_tree(t
, mpz_get_double_int(t
, val
, true));
909 return tree_to_expr(ret
);
912 // Return a typed value as a constant floating-point number.
915 Gcc_backend::float_constant_expression(Btype
* btype
, mpfr_t val
)
917 tree t
= btype
->get_tree();
919 if (t
== error_mark_node
)
920 return this->error_expression();
923 real_from_mpfr(&r1
, val
, t
, GMP_RNDN
);
925 real_convert(&r2
, TYPE_MODE(t
), &r1
);
926 ret
= build_real(t
, r2
);
927 return tree_to_expr(ret
);
930 // Return a typed real and imaginary value as a constant complex number.
933 Gcc_backend::complex_constant_expression(Btype
* btype
, mpfr_t real
, mpfr_t imag
)
935 tree t
= btype
->get_tree();
937 if (t
== error_mark_node
)
938 return this->error_expression();
941 real_from_mpfr(&r1
, real
, TREE_TYPE(t
), GMP_RNDN
);
943 real_convert(&r2
, TYPE_MODE(TREE_TYPE(t
)), &r1
);
946 real_from_mpfr(&r3
, imag
, TREE_TYPE(t
), GMP_RNDN
);
948 real_convert(&r4
, TYPE_MODE(TREE_TYPE(t
)), &r3
);
950 ret
= build_complex(t
, build_real(TREE_TYPE(t
), r2
),
951 build_real(TREE_TYPE(t
), r4
));
952 return tree_to_expr(ret
);
955 // An expression that converts an expression to a different type.
958 Gcc_backend::convert_expression(Btype
* type
, Bexpression
* expr
, Location
)
960 tree type_tree
= type
->get_tree();
961 tree expr_tree
= expr
->get_tree();
962 if (type_tree
== error_mark_node
|| expr_tree
== error_mark_node
)
963 return this->error_expression();
965 tree ret
= fold_convert(type_tree
, expr_tree
);
966 return tree_to_expr(ret
);
969 // An expression as a statement.
972 Gcc_backend::expression_statement(Bexpression
* expr
)
974 return this->make_statement(expr
->get_tree());
977 // Variable initialization.
980 Gcc_backend::init_statement(Bvariable
* var
, Bexpression
* init
)
982 tree var_tree
= var
->get_tree();
983 tree init_tree
= init
->get_tree();
984 if (var_tree
== error_mark_node
|| init_tree
== error_mark_node
)
985 return this->error_statement();
986 gcc_assert(TREE_CODE(var_tree
) == VAR_DECL
);
988 // To avoid problems with GNU ld, we don't make zero-sized
989 // externally visible variables. That might lead us to doing an
990 // initialization of a zero-sized expression to a non-zero sized
991 // variable, or vice-versa. Avoid crashes by omitting the
992 // initializer. Such initializations don't mean anything anyhow.
993 if (int_size_in_bytes(TREE_TYPE(var_tree
)) != 0
994 && init_tree
!= NULL_TREE
995 && int_size_in_bytes(TREE_TYPE(init_tree
)) != 0)
997 DECL_INITIAL(var_tree
) = init_tree
;
998 init_tree
= NULL_TREE
;
1001 tree ret
= build1_loc(DECL_SOURCE_LOCATION(var_tree
), DECL_EXPR
,
1002 void_type_node
, var_tree
);
1003 if (init_tree
!= NULL_TREE
)
1004 ret
= build2_loc(DECL_SOURCE_LOCATION(var_tree
), COMPOUND_EXPR
,
1005 void_type_node
, init_tree
, ret
);
1007 return this->make_statement(ret
);
1013 Gcc_backend::assignment_statement(Bexpression
* lhs
, Bexpression
* rhs
,
1016 tree lhs_tree
= lhs
->get_tree();
1017 tree rhs_tree
= rhs
->get_tree();
1018 if (lhs_tree
== error_mark_node
|| rhs_tree
== error_mark_node
)
1019 return this->error_statement();
1021 // To avoid problems with GNU ld, we don't make zero-sized
1022 // externally visible variables. That might lead us to doing an
1023 // assignment of a zero-sized expression to a non-zero sized
1024 // expression; avoid crashes here by avoiding assignments of
1025 // zero-sized expressions. Such assignments don't really mean
1027 if (int_size_in_bytes(TREE_TYPE(lhs_tree
)) == 0
1028 || int_size_in_bytes(TREE_TYPE(rhs_tree
)) == 0)
1029 return this->compound_statement(this->expression_statement(lhs
),
1030 this->expression_statement(rhs
));
1032 // Sometimes the same unnamed Go type can be created multiple times
1033 // and thus have multiple tree representations. Make sure this does
1034 // not confuse the middle-end.
1035 if (TREE_TYPE(lhs_tree
) != TREE_TYPE(rhs_tree
))
1037 tree lhs_type_tree
= TREE_TYPE(lhs_tree
);
1038 gcc_assert(TREE_CODE(lhs_type_tree
) == TREE_CODE(TREE_TYPE(rhs_tree
)));
1039 if (POINTER_TYPE_P(lhs_type_tree
)
1040 || INTEGRAL_TYPE_P(lhs_type_tree
)
1041 || SCALAR_FLOAT_TYPE_P(lhs_type_tree
)
1042 || COMPLEX_FLOAT_TYPE_P(lhs_type_tree
))
1043 rhs_tree
= fold_convert_loc(location
.gcc_location(), lhs_type_tree
,
1045 else if (TREE_CODE(lhs_type_tree
) == RECORD_TYPE
1046 || TREE_CODE(lhs_type_tree
) == ARRAY_TYPE
)
1048 gcc_assert(int_size_in_bytes(lhs_type_tree
)
1049 == int_size_in_bytes(TREE_TYPE(rhs_tree
)));
1050 rhs_tree
= fold_build1_loc(location
.gcc_location(),
1052 lhs_type_tree
, rhs_tree
);
1056 return this->make_statement(fold_build2_loc(location
.gcc_location(),
1059 lhs_tree
, rhs_tree
));
1065 Gcc_backend::return_statement(Bfunction
* bfunction
,
1066 const std::vector
<Bexpression
*>& vals
,
1069 tree fntree
= bfunction
->get_tree();
1070 if (fntree
== error_mark_node
)
1071 return this->error_statement();
1072 tree result
= DECL_RESULT(fntree
);
1073 if (result
== error_mark_node
)
1074 return this->error_statement();
1077 ret
= fold_build1_loc(location
.gcc_location(), RETURN_EXPR
, void_type_node
,
1079 else if (vals
.size() == 1)
1081 tree val
= vals
.front()->get_tree();
1082 if (val
== error_mark_node
)
1083 return this->error_statement();
1084 tree set
= fold_build2_loc(location
.gcc_location(), MODIFY_EXPR
,
1085 void_type_node
, result
,
1086 vals
.front()->get_tree());
1087 ret
= fold_build1_loc(location
.gcc_location(), RETURN_EXPR
,
1088 void_type_node
, set
);
1092 // To return multiple values, copy the values into a temporary
1093 // variable of the right structure type, and then assign the
1094 // temporary variable to the DECL_RESULT in the return
1096 tree stmt_list
= NULL_TREE
;
1097 tree rettype
= TREE_TYPE(result
);
1098 tree rettmp
= create_tmp_var(rettype
, "RESULT");
1099 tree field
= TYPE_FIELDS(rettype
);
1100 for (std::vector
<Bexpression
*>::const_iterator p
= vals
.begin();
1102 p
++, field
= DECL_CHAIN(field
))
1104 gcc_assert(field
!= NULL_TREE
);
1105 tree ref
= fold_build3_loc(location
.gcc_location(), COMPONENT_REF
,
1106 TREE_TYPE(field
), rettmp
, field
,
1108 tree val
= (*p
)->get_tree();
1109 if (val
== error_mark_node
)
1110 return this->error_statement();
1111 tree set
= fold_build2_loc(location
.gcc_location(), MODIFY_EXPR
,
1113 ref
, (*p
)->get_tree());
1114 append_to_statement_list(set
, &stmt_list
);
1116 gcc_assert(field
== NULL_TREE
);
1117 tree set
= fold_build2_loc(location
.gcc_location(), MODIFY_EXPR
,
1120 tree ret_expr
= fold_build1_loc(location
.gcc_location(), RETURN_EXPR
,
1121 void_type_node
, set
);
1122 append_to_statement_list(ret_expr
, &stmt_list
);
1125 return this->make_statement(ret
);
1131 Gcc_backend::if_statement(Bexpression
* condition
, Bblock
* then_block
,
1132 Bblock
* else_block
, Location location
)
1134 tree cond_tree
= condition
->get_tree();
1135 tree then_tree
= then_block
->get_tree();
1136 tree else_tree
= else_block
== NULL
? NULL_TREE
: else_block
->get_tree();
1137 if (cond_tree
== error_mark_node
1138 || then_tree
== error_mark_node
1139 || else_tree
== error_mark_node
)
1140 return this->error_statement();
1141 tree ret
= build3_loc(location
.gcc_location(), COND_EXPR
, void_type_node
,
1142 cond_tree
, then_tree
, else_tree
);
1143 return this->make_statement(ret
);
1149 Gcc_backend::switch_statement(
1151 const std::vector
<std::vector
<Bexpression
*> >& cases
,
1152 const std::vector
<Bstatement
*>& statements
,
1153 Location switch_location
)
1155 gcc_assert(cases
.size() == statements
.size());
1157 tree stmt_list
= NULL_TREE
;
1158 std::vector
<std::vector
<Bexpression
*> >::const_iterator pc
= cases
.begin();
1159 for (std::vector
<Bstatement
*>::const_iterator ps
= statements
.begin();
1160 ps
!= statements
.end();
1165 source_location loc
= (*ps
!= NULL
1166 ? EXPR_LOCATION((*ps
)->get_tree())
1167 : UNKNOWN_LOCATION
);
1168 tree label
= create_artificial_label(loc
);
1169 tree c
= build_case_label(NULL_TREE
, NULL_TREE
, label
);
1170 append_to_statement_list(c
, &stmt_list
);
1174 for (std::vector
<Bexpression
*>::const_iterator pcv
= pc
->begin();
1178 tree t
= (*pcv
)->get_tree();
1179 if (t
== error_mark_node
)
1180 return this->error_statement();
1181 source_location loc
= EXPR_LOCATION(t
);
1182 tree label
= create_artificial_label(loc
);
1183 tree c
= build_case_label((*pcv
)->get_tree(), NULL_TREE
, label
);
1184 append_to_statement_list(c
, &stmt_list
);
1190 tree t
= (*ps
)->get_tree();
1191 if (t
== error_mark_node
)
1192 return this->error_statement();
1193 append_to_statement_list(t
, &stmt_list
);
1197 tree tv
= value
->get_tree();
1198 if (tv
== error_mark_node
)
1199 return this->error_statement();
1200 tree t
= build3_loc(switch_location
.gcc_location(), SWITCH_EXPR
,
1201 NULL_TREE
, tv
, stmt_list
, NULL_TREE
);
1202 return this->make_statement(t
);
1205 // Pair of statements.
1208 Gcc_backend::compound_statement(Bstatement
* s1
, Bstatement
* s2
)
1210 tree stmt_list
= NULL_TREE
;
1211 tree t
= s1
->get_tree();
1212 if (t
== error_mark_node
)
1213 return this->error_statement();
1214 append_to_statement_list(t
, &stmt_list
);
1216 if (t
== error_mark_node
)
1217 return this->error_statement();
1218 append_to_statement_list(t
, &stmt_list
);
1219 return this->make_statement(stmt_list
);
1222 // List of statements.
1225 Gcc_backend::statement_list(const std::vector
<Bstatement
*>& statements
)
1227 tree stmt_list
= NULL_TREE
;
1228 for (std::vector
<Bstatement
*>::const_iterator p
= statements
.begin();
1229 p
!= statements
.end();
1232 tree t
= (*p
)->get_tree();
1233 if (t
== error_mark_node
)
1234 return this->error_statement();
1235 append_to_statement_list(t
, &stmt_list
);
1237 return this->make_statement(stmt_list
);
1240 // Make a block. For some reason gcc uses a dual structure for
1241 // blocks: BLOCK tree nodes and BIND_EXPR tree nodes. Since the
1242 // BIND_EXPR node points to the BLOCK node, we store the BIND_EXPR in
1246 Gcc_backend::block(Bfunction
* function
, Bblock
* enclosing
,
1247 const std::vector
<Bvariable
*>& vars
,
1248 Location start_location
,
1251 tree block_tree
= make_node(BLOCK
);
1252 if (enclosing
== NULL
)
1254 // FIXME: Permitting FUNCTION to be NULL is a temporary measure
1255 // until we have a proper representation of the init function.
1257 if (function
== NULL
)
1258 fndecl
= current_function_decl
;
1260 fndecl
= function
->get_tree();
1261 gcc_assert(fndecl
!= NULL_TREE
);
1263 // We may have already created a block for local variables when
1264 // we take the address of a parameter.
1265 if (DECL_INITIAL(fndecl
) == NULL_TREE
)
1267 BLOCK_SUPERCONTEXT(block_tree
) = fndecl
;
1268 DECL_INITIAL(fndecl
) = block_tree
;
1272 tree superblock_tree
= DECL_INITIAL(fndecl
);
1273 BLOCK_SUPERCONTEXT(block_tree
) = superblock_tree
;
1275 for (pp
= &BLOCK_SUBBLOCKS(superblock_tree
);
1277 pp
= &BLOCK_CHAIN(*pp
))
1284 tree superbind_tree
= enclosing
->get_tree();
1285 tree superblock_tree
= BIND_EXPR_BLOCK(superbind_tree
);
1286 gcc_assert(TREE_CODE(superblock_tree
) == BLOCK
);
1288 BLOCK_SUPERCONTEXT(block_tree
) = superblock_tree
;
1290 for (pp
= &BLOCK_SUBBLOCKS(superblock_tree
);
1292 pp
= &BLOCK_CHAIN(*pp
))
1297 tree
* pp
= &BLOCK_VARS(block_tree
);
1298 for (std::vector
<Bvariable
*>::const_iterator pv
= vars
.begin();
1302 *pp
= (*pv
)->get_tree();
1303 if (*pp
!= error_mark_node
)
1304 pp
= &DECL_CHAIN(*pp
);
1308 TREE_USED(block_tree
) = 1;
1310 tree bind_tree
= build3_loc(start_location
.gcc_location(), BIND_EXPR
,
1311 void_type_node
, BLOCK_VARS(block_tree
),
1312 NULL_TREE
, block_tree
);
1313 TREE_SIDE_EFFECTS(bind_tree
) = 1;
1315 return new Bblock(bind_tree
);
1318 // Add statements to a block.
1321 Gcc_backend::block_add_statements(Bblock
* bblock
,
1322 const std::vector
<Bstatement
*>& statements
)
1324 tree stmt_list
= NULL_TREE
;
1325 for (std::vector
<Bstatement
*>::const_iterator p
= statements
.begin();
1326 p
!= statements
.end();
1329 tree s
= (*p
)->get_tree();
1330 if (s
!= error_mark_node
)
1331 append_to_statement_list(s
, &stmt_list
);
1334 tree bind_tree
= bblock
->get_tree();
1335 gcc_assert(TREE_CODE(bind_tree
) == BIND_EXPR
);
1336 BIND_EXPR_BODY(bind_tree
) = stmt_list
;
1339 // Return a block as a statement.
1342 Gcc_backend::block_statement(Bblock
* bblock
)
1344 tree bind_tree
= bblock
->get_tree();
1345 gcc_assert(TREE_CODE(bind_tree
) == BIND_EXPR
);
1346 return this->make_statement(bind_tree
);
1349 // This is not static because we declare it with GTY(()) in go-c.h.
1350 tree go_non_zero_struct
;
1352 // Return a type corresponding to TYPE with non-zero size.
1355 Gcc_backend::non_zero_size_type(tree type
)
1357 if (int_size_in_bytes(type
) != 0)
1360 switch (TREE_CODE(type
))
1363 if (TYPE_FIELDS(type
) != NULL_TREE
)
1365 tree ns
= make_node(RECORD_TYPE
);
1366 tree field_trees
= NULL_TREE
;
1367 tree
*pp
= &field_trees
;
1368 for (tree field
= TYPE_FIELDS(type
);
1370 field
= DECL_CHAIN(field
))
1372 tree ft
= TREE_TYPE(field
);
1373 if (field
== TYPE_FIELDS(type
))
1374 ft
= non_zero_size_type(ft
);
1375 tree f
= build_decl(DECL_SOURCE_LOCATION(field
), FIELD_DECL
,
1376 DECL_NAME(field
), ft
);
1377 DECL_CONTEXT(f
) = ns
;
1379 pp
= &DECL_CHAIN(f
);
1381 TYPE_FIELDS(ns
) = field_trees
;
1386 if (go_non_zero_struct
== NULL_TREE
)
1388 type
= make_node(RECORD_TYPE
);
1389 tree field
= build_decl(UNKNOWN_LOCATION
, FIELD_DECL
,
1390 get_identifier("dummy"),
1392 DECL_CONTEXT(field
) = type
;
1393 TYPE_FIELDS(type
) = field
;
1395 go_non_zero_struct
= type
;
1397 return go_non_zero_struct
;
1401 tree element_type
= non_zero_size_type(TREE_TYPE(type
));
1402 return build_array_type_nelts(element_type
, 1);
1412 // Make a global variable.
1415 Gcc_backend::global_variable(const std::string
& package_name
,
1416 const std::string
& pkgpath
,
1417 const std::string
& name
,
1421 bool in_unique_section
,
1424 tree type_tree
= btype
->get_tree();
1425 if (type_tree
== error_mark_node
)
1426 return this->error_variable();
1428 // The GNU linker does not like dynamic variables with zero size.
1429 if ((is_external
|| !is_hidden
) && int_size_in_bytes(type_tree
) == 0)
1430 type_tree
= this->non_zero_size_type(type_tree
);
1432 std::string
var_name(package_name
);
1433 var_name
.push_back('.');
1434 var_name
.append(name
);
1435 tree decl
= build_decl(location
.gcc_location(), VAR_DECL
,
1436 get_identifier_from_string(var_name
),
1439 DECL_EXTERNAL(decl
) = 1;
1441 TREE_STATIC(decl
) = 1;
1444 TREE_PUBLIC(decl
) = 1;
1446 std::string
asm_name(pkgpath
);
1447 asm_name
.push_back('.');
1448 asm_name
.append(name
);
1449 SET_DECL_ASSEMBLER_NAME(decl
, get_identifier_from_string(asm_name
));
1451 TREE_USED(decl
) = 1;
1453 if (in_unique_section
)
1454 resolve_unique_section (decl
, 0, 1);
1456 go_preserve_from_gc(decl
);
1458 return new Bvariable(decl
);
1461 // Set the initial value of a global variable.
1464 Gcc_backend::global_variable_set_init(Bvariable
* var
, Bexpression
* expr
)
1466 tree expr_tree
= expr
->get_tree();
1467 if (expr_tree
== error_mark_node
)
1469 gcc_assert(TREE_CONSTANT(expr_tree
));
1470 tree var_decl
= var
->get_tree();
1471 if (var_decl
== error_mark_node
)
1473 DECL_INITIAL(var_decl
) = expr_tree
;
1475 // If this variable goes in a unique section, it may need to go into
1476 // a different one now that DECL_INITIAL is set.
1477 if (DECL_HAS_IMPLICIT_SECTION_NAME_P (var_decl
))
1479 DECL_SECTION_NAME (var_decl
) = NULL_TREE
;
1480 resolve_unique_section (var_decl
,
1481 compute_reloc_for_constant (expr_tree
),
1486 // Make a local variable.
1489 Gcc_backend::local_variable(Bfunction
* function
, const std::string
& name
,
1490 Btype
* btype
, bool is_address_taken
,
1493 tree type_tree
= btype
->get_tree();
1494 if (type_tree
== error_mark_node
)
1495 return this->error_variable();
1496 tree decl
= build_decl(location
.gcc_location(), VAR_DECL
,
1497 get_identifier_from_string(name
),
1499 DECL_CONTEXT(decl
) = function
->get_tree();
1500 TREE_USED(decl
) = 1;
1501 if (is_address_taken
)
1502 TREE_ADDRESSABLE(decl
) = 1;
1503 go_preserve_from_gc(decl
);
1504 return new Bvariable(decl
);
1507 // Make a function parameter variable.
1510 Gcc_backend::parameter_variable(Bfunction
* function
, const std::string
& name
,
1511 Btype
* btype
, bool is_address_taken
,
1514 tree type_tree
= btype
->get_tree();
1515 if (type_tree
== error_mark_node
)
1516 return this->error_variable();
1517 tree decl
= build_decl(location
.gcc_location(), PARM_DECL
,
1518 get_identifier_from_string(name
),
1520 DECL_CONTEXT(decl
) = function
->get_tree();
1521 DECL_ARG_TYPE(decl
) = type_tree
;
1522 TREE_USED(decl
) = 1;
1523 if (is_address_taken
)
1524 TREE_ADDRESSABLE(decl
) = 1;
1525 go_preserve_from_gc(decl
);
1526 return new Bvariable(decl
);
1529 // Make a temporary variable.
1532 Gcc_backend::temporary_variable(Bfunction
* function
, Bblock
* bblock
,
1533 Btype
* btype
, Bexpression
* binit
,
1534 bool is_address_taken
,
1536 Bstatement
** pstatement
)
1538 tree type_tree
= btype
->get_tree();
1539 tree init_tree
= binit
== NULL
? NULL_TREE
: binit
->get_tree();
1540 if (type_tree
== error_mark_node
|| init_tree
== error_mark_node
)
1542 *pstatement
= this->error_statement();
1543 return this->error_variable();
1547 // We can only use create_tmp_var if the type is not addressable.
1548 if (!TREE_ADDRESSABLE(type_tree
))
1549 var
= create_tmp_var(type_tree
, "GOTMP");
1552 gcc_assert(bblock
!= NULL
);
1553 var
= build_decl(location
.gcc_location(), VAR_DECL
,
1554 create_tmp_var_name("GOTMP"),
1556 DECL_ARTIFICIAL(var
) = 1;
1557 DECL_IGNORED_P(var
) = 1;
1559 // FIXME: Permitting function to be NULL here is a temporary
1560 // measure until we have a proper representation of the init
1562 if (function
!= NULL
)
1563 DECL_CONTEXT(var
) = function
->get_tree();
1566 gcc_assert(current_function_decl
!= NULL_TREE
);
1567 DECL_CONTEXT(var
) = current_function_decl
;
1570 // We have to add this variable to the BLOCK and the BIND_EXPR.
1571 tree bind_tree
= bblock
->get_tree();
1572 gcc_assert(TREE_CODE(bind_tree
) == BIND_EXPR
);
1573 tree block_tree
= BIND_EXPR_BLOCK(bind_tree
);
1574 gcc_assert(TREE_CODE(block_tree
) == BLOCK
);
1575 DECL_CHAIN(var
) = BLOCK_VARS(block_tree
);
1576 BLOCK_VARS(block_tree
) = var
;
1577 BIND_EXPR_VARS(bind_tree
) = BLOCK_VARS(block_tree
);
1580 if (init_tree
!= NULL_TREE
)
1581 DECL_INITIAL(var
) = fold_convert_loc(location
.gcc_location(), type_tree
,
1584 if (is_address_taken
)
1585 TREE_ADDRESSABLE(var
) = 1;
1587 *pstatement
= this->make_statement(build1_loc(location
.gcc_location(),
1589 void_type_node
, var
));
1590 return new Bvariable(var
);
1593 // Create a named immutable initialized data structure.
1596 Gcc_backend::immutable_struct(const std::string
& name
, bool is_hidden
,
1597 bool, Btype
* btype
, Location location
)
1599 tree type_tree
= btype
->get_tree();
1600 if (type_tree
== error_mark_node
)
1601 return this->error_variable();
1602 gcc_assert(TREE_CODE(type_tree
) == RECORD_TYPE
);
1603 tree decl
= build_decl(location
.gcc_location(), VAR_DECL
,
1604 get_identifier_from_string(name
),
1605 build_qualified_type(type_tree
, TYPE_QUAL_CONST
));
1606 TREE_STATIC(decl
) = 1;
1607 TREE_READONLY(decl
) = 1;
1608 TREE_CONSTANT(decl
) = 1;
1609 TREE_USED(decl
) = 1;
1610 DECL_ARTIFICIAL(decl
) = 1;
1612 TREE_PUBLIC(decl
) = 1;
1614 // We don't call rest_of_decl_compilation until we have the
1617 go_preserve_from_gc(decl
);
1618 return new Bvariable(decl
);
1621 // Set the initializer for a variable created by immutable_struct.
1622 // This is where we finish compiling the variable.
1625 Gcc_backend::immutable_struct_set_init(Bvariable
* var
, const std::string
&,
1626 bool, bool is_common
, Btype
*, Location
,
1627 Bexpression
* initializer
)
1629 tree decl
= var
->get_tree();
1630 tree init_tree
= initializer
->get_tree();
1631 if (decl
== error_mark_node
|| init_tree
== error_mark_node
)
1634 DECL_INITIAL(decl
) = init_tree
;
1636 // We can't call make_decl_one_only until we set DECL_INITIAL.
1638 make_decl_one_only(decl
, DECL_ASSEMBLER_NAME(decl
));
1640 // These variables are often unneeded in the final program, so put
1641 // them in their own section so that linker GC can discard them.
1642 resolve_unique_section(decl
,
1643 compute_reloc_for_constant (init_tree
),
1646 rest_of_decl_compilation(decl
, 1, 0);
1649 // Return a reference to an immutable initialized data structure
1650 // defined in another package.
1653 Gcc_backend::immutable_struct_reference(const std::string
& name
, Btype
* btype
,
1656 tree type_tree
= btype
->get_tree();
1657 if (type_tree
== error_mark_node
)
1658 return this->error_variable();
1659 gcc_assert(TREE_CODE(type_tree
) == RECORD_TYPE
);
1660 tree decl
= build_decl(location
.gcc_location(), VAR_DECL
,
1661 get_identifier_from_string(name
),
1662 build_qualified_type(type_tree
, TYPE_QUAL_CONST
));
1663 TREE_READONLY(decl
) = 1;
1664 TREE_CONSTANT(decl
) = 1;
1665 DECL_ARTIFICIAL(decl
) = 1;
1666 TREE_PUBLIC(decl
) = 1;
1667 DECL_EXTERNAL(decl
) = 1;
1668 go_preserve_from_gc(decl
);
1669 return new Bvariable(decl
);
1675 Gcc_backend::label(Bfunction
* function
, const std::string
& name
,
1680 decl
= create_artificial_label(location
.gcc_location());
1683 tree id
= get_identifier_from_string(name
);
1684 decl
= build_decl(location
.gcc_location(), LABEL_DECL
, id
,
1686 DECL_CONTEXT(decl
) = function
->get_tree();
1688 return new Blabel(decl
);
1691 // Make a statement which defines a label.
1694 Gcc_backend::label_definition_statement(Blabel
* label
)
1696 tree lab
= label
->get_tree();
1697 tree ret
= fold_build1_loc(DECL_SOURCE_LOCATION(lab
), LABEL_EXPR
,
1698 void_type_node
, lab
);
1699 return this->make_statement(ret
);
1702 // Make a goto statement.
1705 Gcc_backend::goto_statement(Blabel
* label
, Location location
)
1707 tree lab
= label
->get_tree();
1708 tree ret
= fold_build1_loc(location
.gcc_location(), GOTO_EXPR
, void_type_node
,
1710 return this->make_statement(ret
);
1713 // Get the address of a label.
1716 Gcc_backend::label_address(Blabel
* label
, Location location
)
1718 tree lab
= label
->get_tree();
1720 TREE_ADDRESSABLE(lab
) = 1;
1721 tree ret
= fold_convert_loc(location
.gcc_location(), ptr_type_node
,
1722 build_fold_addr_expr_loc(location
.gcc_location(),
1724 return this->make_expression(ret
);
1727 // The single backend.
1729 static Gcc_backend gcc_backend
;
1731 // Return the backend generator.
1736 return &gcc_backend
;
1739 // FIXME: Temporary functions while converting to the new backend
1743 tree_to_type(tree t
)
1745 return new Btype(t
);
1749 tree_to_expr(tree t
)
1751 return new Bexpression(t
);
1755 tree_to_stat(tree t
)
1757 return new Bstatement(t
);
1761 tree_to_function(tree t
)
1763 return new Bfunction(t
);
1767 tree_to_block(tree t
)
1769 gcc_assert(TREE_CODE(t
) == BIND_EXPR
);
1770 return new Bblock(t
);
1774 type_to_tree(Btype
* bt
)
1776 return bt
->get_tree();
1780 expr_to_tree(Bexpression
* be
)
1782 return be
->get_tree();
1786 stat_to_tree(Bstatement
* bs
)
1788 return bs
->get_tree();
1792 block_to_tree(Bblock
* bb
)
1794 return bb
->get_tree();
1798 var_to_tree(Bvariable
* bv
)
1800 return bv
->get_tree();