Skip to content

Commit 165adb7

Browse files
mi-acV8-internal LUCI CQ
authored andcommitted
Enable the FuzzIL compiler to directly output a JS file
This will be used by an automated script compiling and lifting test cases from e.g. test262. Bug: 442444727 Change-Id: I0b2321e44e0def292cd88a103a46b03960ee1d55 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/8680076 Commit-Queue: Michael Achenbach <[email protected]> Reviewed-by: Matthias Liedtke <[email protected]>
1 parent 3b4ef3a commit 165adb7

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

Sources/FuzzILTool/main.swift

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func loadProgramOrExit(from path: String) -> Program {
9595

9696
let args = Arguments.parse(from: CommandLine.arguments)
9797

98-
if args["-h"] != nil || args["--help"] != nil || args.numPositionalArguments != 1 || args.numOptionalArguments > 2 {
98+
if args["-h"] != nil || args["--help"] != nil || args.numPositionalArguments != 1 {
9999
print("""
100100
Usage:
101101
\(args.programName) options path
@@ -108,6 +108,7 @@ if args["-h"] != nil || args["--help"] != nil || args.numPositionalArguments !=
108108
--dumpProgram : Dumps the internal representation of the program stored in the given protobuf file
109109
--checkCorpus : Attempts to load all .fzil files in a directory and checks if they are statically valid
110110
--compile : Compile the given JavaScript program to a FuzzIL program. Requires node.js
111+
--outputPathJS : If given, --compile will write the lifted JS file to the given path after compilation.
111112
--generate : Generate a random program using Fuzzilli's code generators and save it to the specified path.
112113
--forDifferentialFuzzing : Enable additional features for better support of external differential fuzzing.
113114
""")
@@ -186,17 +187,27 @@ else if args.has("--compile") {
186187
exit(-1)
187188
}
188189

189-
print(fuzzILLifter.lift(program))
190-
print()
191-
print(jsLifter.lift(program))
190+
if let js_path = args["--outputPathJS"] {
191+
let content = jsLifter.lift(program)
192+
do {
193+
try content.write(to: URL(fileURLWithPath: js_path), atomically: false, encoding: String.Encoding.utf8)
194+
} catch {
195+
print("Failed to write file \(js_path): \(error)")
196+
exit(-1)
197+
}
198+
} else {
199+
print(fuzzILLifter.lift(program))
200+
print()
201+
print(jsLifter.lift(program))
192202

193-
do {
194-
let outputPath = URL(fileURLWithPath: path).deletingPathExtension().appendingPathExtension("fzil")
195-
try program.asProtobuf().serializedData().write(to: outputPath)
196-
print("FuzzIL program written to \(outputPath.relativePath)")
197-
} catch {
198-
print("Failed to store output program to disk: \(error)")
199-
exit(-1)
203+
do {
204+
let outputPath = URL(fileURLWithPath: path).deletingPathExtension().appendingPathExtension("fzil")
205+
try program.asProtobuf().serializedData().write(to: outputPath)
206+
print("FuzzIL program written to \(outputPath.relativePath)")
207+
} catch {
208+
print("Failed to store output program to disk: \(error)")
209+
exit(-1)
210+
}
200211
}
201212
}
202213

0 commit comments

Comments
 (0)