Skip to content

Commit

Permalink
Tweaks and fixes while bringing (back) up vsc-solvers
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
  • Loading branch information
mballance committed Mar 8, 2024
1 parent 8a73a9c commit e1908b9
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 8 deletions.
20 changes: 20 additions & 0 deletions python/vsc_dm/pkginfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
import ivpm

class PkgInfo(ivpm.PkgInfo):

def __init__(self):
pkgdir = os.path.dirname(os.path.abspath(__file__))
projdir = os.path.dirname(os.path.dirname(pkgdir))
super().__init__("vsc-dm", os.path.dirname(pkgdir))

if os.path.isdir(os.path.join(projdir, "src")):
self._incdirs = [os.path.join(projdir, "src", "include")]
self._libdirs = [
os.path.join(projdir, "build", "lib"),
os.path.join(projdir, "build", "lib64")]
else:
self._incdirs = [os.path.join(pkgdir, "share", "include")]
self._libdirs = [os.path.join(pkgdir)]

self._libs = ["vsc-dm"]
8 changes: 8 additions & 0 deletions src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include "TypeExprRangelist.h"
#include "TypeExprRef.h"
#include "TypeExprRefBottomUp.h"
#include "TypeExprRefPath.h"
#include "TypeExprRefTopDown.h"
#include "TypeExprSubField.h"
#include "TypeExprVal.h"
Expand Down Expand Up @@ -767,6 +768,13 @@ ITypeExprRefBottomUp *Context::mkTypeExprRefBottomUp(
return new TypeExprRefBottomUp(scope_offset, field_index);
}

ITypeExprRefPath *Context::mkTypeExprRefPath(
ITypeExpr *root,
bool owned,
const std::vector<int32_t> &path) {
return new TypeExprRefPath(root, owned, path);
}

ITypeExprRefTopDown *Context::mkTypeExprRefTopDown() {
return new TypeExprRefTopDown();
}
Expand Down
5 changes: 5 additions & 0 deletions src/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ class Context : public IContext {
int32_t scope_offset,
int32_t field_index) override;

virtual ITypeExprRefPath *mkTypeExprRefPath(
ITypeExpr *root,
bool owned,
const std::vector<int32_t> &path) override;

virtual ITypeExprRefTopDown *mkTypeExprRefTopDown() override;

