aboutsummaryrefslogtreecommitdiff
path: root/gcc/jit/jit-tempdir.h
blob: 955a4bf2fbf1add5d179292cf8554047c1c0b66a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* Managing temporary directories and their content within libgccjit.so
   Copyright (C) 2014-2018 Free Software Foundation, Inc.
   Contributed by David Malcolm <dmalcolm@redhat.com>.

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/>.  */

#ifndef JIT_TEMPDIR_H
#define JIT_TEMPDIR_H

#include "jit-logging.h"

namespace gcc {

namespace jit {

/* A class to keep track of the jit::playback::context's tempdir.

   The tempdir has the following layout:

     /tmp/libgccjit-XXXXXX/
			 ./fake.c
			    (doesn't exist, but the rest of the
			     compiler needs a source code filename)

			 ./fake.s
			      (created by toplev::main)

			 ./fake.so
			      (created by playback::context::convert_to_dso).

  It is normally deleted from the filesystem in the playback::context's
  dtor, unless GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES was set.  */

class tempdir : public log_user
{
 public:
  tempdir (logger *logger, int keep_intermediates);
  ~tempdir ();

  bool create ();

  const char * get_path () const { return m_path_tempdir; }
  const char * get_path_c_file () const { return m_path_c_file; }
  const char * get_path_s_file () const { return m_path_s_file; }
  const char * get_path_so_file () const { return m_path_so_file; }

  /* Add PATH to the vec of tempfiles that must be unlinked.
     Take ownership of the buffer PATH; it will be freed.  */
  void add_temp_file (char *path) { m_tempfiles.safe_push (path); }

 private:
  /* Was GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES set?  If so, keep the
     on-disk tempdir around after this wrapper object goes away.  */
  int m_keep_intermediates;

  /* Allocated using xmalloc (by xstrdup).  */
  char *m_path_template;

  /* This either aliases m_path_template, or is NULL.  */
  char *m_path_tempdir;

  /* The following are allocated using xmalloc.  */
  char *m_path_c_file;
  char *m_path_s_file;
  char *m_path_so_file;

  /* Other files within the tempdir to be cleaned up:
     - certain ahead-of-time compilation artifacts (.o and .exe files)
     - dumpfiles that were requested via gcc_jit_context_enable_dump.  */
  auto_vec <char *> m_tempfiles;
};

} // namespace gcc::jit

} // namespace gcc

#endif /* JIT_TEMPDIR_H */