xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/brig/brigfrontend/brig-arg-block-handler.cc (revision 4c3eb207d36f67d31994830c0a694161fc1ca39b)
1 /* brig-arg-block-handler.cc -- brig arg block start/end directive handling
2    Copyright (C) 2016-2020 Free Software Foundation, Inc.
3    Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
4    for General Processor Tech.
5 
6    This file is part of GCC.
7 
8    GCC is free software; you can redistribute it and/or modify it under
9    the terms of the GNU General Public License as published by the Free
10    Software Foundation; either version 3, or (at your option) any later
11    version.
12 
13    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14    WARRANTY; without even the implied warranty of MERCHANTABILITY or
15    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16    for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with GCC; see the file COPYING3.  If not see
20    <http://www.gnu.org/licenses/>.  */
21 
22 #include "brig-code-entry-handler.h"
23 #include "tree-iterator.h"
24 #include "system.h"
25 #include "errors.h"
26 
27 #include "tree-pretty-print.h"
28 #include "print-tree.h"
29 
30 size_t
operator ()(const BrigBase * base)31 brig_directive_arg_block_handler::operator () (const BrigBase *base)
32 {
33   if (base->kind == BRIG_KIND_DIRECTIVE_ARG_BLOCK_START)
34     {
35       /* Initiate a new code block for the call site.  */
36       tree stmt_list = alloc_stmt_list ();
37       tree bind_expr
38 	= build3 (BIND_EXPR, void_type_node, NULL, stmt_list, NULL);
39       tree block = make_node (BLOCK);
40       BIND_EXPR_BLOCK (bind_expr) = block;
41       static int block_id = 0;
42       BLOCK_NUMBER (block) = block_id++;
43       TREE_USED (block) = 1;
44       tree m_parentblock = DECL_INITIAL (m_parent.m_cf->m_func_decl);
45       BLOCK_SUPERCONTEXT (block) = m_parentblock;
46 
47       chainon (BLOCK_SUBBLOCKS (m_parentblock), block);
48 
49       m_parent.m_cf->m_current_bind_expr = bind_expr;
50       m_parent.m_cf->m_generating_arg_block = true;
51     }
52   else if (base->kind == BRIG_KIND_DIRECTIVE_ARG_BLOCK_END)
53     {
54       /* Restore the used bind expression back to the function
55 	 scope.  */
56       tree new_bind_expr = m_parent.m_cf->m_current_bind_expr;
57       m_parent.m_cf->m_current_bind_expr
58 	= DECL_SAVED_TREE (m_parent.m_cf->m_func_decl);
59       m_parent.m_cf->append_statement (new_bind_expr);
60       m_parent.m_cf->m_generating_arg_block = false;
61     }
62   else
63     gcc_unreachable ();
64 
65   return base->byteCount;
66 }
67