Skip to content

Commit

Permalink
Fix: no redeclaration or re-use of types and functions (#23)
Browse files Browse the repository at this point in the history
* fix: no redeclaration of opaque qcs struct types

* fix: no redeclaration of opaque qcs function types or redundant calls

* chore: revert inkwell crate to upstream repo

* fix: remove initial test check
  • Loading branch information
Steve Manuel committed Apr 15, 2022
1 parent b6da63e commit 121101e
Show file tree
Hide file tree
Showing 8 changed files with 554 additions and 266 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ clap = { version = "3.1.6", features = ["derive"] }

[dependencies.inkwell]
version = "0.1.0"
git = "https://github.com/rigetti/inkwell"
branch = "274-instruction-to-phi"
git = "https://github.com/TheDan64/inkwell"
branch = "master"
features = ["target-x86"]

[dev-dependencies]
Expand Down
32 changes: 23 additions & 9 deletions src/context/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use inkwell::{
context::Context,
module::Module,
types::{PointerType, StructType},
AddressSpace,
};
Expand All @@ -22,6 +23,10 @@ fn build_string_type(context: &Context) -> PointerType {
context.i8_type().ptr_type(AddressSpace::Generic)
}

const TYPE_NAME_EXECUTION_RESULT: &str = "ExecutionResult";
const TYPE_NAME_EXECUTABLE: &str = "Executable";
const TYPE_NAME_EXECUTABLE_CACHE: &str = "ExecutableCache";

pub(crate) struct Types<'ctx> {
string: PointerType<'ctx>,
executable: StructType<'ctx>,
Expand All @@ -30,22 +35,31 @@ pub(crate) struct Types<'ctx> {
}

impl<'ctx> Types<'ctx> {
pub(crate) fn executable(&self) -> StructType<'ctx> {
self.executable
pub(crate) fn executable(&self, module: &Module<'ctx>) -> StructType<'ctx> {
match module.get_struct_type(TYPE_NAME_EXECUTABLE) {
Some(s) => s,
None => self.executable,
}
}

pub(crate) fn executable_cache(&self) -> StructType<'ctx> {
self.executable_cache
pub(crate) fn executable_cache(&self, module: &Module<'ctx>) -> StructType<'ctx> {
match module.get_struct_type(TYPE_NAME_EXECUTABLE_CACHE) {
Some(s) => s,
None => self.executable_cache,
}
}

pub(crate) fn execution_result(&self) -> StructType<'ctx> {
self.execution_result
pub(crate) fn execution_result(&self, module: &Module<'ctx>) -> StructType<'ctx> {
match module.get_struct_type(TYPE_NAME_EXECUTION_RESULT) {
Some(s) => s,
None => self.execution_result,
}
}

pub(crate) fn new(context: &'ctx Context) -> Self {
let execution_result = context.opaque_struct_type("ExecutionResult");
let executable = context.opaque_struct_type("Executable");
let executable_cache = context.opaque_struct_type("ExecutableCache");
let execution_result = context.opaque_struct_type(TYPE_NAME_EXECUTION_RESULT);
let executable = context.opaque_struct_type(TYPE_NAME_EXECUTABLE);
let executable_cache = context.opaque_struct_type(TYPE_NAME_EXECUTABLE_CACHE);

Self {
string: build_string_type(context),
Expand Down
Loading

0 comments on commit 121101e

Please sign in to comment.