Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle named references in structs correctly #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{ mkDerivation, base, bytestring, directory, filepath, llvm-hs
, llvm-hs-pure, mtl, pretty-show, stdenv, tasty, tasty-golden
, tasty-hspec, tasty-hunit, text, transformers, wl-pprint-text
{ mkDerivation, array, base, bytestring, directory, filepath, lib
, llvm-hs llvm-hs-pure, mtl, prettyprinter, tasty, tasty-golden
, tasty-hspec, tasty-hunit, text, transformers
}:
mkDerivation {
pname = "llvm-hs-pretty";
version = "0.1.0.0";
src = ./.;
libraryHaskellDepends = [
base bytestring llvm-hs-pure text wl-pprint-text
array base bytestring llvm-hs-pure text prettyprinter
];
testHaskellDepends = [
base directory filepath llvm-hs llvm-hs-pure mtl pretty-show tasty
base directory filepath llvm-hs llvm-hs-pure mtl tasty
tasty-golden tasty-hspec tasty-hunit text transformers
];
doHaddock = false;
doCheck = false;
doCheck = true;
homepage = "https://github.com/llvm-hs/llvm-hs-pretty";
description = "Pretty printer for LLVM IR";
license = stdenv.lib.licenses.mit;
license = lib.licenses.mit;
}
16 changes: 9 additions & 7 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ let
default_nixpkgs = (import <nixpkgs> {}).fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
rev = "68cc97d306d3187c142cfb2378852f28d47bc098";
sha256 = "07zxbk4g4d51hf7dhsj6h7jy5c2iccm2lwaashj36inkhh9lrqa3";
rev = "a7ecde854aee5c4c7cd6177f54a99d2c1ff28a31"; # 21.11
sha256 = "162dywda2dvfj1248afxc45kcrg83appjd0nmdb541hl7rnncf02";
};
in

{ nixpkgs ? default_nixpkgs }:
{ nixpkgs ? default_nixpkgs, llvm_hs_deps_from_source ? false }:

let

Expand All @@ -16,23 +16,23 @@ let
llvm-hs-repo = orig_pkgs.fetchFromGitHub {
owner = "llvm-hs";
repo = "llvm-hs";
rev = "76cd4d5107862401a7ebbe1bb9cc1cf172fa1d66";
sha256 = "0bnh0yyjflhvc8vjrqsa25k7issnvkvgx149bnq7avka5mx2m99m";
rev = "442bc488c39f0264930c95e2c98b5cf055d53e8e";
sha256 = "1xdxy9gcgs8y32hvvmx2bl9i3h6z967v77g4yp3blqwc2kmbrpg8";
};

hsOverlay = self: super: {
haskellPackages = super.haskellPackages.override {
overrides = self': super': {
llvm-hs-pure = super'.callPackage (import "${llvm-hs-repo}/llvm-hs-pure") {};
llvm-hs = super'.callPackage (import "${llvm-hs-repo}/llvm-hs") {
llvm-config = self.llvm_4;
llvm-config = self.llvm_9;
};
llvm-hs-pretty = super'.callPackage ./. {};
};
};
};

pkgs = import orig_pkgs.path { overlays = [ hsOverlay ]; };
pkgs = import orig_pkgs.path { overlays = if llvm_hs_deps_from_source then [ hsOverlay ] else []; };

env =
let
Expand All @@ -44,6 +44,8 @@ let
allDependencies =
let inherit (pkgs.haskellPackages) llvm-hs-pretty; in
builtins.concatLists [
llvm-hs-pretty.buildInputs
llvm-hs-pretty.propagatedBuildInputs
llvm-hs-pretty.nativeBuildInputs
llvm-hs-pretty.propagatedNativeBuildInputs
]
Expand Down
4 changes: 3 additions & 1 deletion src/LLVM/Pretty/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ instance Typed C.Constant where
typeOf (C.Float t) = typeOf t
typeOf (C.Null t) = t
typeOf (C.AggregateZero t) = t
typeOf (C.Struct {..}) = StructureType isPacked (map typeOf memberValues)
typeOf (C.Struct {..}) = case structName of
Just name -> NamedTypeReference name
Nothing -> StructureType isPacked (map typeOf memberValues)
typeOf (C.Array {..}) = ArrayType (fromIntegral $ length memberValues) memberType
typeOf (C.Vector {..}) = VectorType (fromIntegral $ length memberValues) $
case memberValues of
Expand Down
6 changes: 6 additions & 0 deletions tests/input/named-struct.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; ModuleID = 'simple module'

%struct.coord2d = type {i32, i32}
%struct.vector = type {%struct.coord2d, %struct.coord2d}

@up = global %struct.vector {%struct.coord2d {i32 0, i32 0}, %struct.coord2d {i32 0, i32 1}}