Line data Source code
1 : // Copyright 2018 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_CSA_GENERATOR_H_
6 : #define V8_TORQUE_CSA_GENERATOR_H_
7 :
8 : #include <iostream>
9 :
10 : #include "src/torque/cfg.h"
11 : #include "src/torque/declarable.h"
12 :
13 : namespace v8 {
14 : namespace internal {
15 : namespace torque {
16 :
17 : class CSAGenerator {
18 : public:
19 : CSAGenerator(const ControlFlowGraph& cfg, std::ostream& out,
20 : base::Optional<Builtin::Kind> linkage = base::nullopt)
21 594 : : cfg_(cfg), out_(out), linkage_(linkage) {}
22 : base::Optional<Stack<std::string>> EmitGraph(Stack<std::string> parameters);
23 :
24 : static constexpr const char* ARGUMENTS_VARIABLE_STRING = "arguments";
25 :
26 : static void EmitCSAValue(VisitResult result, const Stack<std::string>& values,
27 : std::ostream& out);
28 :
29 : private:
30 : const ControlFlowGraph& cfg_;
31 : std::ostream& out_;
32 : size_t fresh_id_ = 0;
33 : base::Optional<Builtin::Kind> linkage_;
34 :
35 : std::string PreCallableExceptionPreparation(
36 : base::Optional<Block*> catch_block);
37 : void PostCallableExceptionPreparation(const std::string& catch_name,
38 : const Type* return_type,
39 : base::Optional<Block*> catch_block,
40 : Stack<std::string>* stack);
41 :
42 62580 : std::string FreshNodeName() { return "tmp" + std::to_string(fresh_id_++); }
43 44 : std::string FreshCatchName() { return "catch" + std::to_string(fresh_id_++); }
44 17772 : std::string BlockName(const Block* block) {
45 17772 : return "block" + std::to_string(block->id());
46 : }
47 :
48 : void ProcessArgumentsCommon(const TypeVector& parameter_types,
49 : std::vector<std::string>* args,
50 : std::vector<std::string>* constexpr_arguments,
51 : Stack<std::string>* stack);
52 :
53 : Stack<std::string> EmitBlock(const Block* block);
54 : void EmitInstruction(const Instruction& instruction,
55 : Stack<std::string>* stack);
56 : #define EMIT_INSTRUCTION_DECLARATION(T) \
57 : void EmitInstruction(const T& instruction, Stack<std::string>* stack);
58 : TORQUE_INSTRUCTION_LIST(EMIT_INSTRUCTION_DECLARATION)
59 : #undef EMIT_INSTRUCTION_DECLARATION
60 : };
61 :
62 : } // namespace torque
63 : } // namespace internal
64 : } // namespace v8
65 :
66 : #endif // V8_TORQUE_CSA_GENERATOR_H_
|