Remove preOptimize step from hphpc
[hiphop-php.git] / hphp / php7 / compiler.h
blob93835e9d969abbcf2c35059e1dbdf02e35e0847d
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010- Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_PHP7_COMPILER_H_
18 #define incl_HPHP_PHP7_COMPILER_H_
20 #include "hphp/php7/ast_info.h"
21 #include "hphp/php7/bytecode.h"
22 #include "hphp/php7/cfg.h"
23 #include "hphp/php7/unit.h"
24 #include "hphp/php7/lvalue.h"
25 #include "hphp/php7/zend/zend.h"
27 #include <folly/ScopeGuard.h>
29 #include <exception>
30 #include <stack>
31 #include <string>
33 namespace HPHP { namespace php7 {
35 struct CompilerException : public std::logic_error {
36 explicit CompilerException(const std::string& what)
37 : std::logic_error(what) {}
40 struct LanguageException : CompilerException {
41 explicit LanguageException(const std::string& what)
42 : CompilerException(what) {}
46 * Since we need the argument number to push a F flavored value, this lets us
47 * track expected flavor + argument number
49 * The argument slot is nonzero only when flavor is FuncParam
51 struct Destination {
52 private:
53 Destination(Flavor flavor, uint32_t slot)
54 : flavor(flavor)
55 , slot(slot) {}
57 public:
58 /* implicit */ Destination(Flavor flavor)
59 : flavor(flavor)
60 , slot(0) {
61 assert(flavor != Flavor::FuncParam);
64 static Destination Stack(Flavor flavor) {
65 return flavor;
68 static Destination Param(uint32_t slot) {
69 return {Flavor::FuncParam, slot};
72 const Flavor flavor;
73 const uint32_t slot;
76 void compileProgram(Unit* unit, const zend_ast* ast);
77 void compileFunction(Unit* unit, const zend_ast* ast);
78 CFG compileClass(Unit* unit, const zend_ast* ast);
79 CFG compileStatement(Function* func, const zend_ast* ast);
80 CFG compileExpression(const zend_ast* ast, Destination destination);
81 CFG compileClassref(const zend_ast* ast, bc::ClassrefSlot slot,
82 bool* forward = nullptr);
84 inline std::unique_ptr<Unit> compile(const std::string& filename,
85 const zend_ast* ast) {
86 auto unit = std::make_unique<Unit>();
87 unit->name = filename;
88 compileProgram(unit.get(), ast);
89 return unit;
92 [[noreturn]]
93 void panic(const std::string& msg);
96 }} // HPHP::php7
99 #endif // incl_HPHP_PHP7_COMPILER_H_