Skip to content

Commit

Permalink
Small improvements (#503)
Browse files Browse the repository at this point in the history
* Made it possible to categorize an entity into a TokenCategory

* Add missing .from converting a VariantEntity to a Token.

* Fix issue related to computing related entity IDs in custom token ranges.

* Bug fix in bug fix lol

* Smarter application of std::move in Python bindings, along with specifying move semantics for UserToken.
  • Loading branch information
Peter Goodman authored Jan 8, 2024
1 parent 10434d5 commit 44e67bf
Show file tree
Hide file tree
Showing 842 changed files with 9,879 additions and 9,650 deletions.
22 changes: 18 additions & 4 deletions bin/Bootstrap/PythonBindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
from typing import DefaultDict, Dict, Iterable, List, Set, Tuple, Type
import sys

MX_BIN_BOOSTRAP_DIR = os.path.dirname(__file__)
MX_BIN_BOOSTRAP_DIR = os.path.dirname(os.path.abspath(__file__))
MX_BIN_DIR = os.path.dirname(MX_BIN_BOOSTRAP_DIR)
MX_DIR = os.path.dirname(MX_BIN_DIR)
MX_INCLUDE_DIR = os.path.join(MX_DIR, "include")
MX_BINDINGS_DIR = os.path.join(MX_DIR, "bindings")
MX_BINDINGS_PYTHON_DIR = os.path.join(MX_BINDINGS_DIR, "Python")


TYPES_CPP = """// Copyright (c) 2023-present, Trail of Bits, Inc.
// All rights reserved.
//
Expand Down Expand Up @@ -384,6 +383,7 @@ class UserToken;


METHOD_SPEC_CALL_ARG = "arg_{}.value()"
METHOD_SPEC_CALL_VALUE_ARG = "std::move(arg_{}.value())"


METHOD_SPEC_CALL = """
Expand Down Expand Up @@ -1102,6 +1102,8 @@ def _wrap_method_impl(class_schema: ClassSchema, schema: MethodSchema,
out.append(METHOD_SPEC_CHECK_ARGCOUNT_BEGIN.format(num_args=num_args))

py_args = []
cxx_args = []

if not is_static:
py_args.append("self")

Expand All @@ -1113,10 +1115,15 @@ def _wrap_method_impl(class_schema: ClassSchema, schema: MethodSchema,
arg_name = ARGUMENT_RENAMES.get(arg.name, arg.name) or f"arg_{i}"
py_args.append(f"{arg_name}: {arg.element_type.python_value_name}")

if not isinstance(arg.element_type, ReferenceSchema):
cxx_args.append(METHOD_SPEC_CALL_VALUE_ARG.format(i))
else:
cxx_args.append(METHOD_SPEC_CALL_ARG.format(i))

out.append(METHOD_SPEC_CALL.format(
this=is_static and "T::" or "obj->",
method_name=schema.name,
args=", ".join(METHOD_SPEC_CALL_ARG.format(i) for i in range(num_args))))
args=", ".join(cxx_args)))

out.append(METHOD_SPEC_CHECK_ARGCOUNT_END)

Expand All @@ -1135,15 +1142,22 @@ def _wrap_constructor_impl(class_schema: ClassSchema, schema: MethodSchema,
num_args = len(schema.parameters)
out.append(INIT_SPEC_CHECK_ARGCOUNT_BEGIN.format(num_args=num_args))

cxx_args = []

for i, arg in enumerate(schema.parameters):
FROM_EXPORTS.add(arg.element_type)
out.append(INIT_SPEC_GET_ARG.format(
arg_num=i,
arg_type=arg.element_type.cxx_value_name))

if not isinstance(arg.element_type, ReferenceSchema):
cxx_args.append(METHOD_SPEC_CALL_VALUE_ARG.format(i))
else:
cxx_args.append(METHOD_SPEC_CALL_ARG.format(i))

out.append(INIT_SPEC_CALL.format(
cxx_class_name=class_schema.name,
args=", ".join(METHOD_SPEC_CALL_ARG.format(i) for i in range(num_args))))
args=", ".join(cxx_args)))

out.append(INIT_SPEC_CHECK_ARGCOUNT_END)

Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AArch64SVEPcsAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AArch64VectorPcsAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AMDGPUKernelCallAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AMDGPUNumSGPRAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AMDGPUNumVGPRAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AMDGPUWavesPerEUAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/ARMInterruptAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AVRInterruptAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AVRSignalAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AbiTagAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AccessSpecDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AcquireCapabilityAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AcquireHandleAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AcquiredAfterAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AcquiredBeforeAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AddrLabelExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AddressSpaceAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AdjustedType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AliasAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AlignMac68kAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AlignNaturalAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AlignValueAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AlignedAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AllocAlignAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AllocSizeAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AlwaysDestroyAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AlwaysInlineAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AnalyzerNoReturnAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AnnotateAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AnnotateTypeAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AnyX86InterruptAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
2 changes: 1 addition & 1 deletion bindings/Python/Generated/AST/AnyX86NoCfCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static PyMethodDef gMethods[] = {
break;
}

return ::mx::to_python(T::by_id(arg_0.value(), arg_1.value()));
return ::mx::to_python(T::by_id(arg_0.value(), std::move(arg_1.value())));
}

PyErrorStreamer(PyExc_TypeError)
Expand Down
Loading

0 comments on commit 44e67bf

Please sign in to comment.