Commit fc111bc5 authored by Travis Hance's avatar Travis Hance

ported objmodel.cpp to use rewriter2 exclusively, deprecates rewriter1

parent a5258c49
...@@ -477,7 +477,6 @@ void Assembler::cmp(Register reg1, Register reg2) { ...@@ -477,7 +477,6 @@ void Assembler::cmp(Register reg1, Register reg2) {
reg1_idx -= 8; reg1_idx -= 8;
} }
if (reg2_idx >= 8) { if (reg2_idx >= 8) {
trap();
rex |= REX_B; rex |= REX_B;
reg2_idx -= 8; reg2_idx -= 8;
} }
......
This diff is collapsed.
...@@ -36,7 +36,7 @@ public: ...@@ -36,7 +36,7 @@ public:
enum LocationType : uint8_t { enum LocationType : uint8_t {
Register, Register,
XMMRegister, XMMRegister,
// Stack, Stack,
Scratch, // stack location, relative to the scratch start Scratch, // stack location, relative to the scratch start
// For representing constants that fit in 32-bits, that can be encoded as immediates // For representing constants that fit in 32-bits, that can be encoded as immediates
...@@ -152,13 +152,18 @@ public: ...@@ -152,13 +152,18 @@ public:
#endif #endif
void setDoneUsing(); void setDoneUsing();
bool isDoneUsing();
void ensureDoneUsing();
// RewriterVarUsage2 addUse() { return var->addUse(); }
RewriterVarUsage2 addUse(); RewriterVarUsage2 addUse();
void addGuard(uint64_t val);
void addGuardNotEq(uint64_t val);
void addAttrGuard(int offset, uint64_t val); void addAttrGuard(int offset, uint64_t val);
RewriterVarUsage2 getAttr(int offset, KillFlag kill, Location loc = Location::any()); RewriterVarUsage2 getAttr(int offset, KillFlag kill, Location loc = Location::any());
void setAttr(int offset, RewriterVarUsage2 other); void setAttr(int offset, RewriterVarUsage2 other);
RewriterVarUsage2 cmp(AST_TYPE::AST_TYPE cmp_type, RewriterVarUsage2 other, Location loc = Location::any());
RewriterVarUsage2 toBool(KillFlag kill, Location loc = Location::any());
friend class Rewriter2; friend class Rewriter2;
}; };
...@@ -174,6 +179,10 @@ private: ...@@ -174,6 +179,10 @@ private:
std::unordered_set<Location> locations; std::unordered_set<Location> locations;
bool isInLocation(Location l); bool isInLocation(Location l);
// Indicates that this value is a pointer to a fixed-size range in the scratch space.
// This is a vector of variable usages that keep the range allocated.
std::vector<RewriterVarUsage2> scratch_range;
// Gets a copy of this variable in a register, spilling/reloading if necessary. // Gets a copy of this variable in a register, spilling/reloading if necessary.
// TODO have to be careful with the result since the interface doesn't guarantee // TODO have to be careful with the result since the interface doesn't guarantee
// that the register will still contain your value when you go to use it // that the register will still contain your value when you go to use it
...@@ -189,7 +198,7 @@ public: ...@@ -189,7 +198,7 @@ public:
void incUse(); void incUse();
void decUse(); void decUse();
RewriterVar2(Rewriter2* rewriter, Location location) : rewriter(rewriter), num_uses(1) { RewriterVar2(Rewriter2* rewriter, Location location) : rewriter(rewriter), num_uses(0) {
assert(rewriter); assert(rewriter);
locations.insert(location); locations.insert(location);
} }
...@@ -239,6 +248,11 @@ private: ...@@ -239,6 +248,11 @@ private:
void finishAssembly(int continue_offset) override; void finishAssembly(int continue_offset) override;
std::pair<RewriterVarUsage2, int> _allocate(int n);
int ndecisions;
uint64_t decision_path;
public: public:
// This should be called exactly once for each argument // This should be called exactly once for each argument
RewriterVarUsage2 getArg(int argnum); RewriterVarUsage2 getArg(int argnum);
...@@ -255,6 +269,10 @@ public: ...@@ -255,6 +269,10 @@ public:
RewriterVarUsage2 call(bool can_call_into_python, void* func_addr, std::vector<RewriterVarUsage2> args); RewriterVarUsage2 call(bool can_call_into_python, void* func_addr, std::vector<RewriterVarUsage2> args);
RewriterVarUsage2 call(bool can_call_into_python, void* func_addr, RewriterVarUsage2 arg0); RewriterVarUsage2 call(bool can_call_into_python, void* func_addr, RewriterVarUsage2 arg0);
RewriterVarUsage2 call(bool can_call_into_python, void* func_addr, RewriterVarUsage2 arg0, RewriterVarUsage2 arg1); RewriterVarUsage2 call(bool can_call_into_python, void* func_addr, RewriterVarUsage2 arg0, RewriterVarUsage2 arg1);
RewriterVarUsage2 allocate(int n);
RewriterVarUsage2 allocateAndCopy(RewriterVarUsage2 array, int n);
RewriterVarUsage2 allocateAndCopyPlus1(RewriterVarUsage2 first_elem, RewriterVarUsage2 rest, int n_rest);
void deallocateStack(int nbytes);
void commit(); void commit();
void commitReturning(RewriterVarUsage2 rtn); void commitReturning(RewriterVarUsage2 rtn);
...@@ -263,6 +281,8 @@ public: ...@@ -263,6 +281,8 @@ public:
static Rewriter2* createRewriter(void* rtn_addr, int num_args, const char* debug_name); static Rewriter2* createRewriter(void* rtn_addr, int num_args, const char* debug_name);
void addDecision(int way);
friend class RewriterVar2; friend class RewriterVar2;
friend class RewriterVarUsage2; friend class RewriterVarUsage2;
}; };
......
...@@ -1812,7 +1812,7 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) { ...@@ -1812,7 +1812,7 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) {
if (source->ast->type == AST_TYPE::ClassDef) { if (source->ast->type == AST_TYPE::ClassDef) {
// A classdef always starts with "__module__ = __name__" // A classdef always starts with "__module__ = __name__"
Box* module_name = source->parent_module->getattr("__name__", NULL, NULL); Box* module_name = source->parent_module->getattr("__name__", NULL);
assert(module_name->cls == str_cls); assert(module_name->cls == str_cls);
AST_Assign* module_assign = new AST_Assign(); AST_Assign* module_assign = new AST_Assign();
module_assign->targets.push_back(makeName("__module__", AST_TYPE::Store)); module_assign->targets.push_back(makeName("__module__", AST_TYPE::Store));
......
...@@ -54,6 +54,11 @@ struct ArgPassSpec { ...@@ -54,6 +54,11 @@ struct ArgPassSpec {
int totalPassed() { return num_args + num_keywords + (has_starargs ? 1 : 0) + (has_kwargs ? 1 : 0); } int totalPassed() { return num_args + num_keywords + (has_starargs ? 1 : 0) + (has_kwargs ? 1 : 0); }
uintptr_t asInt() const { return *reinterpret_cast<const uintptr_t*>(this); } uintptr_t asInt() const { return *reinterpret_cast<const uintptr_t*>(this); }
void dump() {
printf("(has_starargs=%s, has_kwargs=%s, num_keywords=%d, num_args=%d)\n", has_starargs ? "true" : "false",
has_kwargs ? "true" : "false", num_keywords, num_args);
}
}; };
static_assert(sizeof(ArgPassSpec) <= sizeof(void*), "ArgPassSpec doesn't fit in register!"); static_assert(sizeof(ArgPassSpec) <= sizeof(void*), "ArgPassSpec doesn't fit in register!");
...@@ -233,7 +238,7 @@ public: ...@@ -233,7 +238,7 @@ public:
}; };
typedef std::vector<CompiledFunction*> FunctionList; typedef std::vector<CompiledFunction*> FunctionList;
class CallRewriteArgs; class CallRewriteArgs2;
class CLFunction { class CLFunction {
public: public:
int num_args; int num_args;
...@@ -249,7 +254,7 @@ public: ...@@ -249,7 +254,7 @@ public:
// of the normal dispatch through the functionlist. // of the normal dispatch through the functionlist.
// This can be used to implement functions which know how to rewrite themselves, // This can be used to implement functions which know how to rewrite themselves,
// such as typeCall. // such as typeCall.
typedef Box* (*InternalCallable)(BoxedFunction*, CallRewriteArgs*, ArgPassSpec, Box*, Box*, Box*, Box**, typedef Box* (*InternalCallable)(BoxedFunction*, CallRewriteArgs2*, ArgPassSpec, Box*, Box*, Box*, Box**,
const std::vector<const std::string*>*); const std::vector<const std::string*>*);
InternalCallable internal_callable = NULL; InternalCallable internal_callable = NULL;
...@@ -372,7 +377,6 @@ private: ...@@ -372,7 +377,6 @@ private:
class SetattrRewriteArgs2; class SetattrRewriteArgs2;
class GetattrRewriteArgs;
class GetattrRewriteArgs2; class GetattrRewriteArgs2;
class DelattrRewriteArgs2; class DelattrRewriteArgs2;
...@@ -404,8 +408,8 @@ public: ...@@ -404,8 +408,8 @@ public:
this->setattr(attr, val, NULL); this->setattr(attr, val, NULL);
} }
Box* getattr(const std::string& attr, GetattrRewriteArgs* rewrite_args, GetattrRewriteArgs2* rewrite_args2); Box* getattr(const std::string& attr, GetattrRewriteArgs2* rewrite_args2);
Box* getattr(const std::string& attr) { return getattr(attr, NULL, NULL); } Box* getattr(const std::string& attr) { return getattr(attr, NULL); }
void delattr(const std::string& attr, DelattrRewriteArgs2* rewrite_args); void delattr(const std::string& attr, DelattrRewriteArgs2* rewrite_args);
}; };
......
...@@ -56,7 +56,7 @@ extern "C" Box* dir(Box* obj) { ...@@ -56,7 +56,7 @@ extern "C" Box* dir(Box* obj) {
} }
// If __dict__ is present use its keys and add the reset below // If __dict__ is present use its keys and add the reset below
Box* obj_dict = getattr_internal(obj, "__dict__", false, true, nullptr, nullptr); Box* obj_dict = getattr_internal(obj, "__dict__", false, true, nullptr);
if (obj_dict && obj_dict->cls == dict_cls) { if (obj_dict && obj_dict->cls == dict_cls) {
result = new BoxedList(); result = new BoxedList();
for (auto& kv : static_cast<BoxedDict*>(obj_dict)->d) { for (auto& kv : static_cast<BoxedDict*>(obj_dict)->d) {
...@@ -326,7 +326,7 @@ Box* getattrFunc(Box* obj, Box* _str, Box* default_value) { ...@@ -326,7 +326,7 @@ Box* getattrFunc(Box* obj, Box* _str, Box* default_value) {
} }
BoxedString* str = static_cast<BoxedString*>(_str); BoxedString* str = static_cast<BoxedString*>(_str);
Box* rtn = getattr_internal(obj, str->s, true, true, NULL, NULL); Box* rtn = getattr_internal(obj, str->s, true, true, NULL);
if (!rtn) { if (!rtn) {
if (default_value) if (default_value)
...@@ -345,7 +345,7 @@ Box* hasattr(Box* obj, Box* _str) { ...@@ -345,7 +345,7 @@ Box* hasattr(Box* obj, Box* _str) {
} }
BoxedString* str = static_cast<BoxedString*>(_str); BoxedString* str = static_cast<BoxedString*>(_str);
Box* attr = getattr_internal(obj, str->s, true, true, NULL, NULL); Box* attr = getattr_internal(obj, str->s, true, true, NULL);
Box* rtn = attr ? True : False; Box* rtn = attr ? True : False;
return rtn; return rtn;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -81,30 +81,29 @@ extern "C" void assertFail(BoxedModule* inModule, Box* msg); ...@@ -81,30 +81,29 @@ extern "C" void assertFail(BoxedModule* inModule, Box* msg);
extern "C" bool isSubclass(BoxedClass* child, BoxedClass* parent); extern "C" bool isSubclass(BoxedClass* child, BoxedClass* parent);
extern "C" BoxedClosure* createClosure(BoxedClosure* parent_closure); extern "C" BoxedClosure* createClosure(BoxedClosure* parent_closure);
class BinopRewriteArgs; class BinopRewriteArgs2;
extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, BinopRewriteArgs* rewrite_args); extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, BinopRewriteArgs2* rewrite_args);
Box* typeCallInternal(BoxedFunction* f, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2, class CallRewriteArgs2;
Box* typeCallInternal(BoxedFunction* f, CallRewriteArgs2* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2,
Box* arg3, Box** args, const std::vector<const std::string*>* keyword_names); Box* arg3, Box** args, const std::vector<const std::string*>* keyword_names);
class CallRewriteArgs;
enum LookupScope { enum LookupScope {
CLASS_ONLY = 1, CLASS_ONLY = 1,
INST_ONLY = 2, INST_ONLY = 2,
CLASS_OR_INST = 3, CLASS_OR_INST = 3,
}; };
extern "C" Box* callattrInternal(Box* obj, const std::string* attr, LookupScope, CallRewriteArgs* rewrite_args, extern "C" Box* callattrInternal(Box* obj, const std::string* attr, LookupScope, CallRewriteArgs2* rewrite_args,
ArgPassSpec argspec, Box* arg1, Box* arg2, Box* arg3, Box** args, ArgPassSpec argspec, Box* arg1, Box* arg2, Box* arg3, Box** args,
const std::vector<const std::string*>* keyword_names); const std::vector<const std::string*>* keyword_names);
extern "C" void delattr_internal(Box* obj, const std::string& attr, bool allow_custom, extern "C" void delattr_internal(Box* obj, const std::string& attr, bool allow_custom,
DelattrRewriteArgs2* rewrite_args); DelattrRewriteArgs2* rewrite_args);
struct CompareRewriteArgs; struct CompareRewriteArgs2;
Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrite_args); Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs2* rewrite_args);
Box* getattr_internal(Box* obj, const std::string& attr, bool check_cls, bool allow_custom, Box* getattr_internal(Box* obj, const std::string& attr, bool check_cls, bool allow_custom,
GetattrRewriteArgs* rewrite_args, GetattrRewriteArgs2* rewrite_args2); GetattrRewriteArgs2* rewrite_args2);
Box* typeLookup(BoxedClass* cls, const std::string& attr, GetattrRewriteArgs* rewrite_args, Box* typeLookup(BoxedClass* cls, const std::string& attr, GetattrRewriteArgs2* rewrite_args2);
GetattrRewriteArgs2* rewrite_args2);
extern "C" void raiseAttributeErrorStr(const char* typeName, const char* attr) __attribute__((__noreturn__)); extern "C" void raiseAttributeErrorStr(const char* typeName, const char* attr) __attribute__((__noreturn__));
extern "C" void raiseAttributeError(Box* obj, const char* attr) __attribute__((__noreturn__)); extern "C" void raiseAttributeError(Box* obj, const char* attr) __attribute__((__noreturn__));
...@@ -114,7 +113,7 @@ Box* typeCall(Box*, BoxedList*); ...@@ -114,7 +113,7 @@ Box* typeCall(Box*, BoxedList*);
Box* typeNew(Box*, Box*); Box* typeNew(Box*, Box*);
bool isUserDefined(BoxedClass* cls); bool isUserDefined(BoxedClass* cls);
Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, Box* callCLFunc(CLFunction* f, CallRewriteArgs2* rewrite_args, int num_output_args, BoxedClosure* closure,
BoxedGenerator* generator, Box* oarg1, Box* oarg2, Box* oarg3, Box** oargs); BoxedGenerator* generator, Box* oarg1, Box* oarg2, Box* oarg3, Box** oargs);
} }
#endif #endif
...@@ -84,7 +84,7 @@ extern "C" BoxedFunction::BoxedFunction(CLFunction* f) ...@@ -84,7 +84,7 @@ extern "C" BoxedFunction::BoxedFunction(CLFunction* f)
// this->giveAttr("__name__", boxString(&f->source->ast->name)); // this->giveAttr("__name__", boxString(&f->source->ast->name));
this->giveAttr("__name__", boxString(f->source->getName())); this->giveAttr("__name__", boxString(f->source->getName()));
Box* modname = f->source->parent_module->getattr("__name__", NULL, NULL); Box* modname = f->source->parent_module->getattr("__name__", NULL);
this->giveAttr("__module__", modname); this->giveAttr("__module__", modname);
} }
...@@ -110,7 +110,7 @@ extern "C" BoxedFunction::BoxedFunction(CLFunction* f, std::initializer_list<Box ...@@ -110,7 +110,7 @@ extern "C" BoxedFunction::BoxedFunction(CLFunction* f, std::initializer_list<Box
// this->giveAttr("__name__", boxString(&f->source->ast->name)); // this->giveAttr("__name__", boxString(&f->source->ast->name));
this->giveAttr("__name__", boxString(f->source->getName())); this->giveAttr("__name__", boxString(f->source->getName()));
Box* modname = f->source->parent_module->getattr("__name__", NULL, NULL); Box* modname = f->source->parent_module->getattr("__name__", NULL);
this->giveAttr("__module__", modname); this->giveAttr("__module__", modname);
} }
...@@ -513,7 +513,7 @@ Box* objectNew(BoxedClass* cls, BoxedTuple* args) { ...@@ -513,7 +513,7 @@ Box* objectNew(BoxedClass* cls, BoxedTuple* args) {
if (args->elts.size() != 0) { if (args->elts.size() != 0) {
// TODO slow // TODO slow
if (typeLookup(cls, "__init__", NULL, NULL) == typeLookup(object_cls, "__init__", NULL, NULL)) if (typeLookup(cls, "__init__", NULL) == typeLookup(object_cls, "__init__", NULL))
raiseExcHelper(TypeError, "object.__new__() takes no parameters"); raiseExcHelper(TypeError, "object.__new__() takes no parameters");
} }
......
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