• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_TORQUE_TORQUE_COMPILER_H_
6 #define V8_TORQUE_TORQUE_COMPILER_H_
7 
8 #include "src/torque/ast.h"
9 #include "src/torque/contextual.h"
10 #include "src/torque/kythe-data.h"
11 #include "src/torque/server-data.h"
12 #include "src/torque/source-positions.h"
13 #include "src/torque/utils.h"
14 
15 namespace v8 {
16 namespace internal {
17 namespace torque {
18 
19 struct TorqueCompilerOptions {
20   std::string output_directory = "";
21   std::string v8_root = "";
22   bool collect_language_server_data = false;
23   bool collect_kythe_data = false;
24 
25   // dcheck(...) are only generated for debug builds. To provide
26   // language server support for statements inside dchecks, this flag
27   // can force generate them.
28   bool force_assert_statements = false;
29 
30   // Forge (Google3) can only run 64-bit executables. As Torque runs as part
31   // of the build process, we need a "cross-compile" mode when we target 32-bit
32   // architectures. Note that this does not needed in Chromium/V8 land, since we
33   // always build with the same bit width as the target architecture.
34   bool force_32bit_output = false;
35 
36   // Adds extra comments in output that show Torque intermediate representation.
37   bool annotate_ir = false;
38 
39   // Strips the v8-root in case the source path contains it as a prefix.
40   bool strip_v8_root = false;
41 };
42 
43 struct TorqueCompilerResult {
44   // Map translating SourceIds to filenames. This field is
45   // set on errors, so the SourcePosition of the error can be
46   // resolved.
47   base::Optional<SourceFileMap> source_file_map;
48 
49   // Eagerly collected data needed for the LanguageServer.
50   // Set the corresponding options flag to enable.
51   LanguageServerData language_server_data;
52 
53   // Errors collected during compilation.
54   std::vector<TorqueMessage> messages;
55 };
56 
57 struct TorqueCompilationUnit {
58   std::string source_file_path;
59   std::string file_content;
60 };
61 
62 V8_EXPORT_PRIVATE TorqueCompilerResult
63 CompileTorque(const std::string& source, TorqueCompilerOptions options);
64 TorqueCompilerResult CompileTorque(std::vector<std::string> files,
65                                    TorqueCompilerOptions options);
66 V8_EXPORT_PRIVATE TorqueCompilerResult CompileTorqueForKythe(
67     std::vector<TorqueCompilationUnit> units, TorqueCompilerOptions options,
68     KytheConsumer* kythe_consumer);
69 
70 }  // namespace torque
71 }  // namespace internal
72 }  // namespace v8
73 
74 #endif  // V8_TORQUE_TORQUE_COMPILER_H_
75