virtual ITypeExprSubField *mkTypeExprSubField(
Expand Down
41 changes: 41 additions & 0 deletions src/TypeExprRefPath.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* TypeExprRefPath.cpp
*
* Copyright 2023 Matthew Ballance and Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Created on:
* Author:
*/
#include "TypeExprRefPath.h"


namespace vsc {
namespace dm {


TypeExprRefPath::TypeExprRefPath(
ITypeExpr *root,
bool owned,
const std::vector<int32_t> &path) : TypeExprRef(root, owned),
m_path(path.begin(), path.end()) {

}

TypeExprRefPath::~TypeExprRefPath() {

}

}
}
56 changes: 56 additions & 0 deletions src/TypeExprRefPath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* TypeExprRefPath.h
*
* Copyright 2023 Matthew Ballance and Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Created on:
* Author:
*/
#pragma once
#include "vsc/dm/ITypeExprRefPath.h"
#include "TypeExprRef.h"

namespace vsc {
namespace dm {



class TypeExprRefPath :
public virtual ITypeExprRefPath,
public virtual TypeExprRef {
public:
TypeExprRefPath(
ITypeExpr *root,
bool owned,
const std::vector<int32_t> &path);

virtual ~TypeExprRefPath();

virtual const std::vector<int32_t> &getPath() const override {
return m_path;
}

virtual void accept(IVisitor *v) override {
v->visitTypeExprRefPath(this);
}

private:
std::vector<int32_t> m_path;
};

}
}


6 changes: 6 additions & 0 deletions src/include/vsc/dm/IContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "vsc/dm/ITypeExprRangelist.h"
#include "vsc/dm/ITypeExprRef.h"
#include "vsc/dm/ITypeExprRefBottomUp.h"
#include "vsc/dm/ITypeExprRefPath.h"
#include "vsc/dm/ITypeExprRefTopDown.h"
#include "vsc/dm/ITypeExprSubField.h"
#include "vsc/dm/ITypeExprUnary.h"
Expand Down Expand Up @@ -356,6 +357,11 @@ class IContext : public virtual IValAlloc {
int32_t scope_offset,
int32_t field_index) = 0;

virtual ITypeExprRefPath *mkTypeExprRefPath(
ITypeExpr *root,
bool owned,
const std::vector<int32_t> &path) = 0;

virtual ITypeExprRefTopDown *mkTypeExprRefTopDown() = 0;

virtual ITypeExprSubField *mkTypeExprSubField(
Expand Down
41 changes: 41 additions & 0 deletions src/include/vsc/dm/ITypeExprRefPath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* ITypeExprRefPath.h
*
* Copyright 2023 Matthew Ballance and Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Created on:
* Author:
*/
#pragma once
#include <vector>
#include "vsc/dm/ITypeExprRef.h"

namespace vsc {
namespace dm {


class ITypeExprRefPath : public virtual ITypeExprRef {
public:

virtual ~ITypeExprRefPath() { }

virtual const std::vector<int32_t> &getPath() const = 0;

};

} /* namespace dm */
} /* namespace vsc */


3 changes: 3 additions & 0 deletions src/include/vsc/dm/IVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class ITypeExprRange;
class ITypeExprRangelist;
class ITypeExprRef;
class ITypeExprRefBottomUp;
class ITypeExprRefPath;
class ITypeExprRefTopDown;
class ITypeExprSubField;
class ITypeExprUnary;
Expand Down Expand Up @@ -240,6 +241,8 @@ class IVisitor {

virtual void visitTypeExprRefBottomUp(ITypeExprRefBottomUp *e) = 0;

virtual void visitTypeExprRefPath(ITypeExprRefPath *e) = 0;

virtual void visitTypeExprRefTopDown(ITypeExprRefTopDown *e) = 0;

virtual void visitTypeExprSubField(ITypeExprSubField *e) = 0;
Expand Down
7 changes: 7 additions & 0 deletions src/include/vsc/dm/impl/ContextDelegator.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ class ContextDelegator : public virtual vsc::dm::IContext {
return m_ctxt->mkTypeExprRefBottomUp(scope_offset, field_index);
}

virtual ITypeExprRefPath *mkTypeExprRefPath(
ITypeExpr *target,
bool owned,
const std::vector<int32_t> &path) override {
return m_ctxt->mkTypeExprRefPath(target, owned, path);
}

virtual ITypeExprRefTopDown *mkTypeExprRefTopDown() {
return m_ctxt->mkTypeExprRefTopDown();
}
Expand Down
18 changes: 10 additions & 8 deletions src/include/vsc/dm/impl/ValRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ class ValRef {
// return type()->copyVal(*this);
}

ValRef toMutable() const {
ValRef toMutable(bool move=false) const {
Flags flags = (move)?m_flags:VALREF_CLRFLAG(m_flags, Flags::Owned);
// We want
if (VALREF_FLAGSET(m_flags, Flags::Mutable)) {
if (VALREF_FLAGSET(flags, Flags::Mutable)) {
// This value is already mutable
// It might be a value with locally-held storage (eg simple int).
// It might be a reference to a field within an aggregate. If it
Expand All @@ -171,7 +172,7 @@ class ValRef {

// Either way, the referent will not hold ownership of any
// allocated storage
Flags flags = VALREF_CLRFLAG(m_flags, Flags::Owned);
flags = VALREF_CLRFLAG(flags, Flags::Owned);

// A mutable ref must change its source. In order for that
// to happen, we need to convert a non-pointer reference
Expand All @@ -181,13 +182,13 @@ class ValRef {
// pointer semantics

uintptr_t vp = m_vp;
if (VALREF_FLAGSET(m_flags, Flags::Scalar) && !VALREF_FLAGSET(m_flags, Flags::IsPtr)) {
if (VALREF_FLAGSET(flags, Flags::Scalar) && !VALREF_FLAGSET(flags, Flags::IsPtr)) {
VALREF_DEBUG(stdout, "Transform to pointer\n");
vp = reinterpret_cast<uintptr_t>(&m_vp);
flags = VALREF_SETFLAG(flags, Flags::IsPtr);
}

return (VALREF_FLAGSET(m_flags, Flags::HasField))?
return (VALREF_FLAGSET(flags, Flags::HasField))?
ValRef(vp, m_type_field.m_field, flags):ValRef(vp, m_type_field.m_type, flags);
} else {
// TODO: maybe this is just a failure?
Expand All @@ -201,13 +202,14 @@ class ValRef {
}
}

ValRef toImmutable() const {
ValRef toImmutable(bool move=false) const {
Flags flags = (move)?m_flags:VALREF_CLRFLAG(m_flags, Flags::Owned);
if (VALREF_FLAGSET(m_flags, Flags::HasField)) {
return ValRef(m_vp, m_type_field.m_field,
VALREF_CLRFLAG(m_flags, Flags::Mutable));
VALREF_CLRFLAG(flags, Flags::Mutable));
} else {
return ValRef(m_vp, m_type_field.m_type,
VALREF_CLRFLAG(m_flags, Flags::Mutable));
VALREF_CLRFLAG(flags, Flags::Mutable));
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/include/vsc/dm/impl/VisitorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include "vsc/dm/ITypeExprRangelist.h"
#include "vsc/dm/ITypeExprRef.h"
#include "vsc/dm/ITypeExprRefBottomUp.h"
#include "vsc/dm/ITypeExprRefPath.h"
#include "vsc/dm/ITypeExprRefTopDown.h"
#include "vsc/dm/ITypeExprSubField.h"
#include "vsc/dm/ITypeExprUnary.h"
Expand Down Expand Up @@ -400,6 +401,8 @@ class VisitorBase : public virtual IVisitor {

virtual void visitTypeExprRefBottomUp(ITypeExprRefBottomUp *e) override { }

virtual void visitTypeExprRefPath(ITypeExprRefPath *e) override { }

virtual void visitTypeExprRefTopDown(ITypeExprRefTopDown *e) override { }

virtual void visitTypeExprSubField(ITypeExprSubField *e) override {
Expand Down

0 comments on commit e1908b9

Please sign in to comment.