Skip to content

Instantly share code, notes, and snippets.

@mraleph
Created December 6, 2017 16:08
Show Gist options
  • Save mraleph/ba92961dddfcb668b8ca84fc9cf0cb36 to your computer and use it in GitHub Desktop.
Save mraleph/ba92961dddfcb668b8ca84fc9cf0cb36 to your computer and use it in GitHub Desktop.
#define __ f+=
struct Bind {
Bind(BlockEntryInstr* block) : block(block) { }
BlockEntryInstr* block;
}
Fragment operator + (const Fragment& f, const Bind& bind) {
return Fragment(f.entry, bind.block);
}
Fragment PrologueBuilder::BuildTypeArgumentsLengthCheck(bool strong,
JoinEntryInstr* nsm,
bool expect_type_args) {
Fragment f;
JoinEntryInstr* done = BuildJoinEntry();
// Type args are always optional, so length can always be zero.
// If expect_type_args, a non-zero length must match the declaration length.
TargetEntryInstr *then, *fail;
__ LoadArgDescriptor();
__ LoadField(ArgumentsDescriptor::type_args_len_offset());
if (strong) {
__ IntConstant(ArgumentsDescriptor::TypeArgsLenField::mask());
__ SmiBinaryOp(Token::kBIT_AND, true);
}
if (expect_type_args) {
LocalVariable* len = MakeTemporary();
TargetEntryInstr *otherwise, *then2;
__ LoadLocal(len);
__ IntConstant(0);
__ BranchIfEqual(&then, &otherwise);
__ Bind(otherwise);
__ IntConstant(function_.NumTypeParameters());
__ BranchIfEqual(&then2, &fail);
__ Bind(then2);
__ Goto(done);
} else {
__ IntConstant(0);
__ BranchIfEqual(&then, &fail);
}
__ Bind(then)
__ Goto(done);
__ Bind(fail);
__ Goto(nsm);
return f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment