Skip to content

Conversation

SahilPatidar
Copy link
Contributor

Reimplement value printing on top of ORC MemoryAccess. The previous
implementation only supported in-process evaluation; with this new
design it now works in both in-process and out-of-process modes.

The implementation introduces a ValueBuffer hierarchy (Builtin, Array,
Pointer) for capturing evaluated values, a ReaderDispatcher for reading
values from MemoryAccess, and a ValueToString printer for converting
buffers back to strings.

@SahilPatidar
Copy link
Contributor Author

@vgvassilev This is still a draft — some parts are not implemented yet (e.g. record and function types), but I shared it so you can see the idea and check if the approach looks feasible.

@SahilPatidar
Copy link
Contributor Author

And also I need a way to detect whether the interpreter is running in-process or out-of-process.

return Str;
case clang::BuiltinType::Short:
SS << V.getShort();
SS << B.as<short>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we have to cast the data when we know its type? If that's needed for out-of-process where the host and target architectures do not match, we should probably somehow do it in a separate facility because getX is much faster on matching architectures.

Copy link
Contributor Author

@SahilPatidar SahilPatidar Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I’m not using our existing Value, I introduced a universal buffer for built-in types (including strings).

class BuiltinValueBuffer : public ValueBuffer {
public:
  std::vector<uint8_t> raw;
 
  BuiltinValueBuffer(QualType _Ty) : ValueBuffer(K_Builtin) { Ty = _Ty; }
  
  template <typename T> T as() const {
    T v{};
    // assert(raw.size() >= sizeof(T) && "Buffer too small for type!");
    memcpy(&v, raw.data(), sizeof(T));
    return v;
  }
  static bool classof(const ValueBuffer *B) { return B->isBuiltin(); }
};

I use ValueBuffer to read memory directly into a buffer sized for the type, and at print time we cast the raw data back to the correct type.
If we use a Value-kind structure, we need to read memory, cast it, and set the value at read time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants