From d03b575c60efb465f012618db21894c6269f2088 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Wed, 12 Dec 2018 10:54:37 +0900 Subject: [PATCH] [coco/generic] Return allocated span (#2630) Now, allocate method in PlainWeightContext returns the allocated span as its return. Signed-off-by: Jonghyun Park --- contrib/coco/generic/include/coco/IR/PlainWeightContext.h | 5 ++--- contrib/coco/generic/src/IR/Data.cpp | 3 ++- contrib/coco/generic/src/IR/Data.test.cpp | 14 ++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/contrib/coco/generic/include/coco/IR/PlainWeightContext.h b/contrib/coco/generic/include/coco/IR/PlainWeightContext.h index be50c39..9f84092 100644 --- a/contrib/coco/generic/include/coco/IR/PlainWeightContext.h +++ b/contrib/coco/generic/include/coco/IR/PlainWeightContext.h @@ -43,12 +43,11 @@ template struct PlainWeightContext * @require the following code SHOULD work for any bag "b": * PlainWeightContext ctx; * - * ctx.allocate(b); - * auto span = ctx.weight(b); + * auto span = ctx.allocate(b); * assert(span.data() != nullptr); * assert(span.size() == bag->size()); */ - virtual void allocate(const Bag *) = 0; + virtual Span allocate(const Bag *) = 0; // WARN Depercated virtual void allocate(const KernelObject *) = 0; diff --git a/contrib/coco/generic/src/IR/Data.cpp b/contrib/coco/generic/src/IR/Data.cpp index 19fd23a..557666d 100644 --- a/contrib/coco/generic/src/IR/Data.cpp +++ b/contrib/coco/generic/src/IR/Data.cpp @@ -122,10 +122,11 @@ public: PlainWeightContextImpl(PlainWeightContextImpl &&) = delete; public: - void allocate(const coco::Bag *bag) override + coco::Span allocate(const coco::Bag *bag) override { assert(bag != nullptr); _blob->allocate(bag, sizeof(T)); + return weight(bag); } void allocate(const coco::KernelObject *obj) override diff --git a/contrib/coco/generic/src/IR/Data.test.cpp b/contrib/coco/generic/src/IR/Data.test.cpp index cd3bea6..6cd54b0 100644 --- a/contrib/coco/generic/src/IR/Data.test.cpp +++ b/contrib/coco/generic/src/IR/Data.test.cpp @@ -50,14 +50,16 @@ TEST(IR_DATA, allocate_and_link_bag) } // Allocate a weight space - d->f32()->allocate(bag); - - // weight(...) SHOULD return a valid for a valid bag { - auto span = d->f32()->weight(bag); + auto allocated_span = d->f32()->allocate(bag); - ASSERT_NE(span.data(), nullptr); - ASSERT_EQ(span.size(), bag->size()); + ASSERT_NE(allocated_span.data(), nullptr); + ASSERT_EQ(allocated_span.size(), bag->size()); + + auto retrieved_span = d->f32()->weight(bag); + + ASSERT_EQ(allocated_span.data(), retrieved_span.data()); + ASSERT_EQ(allocated_span.size(), retrieved_span.size()); } } -- 2.7.4