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 : : cfg_(cfg),
22 : out_(out),
23 : linkage_(linkage),
24 1337 : previous_position_(SourcePosition::Invalid()) {}
25 : base::Optional<Stack<std::string>> EmitGraph(Stack<std::string> parameters);
26 :
27 : static constexpr const char* ARGUMENTS_VARIABLE_STRING = "arguments";
28 :
29 : static void EmitCSAValue(VisitResult result, const Stack<std::string>& values,
30 : std::ostream& out);
31 :
32 : private:
33 : const ControlFlowGraph& cfg_;
34 : std::ostream& out_;
35 : size_t fresh_id_ = 0;
36 : base::Optional<Builtin::Kind> linkage_;
37 : SourcePosition previous_position_;
38 :
39 : void EmitSourcePosition(SourcePosition pos, bool always_emit = false);
40 :
41 : std::string PreCallableExceptionPreparation(
42 : base::Optional<Block*> catch_block);
43 : void PostCallableExceptionPreparation(const std::string& catch_name,
44 : const Type* return_type,
45 : base::Optional<Block*> catch_block,
46 : Stack<std::string>* stack);
47 :
48 156759 : std::string FreshNodeName() { return "tmp" + std::to_string(fresh_id_++); }
49 39 : std::string FreshCatchName() { return "catch" + std::to_string(fresh_id_++); }
50 30772 : std::string BlockName(const Block* block) {
51 61544 : return "block" + std::to_string(block->id());
52 : }
53 :
54 : void ProcessArgumentsCommon(const TypeVector& parameter_types,
55 : std::vector<std::string>* args,
56 : std::vector<std::string>* constexpr_arguments,
57 : Stack<std::string>* stack);
58 :
59 : Stack<std::string> EmitBlock(const Block* block);
60 : void EmitInstruction(const Instruction& instruction,
61 : Stack<std::string>* stack);
62 : #define EMIT_INSTRUCTION_DECLARATION(T) \
63 : void EmitInstruction(const T& instruction, Stack<std::string>* stack);
64 : TORQUE_INSTRUCTION_LIST(EMIT_INSTRUCTION_DECLARATION)
65 : #undef EMIT_INSTRUCTION_DECLARATION
66 : };
67 :
68 : } // namespace torque
69 : } // namespace internal
70 : } // namespace v8
71 :
72 : #endif // V8_TORQUE_CSA_GENERATOR_H_
|