mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-30 03:34:25 +03:00
add new Literal API for pure literal expressions:
Design compile time api hs_compile_lit() and hs_compile_lit_multi() to handle pure literal pattern sets. Corresponding option --literal-on is added for hyperscan testing suites. Extended parameters and part of flags are not supported for this api.
This commit is contained in:
committed by
Chang, Harry
parent
8bfbf07f75
commit
23e5f06594
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2018, Intel Corporation
|
||||
* Copyright (c) 2015-2019, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -106,6 +106,8 @@ bool dump_intermediate = true;
|
||||
bool force_edit_distance = false;
|
||||
u32 edit_distance = 0;
|
||||
|
||||
int use_literal_api = 0;
|
||||
|
||||
} // namespace
|
||||
|
||||
// Usage statement.
|
||||
@@ -139,6 +141,7 @@ void usage(const char *name, const char *error) {
|
||||
printf(" -8 Force UTF8 mode on all patterns.\n");
|
||||
printf(" -L Apply HS_FLAG_SOM_LEFTMOST to all patterns.\n");
|
||||
printf(" --prefilter Apply HS_FLAG_PREFILTER to all patterns.\n");
|
||||
printf(" --literal-on Use Hyperscan pure literal matching API.\n");
|
||||
printf("\n");
|
||||
printf("Example:\n");
|
||||
printf("$ %s -e pattern.file -s sigfile\n", name);
|
||||
@@ -163,6 +166,7 @@ void processArgs(int argc, char *argv[], Grey &grey) {
|
||||
{"utf8", no_argument, nullptr, '8'},
|
||||
{"prefilter", no_argument, &force_prefilter, 1},
|
||||
{"som-width", required_argument, nullptr, 'd'},
|
||||
{"literal-on", no_argument, &use_literal_api, 1},
|
||||
{nullptr, 0, nullptr, 0}
|
||||
};
|
||||
|
||||
@@ -501,9 +505,23 @@ unsigned int dumpDataMulti(const vector<const char *> &patterns,
|
||||
hs_database_t *db = nullptr;
|
||||
hs_compile_error_t *compile_err;
|
||||
|
||||
hs_error_t err = hs_compile_multi_int(
|
||||
patterns.data(), flags.data(), ids.data(), ext.c_array(),
|
||||
patterns.size(), mode, plat_info.get(), &db, &compile_err, grey);
|
||||
hs_error_t err;
|
||||
const size_t count = patterns.size();
|
||||
if (use_literal_api) {
|
||||
// Compute length of each pattern.
|
||||
vector<size_t> lens(count);
|
||||
for (unsigned int i = 0; i < count; i++) {
|
||||
lens[i] = strlen(patterns[i]);
|
||||
}
|
||||
err = hs_compile_lit_multi_int(patterns.data(), flags.data(),
|
||||
ids.data(), ext.c_array(), lens.data(),
|
||||
count, mode, plat_info.get(), &db,
|
||||
&compile_err, grey);
|
||||
} else {
|
||||
err = hs_compile_multi_int(patterns.data(), flags.data(), ids.data(),
|
||||
ext.c_array(), count, mode, plat_info.get(),
|
||||
&db, &compile_err, grey);
|
||||
}
|
||||
|
||||
if (err != HS_SUCCESS) {
|
||||
if (compile_err && compile_err->message) {
|
||||
|
Reference in New Issue
Block a user