Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute static memory requirements of methods. #218

Merged
merged 5 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tools/verifier/verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ Analyze(const char* file)
{
char error[255];
AutoPtr<IPluginRuntime> rt(sEnv->APIv2()->LoadBinaryFromFile(file, error, sizeof(error)));
if (!rt)
if (!rt) {
fprintf(stdout, "Could not load .smx file: %s\n", error);
return false;
}

if (sVerbose) {
uint32_t index;
Expand Down
36 changes: 36 additions & 0 deletions vm/control-flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ enum class BlockEnd {
Jump
};

class IBlockData
{
public:
virtual ~IBlockData()
{}
};

class Block :
public ke::Refcounted<Block>,
public ke::InlineListNode<Block>
Expand Down Expand Up @@ -104,6 +111,15 @@ class Block :
return is_loop_header_;
}

template <typename T>
T* data() const {
return static_cast<T*>(data_.get());
}
void setData(IBlockData* data) {
ke::UniquePtr<IBlockData> ptr(data);
data_ = ke::Move(ptr);
}

void addTarget(Block* target);
void endWithJump(const uint8_t* cip, Block* target);
void end(const uint8_t* end_at, BlockEnd end_type);
Expand All @@ -126,6 +142,7 @@ class Block :
ControlFlowGraph& graph_;
ke::Vector<ke::RefPtr<Block>> predecessors_;
ke::Vector<ke::RefPtr<Block>> successors_;
ke::UniquePtr<IBlockData> data_;

// Note that |end| is dependent on end_type. If it's Insn, then end_ should
// be the |start| of the last instruction, since that is the terminating
Expand Down Expand Up @@ -213,6 +230,25 @@ class ControlFlowGraph : public ke::Refcounted<ControlFlowGraph>
uint32_t epoch_;
};

template <typename T>
class AutoClearBlockData
{
public:
AutoClearBlockData(ControlFlowGraph* graph)
: graph_(graph)
{
for (auto iter = graph_->rpoBegin(); iter != graph_->rpoEnd(); iter++)
iter->setData(new T());
}
~AutoClearBlockData() {
for (auto iter = graph_->rpoBegin(); iter != graph_->rpoEnd(); iter++)
iter->setData(nullptr);
}

private:
ControlFlowGraph* graph_;
};

} // namespace sp

#endif // _include_sourcepawn_vm_control_flow_h_
7 changes: 6 additions & 1 deletion vm/graph-builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,12 @@ GraphBuilder::prescan()
return error(SP_ERROR_INVALID_INSTRUCTION);
opcode_params = (ncases * 2) + 1;
} else {
opcode_params = kOpcodeSizes[op] - 1;
int opcode_size = kOpcodeSizes[op];
if (opcode_size == 0) {
// This opcode is not generated, and is therefore illegal.
return error(SP_ERROR_INVALID_INSTRUCTION);
}
opcode_params = opcode_size - 1;
}
assert(opcode_params >= 0);

Expand Down
Loading