-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
733 changed files
with
18,530 additions
and
14,323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# This CITATION.cff file was generated with cffinit. | ||
# Visit https://bit.ly/cffinit to generate yours today! | ||
|
||
cff-version: 1.2.0 | ||
title: Multiplier | ||
message: >- | ||
If you use this software, please cite it using the | ||
metadata from this file. | ||
type: software | ||
authors: | ||
- given-names: Peter | ||
family-names: Goodman | ||
email: [email protected] | ||
affiliation: Trail of Bits | ||
- given-names: Akshay | ||
family-names: Kumar | ||
email: [email protected] | ||
affiliation: Trail of Bits | ||
repository-code: 'https://github.com/trailofbits/multiplier' | ||
abstract: >- | ||
Multiplier provides precise and comprehensive code | ||
understanding capabilities. It does so by saving build | ||
artifacts into a database, and then making them | ||
persistently accessible using a C++ or Python API. | ||
Multiplier emphasizes the ability to unique identify all | ||
entities in a build process, including individual tokens, | ||
AST nodes, and intermediate representations. With | ||
Multiplier, an analyst can identify code patterns of | ||
interest over one of the representations, and then | ||
accurately relay results back to humans in a readable | ||
form, or to follow-on scripts via entity IDs. | ||
Multiplier's APIs are extensive, and often provide as-good | ||
or better-than compiler-level quality information, but | ||
linked at a whole-program granularity. We like to say that | ||
with its APIs, you can get everywhere from anywhere. | ||
keywords: | ||
- c | ||
- c++ | ||
- clang | ||
- compiler | ||
- index | ||
- analysis | ||
- intermediate representation | ||
- ast | ||
- abstract syntax tree | ||
- parsing | ||
license: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright (c) 2022-present, Trail of Bits, Inc. | ||
// All rights reserved. | ||
// | ||
// This source code is licensed in accordance with the terms specified in | ||
// the LICENSE file found in the root directory of this source tree. | ||
|
||
#include <gflags/gflags.h> | ||
#include <glog/logging.h> | ||
#include <sstream> | ||
|
||
#include "Index.h" | ||
#include <multiplier/AST.h> | ||
|
||
DEFINE_uint64(entity_id, 0, "ID of the entity to print"); | ||
|
||
namespace { | ||
|
||
mx::TokenRange TryGetTokens(const mx::VariantEntity &entity) { | ||
if (std::holds_alternative<mx::Stmt>(entity)) { | ||
return std::get<mx::Stmt>(entity).tokens(); | ||
} | ||
|
||
if (std::holds_alternative<mx::Decl>(entity)) { | ||
return std::get<mx::Decl>(entity).tokens(); | ||
} | ||
|
||
if (std::holds_alternative<mx::Attr>(entity)) { | ||
return std::get<mx::Attr>(entity).tokens(); | ||
} | ||
|
||
if (std::holds_alternative<mx::Designator>(entity)) { | ||
return std::get<mx::Designator>(entity).tokens(); | ||
} | ||
|
||
if (std::holds_alternative<mx::CXXBaseSpecifier>(entity)) { | ||
return std::get<mx::CXXBaseSpecifier>(entity).tokens(); | ||
} | ||
|
||
if (std::holds_alternative<mx::CXXCtorInitializer>(entity)) { | ||
return std::get<mx::CXXCtorInitializer>(entity).tokens(); | ||
} | ||
|
||
if (std::holds_alternative<mx::Macro>(entity)) { | ||
return std::get<mx::Macro>(entity).root().use_tokens(); | ||
} | ||
|
||
if (std::holds_alternative<mx::Token>(entity)) { | ||
return std::get<mx::Token>(entity); | ||
} | ||
|
||
return mx::TokenRange(); | ||
} | ||
|
||
} // namespace | ||
|
||
int main(int argc, char *argv[]) { | ||
std::stringstream ss; | ||
ss | ||
<< "Usage: " << argv[0] | ||
<< " [--db DATABASE] --entity_id ID\n"; | ||
|
||
google::SetUsageMessage(ss.str()); | ||
google::ParseCommandLineFlags(&argc, &argv, false); | ||
google::InitGoogleLogging(argv[0]); | ||
|
||
mx::Index index = InitExample(true); | ||
|
||
auto maybe_entity = index.entity(FLAGS_entity_id); | ||
|
||
auto references = mx::Reference::to(maybe_entity); | ||
for (mx::Reference ref : references) { | ||
auto context = ref.context(); | ||
auto referer = ref.as_variant(); | ||
auto frag = mx::Fragment::containing(referer); | ||
if (!frag) { | ||
continue; | ||
} | ||
|
||
mx::TokenRange entity_tokens = TryGetTokens(context); | ||
if (!entity_tokens) { | ||
entity_tokens = TryGetTokens(referer); | ||
} | ||
|
||
if (!entity_tokens) { | ||
continue; | ||
} | ||
|
||
std::cout | ||
<< "Context ID: " << mx::EntityId(context).Pack() << '\n' | ||
<< "Referer ID: " << mx::EntityId(referer).Pack() << '\n' | ||
<< "Reference kind: " << ref.kind().data() << '\n'; | ||
|
||
// Print out the tokens of this fragment as they appear in the file. | ||
RenderFragment(std::cout, *frag, entity_tokens, "", true); | ||
std::cout << "\n\n"; | ||
|
||
} | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.