Commit db34c5a1 authored by Austin Eng's avatar Austin Eng Committed by Commit Bot

[fastcall] Introduce a builder pattern for specifying type modifiers

- Add a CFunctionBuilder interface to allow adding modifier flags
  to argument types. This will be used to support IDL attributes
  like [EnforceRange], [Clamp], and [AllowShared]. This CL adds
  only the interface, but the actual modifier flags do not exist
  yet as they would not be implemented.
- Remove the internals of the old CFunction type inference and
  implement it on top of CFunctionBuilder.

Bug: chromium:1052746
Change-Id: I09a7cba07105097517a8426a8eeb891393883ac6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2686686Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73024}
parent d98b12d3
This diff is collapsed.
...@@ -9987,6 +9987,21 @@ CFunction::CFunction(const void* address, const CFunctionInfo* type_info) ...@@ -9987,6 +9987,21 @@ CFunction::CFunction(const void* address, const CFunctionInfo* type_info)
CHECK_NOT_NULL(type_info_); CHECK_NOT_NULL(type_info_);
} }
CFunctionInfo::CFunctionInfo(const CTypeInfo& return_info,
unsigned int arg_count, const CTypeInfo* arg_info)
: return_info_(return_info), arg_count_(arg_count), arg_info_(arg_info) {
if (arg_count_ > 0) {
for (unsigned int i = 0; i < arg_count_ - 1; ++i) {
DCHECK(arg_info_[i].GetType() != CTypeInfo::kCallbackOptionsType);
}
}
}
const CTypeInfo& CFunctionInfo::ArgumentInfo(unsigned int index) const {
DCHECK_LT(index, ArgumentCount());
return arg_info_[index];
}
RegisterState::RegisterState() RegisterState::RegisterState()
: pc(nullptr), sp(nullptr), fp(nullptr), lr(nullptr) {} : pc(nullptr), sp(nullptr), fp(nullptr), lr(nullptr) {}
RegisterState::~RegisterState() = default; RegisterState::~RegisterState() = default;
......
...@@ -27937,37 +27937,28 @@ void CallWithUnexpectedObjectType(v8::Local<v8::Value> receiver) { ...@@ -27937,37 +27937,28 @@ void CallWithUnexpectedObjectType(v8::Local<v8::Value> receiver) {
} }
class TestCFunctionInfo : public v8::CFunctionInfo { class TestCFunctionInfo : public v8::CFunctionInfo {
const v8::CTypeInfo& ReturnInfo() const override { static constexpr unsigned int kArgCount = 2u;
static v8::CTypeInfo return_info =
v8::CTypeInfo(v8::CTypeInfo::Type::kVoid);
return return_info;
}
unsigned int ArgumentCount() const override { return 2; }
const v8::CTypeInfo& ArgumentInfo(unsigned int index) const override {
static v8::CTypeInfo type_info0 =
v8::CTypeInfo(v8::CTypeInfo::Type::kV8Value);
static v8::CTypeInfo type_info1 = v8::CTypeInfo(v8::CTypeInfo::Type::kBool);
switch (index) {
case 0:
return type_info0;
case 1:
return type_info1;
default:
UNREACHABLE();
}
}
bool HasOptions() const override { return false; } public:
TestCFunctionInfo()
: v8::CFunctionInfo(v8::CTypeInfo(v8::CTypeInfo::Type::kVoid), kArgCount,
arg_info_storage_),
arg_info_storage_{
v8::CTypeInfo(v8::CTypeInfo::Type::kV8Value),
v8::CTypeInfo(v8::CTypeInfo::Type::kBool),
} {}
private:
const v8::CTypeInfo arg_info_storage_[kArgCount];
}; };
void CheckDynamicTypeInfo() { void CheckDynamicTypeInfo() {
LocalContext env; LocalContext env;
static TestCFunctionInfo type_info; static TestCFunctionInfo type_info;
v8::CFunction c_func = v8::CFunction c_func = v8::CFunction(
v8::CFunction::Make(ApiNumberChecker<bool>::FastCallback, &type_info); reinterpret_cast<const void*>(ApiNumberChecker<bool>::FastCallback),
&type_info);
CHECK_EQ(c_func.ArgumentCount(), 2); CHECK_EQ(c_func.ArgumentCount(), 2);
CHECK_EQ(c_func.ArgumentInfo(0).GetType(), v8::CTypeInfo::Type::kV8Value); CHECK_EQ(c_func.ArgumentInfo(0).GetType(), v8::CTypeInfo::Type::kV8Value);
CHECK_EQ(c_func.ArgumentInfo(1).GetType(), v8::CTypeInfo::Type::kBool); CHECK_EQ(c_func.ArgumentInfo(1).GetType(), v8::CTypeInfo::Type::kBool);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment