Files
sdk/runtime/llvm_codegen/codegen/custom_zone.h
T
Martin Kustermann 4ea512b4c1 [llvm_codegen] Use exclusively SExpression support from VM and nothing else.
The LLVM code generator should only consume the serialized IR and not use any other VM functionality.
This CL adds a custom zone which can be used for the deserialized IR nodes and removes any
Dart_SetVMFlags/Dart_Initialize/ApiZone/... calls.

This works with the existing example:

    % ninja -C out/ReleaseX64 codegen
    % out/ReleaseX64/codegen runtime/llvm_codegen/test/codegen/Inputs/hello.sex
    ...
    define void @"hello.dart::main"() {

    B1:
      %0 = call i8* @llvm.stacksave()
      %1 = ptrtoint i8* %0 to i64
      %2 = load i64, i64 addrspace(256)* inttoptr (i64 72 to i64 addrspace(256)*)
      %3 = icmp ult i64 %1, %2
      br i1 %3, label %4, label %5
      ...
      ret void
    }
    ...
Change-Id: I1d07ba6bc122d100c73f97cfa961d36240489666
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/120792
Commit-Queue: Martin Kustermann <kustermann@google.com>
Auto-Submit: Martin Kustermann <kustermann@google.com>
Reviewed-by: Teagan Strickland <sstrickl@google.com>
2019-10-30 16:27:04 +00:00

53 lines
1.4 KiB
C++

// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef RUNTIME_LLVM_CODEGEN_CODEGEN_CUSTOM_ZONE_H_
#define RUNTIME_LLVM_CODEGEN_CODEGEN_CUSTOM_ZONE_H_
#include <vector>
// We use a custom zone here which doesn't depend on VM internals (e.g. handles,
// thread, ...)
#if defined(RUNTIME_VM_ZONE_H_)
#error "We want our own zone implementation"
#endif
#define RUNTIME_VM_ZONE_H_
namespace dart {
class Zone {
public:
Zone() {}
~Zone();
template <class ElementType>
inline ElementType* Alloc(intptr_t length) {
return static_cast<ElementType*>(
AllocUnsafe(sizeof(ElementType) * length));
}
template <class ElementType>
inline ElementType* Realloc(ElementType* old_array,
intptr_t old_length,
intptr_t new_length) {
void* memory = AllocUnsafe(sizeof(ElementType) * new_length);
memmove(memory, old_array, sizeof(ElementType) * old_length);
return static_cast<ElementType*>(memory);
}
template <class ElementType>
void Free(ElementType* old_array, intptr_t len) {}
void* AllocUnsafe(intptr_t size);
private:
Zone(const Zone&) = delete;
void operator=(const Zone&) = delete;
std::vector<void*> buffers_;
};
} // namespace dart
#endif // RUNTIME_LLVM_CODEGEN_CODEGEN_CUSTOM_ZONE_H_