-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
CodeGenConfiguration.scala
70 lines (62 loc) · 2.57 KB
/
CodeGenConfiguration.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.cypher.internal.compatibility.v3_3.runtime.compiled.codegen
import java.nio.file.{Path, Paths}
import org.neo4j.cypher.internal.frontend.v3_3.InternalException
/**
* Configuration modes for code generation
*/
sealed trait CodeGenMode
/**
* Produces source code
*/
case object SourceCodeMode extends CodeGenMode
/**
* Produce byte code directly
*/
case object ByteCodeMode extends CodeGenMode
/**
* Configuration class for code generation
*
* @param mode The mode of code generation
* @param showSource if `true` source code is stored and returned
* @param packageName The name of the v3_3 the produced code should belong to
*/
case class CodeGenConfiguration(mode: CodeGenMode = CodeGenMode.default,
showSource: Boolean = false,
showByteCode: Boolean = false,
saveSource: Option[Path] = None,
packageName: String = "org.neo4j.cypher.internal.compiler.v3_3.generated"
)
object CodeGenConfiguration {
def apply(debugOptions: Set[String]): CodeGenConfiguration = {
val mode = if(debugOptions.contains("generate_java_source")) SourceCodeMode else ByteCodeMode
val show_java_source = debugOptions.contains("show_java_source")
if (show_java_source && mode != SourceCodeMode) {
throw new InternalException("Can only 'debug=show_java_source' if 'debug=generate_java_source'.")
}
val show_bytecode = debugOptions.contains("show_bytecode")
val saveSource = Option(System.getProperty("org.neo4j.cypher.DEBUG.generated_source_location")).map(Paths.get(_))
CodeGenConfiguration(mode, show_java_source, show_bytecode, saveSource)
}
}
object CodeGenMode {
val default = ByteCodeMode
}