1 /****************************************************************************
2  * Copyright (C) 2009 by Matteo Franchin                                    *
3  *                                                                          *
4  * This file is part of Box.                                                *
5  *                                                                          *
6  *   Box is free software: you can redistribute it and/or modify it         *
7  *   under the terms of the GNU Lesser General Public License as published  *
8  *   by the Free Software Foundation, either version 3 of the License, or   *
9  *   (at your option) any later version.                                    *
10  *                                                                          *
11  *   Box is distributed in the hope that it will be useful,                 *
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
14  *   GNU Lesser General Public License for more details.                    *
15  *                                                                          *
16  *   You should have received a copy of the GNU Lesser General Public       *
17  *   License along with Box.  If not, see <http://www.gnu.org/licenses/>.   *
18  ****************************************************************************/
19 
20 /**
21  * @file compiler.h
22  * @brief The compiler of Box.
23  *
24  * A nice description...
25  */
26 
27 #ifndef _BOX_COMPILER_H
28 #  define _BOX_COMPILER_H
29 
30 #  include <box/types.h>
31 #  include <box/vm_priv.h>
32 #  include <box/ast.h>
33 #  include <box/paths.h>
34 
35 
36 /**
37  * @brief The Box Compiler.
38  */
39 typedef struct BoxCmp_struct BoxCmp;
40 
41 
42 BOXEXPORT BoxCmp *
43 BoxCmp_Create(BoxVM *target_vm);
44 
45 BOXEXPORT void
46 BoxCmp_Destroy(BoxCmp *c);
47 
48 /**
49  * Steal the VM which is being used as the target for the compilation.
50  */
51 BOXEXPORT BoxVM *
52 BoxCmp_Steal_VM(BoxCmp *c);
53 
54 /**
55  * Create the compiler and use it to parse the given file, returning the
56  * virtual machine object which was used as the target of the compilation
57  * and putting in '*main' the BoxVMCallNum of the main procedure of the
58  * compiled source.
59  */
60 BOXEXPORT BoxVM *
61 Box_Compile_To_VM_From_File(BoxVMCallNum *main, BoxVM *target_vm,
62 			    FILE *file, const char *file_name,
63 			    const char *setup_file_name,
64 			    BoxPaths *paths);
65 
66 /**
67  * @brief Compile from the give abstract syntax tree.
68  *
69  * @param c Compiler to use.
70  * @param program Abstract syntax tree of the program to compile.
71  */
72 BOXEXPORT void
73 BoxCmp_Compile(BoxCmp *c, ASTNode *program);
74 
75 #endif /* _BOX_COMPILER_H */
76