Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(459)

Unified Diff: lib/Bitcode/NaCl/TestUtils/NaClRandNumGen.cpp

Issue 1156103003: Initial implementation of a record-level bitcode fuzzer. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@fuzz
Patch Set: Fix issues in last patch. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/Bitcode/NaCl/TestUtils/NaClFuzz.cpp ('k') | lib/Bitcode/NaCl/TestUtils/NaClSimpleRecordFuzzer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/Bitcode/NaCl/TestUtils/NaClRandNumGen.cpp
diff --git a/lib/Bitcode/NaCl/TestUtils/NaClRandNumGen.cpp b/lib/Bitcode/NaCl/TestUtils/NaClRandNumGen.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5eb89d9fe7819abef6d9b7b375e82e5ce263f42c
--- /dev/null
+++ b/lib/Bitcode/NaCl/TestUtils/NaClRandNumGen.cpp
@@ -0,0 +1,44 @@
+//===- NaClRandNumGen.cpp - Random number generator -----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides a default implementation of a random number generator.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Bitcode/NaCl/NaClRandNumGen.h"
+
+#include <vector>
+#include <algorithm>
+
+namespace naclfuzz {
+
+// Put destructor in .cpp file guarantee vtable construction.
+RandomNumberGenerator::~RandomNumberGenerator() {}
+
+DefaultRandomNumberGenerator::DefaultRandomNumberGenerator(llvm::StringRef Seed)
+ : Seed(Seed) {
+ saltSeed(0);
+}
+
+uint64_t DefaultRandomNumberGenerator::operator()() {
+ return Generator();
+}
+
+void DefaultRandomNumberGenerator::saltSeed(uint64_t Salt) {
+ // Combine seed and salt and pass to generator.
+ std::vector<uint32_t> Data;
+ Data.reserve(Seed.size() + 2);
+ Data.push_back(static_cast<uint32_t>(Salt));
+ Data.push_back(static_cast<uint32_t>(Salt >> 32));
+ std::copy(Seed.begin(), Seed.end(), Data.end());
+ std::seed_seq SeedSeq(Data.begin(), Data.end());
+ Generator.seed(SeedSeq);
+}
+
+} // end of namespace naclfuzz
« no previous file with comments | « lib/Bitcode/NaCl/TestUtils/NaClFuzz.cpp ('k') | lib/Bitcode/NaCl/TestUtils/NaClSimpleRecordFuzzer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698