Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 3efb72b

Browse files
authored
Added some C APIs for llvm Jit compilation (#847)
1 parent 0fda677 commit 3efb72b

File tree

6 files changed

+67
-10
lines changed

6 files changed

+67
-10
lines changed

src/Qir/Runtime/lib/QIR/context.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <cassert>
55

66
#include "QirContext.hpp"
7+
#include "QirContext.h"
78

89
#include "CoreTypes.hpp"
910
#include "QirRuntimeApi_I.hpp"
@@ -25,6 +26,11 @@ namespace Quantum
2526
g_context = std::make_unique<QirExecutionContext>(driver, trackAllocatedObjects);
2627
}
2728

29+
extern "C" void InitializeQirContext(void* driver, bool trackAllocatedObjects)
30+
{
31+
InitializeQirContext((IRuntimeDriver*)driver, trackAllocatedObjects);
32+
}
33+
2834
void ReleaseQirContext()
2935
{
3036
assert(g_context != nullptr);

src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "QirRuntimeApi_I.hpp"
2929
#include "QSharpSimApi_I.hpp"
3030
#include "SimFactory.hpp"
31+
#include "SimFactory.h"
3132
#include "OutputStream.hpp"
3233
#include "QubitManager.hpp"
3334

@@ -646,5 +647,11 @@ namespace Quantum
646647
{
647648
return std::make_unique<CFullstateSimulator>(userProvidedSeed);
648649
}
650+
651+
extern "C" void* CreateFullstateSimulatorC(uint32_t userProvidedSeed)
652+
{
653+
return (IRuntimeDriver*)new CFullstateSimulator(userProvidedSeed);
654+
}
655+
649656
} // namespace Quantum
650657
} // namespace Microsoft
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef COREDEFINES_H
2+
#define COREDEFINES_H
3+
4+
#ifdef _WIN32
5+
#ifdef EXPORT_QIR_API
6+
#define QIR_SHARED_API __declspec(dllexport)
7+
#else
8+
#define QIR_SHARED_API __declspec(dllimport)
9+
#endif
10+
#else
11+
#define QIR_SHARED_API
12+
#endif
13+
14+
#endif // #ifndef COREDEFINES_H

src/Qir/Runtime/public/CoreTypes.hpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,7 @@
44
#pragma once
55

66
#include <cstdint>
7-
8-
#ifdef _WIN32
9-
#ifdef EXPORT_QIR_API
10-
#define QIR_SHARED_API __declspec(dllexport)
11-
#else
12-
#define QIR_SHARED_API __declspec(dllimport)
13-
#endif
14-
#else
15-
#define QIR_SHARED_API
16-
#endif
7+
#include "CoreDefines.h"
178

189
// The core types will be exposed in the C-interfaces for interop, thus no
1910
// namespaces or scoped enums can be used to define them.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef QIRCONTEXT_H
2+
#define QIRCONTEXT_H
3+
4+
#include <stdbool.h>
5+
#include "CoreDefines.h"
6+
7+
#ifdef __cplusplus
8+
extern "C"
9+
{
10+
#endif
11+
12+
QIR_SHARED_API void InitializeQirContext(void* driver, bool trackAllocatedObjects);
13+
14+
#ifdef __cplusplus
15+
} // extern "C"
16+
#endif
17+
18+
#endif // #ifndef QIRCONTEXT_H
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
#ifndef SIMFACTORY_H
5+
#define SIMFACTORY_H
6+
7+
#include <stdint.h>
8+
#include "CoreDefines.h"
9+
10+
#ifdef __cplusplus
11+
extern "C"
12+
{
13+
#endif
14+
15+
QIR_SHARED_API void* CreateFullstateSimulatorC(uint32_t userProvidedSeed);
16+
17+
#ifdef __cplusplus
18+
} // extern "C"
19+
#endif
20+
21+
#endif // #ifndef SIMFACTORY_H

0 commit comments

Comments
 (0)