From 2fd4aed3ebb222af1a2bfb46578aa5be23f8f497 Mon Sep 17 00:00:00 2001 From: Gavrilikhin Daniil Date: Sun, 19 May 2024 16:23:45 +0800 Subject: [PATCH] Small improvements (#178) * Revert last 4 arc commits (#179) * Revert "Basic arc classes (breaks Array, MemoryAddress, References) (#177)" This reverts commit 6593940894f6b2ff1c6eb21f5b0bd97a7d999c4d. * Revert "Make string to be arc (#176)" This reverts commit e3a2298ce876e13f41ed0e3699169423eacc629a. * Revert "Make rational to be arc (#175)" This reverts commit 8c52c17b411f36b85567f80143e66567a6610409. * Revert "Pass by ref for integer (#174)" This reverts commit 584df805736d20fc7e119e1546cd695327b40b8c. * Small improvements --- README.md | 1 + ppl/src/core.ppl | 22 +- src/hir/declarations/types.rs | 10 +- src/ir/to_ir.rs | 52 +- src/ir/types.rs | 22 +- src/runtime/src/assert.rs | 2 +- src/runtime/src/integer.rs | 28 +- src/runtime/src/memory.rs | 18 - src/runtime/src/rational.rs | 23 +- src/runtime/src/string.rs | 23 +- src/semantics/to_hir.rs | 95 +-- .../snapshots/ppl__tests__address_of.hir.snap | 2 +- .../snapshots/ppl__tests__address_of.ir.snap | 240 ++++++-- .../snapshots/ppl__tests__array.hir.snap | 108 ++-- ...pl__tests__candidate_not_viable.error.snap | 48 +- src/tests/snapshots/ppl__tests__clone.ir.snap | 207 +++++-- .../ppl__tests__common_functions.ir.snap | 126 +++- .../ppl__tests__consume_greater.ir.snap | 119 +++- src/tests/snapshots/ppl__tests__deps.ir.snap | 111 +++- .../ppl__tests__deref_member_ref.ir.snap | 194 ++++-- .../snapshots/ppl__tests__destructor.ir.snap | 168 ++++-- .../ppl__tests__empty_constructor.hir.snap | 8 +- .../ppl__tests__empty_constructor.ir.snap | 231 +++++-- .../snapshots/ppl__tests__escaped_id.ir.snap | 134 +++- .../snapshots/ppl__tests__generics.ir.snap | 289 ++++++--- .../snapshots/ppl__tests__import_all.ir.snap | 140 ++++- .../snapshots/ppl__tests__integer.hir.snap | 2 +- .../snapshots/ppl__tests__integer.ir.snap | 250 +++++--- .../snapshots/ppl__tests__memory.hir.snap | 12 +- .../snapshots/ppl__tests__memory.ir.snap | 318 ++++++---- .../ppl__tests__monomorphize.ir.snap | 189 ++++-- ...l__tests__monomorphize_predeclared.ir.snap | 141 ++++- .../snapshots/ppl__tests__multifile.ir.snap | 114 +++- .../snapshots/ppl__tests__plus_assign.ir.snap | 221 ++++--- src/tests/snapshots/ppl__tests__ppl.ir.snap | 109 +++- .../ppl__tests__predeclare_function.ir.snap | 194 ++++-- .../ppl__tests__predeclare_vars.ir.snap | 202 +++++-- .../snapshots/ppl__tests__rational.ir.snap | 449 ++++++++------ .../ppl__tests__reference_mut.hir.snap | 4 +- .../ppl__tests__reference_mut.ir.snap | 207 +++++-- .../ppl__tests__reference_to_literal.ir.snap | 159 ++++- .../ppl__tests__reference_to_none.ir.snap | 134 +++- .../snapshots/ppl__tests__references.hir.snap | 8 +- .../snapshots/ppl__tests__references.ir.snap | 283 +++++---- .../snapshots/ppl__tests__references.run.snap | 25 +- src/tests/snapshots/ppl__tests__star.ir.snap | 140 ++++- .../snapshots/ppl__tests__string.hir.snap | 12 +- .../snapshots/ppl__tests__string.ir.snap | 303 +++++++--- .../snapshots/ppl__tests__supertraits.ir.snap | 159 ++++- .../ppl__tests__trait_with_ref.ir.snap | 163 +++-- .../snapshots/ppl__tests__traits.ir.snap | 178 ++++-- .../ppl__tests__type_as_value.hir.snap | 40 +- .../ppl__tests__type_as_value.ir.snap | 571 ++++++++++-------- .../snapshots/ppl__tests__type_of.hir.snap | 8 +- .../snapshots/ppl__tests__type_of.ir.snap | 229 +++++-- 55 files changed, 5153 insertions(+), 2092 deletions(-) diff --git a/README.md b/README.md index f636191c..f5ebd608 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ ### Current task * [ ] Printable trait should take references --- +* [ ] migrate to pass-by-ref (branch `arc`) * [ ] Prefer candidates with mutable references, when possible * [ ] Fix problems with to_ir and loading references (especially globals). This causes issues in iterator * [ ] Benchmark for linear algebra diff --git a/ppl/src/core.ppl b/ppl/src/core.ppl index 0266c046..5259afd0 100644 --- a/ppl/src/core.ppl +++ b/ppl/src/core.ppl @@ -71,9 +71,13 @@ fn String from -> String: //================================= // Integer //================================= +type IntegerImpl + @builtin -type Integer +type Integer: + impl: Reference +@builtin fn default <:Type> => 0 @mangle_as("integer_eq_integer") @@ -115,18 +119,21 @@ fn % -> Integer @mangle_as("integer_as_string") fn String from <:Integer> -> String -@mangle_as("clone_integer") -fn clone <:&Integer> -> Integer - @mangle_as("destroy_integer") fn destroy <:&mut Integer> + +@mangle_as("clone_integer") +fn clone <:&Integer> -> Integer //--------------------------------- //================================= // Rational //================================= +type RationalImpl + @builtin -type Rational +type Rational: + impl: Reference fn default <:Type> => 0.0 @@ -167,8 +174,11 @@ fn clone <:&Rational> -> Rational //================================= // String //================================= +type StringImpl + @builtin -type String +type String: + impl: Reference fn default <:Type> => "" diff --git a/src/hir/declarations/types.rs b/src/hir/declarations/types.rs index 9fdf9b38..d154d7c6 100644 --- a/src/hir/declarations/types.rs +++ b/src/hir/declarations/types.rs @@ -402,7 +402,15 @@ impl ClassData { if let Some(builtin) = &self.builtin { return builtin.size_in_bytes(); } - return POINTER_SIZE; + + if self.is_opaque() { + return POINTER_SIZE; + } + + self.members + .iter() + .map(|m| m.ty().size_in_bytes()) + .sum::() } } diff --git a/src/ir/to_ir.rs b/src/ir/to_ir.rs index 5fe76893..cd0e9c46 100644 --- a/src/ir/to_ir.rs +++ b/src/ir/to_ir.rs @@ -247,16 +247,24 @@ impl<'llvm, C: Context<'llvm>> ToIR<'llvm, C> for ClassData { return context.types().f64().into(); } - if self.is_any_reference() { + if self.members.is_empty() { return context.types().opaque(&self.basename).into(); } - let field_types = self - .members - .iter() - .filter_map(|m| m.ty().to_ir(context).try_into_basic_type().ok()) - .collect::>(); - context.types().arc(&self.name(), &field_types).into() + if let Some(ty) = context.llvm().get_struct_type(&self.name()) { + return ty.into(); + } + + let ty = context.llvm().opaque_struct_type(&self.name()); + ty.set_body( + self.members + .iter() + .filter_map(|m| m.ty().to_ir(context).try_into_basic_type().ok()) + .collect::>() + .as_slice(), + false, + ); + ty.into() } } @@ -559,30 +567,12 @@ impl<'llvm, 'm> ToIR<'llvm, FunctionContext<'llvm, 'm, '_>> for Constructor { .try_into_basic_type() .expect("non-basic type constructor"); let alloca = context.builder.build_alloca(ty, "").unwrap(); - - let ptr = context.builder.build_struct_gep(ty, alloca, 0, "").unwrap(); - let data_ty = context - .types() - .arc_data(&self.ty.referenced_type.name()) - .unwrap(); - let arc = context - .builder - .build_call( - context.functions().create_arc(), - &[data_ty.size_of().unwrap().into()], - "", - ) - .unwrap() - .try_as_basic_value() - .left() - .unwrap(); - context.builder.build_store(ptr, arc).unwrap(); for init in self.initializers.iter().filter(|i| !i.value.ty().is_none()) { let field = context .builder .build_struct_gep( - data_ty, - ptr, + ty, + alloca, init.index as u32, format!("{}.{}", self.ty.referenced_type.name(), init.member.name()).as_str(), ) @@ -618,16 +608,10 @@ impl<'llvm, 'm> HIRExpressionLoweringWithoutLoad<'llvm, 'm> for MemberReference let base = base.unwrap().into_pointer_value(); let ty = self.base.ty().to_ir(context).try_into_basic_type().unwrap(); - let ptr = context - .builder - .build_struct_gep(ty, base, 0, "") - .unwrap() - .into(); - let data_ty = context.types().arc_data(&self.base.ty().name()).unwrap(); Some( context .builder - .build_struct_gep(data_ty, ptr, self.index as u32, &self.member.name()) + .build_struct_gep(ty, base, self.index as u32, &self.member.name()) .unwrap() .into(), ) diff --git a/src/ir/types.rs b/src/ir/types.rs index 22e3bfed..0d562dd0 100644 --- a/src/ir/types.rs +++ b/src/ir/types.rs @@ -1,6 +1,6 @@ use inkwell::{ context::ContextRef, - types::{BasicTypeEnum, FloatType, IntType, PointerType, StructType, VoidType}, + types::{FloatType, IntType, PointerType, StructType, VoidType}, AddressSpace, }; @@ -71,26 +71,16 @@ impl<'llvm> Types<'llvm> { } /// Get wrapper around pointer to opaque impl - pub fn arc(&self, name: &str, field_types: &[BasicTypeEnum<'llvm>]) -> StructType<'llvm> { + fn with_impl(&self, name: &str) -> StructType<'llvm> { if let Some(ty) = self.llvm.get_struct_type(name) { return ty; } - let data_ty = self.llvm.opaque_struct_type(&format!("{name}Impl")); - if !field_types.is_empty() { - data_ty.set_body(field_types, false); - } - let ty = self.llvm.opaque_struct_type(name); - ty.set_body(&[self.pointer().into()], false); + ty.set_body(&[self.opaque(&format!("{name}Impl")).into()], false); ty } - /// Get LLVM struct type for data of ARC type - pub fn arc_data(&self, name: &str) -> Option> { - self.llvm.get_struct_type(&format!("{name}Impl")) - } - /// LLVM IR for [`Class`](Type::Class) type pub fn opaque(&self, name: &str) -> PointerType<'llvm> { self.get_or_add_opaque_struct(name); @@ -104,17 +94,17 @@ impl<'llvm> Types<'llvm> { /// LLVM IR for [`Integer`](Type::Integer) type pub fn integer(&self) -> StructType<'llvm> { - self.arc("Integer", &[]) + self.with_impl("Integer") } /// LLVM IR for `Rational` type pub fn rational(&self) -> StructType<'llvm> { - self.arc("Rational", &[]) + self.with_impl("Rational") } /// LLVM IR for [`String`](Type::String) type pub fn string(&self) -> StructType<'llvm> { - self.arc("String", &[]) + self.with_impl("String") } /// LLVM IR for C string type diff --git a/src/runtime/src/assert.rs b/src/runtime/src/assert.rs index 2993e59f..b20e7bd9 100644 --- a/src/runtime/src/assert.rs +++ b/src/runtime/src/assert.rs @@ -7,7 +7,7 @@ use crate::String; /// ``` #[no_mangle] pub extern "C" fn assert(condition: bool, message: &String) { - let message = message.as_ref(); + let message = unsafe { message.data.as_ref().unwrap() }; if !condition { println!("Assertion failed: {message}"); } diff --git a/src/runtime/src/integer.rs b/src/runtime/src/integer.rs index 2666a970..1de54acd 100644 --- a/src/runtime/src/integer.rs +++ b/src/runtime/src/integer.rs @@ -2,38 +2,40 @@ use std::ffi::c_char; use rug::ops::Pow; -use crate::{decrement_strong_count, increment_strong_count, Rational, String}; - -use std::sync::Arc; +use crate::{Rational, String}; /// Big integer number. /// Wrapper around pointer to [`rug::Integer`]. /// /// # PPL /// ```no_run +/// type IntegerImpl +/// /// @builtin -/// type Integer +/// type Integer: +/// impl: Reference /// ``` #[repr(C)] -pub struct Integer(pub *const rug::Integer); +pub struct Integer { + pub data: *mut rug::Integer, +} impl Clone for Integer { fn clone(&self) -> Self { - increment_strong_count(self.0 as *const _); - Self(self.0) + self.as_ref().into() } } impl Drop for Integer { fn drop(&mut self) { - decrement_strong_count(self.0 as *const _); + let _ = unsafe { Box::from_raw(self.data) }; } } impl Integer { /// Get the inner value pub fn as_ref(&self) -> &rug::Integer { - unsafe { &*self.0 } + unsafe { &*self.data } } } @@ -42,8 +44,10 @@ where rug::Integer: From, { fn from(x: T) -> Self { - let this = Arc::new(rug::Integer::from(x)); - Self(Arc::into_raw(this)) + let this = Box::new(rug::Integer::from(x)); + Self { + data: Box::into_raw(this), + } } } @@ -215,7 +219,7 @@ pub extern "C" fn integer_mod_integer(x: Integer, y: Integer) -> Integer { /// ``` #[no_mangle] pub extern "C" fn destroy_integer(x: &mut Integer) { - decrement_strong_count(x.0 as *const _); + let _ = unsafe { Box::from_raw(x.data) }; } /// # PPL diff --git a/src/runtime/src/memory.rs b/src/runtime/src/memory.rs index 879a41d0..27354894 100644 --- a/src/runtime/src/memory.rs +++ b/src/runtime/src/memory.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use libc::{c_void, malloc, memcpy, size_t}; use crate::{integer_from_i64, integer_from_u64, Integer, String, Type}; @@ -108,19 +106,3 @@ pub extern "C" fn copy_bytes(n: &Integer, src: &MemoryAddress, dst: &MemoryAddre let n = n.as_ref().to_usize().unwrap() as size_t; unsafe { memcpy(dest, src, n) }; } - -#[no_mangle] -pub extern "C" fn create_arc(bytes: usize) -> *const c_void { - let bytes = unsafe { Arc::<[u8]>::new_zeroed_slice(bytes).assume_init() }; - Arc::into_raw(bytes) as *const c_void -} - -#[no_mangle] -pub extern "C" fn increment_strong_count(ptr: *const c_void) { - unsafe { Arc::increment_strong_count(ptr) } -} - -#[no_mangle] -pub extern "C" fn decrement_strong_count(ptr: *const c_void) { - unsafe { Arc::decrement_strong_count(ptr) } -} diff --git a/src/runtime/src/rational.rs b/src/runtime/src/rational.rs index 1d8f6d49..6a8b4eba 100644 --- a/src/runtime/src/rational.rs +++ b/src/runtime/src/rational.rs @@ -1,8 +1,8 @@ -use std::{ffi::c_char, sync::Arc}; +use std::ffi::c_char; use rug::{ops::Pow, Integer}; -use crate::{decrement_strong_count, increment_strong_count, String}; +use crate::String; /// Rational number. /// Wrapper around pointer to [`rug::Rational`]. @@ -16,25 +16,26 @@ use crate::{decrement_strong_count, increment_strong_count, String}; /// impl: Reference /// ``` #[repr(C)] -pub struct Rational(pub *const rug::Rational); +pub struct Rational { + pub data: *mut rug::Rational, +} impl Clone for Rational { fn clone(&self) -> Self { - increment_strong_count(self.0 as *const _); - Self(self.0) + self.as_ref().into() } } impl Drop for Rational { fn drop(&mut self) { - decrement_strong_count(self.0 as *const _); + let _ = unsafe { Box::from_raw(self.data) }; } } impl Rational { /// Get the inner value pub fn as_ref(&self) -> &rug::Rational { - unsafe { &*self.0 } + unsafe { &*self.data } } } @@ -43,8 +44,10 @@ where rug::Rational: From, { fn from(x: T) -> Self { - let this = Arc::new(rug::Rational::from(x)); - Self(Arc::into_raw(this)) + let this = Box::new(rug::Rational::from(x)); + Self { + data: Box::into_raw(this), + } } } @@ -156,7 +159,7 @@ pub extern "C" fn rational_less_rational(x: Rational, y: Rational) -> bool { /// ``` #[no_mangle] pub extern "C" fn destroy_rational(x: &mut Rational) { - decrement_strong_count(x.0 as *const _); + let _ = unsafe { Box::from_raw(x.data) }; } /// # PPL diff --git a/src/runtime/src/string.rs b/src/runtime/src/string.rs index d4c67fb0..ca93fce3 100644 --- a/src/runtime/src/string.rs +++ b/src/runtime/src/string.rs @@ -1,6 +1,4 @@ -use std::{ffi::c_char, io::Write, sync::Arc}; - -use crate::{decrement_strong_count, increment_strong_count}; +use std::{ffi::c_char, io::Write}; /// PPL's String type. /// Wrapper around pointer to [`std::string::String`]. @@ -14,25 +12,26 @@ use crate::{decrement_strong_count, increment_strong_count}; /// impl: Reference /// ``` #[repr(C)] -pub struct String(pub *const std::string::String); +pub struct String { + pub data: *mut std::string::String, +} impl Clone for String { fn clone(&self) -> Self { - increment_strong_count(self.0 as *const _); - Self(self.0) + self.as_ref().into() } } impl Drop for String { fn drop(&mut self) { - decrement_strong_count(self.0 as *const _); + let _ = unsafe { Box::from_raw(self.data) }; } } impl String { /// Get the inner value pub fn as_ref(&self) -> &std::string::String { - unsafe { &*self.0 } + unsafe { &*self.data } } } @@ -41,8 +40,10 @@ where std::string::String: From, { fn from(x: T) -> Self { - let this = Arc::new(std::string::String::from(x)); - Self(Arc::into_raw(this)) + let this = Box::new(std::string::String::from(x)); + Self { + data: Box::into_raw(this), + } } } @@ -89,7 +90,7 @@ pub extern "C" fn print_string(str: String) { /// ``` #[no_mangle] pub extern "C" fn destroy_string(x: &mut String) { - decrement_strong_count(x.0 as *const _); + let _ = unsafe { Box::from_raw(x.data) }; } /// # PPL diff --git a/src/semantics/to_hir.rs b/src/semantics/to_hir.rs index fee26e9d..d0a9105d 100644 --- a/src/semantics/to_hir.rs +++ b/src/semantics/to_hir.rs @@ -10,19 +10,20 @@ use crate::compilation::Compiler; use crate::from_decimal::FromDecimal; use crate::hir::{ self, FunctionNamePart, Generic, GenericType, Member, ModuleData, Parameter, Specialize, Type, - TypeReference, Typed, + TypeReference, Typed, Variable, VariableData, }; -use crate::mutability::Mutable; +use crate::mutability::{Mutability, Mutable}; use crate::named::Named; use crate::semantics::clone::Clonner; use crate::semantics::{ InsertDestructors, ParameterNamer, TemporariesInserter, TraitFunctionsLinker, }; -use crate::syntax::Ranged; +use crate::syntax::{Identifier, Keyword, Ranged}; use crate::{AddSourceLocation, ErrVec, SourceLocation, WithSourceLocation}; use super::{ - error::*, Context, Convert, ConvertibleTo, Declare, GenericContext, Implicit, ModuleContext, + error::*, AddDeclaration, Context, Convert, ConvertibleTo, Declare, FindDeclaration, + GenericContext, Implicit, ModuleContext, }; use crate::ast::{self, CallNamePart, FnKind, If}; use crate::semantics::monomorphize::Monomorphize; @@ -986,40 +987,62 @@ impl ReplaceWithTypeInfo for TypeReference { return self.clone().into(); } - hir::Constructor { - ty: hir::TypeReference { - span: self.range(), - referenced_type: self.type_for_type.clone(), - type_for_type: context - .builtin() - .types() - .type_of(self.type_for_type.clone()), - }, - initializers: vec![ - hir::Initializer { - span: 0..0, - index: 0, - member: self.type_for_type.members()[0].clone(), - value: hir::Literal::String { - span: 0..0, - value: self.referenced_type.name().to_string(), - ty: context.builtin().types().string(), - } - .into(), - }, - hir::Initializer { - span: 0..0, - index: 1, - member: self.type_for_type.members()[1].clone(), - value: hir::Literal::Integer { - span: 0..0, - value: self.referenced_type.size_in_bytes().into(), - ty: context.builtin().types().integer(), + let name = self.type_for_type.name().to_string(); + let variable = if let Some(var) = context.module().find_variable(&name) { + var + } else { + let var = Variable::new(VariableData { + keyword: Keyword::<"let">::at(self.start()), + mutability: Mutability::Immutable, + name: Identifier::from(name).at(self.start()), + ty: self.type_for_type.clone(), + type_reference: None, + initializer: Some( + hir::Constructor { + ty: hir::TypeReference { + span: self.range(), + referenced_type: self.type_for_type.clone(), + type_for_type: context + .builtin() + .types() + .type_of(self.type_for_type.clone()), + }, + initializers: vec![ + hir::Initializer { + span: 0..0, + index: 0, + member: self.type_for_type.members()[0].clone(), + value: hir::Literal::String { + span: 0..0, + value: self.referenced_type.name().to_string(), + ty: context.builtin().types().string(), + } + .into(), + }, + hir::Initializer { + span: 0..0, + index: 1, + member: self.type_for_type.members()[1].clone(), + value: hir::Literal::Integer { + span: 0..0, + value: self.referenced_type.size_in_bytes().into(), + ty: context.builtin().types().integer(), + } + .into(), + }, + ], + rbrace: self.end() - 1, } .into(), - }, - ], - rbrace: self.end() - 1, + ), + }); + context.module_mut().add_variable(var.clone()); + var.into() + }; + + hir::VariableReference { + span: self.range(), + variable, } .into() } diff --git a/src/tests/snapshots/ppl__tests__address_of.hir.snap b/src/tests/snapshots/ppl__tests__address_of.hir.snap index 9343ae8b..24c59e11 100644 --- a/src/tests/snapshots/ppl__tests__address_of.hir.snap +++ b/src/tests/snapshots/ppl__tests__address_of.hir.snap @@ -5,7 +5,7 @@ expression: hir let x: Integer = 0 `println <:Integer>`(`clone <:Reference>`((x:Integer))) let address: MemoryAddress = `address of <:Reference>`((&x:Reference)) -let x_mut_ref: ReferenceMut = `<:Type> at <:Reference>`(Type { name: "Integer", size: 8 }, (&address:Reference)) +let x_mut_ref: ReferenceMut = `<:Type> at <:Reference>`((Type:Type), (&address:Reference)) (x_mut_ref:ReferenceMut) = 1 `println <:Integer>`(`clone <:Reference>`((x:Integer))) `destroy <:ReferenceMut>`((x:Integer)) diff --git a/src/tests/snapshots/ppl__tests__address_of.ir.snap b/src/tests/snapshots/ppl__tests__address_of.ir.snap index 52c2289f..6b246267 100644 --- a/src/tests/snapshots/ppl__tests__address_of.ir.snap +++ b/src/tests/snapshots/ppl__tests__address_of.ir.snap @@ -5,53 +5,152 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Integer = type { ptr } -%MemoryAddress = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } - +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%MemoryAddress = type { %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@4 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 @x = global %Integer zeroinitializer @address = global %MemoryAddress zeroinitializer @x_mut_ref = global ptr null -@0 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 - -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - %1 = call %Integer @clone_integer(ptr @x), !dbg !8 - call void @"println <:Integer>"(%Integer %1), !dbg !8 - call void @initialize.1(), !dbg !9 - call void @initialize.2(), !dbg !10 - %2 = load ptr, ptr @x_mut_ref, align 8, !dbg !11 - %3 = call %Integer @integer_from_i64(i64 1), !dbg !12 - store %Integer %3, ptr %2, align 8, !dbg !12 - %4 = call %Integer @clone_integer(ptr @x), !dbg !13 - call void @"println <:Integer>"(%Integer %4), !dbg !13 - call void @destroy_integer(ptr @x), !dbg !14 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 br label %return, !dbg !14 return: ; preds = %0 ret void } -define private void @initialize() !dbg !15 { - %1 = call %Integer @integer_from_i64(i64 0), !dbg !16 - store %Integer %1, ptr @x, align 8, !dbg !16 - br label %return, !dbg !16 +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 return: ; preds = %0 ret void } -declare %Integer @integer_from_i64(i64) +define private void @initialize.4() !dbg !18 { + %1 = alloca %"Type", align 8, !dbg !19 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !19 + %2 = call %String @string_from_c_string_and_length(ptr @4, i64 7), !dbg !20 + store %String %2, ptr %"Type.name", align 8, !dbg !20 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !20 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !20 + store %Integer %3, ptr %"Type.size", align 8, !dbg !20 + %4 = load %"Type", ptr %1, align 8, !dbg !20 + store %"Type" %4, ptr @"Type", align 8, !dbg !20 + br label %return, !dbg !20 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !21 { + call void @initialize(), !dbg !22 + call void @initialize.1(), !dbg !22 + call void @initialize.2(), !dbg !23 + call void @initialize.3(), !dbg !24 + call void @initialize.4(), !dbg !25 + call void @initialize.5(), !dbg !26 + %1 = call %Integer @clone_integer(ptr @x), !dbg !27 + call void @"println <:Integer>"(%Integer %1), !dbg !27 + call void @initialize.6(), !dbg !28 + call void @initialize.7(), !dbg !25 + %2 = load ptr, ptr @x_mut_ref, align 8, !dbg !29 + %3 = call %Integer @integer_from_i64(i64 1), !dbg !30 + store %Integer %3, ptr %2, align 8, !dbg !30 + %4 = call %Integer @clone_integer(ptr @x), !dbg !31 + call void @"println <:Integer>"(%Integer %4), !dbg !31 + call void @destroy_integer(ptr @x), !dbg !32 + br label %return, !dbg !32 + +return: ; preds = %0 + ret void +} + +define private void @initialize.5() !dbg !33 { + %1 = call %Integer @integer_from_i64(i64 0), !dbg !34 + store %Integer %1, ptr @x, align 8, !dbg !34 + br label %return, !dbg !34 -define private void @"println <:Integer>"(%Integer %0) !dbg !17 { +return: ; preds = %0 + ret void +} + +define private void @"println <:Integer>"(%Integer %0) !dbg !35 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !18 - %3 = call %String @integer_as_string(%Integer %2), !dbg !18 - call void @"println <:String>"(%String %3), !dbg !18 - br label %return, !dbg !18 + %2 = load %Integer, ptr %x, align 8, !dbg !36 + %3 = call %String @integer_as_string(%Integer %2), !dbg !36 + call void @"println <:String>"(%String %3), !dbg !36 + br label %return, !dbg !36 return: ; preds = %1 ret void @@ -63,10 +162,10 @@ declare %String @integer_as_string(%Integer) declare %Integer @clone_integer(ptr) -define private void @initialize.1() !dbg !19 { - %1 = call %MemoryAddress @address_of(ptr @x), !dbg !20 - store %MemoryAddress %1, ptr @address, align 8, !dbg !20 - br label %return, !dbg !20 +define private void @initialize.6() !dbg !37 { + %1 = call %MemoryAddress @address_of(ptr @x), !dbg !38 + store %MemoryAddress %1, ptr @address, align 8, !dbg !38 + br label %return, !dbg !38 return: ; preds = %0 ret void @@ -74,19 +173,11 @@ return: ; preds = %0 declare %MemoryAddress @address_of(ptr) -define private void @initialize.2() !dbg !21 { - %1 = alloca %"Type", align 8, !dbg !22 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !22 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !22 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 7), !dbg !23 - store %String %2, ptr %"Type.name", align 8, !dbg !23 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !23 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !23 - store %Integer %3, ptr %"Type.size", align 8, !dbg !23 - %4 = load %"Type", ptr %1, align 8, !dbg !23 - %5 = call ptr @read_memory(%"Type" %4, ptr @address), !dbg !24 - store ptr %5, ptr @x_mut_ref, align 8, !dbg !24 - br label %return, !dbg !24 +define private void @initialize.7() !dbg !39 { + %1 = load %"Type", ptr @"Type", align 8, !dbg !40 + %2 = call ptr @read_memory(%"Type" %1, ptr @address), !dbg !41 + store ptr %2, ptr @x_mut_ref, align 8, !dbg !41 + br label %return, !dbg !41 return: ; preds = %0 ret void @@ -94,8 +185,6 @@ return: ; preds = %0 declare ptr @read_memory(%"Type", ptr) -declare %String @string_from_c_string_and_length(ptr, i64) - declare void @destroy_integer(ptr) !llvm.module.flags = !{!0} @@ -104,25 +193,42 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 8, scope: !3) -!8 = !DILocation(line: 1, column: 8, scope: !3) -!9 = !DILocation(line: 3, column: 14, scope: !3) -!10 = !DILocation(line: 4, column: 16, scope: !3) -!11 = !DILocation(line: 5, scope: !3) -!12 = !DILocation(line: 5, column: 12, scope: !3) -!13 = !DILocation(line: 6, column: 8, scope: !3) -!14 = !DILocation(line: 0, scope: !3) -!15 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!16 = !DILocation(line: 0, column: 8, scope: !15) -!17 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!18 = !DILocation(line: 7, scope: !17) -!19 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!20 = !DILocation(line: 3, column: 25, scope: !19) -!21 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !3, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!22 = !DILocation(line: 4, column: 16, scope: !21) -!23 = !DILocation(line: 0, scope: !21) -!24 = !DILocation(line: 4, column: 27, scope: !21) +!7 = !DILocation(line: 7, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 7, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 4, column: 15, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 4, column: 10, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 4, column: 16, scope: !18) +!20 = !DILocation(line: 0, scope: !18) +!21 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!22 = !DILocation(line: 7, scope: !21) +!23 = !DILocation(line: 4, column: 15, scope: !21) +!24 = !DILocation(line: 4, column: 10, scope: !21) +!25 = !DILocation(line: 4, column: 16, scope: !21) +!26 = !DILocation(line: 0, column: 8, scope: !21) +!27 = !DILocation(line: 1, column: 8, scope: !21) +!28 = !DILocation(line: 3, column: 14, scope: !21) +!29 = !DILocation(line: 5, scope: !21) +!30 = !DILocation(line: 5, column: 12, scope: !21) +!31 = !DILocation(line: 6, column: 8, scope: !21) +!32 = !DILocation(line: 0, scope: !21) +!33 = distinct !DISubprogram(name: "initialize.5", linkageName: "initialize.5", scope: !21, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!34 = !DILocation(line: 0, column: 8, scope: !33) +!35 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !21, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!36 = !DILocation(line: 7, scope: !35) +!37 = distinct !DISubprogram(name: "initialize.6", linkageName: "initialize.6", scope: !21, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!38 = !DILocation(line: 3, column: 25, scope: !37) +!39 = distinct !DISubprogram(name: "initialize.7", linkageName: "initialize.7", scope: !21, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!40 = !DILocation(line: 4, column: 16, scope: !39) +!41 = !DILocation(line: 4, column: 27, scope: !39) diff --git a/src/tests/snapshots/ppl__tests__array.hir.snap b/src/tests/snapshots/ppl__tests__array.hir.snap index abaf84e2..6907d3c5 100644 --- a/src/tests/snapshots/ppl__tests__array.hir.snap +++ b/src/tests/snapshots/ppl__tests__array.hir.snap @@ -2,7 +2,7 @@ source: src/tests/mod.rs expression: hir --- -let mut arr: Array = `<:Type> [ ]`(Type { name: "Integer", size: 8 }) +let mut arr: Array = `<:Type> [ ]`((Type:Type)) `println <:Array>`((arr:Array)) if `<:Reference>> is empty`((&arr:ReferenceMut>)): `println <:String>`("Empty") @@ -25,22 +25,22 @@ while `<:Integer> <= <:Integer>`(`clone <:Reference>`((i:Integer)), 10) fn size of > -> Integer: - let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4426:Integer) + let $tmp@4582: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4582:Integer) fn allocate <$arg1: Type> -> MemoryAddress: - let $tmp@760: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`(Type { name: "Integer", size: 8 }))) + let $tmp@825: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`((Type:Type)))) `destroy <:ReferenceMut>`((n:Integer)) - return ($tmp@760:MemoryAddress) + return ($tmp@825:MemoryAddress) fn <$arg0: Type> [ ] -> Array: let capacity: Integer = 8 - let data: MemoryAddress = `allocate <:Integer> <:Type>`(`clone <:Reference>`((capacity:Integer)), Type { name: "Integer", size: 8 }) - let $tmp@273: Array = Array { size: 0, capacity: `clone <:Reference>`((capacity:Integer)), data: (data:MemoryAddress) } + let data: MemoryAddress = `allocate <:Integer> <:Type>`(`clone <:Reference>`((capacity:Integer)), (Type:Type)) + let $tmp@427: Array = Array { size: 0, capacity: `clone <:Reference>`((capacity:Integer)), data: (data:MemoryAddress) } `destroy <:ReferenceMut>`((capacity:Integer)) - return ($tmp@273:Array) + return ($tmp@427:Array) fn String from > -> String: @@ -56,9 +56,9 @@ fn String from > -> String: `destroy <:ReferenceMut>`((i:Integer)) `<:ReferenceMut> += <:String>`((&str:ReferenceMut), "]") - let $tmp@1782: String = `clone <:Reference>`((str:String)) + let $tmp@1936: String = `clone <:Reference>`((str:String)) `destroy <:ReferenceMut>`((str:String)) - return ($tmp@1782:String) + return ($tmp@1936:String) fn println > -> None: @@ -68,40 +68,40 @@ fn println > -> None: fn >> is empty -> Bool: - let $tmp@1458: Bool = `<:Integer> == <:Integer>`(`clone <:Reference>`((*array:Array).size), 0) - return ($tmp@1458:Bool) + let $tmp@1612: Bool = `<:Integer> == <:Integer>`(`clone <:Reference>`((*array:Array).size), 0) + return ($tmp@1612:Bool) fn size of > -> Integer: - let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4426:Integer) + let $tmp@4582: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4582:Integer) fn size of > -> Integer: - let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4426:Integer) + let $tmp@4582: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4582:Integer) fn allocate <$arg1: Type> -> MemoryAddress: - let $tmp@760: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`(Type { name: "Integer", size: 8 }))) + let $tmp@825: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`((Type:Type)))) `destroy <:ReferenceMut>`((n:Integer)) - return ($tmp@760:MemoryAddress) + return ($tmp@825:MemoryAddress) @mangle_as("address_of") fn address of > -> MemoryAddress fn push to >> -> None: - let bytes: Integer = `size of <:Type>`(Type { name: "Integer", size: 8 }) + let bytes: Integer = `size of <:Type>`((Type:Type)) if `<:Integer> == <:Integer>`(`clone <:Reference>`((*array:Array).size), `clone <:Reference>`((*array:Array).capacity)): let new_capacity: Integer = `<:Integer> * <:Integer>`(`clone <:Reference>`((*array:Array).capacity), 2) - let new_data: MemoryAddress = `allocate <:Integer> <:Type>`(`clone <:Reference>`((new_capacity:Integer)), Type { name: "Integer", size: 8 }) + let new_data: MemoryAddress = `allocate <:Integer> <:Type>`(`clone <:Reference>`((new_capacity:Integer)), (Type:Type)) let mut i: Integer = 0 while `<:Integer> < <:Integer>`(`clone <:Reference>`((i:Integer)), `clone <:Reference>`((*array:Array).size)): let offset: Integer = `<:Integer> * <:Integer>`(`clone <:Reference>`((i:Integer)), `clone <:Reference>`((bytes:Integer))) - let $tmp@1199: MemoryAddress = `<:MemoryAddress> + <:Integer>`((*array:Array).data, `clone <:Reference>`((offset:Integer))) - let $tmp@1224: MemoryAddress = `<:MemoryAddress> + <:Integer>`((new_data:MemoryAddress), `clone <:Reference>`((offset:Integer))) - `copy <:Reference> bytes from <:Reference> to <:Reference>`((&bytes:Reference), (&$tmp@1199:Reference), (&$tmp@1224:Reference)) + let $tmp@1353: MemoryAddress = `<:MemoryAddress> + <:Integer>`((*array:Array).data, `clone <:Reference>`((offset:Integer))) + let $tmp@1378: MemoryAddress = `<:MemoryAddress> + <:Integer>`((new_data:MemoryAddress), `clone <:Reference>`((offset:Integer))) + `copy <:Reference> bytes from <:Reference> to <:Reference>`((&bytes:Reference), (&$tmp@1353:Reference), (&$tmp@1378:Reference)) `<:ReferenceMut> += <:Integer>`((&i:ReferenceMut), 1) `destroy <:ReferenceMut>`((offset:Integer)) @@ -112,9 +112,9 @@ fn push to >> -> None: `destroy <:ReferenceMut>`((new_capacity:Integer)) `destroy <:ReferenceMut>`((i:Integer)) - let $tmp@1352: MemoryAddress = `address of <:Reference>`((&x:Reference)) - let $tmp@1370: MemoryAddress = `<:MemoryAddress> + <:Integer>`((*array:Array).data, `<:Integer> * <:Integer>`(`clone <:Reference>`((*array:Array).size), `clone <:Reference>`((bytes:Integer)))) - `copy <:Reference> bytes from <:Reference> to <:Reference>`((&bytes:Reference), (&$tmp@1352:Reference), (&$tmp@1370:Reference)) + let $tmp@1506: MemoryAddress = `address of <:Reference>`((&x:Reference)) + let $tmp@1524: MemoryAddress = `<:MemoryAddress> + <:Integer>`((*array:Array).data, `<:Integer> * <:Integer>`(`clone <:Reference>`((*array:Array).size), `clone <:Reference>`((bytes:Integer)))) + `copy <:Reference> bytes from <:Reference> to <:Reference>`((&bytes:Reference), (&$tmp@1506:Reference), (&$tmp@1524:Reference)) `<:ReferenceMut> += <:Integer>`((&(*array:Array).size:ReferenceMut), 1) `destroy <:ReferenceMut>`((bytes:Integer)) @@ -132,9 +132,9 @@ fn String from > -> String: `destroy <:ReferenceMut>`((i:Integer)) `<:ReferenceMut> += <:String>`((&str:ReferenceMut), "]") - let $tmp@1782: String = `clone <:Reference>`((str:String)) + let $tmp@1936: String = `clone <:Reference>`((str:String)) `destroy <:ReferenceMut>`((str:String)) - return ($tmp@1782:String) + return ($tmp@1936:String) fn println > -> None: @@ -144,13 +144,13 @@ fn println > -> None: fn >> is not empty -> Bool: - let $tmp@1515: Bool = `<:Integer> > <:Integer>`(`clone <:Reference>`((*array:Array).size), 0) - return ($tmp@1515:Bool) + let $tmp@1669: Bool = `<:Integer> > <:Integer>`(`clone <:Reference>`((*array:Array).size), 0) + return ($tmp@1669:Bool) fn size of > -> Integer: - let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4426:Integer) + let $tmp@4582: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4582:Integer) @mangle_as("read_memory") @@ -160,13 +160,13 @@ fn > at > -> Refere fn > at > -> ReferenceMut fn >> [ ] -> ReferenceMut: - let $tmp@630: String = "Index out of bounds" - `assert <:Bool> <:Reference>`(`<:Bool> and <:Bool>`(`<:Integer> <= <:Integer>`(0, `clone <:Reference>`((i:Integer))), `<:Integer> < <:Integer>`(`clone <:Reference>`((i:Integer)), `clone <:Reference>`((*array:Array).size))), (&$tmp@630:Reference)) - let address: MemoryAddress = `<:MemoryAddress> + <:Integer>`((*array:Array).data, `<:Integer> * <:Integer>`(`clone <:Reference>`((i:Integer)), `size of <:Type>`(Type { name: "Integer", size: 8 }))) - let mut $tmp@704: ReferenceMut = `<:Type> at <:Reference>`(Type { name: "Integer", size: 8 }, (&address:Reference)) + let $tmp@784: String = "Index out of bounds" + `assert <:Bool> <:Reference>`(`<:Bool> and <:Bool>`(`<:Integer> <= <:Integer>`(0, `clone <:Reference>`((i:Integer))), `<:Integer> < <:Integer>`(`clone <:Reference>`((i:Integer)), `clone <:Reference>`((*array:Array).size))), (&$tmp@784:Reference)) + let address: MemoryAddress = `<:MemoryAddress> + <:Integer>`((*array:Array).data, `<:Integer> * <:Integer>`(`clone <:Reference>`((i:Integer)), `size of <:Type>`((Type:Type)))) + let mut $tmp@858: ReferenceMut = `<:Type> at <:Reference>`((Type:Type), (&address:Reference)) `destroy <:ReferenceMut>`((i:Integer)) - `destroy <:ReferenceMut>`(($tmp@630:String)) - return ($tmp@704:ReferenceMut) + `destroy <:ReferenceMut>`(($tmp@784:String)) + return ($tmp@858:ReferenceMut) @mangle_as("integer_as_string") @@ -194,35 +194,35 @@ fn <= -> Bool: fn size of > -> Integer: - let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4426:Integer) + let $tmp@4582: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4582:Integer) fn size of > -> Integer: - let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4426:Integer) + let $tmp@4582: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4582:Integer) fn allocate <$arg1: Type> -> MemoryAddress: - let $tmp@760: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`(Type { name: "Integer", size: 8 }))) + let $tmp@825: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`((Type:Type)))) `destroy <:ReferenceMut>`((n:Integer)) - return ($tmp@760:MemoryAddress) + return ($tmp@825:MemoryAddress) @mangle_as("address_of") fn address of > -> MemoryAddress fn push to >> -> None: - let bytes: Integer = `size of <:Type>`(Type { name: "Integer", size: 8 }) + let bytes: Integer = `size of <:Type>`((Type:Type)) if `<:Integer> == <:Integer>`(`clone <:Reference>`((*array:Array).size), `clone <:Reference>`((*array:Array).capacity)): let new_capacity: Integer = `<:Integer> * <:Integer>`(`clone <:Reference>`((*array:Array).capacity), 2) - let new_data: MemoryAddress = `allocate <:Integer> <:Type>`(`clone <:Reference>`((new_capacity:Integer)), Type { name: "Integer", size: 8 }) + let new_data: MemoryAddress = `allocate <:Integer> <:Type>`(`clone <:Reference>`((new_capacity:Integer)), (Type:Type)) let mut i: Integer = 0 while `<:Integer> < <:Integer>`(`clone <:Reference>`((i:Integer)), `clone <:Reference>`((*array:Array).size)): let offset: Integer = `<:Integer> * <:Integer>`(`clone <:Reference>`((i:Integer)), `clone <:Reference>`((bytes:Integer))) - let $tmp@1199: MemoryAddress = `<:MemoryAddress> + <:Integer>`((*array:Array).data, `clone <:Reference>`((offset:Integer))) - let $tmp@1224: MemoryAddress = `<:MemoryAddress> + <:Integer>`((new_data:MemoryAddress), `clone <:Reference>`((offset:Integer))) - `copy <:Reference> bytes from <:Reference> to <:Reference>`((&bytes:Reference), (&$tmp@1199:Reference), (&$tmp@1224:Reference)) + let $tmp@1353: MemoryAddress = `<:MemoryAddress> + <:Integer>`((*array:Array).data, `clone <:Reference>`((offset:Integer))) + let $tmp@1378: MemoryAddress = `<:MemoryAddress> + <:Integer>`((new_data:MemoryAddress), `clone <:Reference>`((offset:Integer))) + `copy <:Reference> bytes from <:Reference> to <:Reference>`((&bytes:Reference), (&$tmp@1353:Reference), (&$tmp@1378:Reference)) `<:ReferenceMut> += <:Integer>`((&i:ReferenceMut), 1) `destroy <:ReferenceMut>`((offset:Integer)) @@ -233,9 +233,9 @@ fn push to >> -> None: `destroy <:ReferenceMut>`((new_capacity:Integer)) `destroy <:ReferenceMut>`((i:Integer)) - let $tmp@1352: MemoryAddress = `address of <:Reference>`((&x:Reference)) - let $tmp@1370: MemoryAddress = `<:MemoryAddress> + <:Integer>`((*array:Array).data, `<:Integer> * <:Integer>`(`clone <:Reference>`((*array:Array).size), `clone <:Reference>`((bytes:Integer)))) - `copy <:Reference> bytes from <:Reference> to <:Reference>`((&bytes:Reference), (&$tmp@1352:Reference), (&$tmp@1370:Reference)) + let $tmp@1506: MemoryAddress = `address of <:Reference>`((&x:Reference)) + let $tmp@1524: MemoryAddress = `<:MemoryAddress> + <:Integer>`((*array:Array).data, `<:Integer> * <:Integer>`(`clone <:Reference>`((*array:Array).size), `clone <:Reference>`((bytes:Integer)))) + `copy <:Reference> bytes from <:Reference> to <:Reference>`((&bytes:Reference), (&$tmp@1506:Reference), (&$tmp@1524:Reference)) `<:ReferenceMut> += <:Integer>`((&(*array:Array).size:ReferenceMut), 1) `destroy <:ReferenceMut>`((bytes:Integer)) @@ -260,9 +260,9 @@ fn String from > -> String: `destroy <:ReferenceMut>`((i:Integer)) `<:ReferenceMut> += <:String>`((&str:ReferenceMut), "]") - let $tmp@1782: String = `clone <:Reference>`((str:String)) + let $tmp@1936: String = `clone <:Reference>`((str:String)) `destroy <:ReferenceMut>`((str:String)) - return ($tmp@1782:String) + return ($tmp@1936:String) fn println > -> None: diff --git a/src/tests/snapshots/ppl__tests__candidate_not_viable.error.snap b/src/tests/snapshots/ppl__tests__candidate_not_viable.error.snap index b4d00d15..058aba36 100644 --- a/src/tests/snapshots/ppl__tests__candidate_not_viable.error.snap +++ b/src/tests/snapshots/ppl__tests__candidate_not_viable.error.snap @@ -19,12 +19,12 @@ Advice: ☞ candidate is not viable × expected `Integer` type, got `Rational` Error: × Integer - ╭─[core.ppl:91:5] - 90 │ @mangle_as("integer_plus_integer") - 91 │ fn <:Integer> + <:Integer> -> Integer + ╭─[core.ppl:95:5] + 94 │ @mangle_as("integer_plus_integer") + 95 │ fn <:Integer> + <:Integer> -> Integer · ▲ · ╰── this has `Integer` type - 92 │ + 96 │ ╰──── Error: × Rational ╭─[main.ppl:1:1] @@ -39,12 +39,12 @@ Advice: ☞ candidate is not viable × expected `Rational` type, got `Integer` Error: × Rational - ╭─[core.ppl:145:19] - 144 │ @mangle_as("rational_plus_rational") - 145 │ fn <:Rational> + <:Rational> -> Rational + ╭─[core.ppl:152:19] + 151 │ @mangle_as("rational_plus_rational") + 152 │ fn <:Rational> + <:Rational> -> Rational · ▲ · ╰── this has `Rational` type - 146 │ + 153 │ ╰──── Error: × Integer ╭─[main.ppl:1:7] @@ -59,12 +59,12 @@ Advice: ☞ candidate is not viable × expected `String` type, got `Rational` Error: × String - ╭─[core.ppl:177:5] - 176 │ @mangle_as("string_plus_string") - 177 │ fn <:String> + <:String> -> String + ╭─[core.ppl:187:5] + 186 │ @mangle_as("string_plus_string") + 187 │ fn <:String> + <:String> -> String · ▲ · ╰── this has `String` type - 178 │ + 188 │ ╰──── Error: × Rational ╭─[main.ppl:1:1] @@ -79,12 +79,12 @@ Advice: ☞ candidate is not viable × expected `MemoryAddress` type, got `Rational` Error: × MemoryAddress - ╭─[memory.ppl:13:5] - 12 │ /// Get another memory address by adding offset to this one - 13 │ fn + -> MemoryAddress: + ╭─[memory.ppl:15:5] + 14 │ /// Get another memory address by adding offset to this one + 15 │ fn + -> MemoryAddress: · ───┬─── · ╰── this has `MemoryAddress` type - 14 │ let value = address.value + offset + 16 │ let value = address.value + offset ╰──── Error: × Rational ╭─[main.ppl:1:1] @@ -99,12 +99,12 @@ Advice: ☞ candidate is not viable × expected `I32` type, got `Rational` Error: × I32 - ╭─[i32.ppl:12:5] - 11 │ @mangle_as("i32_plus_i32") - 12 │ fn <:I32> + <:I32> -> I32 + ╭─[i32.ppl:14:5] + 13 │ @mangle_as("i32_plus_i32") + 14 │ fn <:I32> + <:I32> -> I32 · ▲ · ╰── this has `I32` type - 13 │ + 15 │ ╰──── Error: × Rational ╭─[main.ppl:1:1] @@ -119,12 +119,12 @@ Advice: ☞ candidate is not viable × expected `F64` type, got `Rational` Error: × F64 - ╭─[f64.ppl:12:5] - 11 │ @mangle_as("f64_plus_f64") - 12 │ fn <:F64> + <:F64> -> F64 + ╭─[f64.ppl:14:5] + 13 │ @mangle_as("f64_plus_f64") + 14 │ fn <:F64> + <:F64> -> F64 · ▲ · ╰── this has `F64` type - 13 │ + 15 │ ╰──── Error: × Rational ╭─[main.ppl:1:1] diff --git a/src/tests/snapshots/ppl__tests__clone.ir.snap b/src/tests/snapshots/ppl__tests__clone.ir.snap index 352beebf..8f176592 100644 --- a/src/tests/snapshots/ppl__tests__clone.ir.snap +++ b/src/tests/snapshots/ppl__tests__clone.ir.snap @@ -5,52 +5,134 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Integer = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } - +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 @x = global %Integer zeroinitializer @y = global %Integer zeroinitializer -@0 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 - -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - call void @initialize.1(), !dbg !8 - %1 = call %Integer @clone_integer(ptr @x), !dbg !9 - call void @"println <:Integer>"(%Integer %1), !dbg !9 - %2 = call %Integer @clone_integer(ptr @y), !dbg !10 - call void @"println <:Integer>"(%Integer %2), !dbg !10 - %3 = call %String @string_from_c_string_and_length(ptr @0, i64 0), !dbg !11 - call void @"println <:String>"(%String %3), !dbg !11 - call void @destroy_integer(ptr @y), !dbg !12 - %4 = call %Integer @integer_from_i64(i64 2), !dbg !13 - store %Integer %4, ptr @y, align 8, !dbg !13 - %5 = call %Integer @clone_integer(ptr @x), !dbg !14 - call void @"println <:Integer>"(%Integer %5), !dbg !14 - %6 = call %Integer @clone_integer(ptr @y), !dbg !15 - call void @"println <:Integer>"(%Integer %6), !dbg !15 - call void @destroy_integer(ptr @x), !dbg !16 - call void @destroy_integer(ptr @y), !dbg !17 +@4 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 br label %return, !dbg !17 return: ; preds = %0 ret void } -define private void @initialize() !dbg !18 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !19 - store %Integer %1, ptr @x, align 8, !dbg !19 - br label %return, !dbg !19 +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !20 + call void @initialize.3(), !dbg !21 + call void @initialize.4(), !dbg !22 + call void @initialize.5(), !dbg !23 + %1 = call %Integer @clone_integer(ptr @x), !dbg !24 + call void @"println <:Integer>"(%Integer %1), !dbg !24 + %2 = call %Integer @clone_integer(ptr @y), !dbg !25 + call void @"println <:Integer>"(%Integer %2), !dbg !25 + %3 = call %String @string_from_c_string_and_length(ptr @4, i64 0), !dbg !26 + call void @"println <:String>"(%String %3), !dbg !26 + call void @destroy_integer(ptr @y), !dbg !27 + %4 = call %Integer @integer_from_i64(i64 2), !dbg !28 + store %Integer %4, ptr @y, align 8, !dbg !28 + %5 = call %Integer @clone_integer(ptr @x), !dbg !29 + call void @"println <:Integer>"(%Integer %5), !dbg !29 + %6 = call %Integer @clone_integer(ptr @y), !dbg !30 + call void @"println <:Integer>"(%Integer %6), !dbg !30 + call void @destroy_integer(ptr @x), !dbg !31 + call void @destroy_integer(ptr @y), !dbg !32 + br label %return, !dbg !32 return: ; preds = %0 ret void } -declare %Integer @integer_from_i64(i64) +define private void @initialize.4() !dbg !33 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !34 + store %Integer %1, ptr @x, align 8, !dbg !34 + br label %return, !dbg !34 -define private void @initialize.1() !dbg !20 { - %1 = call %Integer @clone_integer(ptr @x), !dbg !21 - store %Integer %1, ptr @y, align 8, !dbg !21 - br label %return, !dbg !21 +return: ; preds = %0 + ret void +} + +define private void @initialize.5() !dbg !35 { + %1 = call %Integer @clone_integer(ptr @x), !dbg !36 + store %Integer %1, ptr @y, align 8, !dbg !36 + br label %return, !dbg !36 return: ; preds = %0 ret void @@ -58,13 +140,13 @@ return: ; preds = %0 declare %Integer @clone_integer(ptr) -define private void @"println <:Integer>"(%Integer %0) !dbg !22 { +define private void @"println <:Integer>"(%Integer %0) !dbg !37 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !23 - %3 = call %String @integer_as_string(%Integer %2), !dbg !23 - call void @"println <:String>"(%String %3), !dbg !23 - br label %return, !dbg !23 + %2 = load %Integer, ptr %x, align 8, !dbg !38 + %3 = call %String @integer_as_string(%Integer %2), !dbg !38 + call void @"println <:String>"(%String %3), !dbg !38 + br label %return, !dbg !38 return: ; preds = %1 ret void @@ -74,8 +156,6 @@ declare void @"println <:String>"(%String) declare %String @integer_as_string(%Integer) -declare %String @string_from_c_string_and_length(ptr, i64) - declare void @destroy_integer(ptr) !llvm.module.flags = !{!0} @@ -84,24 +164,39 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 10, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 8, scope: !3) -!8 = !DILocation(line: 1, column: 12, scope: !3) -!9 = !DILocation(line: 2, column: 8, scope: !3) -!10 = !DILocation(line: 3, column: 8, scope: !3) -!11 = !DILocation(line: 5, column: 8, scope: !3) -!12 = !DILocation(line: 7, scope: !3) -!13 = !DILocation(line: 7, column: 4, scope: !3) -!14 = !DILocation(line: 8, column: 8, scope: !3) -!15 = !DILocation(line: 9, column: 8, scope: !3) -!16 = !DILocation(line: 0, scope: !3) -!17 = !DILocation(line: 1, scope: !3) -!18 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!19 = !DILocation(line: 0, column: 8, scope: !18) -!20 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!21 = !DILocation(line: 1, column: 12, scope: !20) -!22 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 10, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!23 = !DILocation(line: 10, scope: !22) +!7 = !DILocation(line: 10, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 10, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 10, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 8, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 7, column: 1, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 10, scope: !18) +!20 = !DILocation(line: 8, scope: !18) +!21 = !DILocation(line: 7, column: 1, scope: !18) +!22 = !DILocation(line: 0, column: 8, scope: !18) +!23 = !DILocation(line: 1, column: 12, scope: !18) +!24 = !DILocation(line: 2, column: 8, scope: !18) +!25 = !DILocation(line: 3, column: 8, scope: !18) +!26 = !DILocation(line: 5, column: 8, scope: !18) +!27 = !DILocation(line: 7, scope: !18) +!28 = !DILocation(line: 7, column: 4, scope: !18) +!29 = !DILocation(line: 8, column: 8, scope: !18) +!30 = !DILocation(line: 9, column: 8, scope: !18) +!31 = !DILocation(line: 0, scope: !18) +!32 = !DILocation(line: 1, scope: !18) +!33 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !18, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!34 = !DILocation(line: 0, column: 8, scope: !33) +!35 = distinct !DISubprogram(name: "initialize.5", linkageName: "initialize.5", scope: !18, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!36 = !DILocation(line: 1, column: 12, scope: !35) +!37 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !18, file: !2, line: 10, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!38 = !DILocation(line: 10, scope: !37) diff --git a/src/tests/snapshots/ppl__tests__common_functions.ir.snap b/src/tests/snapshots/ppl__tests__common_functions.ir.snap index 97cca83a..7fe7d1df 100644 --- a/src/tests/snapshots/ppl__tests__common_functions.ir.snap +++ b/src/tests/snapshots/ppl__tests__common_functions.ir.snap @@ -5,30 +5,113 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" +%"Type" = type { %String, %Integer } %String = type { ptr } +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } -@0 = private unnamed_addr constant [4 x i8] c"foo\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@4 = private unnamed_addr constant [4 x i8] c"foo\00", align 1 -define void @main.execute() !dbg !3 { - call void @foo(), !dbg !7 - br label %return, !dbg !7 +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 return: ; preds = %0 ret void } -define void @foo() !dbg !8 { - %1 = call %String @string_from_c_string_and_length(ptr @0, i64 3), !dbg !9 - call void @"println <:String>"(%String %1), !dbg !9 - br label %return, !dbg !10 +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 return: ; preds = %0 ret void } -declare void @"println <:String>"(%String) +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 -declare %String @string_from_c_string_and_length(ptr, i64) +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !19 + call void @initialize.3(), !dbg !19 + call void @foo(), !dbg !20 + br label %return, !dbg !20 + +return: ; preds = %0 + ret void +} + +define void @foo() !dbg !21 { + %1 = call %String @string_from_c_string_and_length(ptr @4, i64 3), !dbg !22 + call void @"println <:String>"(%String %1), !dbg !22 + br label %return, !dbg !23 + +return: ; preds = %0 + ret void +} + +declare void @"println <:String>"(%String) !llvm.module.flags = !{!0} !llvm.dbg.cu = !{!1} @@ -36,11 +119,24 @@ declare %String @string_from_c_string_and_length(ptr, i64) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 1, scope: !3) -!8 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!9 = !DILocation(line: 0, column: 18, scope: !8) -!10 = !DILocation(line: 0, column: 10, scope: !8) +!7 = !DILocation(line: 1, column: 5, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 1, column: 5, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 1, column: 5, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 1, column: 5, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 1, column: 5, scope: !18) +!20 = !DILocation(line: 1, scope: !18) +!21 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !18, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!22 = !DILocation(line: 0, column: 18, scope: !21) +!23 = !DILocation(line: 0, column: 10, scope: !21) diff --git a/src/tests/snapshots/ppl__tests__consume_greater.ir.snap b/src/tests/snapshots/ppl__tests__consume_greater.ir.snap index 7db3af41..3f95dae9 100644 --- a/src/tests/snapshots/ppl__tests__consume_greater.ir.snap +++ b/src/tests/snapshots/ppl__tests__consume_greater.ir.snap @@ -5,34 +5,129 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Point" = type { ptr } -%"PointImpl" = type { %Integer } +%"Type" = type { %String, %Integer } +%String = type { ptr } %Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Point" = type { %Integer } -define void @main.execute() !dbg !3 { - %1 = alloca %"Point", align 8, !dbg !7 - %"Point.data" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !7 - %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !7 - %2 = call %Integer @integer_from_i64(i64 1), !dbg !8 - store %Integer %2, ptr %"Point.x", align 8, !dbg !8 - %3 = load %"Point", ptr %1, align 8, !dbg !8 +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 br label %return, !dbg !8 return: ; preds = %0 ret void } +declare %String @string_from_c_string_and_length(ptr, i64) + declare %Integer @integer_from_i64(i64) +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !19 + call void @initialize.3(), !dbg !19 + %1 = alloca %"Point", align 8, !dbg !20 + %"Point.x" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !20 + %2 = call %Integer @integer_from_i64(i64 1), !dbg !21 + store %Integer %2, ptr %"Point.x", align 8, !dbg !21 + %3 = load %"Point", ptr %1, align 8, !dbg !21 + br label %return, !dbg !21 + +return: ; preds = %0 + ret void +} + !llvm.module.flags = !{!0} !llvm.dbg.cu = !{!1} !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 3, scope: !3) -!8 = !DILocation(line: 3, column: 20, scope: !3) +!7 = !DILocation(line: 3, column: 23, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 3, column: 23, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 3, column: 23, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 3, column: 23, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 3, column: 23, scope: !18) +!20 = !DILocation(line: 3, scope: !18) +!21 = !DILocation(line: 3, column: 20, scope: !18) diff --git a/src/tests/snapshots/ppl__tests__deps.ir.snap b/src/tests/snapshots/ppl__tests__deps.ir.snap index 270b18ad..d69403f8 100644 --- a/src/tests/snapshots/ppl__tests__deps.ir.snap +++ b/src/tests/snapshots/ppl__tests__deps.ir.snap @@ -5,9 +5,97 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -define void @main.execute() !dbg !3 { - call void @"say hello"(), !dbg !7 - br label %return, !dbg !7 +%"Type" = type { %String, %Integer } +%String = type { ptr } +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !19 + call void @initialize.3(), !dbg !19 + call void @"say hello"(), !dbg !20 + br label %return, !dbg !20 return: ; preds = %0 ret void @@ -21,8 +109,21 @@ declare void @"say hello"() !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 2, scope: !3) +!7 = !DILocation(line: 3, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 3, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 3, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 3, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 3, scope: !18) +!20 = !DILocation(line: 2, scope: !18) diff --git a/src/tests/snapshots/ppl__tests__deref_member_ref.ir.snap b/src/tests/snapshots/ppl__tests__deref_member_ref.ir.snap index e65bf666..17d49d0a 100644 --- a/src/tests/snapshots/ppl__tests__deref_member_ref.ir.snap +++ b/src/tests/snapshots/ppl__tests__deref_member_ref.ir.snap @@ -5,70 +5,149 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Point = type { ptr } -%Integer = type { ptr } -%PointImpl = type { %Integer, %Integer } +%"Type" = type { %String, %Integer } %String = type { ptr } - +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%Point = type { %Integer, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 @"$tmp@80" = global %Point zeroinitializer -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - %1 = call %Integer @"x of <:Reference>"(ptr @"$tmp@80"), !dbg !7 - call void @"println <:Integer>"(%Integer %1), !dbg !7 - br label %return, !dbg !7 +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 return: ; preds = %0 ret void } -define %Integer @"x of <:Reference>"(ptr %0) !dbg !8 { +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !20 + call void @initialize.3(), !dbg !21 + call void @initialize.4(), !dbg !22 + %1 = call %Integer @"x of <:Reference>"(ptr @"$tmp@80"), !dbg !22 + call void @"println <:Integer>"(%Integer %1), !dbg !22 + br label %return, !dbg !22 + +return: ; preds = %0 + ret void +} + +define %Integer @"x of <:Reference>"(ptr %0) !dbg !23 { %return_value = alloca %Integer, align 8 %p = alloca ptr, align 8 store ptr %0, ptr %p, align 8 - %2 = load ptr, ptr %p, align 8, !dbg !9 - %3 = getelementptr inbounds %Point, ptr %2, i32 0, i32 0, !dbg !9 - %x = getelementptr inbounds %PointImpl, ptr %3, i32 0, i32 0, !dbg !9 - %4 = call %Integer @clone_integer(ptr %x), !dbg !9 - %"$tmp@61" = alloca %Integer, align 8, !dbg !9 - store %Integer %4, ptr %"$tmp@61", align 8, !dbg !9 - %5 = load %Integer, ptr %"$tmp@61", align 8, !dbg !9 - store %Integer %5, ptr %return_value, align 8, !dbg !9 - br label %return, !dbg !9 + %2 = load ptr, ptr %p, align 8, !dbg !24 + %x = getelementptr inbounds %Point, ptr %2, i32 0, i32 0, !dbg !24 + %3 = call %Integer @clone_integer(ptr %x), !dbg !24 + %"$tmp@61" = alloca %Integer, align 8, !dbg !24 + store %Integer %3, ptr %"$tmp@61", align 8, !dbg !24 + %4 = load %Integer, ptr %"$tmp@61", align 8, !dbg !24 + store %Integer %4, ptr %return_value, align 8, !dbg !24 + br label %return, !dbg !24 return: ; preds = %1 - %6 = load %Integer, ptr %return_value, align 8 - ret %Integer %6 + %5 = load %Integer, ptr %return_value, align 8 + ret %Integer %5 } declare %Integer @clone_integer(ptr) -define private void @initialize() !dbg !10 { - %1 = alloca %Point, align 8, !dbg !11 - %Point.data = getelementptr inbounds %Point, ptr %1, i32 0, i32 0, !dbg !11 - %Point.x = getelementptr inbounds %PointImpl, ptr %Point.data, i32 0, i32 0, !dbg !11 - %2 = call %Integer @integer_from_i64(i64 1), !dbg !12 - store %Integer %2, ptr %Point.x, align 8, !dbg !12 - %Point.y = getelementptr inbounds %PointImpl, ptr %Point.data, i32 0, i32 1, !dbg !12 - %3 = call %Integer @integer_from_i64(i64 2), !dbg !13 - store %Integer %3, ptr %Point.y, align 8, !dbg !13 - %4 = load %Point, ptr %1, align 8, !dbg !13 - store %Point %4, ptr @"$tmp@80", align 8, !dbg !13 - br label %return, !dbg !13 +define private void @initialize.4() !dbg !25 { + %1 = alloca %Point, align 8, !dbg !26 + %Point.x = getelementptr inbounds %Point, ptr %1, i32 0, i32 0, !dbg !26 + %2 = call %Integer @integer_from_i64(i64 1), !dbg !27 + store %Integer %2, ptr %Point.x, align 8, !dbg !27 + %Point.y = getelementptr inbounds %Point, ptr %1, i32 0, i32 1, !dbg !27 + %3 = call %Integer @integer_from_i64(i64 2), !dbg !28 + store %Integer %3, ptr %Point.y, align 8, !dbg !28 + %4 = load %Point, ptr %1, align 8, !dbg !28 + store %Point %4, ptr @"$tmp@80", align 8, !dbg !28 + br label %return, !dbg !28 return: ; preds = %0 ret void } -declare %Integer @integer_from_i64(i64) - -define private void @"println <:Integer>"(%Integer %0) !dbg !14 { +define private void @"println <:Integer>"(%Integer %0) !dbg !29 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !15 - %3 = call %String @integer_as_string(%Integer %2), !dbg !15 - call void @"println <:String>"(%String %3), !dbg !15 - br label %return, !dbg !15 + %2 = load %Integer, ptr %x, align 8, !dbg !30 + %3 = call %String @integer_as_string(%Integer %2), !dbg !30 + call void @"println <:String>"(%String %3), !dbg !30 + br label %return, !dbg !30 return: ; preds = %1 ret void @@ -84,16 +163,31 @@ declare %String @integer_as_string(%Integer) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 5, column: 14, scope: !3) -!8 = distinct !DISubprogram(name: "x of <:Reference>", linkageName: "x of <:Reference>", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!9 = !DILocation(line: 3, column: 33, scope: !8) -!10 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!11 = !DILocation(line: 5, column: 14, scope: !10) -!12 = !DILocation(line: 5, column: 25, scope: !10) -!13 = !DILocation(line: 5, column: 31, scope: !10) -!14 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!15 = !DILocation(line: 5, column: 34, scope: !14) +!7 = !DILocation(line: 5, column: 34, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 5, column: 34, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 3, column: 35, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 3, column: 30, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 5, column: 34, scope: !18) +!20 = !DILocation(line: 3, column: 35, scope: !18) +!21 = !DILocation(line: 3, column: 30, scope: !18) +!22 = !DILocation(line: 5, column: 14, scope: !18) +!23 = distinct !DISubprogram(name: "x of <:Reference>", linkageName: "x of <:Reference>", scope: !18, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!24 = !DILocation(line: 3, column: 33, scope: !23) +!25 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !18, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!26 = !DILocation(line: 5, column: 14, scope: !25) +!27 = !DILocation(line: 5, column: 25, scope: !25) +!28 = !DILocation(line: 5, column: 31, scope: !25) +!29 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !18, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!30 = !DILocation(line: 5, column: 34, scope: !29) diff --git a/src/tests/snapshots/ppl__tests__destructor.ir.snap b/src/tests/snapshots/ppl__tests__destructor.ir.snap index 4fed4710..82bbfe09 100644 --- a/src/tests/snapshots/ppl__tests__destructor.ir.snap +++ b/src/tests/snapshots/ppl__tests__destructor.ir.snap @@ -5,34 +5,117 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%DestructibleClass = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } -@0 = private unnamed_addr constant [11 x i8] c"destructor\00", align 1 -@x = global %DestructibleClass zeroinitializer -@1 = private unnamed_addr constant [5 x i8] c"done\00", align 1 - -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - call void @"destroy <:ReferenceMut>"(ptr @x), !dbg !8 - %1 = alloca %DestructibleClass, align 8, !dbg !9 - %DestructibleClass.data = getelementptr inbounds %DestructibleClass, ptr %1, i32 0, i32 0, !dbg !9 - store ptr %1, ptr @x, align 8, !dbg !9 - %2 = call %String @string_from_c_string_and_length(ptr @1, i64 4), !dbg !10 - call void @"println <:String>"(%String %2), !dbg !10 - call void @"destroy <:ReferenceMut>"(ptr @x), !dbg !11 +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@4 = private unnamed_addr constant [11 x i8] c"destructor\00", align 1 +@x = global ptr null +@5 = private unnamed_addr constant [5 x i8] c"done\00", align 1 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 br label %return, !dbg !11 return: ; preds = %0 ret void } -define void @"destroy <:ReferenceMut>"(ptr %0) !dbg !12 { +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !20 + call void @initialize.2(), !dbg !21 + call void @initialize.3(), !dbg !22 + call void @initialize.4(), !dbg !23 + call void @"destroy <:ReferenceMut>"(ptr @x), !dbg !24 + %1 = alloca ptr, align 8, !dbg !25 + store ptr %1, ptr @x, align 8, !dbg !25 + %2 = call %String @string_from_c_string_and_length(ptr @5, i64 4), !dbg !26 + call void @"println <:String>"(%String %2), !dbg !26 + call void @"destroy <:ReferenceMut>"(ptr @x), !dbg !27 + br label %return, !dbg !27 + +return: ; preds = %0 + ret void +} + +define void @"destroy <:ReferenceMut>"(ptr %0) !dbg !28 { %"$arg0" = alloca ptr, align 8 store ptr %0, ptr %"$arg0", align 8 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 10), !dbg !13 - call void @"println <:String>"(%String %2), !dbg !13 - br label %return, !dbg !14 + %2 = call %String @string_from_c_string_and_length(ptr @4, i64 10), !dbg !29 + call void @"println <:String>"(%String %2), !dbg !29 + br label %return, !dbg !30 return: ; preds = %1 ret void @@ -40,13 +123,10 @@ return: ; preds = %1 declare void @"println <:String>"(%String) -declare %String @string_from_c_string_and_length(ptr, i64) - -define private void @initialize() !dbg !15 { - %1 = alloca %DestructibleClass, align 8, !dbg !16 - %DestructibleClass.data = getelementptr inbounds %DestructibleClass, ptr %1, i32 0, i32 0, !dbg !16 - store ptr %1, ptr @x, align 8, !dbg !16 - br label %return, !dbg !16 +define private void @initialize.4() !dbg !31 { + %1 = alloca ptr, align 8, !dbg !32 + store ptr %1, ptr @x, align 8, !dbg !32 + br label %return, !dbg !32 return: ; preds = %0 ret void @@ -58,17 +138,33 @@ return: ; preds = %0 !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 4, column: 12, scope: !3) -!8 = !DILocation(line: 5, scope: !3) -!9 = !DILocation(line: 5, column: 4, scope: !3) -!10 = !DILocation(line: 7, column: 8, scope: !3) -!11 = !DILocation(line: 4, scope: !3) -!12 = distinct !DISubprogram(name: "destroy <:ReferenceMut>", linkageName: "destroy <:ReferenceMut>", scope: !3, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 2, column: 48, scope: !12) -!14 = !DILocation(line: 2, column: 40, scope: !12) -!15 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!16 = !DILocation(line: 4, column: 12, scope: !15) +!7 = !DILocation(line: 5, column: 16, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 9, column: 24, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 2, column: 39, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 2, column: 34, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 5, column: 16, scope: !18) +!20 = !DILocation(line: 9, column: 24, scope: !18) +!21 = !DILocation(line: 2, column: 39, scope: !18) +!22 = !DILocation(line: 2, column: 34, scope: !18) +!23 = !DILocation(line: 4, column: 12, scope: !18) +!24 = !DILocation(line: 5, scope: !18) +!25 = !DILocation(line: 5, column: 4, scope: !18) +!26 = !DILocation(line: 7, column: 8, scope: !18) +!27 = !DILocation(line: 4, scope: !18) +!28 = distinct !DISubprogram(name: "destroy <:ReferenceMut>", linkageName: "destroy <:ReferenceMut>", scope: !18, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!29 = !DILocation(line: 2, column: 48, scope: !28) +!30 = !DILocation(line: 2, column: 40, scope: !28) +!31 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !18, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!32 = !DILocation(line: 4, column: 12, scope: !31) diff --git a/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap b/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap index c5147026..cdd6516c 100644 --- a/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap +++ b/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap @@ -10,13 +10,13 @@ let a: A = A { } fn type of <$arg0: A> -> Type: - let $tmp@4483: Type = Type { name: "A", size: 8 } - return ($tmp@4483:Type) + let $tmp@4639: Type = (Type:Type) + return ($tmp@4639:Type) fn String from > -> String: - let $tmp@4358: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4358:String) + let $tmp@4514: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4514:String) fn println > -> None: diff --git a/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap b/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap index 2537bbf7..1884f5ff 100644 --- a/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap +++ b/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap @@ -5,43 +5,142 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%A = type { ptr } -%"Type" = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } -%"TypeImpl" = type { %String, %Integer } %Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@4 = private unnamed_addr constant [2 x i8] c"A\00", align 1 +@a = global ptr null + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 -@a = global %A zeroinitializer -@0 = private unnamed_addr constant [2 x i8] c"A\00", align 1 +return: ; preds = %0 + ret void +} -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - %1 = load %A, ptr @a, align 8, !dbg !8 - %2 = call %"Type" @"type of <:A>"(%A %1), !dbg !8 - call void @"println <:Type>"(%"Type" %2), !dbg !8 - br label %return, !dbg !8 +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 return: ; preds = %0 ret void } -define private void @initialize() !dbg !9 { - %1 = alloca %A, align 8, !dbg !10 - %A.data = getelementptr inbounds %A, ptr %1, i32 0, i32 0, !dbg !10 - store ptr %1, ptr @a, align 8, !dbg !10 - br label %return, !dbg !10 +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 return: ; preds = %0 ret void } -define private void @"println <:Type>"(%"Type" %0) !dbg !11 { +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define private void @initialize.4() !dbg !18 { + %1 = alloca %"Type", align 8, !dbg !19 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !19 + %2 = call %String @string_from_c_string_and_length(ptr @4, i64 1), !dbg !20 + store %String %2, ptr %"Type.name", align 8, !dbg !20 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !20 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !20 + store %Integer %3, ptr %"Type.size", align 8, !dbg !20 + %4 = load %"Type", ptr %1, align 8, !dbg !20 + store %"Type" %4, ptr @"Type", align 8, !dbg !20 + br label %return, !dbg !20 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !21 { + call void @initialize(), !dbg !22 + call void @initialize.1(), !dbg !22 + call void @initialize.2(), !dbg !22 + call void @initialize.3(), !dbg !22 + call void @initialize.4(), !dbg !22 + call void @initialize.5(), !dbg !23 + %1 = load ptr, ptr @a, align 8, !dbg !24 + %2 = call %"Type" @"type of <:A>"(ptr %1), !dbg !24 + call void @"println <:Type>"(%"Type" %2), !dbg !24 + br label %return, !dbg !24 + +return: ; preds = %0 + ret void +} + +define private void @initialize.5() !dbg !25 { + %1 = alloca ptr, align 8, !dbg !26 + store ptr %1, ptr @a, align 8, !dbg !26 + br label %return, !dbg !26 + +return: ; preds = %0 + ret void +} + +define private void @"println <:Type>"(%"Type" %0) !dbg !27 { %x = alloca %"Type", align 8 store %"Type" %0, ptr %x, align 8 - %2 = load %"Type", ptr %x, align 8, !dbg !12 - %3 = call %String @"String from <:Type>"(%"Type" %2), !dbg !12 - call void @"println <:String>"(%String %3), !dbg !12 - br label %return, !dbg !12 + %2 = load %"Type", ptr %x, align 8, !dbg !28 + %3 = call %String @"String from <:Type>"(%"Type" %2), !dbg !28 + call void @"println <:String>"(%String %3), !dbg !28 + br label %return, !dbg !28 return: ; preds = %1 ret void @@ -49,72 +148,74 @@ return: ; preds = %1 declare void @"println <:String>"(%String) -define private %String @"String from <:Type>"(%"Type" %0) !dbg !13 { +define private %String @"String from <:Type>"(%"Type" %0) !dbg !29 { %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !14 - %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !14 - %3 = call %String @clone_string(ptr %name), !dbg !14 - %"$tmp@4358" = alloca %String, align 8, !dbg !14 - store %String %3, ptr %"$tmp@4358", align 8, !dbg !14 - %4 = load %String, ptr %"$tmp@4358", align 8, !dbg !14 - store %String %4, ptr %return_value, align 8, !dbg !14 - br label %return, !dbg !14 + %name = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !30 + %2 = call %String @clone_string(ptr %name), !dbg !30 + %"$tmp@4514" = alloca %String, align 8, !dbg !30 + store %String %2, ptr %"$tmp@4514", align 8, !dbg !30 + %3 = load %String, ptr %"$tmp@4514", align 8, !dbg !30 + store %String %3, ptr %return_value, align 8, !dbg !30 + br label %return, !dbg !30 return: ; preds = %1 - %5 = load %String, ptr %return_value, align 8 - ret %String %5 + %4 = load %String, ptr %return_value, align 8 + ret %String %4 } declare %String @clone_string(ptr) -define private %"Type" @"type of <:A>"(%A %0) !dbg !15 { +define private %"Type" @"type of <:A>"(ptr %0) !dbg !31 { %return_value = alloca %"Type", align 8 - %"$arg0" = alloca %A, align 8 - store %A %0, ptr %"$arg0", align 8 - %2 = alloca %"Type", align 8, !dbg !16 - %"Type.data" = getelementptr inbounds %"Type", ptr %2, i32 0, i32 0, !dbg !16 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !16 - %3 = call %String @string_from_c_string_and_length(ptr @0, i64 1), !dbg !17 - store %String %3, ptr %"Type.name", align 8, !dbg !17 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !17 - %4 = call %Integer @integer_from_i64(i64 8), !dbg !17 - store %Integer %4, ptr %"Type.size", align 8, !dbg !17 - %5 = load %"Type", ptr %2, align 8, !dbg !17 - %"$tmp@4483" = alloca %"Type", align 8, !dbg !17 - store %"Type" %5, ptr %"$tmp@4483", align 8, !dbg !17 - %6 = load %"Type", ptr %"$tmp@4483", align 8, !dbg !16 - store %"Type" %6, ptr %return_value, align 8, !dbg !16 - br label %return, !dbg !16 + %"$arg0" = alloca ptr, align 8 + store ptr %0, ptr %"$arg0", align 8 + %2 = load %"Type", ptr @"Type", align 8, !dbg !32 + %"$tmp@4639" = alloca %"Type", align 8, !dbg !32 + store %"Type" %2, ptr %"$tmp@4639", align 8, !dbg !32 + %3 = load %"Type", ptr %"$tmp@4639", align 8, !dbg !32 + store %"Type" %3, ptr %return_value, align 8, !dbg !32 + br label %return, !dbg !32 return: ; preds = %1 - %7 = load %"Type", ptr %return_value, align 8 - ret %"Type" %7 + %4 = load %"Type", ptr %return_value, align 8 + ret %"Type" %4 } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - !llvm.module.flags = !{!0} !llvm.dbg.cu = !{!1} !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 1, column: 8, scope: !3) -!8 = !DILocation(line: 2, column: 19, scope: !3) -!9 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 1, column: 8, scope: !9) -!11 = distinct !DISubprogram(name: "println <:Type>", linkageName: "println <:Type>", scope: !3, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!12 = !DILocation(line: 2, column: 21, scope: !11) -!13 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !11, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!14 = !DILocation(line: 2, column: 21, scope: !13) -!15 = distinct !DISubprogram(name: "type of <:A>", linkageName: "type of <:A>", scope: !3, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!7 = !DILocation(line: 2, column: 21, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 2, column: 21, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 2, column: 21, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !16 = !DILocation(line: 2, column: 21, scope: !15) !17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 2, column: 21, scope: !18) +!20 = !DILocation(line: 0, scope: !18) +!21 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!22 = !DILocation(line: 2, column: 21, scope: !21) +!23 = !DILocation(line: 1, column: 8, scope: !21) +!24 = !DILocation(line: 2, column: 19, scope: !21) +!25 = distinct !DISubprogram(name: "initialize.5", linkageName: "initialize.5", scope: !21, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!26 = !DILocation(line: 1, column: 8, scope: !25) +!27 = distinct !DISubprogram(name: "println <:Type>", linkageName: "println <:Type>", scope: !21, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!28 = !DILocation(line: 2, column: 21, scope: !27) +!29 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !27, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!30 = !DILocation(line: 2, column: 21, scope: !29) +!31 = distinct !DISubprogram(name: "type of <:A>", linkageName: "type of <:A>", scope: !21, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!32 = !DILocation(line: 2, column: 21, scope: !31) diff --git a/src/tests/snapshots/ppl__tests__escaped_id.ir.snap b/src/tests/snapshots/ppl__tests__escaped_id.ir.snap index 08852644..c132f1fa 100644 --- a/src/tests/snapshots/ppl__tests__escaped_id.ir.snap +++ b/src/tests/snapshots/ppl__tests__escaped_id.ir.snap @@ -5,32 +5,115 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" +%"Type" = type { %String, %Integer } +%String = type { ptr } %Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 @if = global %Integer zeroinitializer -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - call void @destroy_integer(ptr @if), !dbg !8 - %1 = call %Integer @integer_from_i64(i64 2), !dbg !9 - store %Integer %1, ptr @if, align 8, !dbg !9 - call void @destroy_integer(ptr @if), !dbg !10 - br label %return, !dbg !10 +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 return: ; preds = %0 ret void } -define private void @initialize() !dbg !11 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !12 - store %Integer %1, ptr @if, align 8, !dbg !12 - br label %return, !dbg !12 +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 return: ; preds = %0 ret void } -declare %Integer @integer_from_i64(i64) +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !19 + call void @initialize.3(), !dbg !19 + call void @initialize.4(), !dbg !20 + call void @destroy_integer(ptr @if), !dbg !21 + %1 = call %Integer @integer_from_i64(i64 2), !dbg !22 + store %Integer %1, ptr @if, align 8, !dbg !22 + call void @destroy_integer(ptr @if), !dbg !23 + br label %return, !dbg !23 + +return: ; preds = %0 + ret void +} + +define private void @initialize.4() !dbg !24 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !25 + store %Integer %1, ptr @if, align 8, !dbg !25 + br label %return, !dbg !25 + +return: ; preds = %0 + ret void +} declare void @destroy_integer(ptr) @@ -40,13 +123,26 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 15, scope: !3) -!8 = !DILocation(line: 1, scope: !3) -!9 = !DILocation(line: 1, column: 7, scope: !3) -!10 = !DILocation(line: 0, scope: !3) -!11 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!12 = !DILocation(line: 0, column: 15, scope: !11) +!7 = !DILocation(line: 1, column: 8, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 1, column: 8, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 1, column: 8, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 1, column: 8, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 1, column: 8, scope: !18) +!20 = !DILocation(line: 0, column: 15, scope: !18) +!21 = !DILocation(line: 1, scope: !18) +!22 = !DILocation(line: 1, column: 7, scope: !18) +!23 = !DILocation(line: 0, scope: !18) +!24 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !18, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!25 = !DILocation(line: 0, column: 15, scope: !24) diff --git a/src/tests/snapshots/ppl__tests__generics.ir.snap b/src/tests/snapshots/ppl__tests__generics.ir.snap index 9856bdda..c4c1f103 100644 --- a/src/tests/snapshots/ppl__tests__generics.ir.snap +++ b/src/tests/snapshots/ppl__tests__generics.ir.snap @@ -5,87 +5,165 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Integer = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } -%"Point" = type { ptr } -%"PointImpl" = type { %Integer, %Integer } +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Point" = type { %Integer, %Integer } +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 @x = global %Integer zeroinitializer -@0 = private unnamed_addr constant [6 x i8] c"hello\00", align 1 - -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - %1 = call %Integer @clone_integer(ptr @x), !dbg !8 - %2 = call %Integer @integer_from_i64(i64 0), !dbg !9 - %3 = call i1 @integer_eq_integer(%Integer %1, %Integer %2), !dbg !9 - call void @"println <:Bool>"(i1 %3), !dbg !9 - %4 = call %Integer @integer_from_i64(i64 1), !dbg !10 - %5 = call %Integer @"id <:Integer>"(%Integer %4), !dbg !10 - %6 = call %Integer @integer_from_i64(i64 1), !dbg !11 - %7 = call i1 @integer_eq_integer(%Integer %5, %Integer %6), !dbg !11 - call void @"println <:Bool>"(i1 %7), !dbg !11 - %8 = call %String @string_from_c_string_and_length(ptr @0, i64 5), !dbg !12 - %9 = call %String @"id <:String>"(%String %8), !dbg !12 - call void @"println <:String>"(%String %9), !dbg !12 - %10 = alloca %"Point", align 8, !dbg !13 - %"Point.data" = getelementptr inbounds %"Point", ptr %10, i32 0, i32 0, !dbg !13 - %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !13 - %11 = call %Integer @integer_from_i64(i64 0), !dbg !14 - store %Integer %11, ptr %"Point.x", align 8, !dbg !14 - %"Point.y" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 1, !dbg !14 - %12 = call %Integer @integer_from_i64(i64 0), !dbg !15 - store %Integer %12, ptr %"Point.y", align 8, !dbg !15 - %13 = load %"Point", ptr %10, align 8, !dbg !15 - %14 = call %"Point" @"id <:Point>"(%"Point" %13), !dbg !15 - call void @destroy_integer(ptr @x), !dbg !16 - br label %return, !dbg !16 +@4 = private unnamed_addr constant [6 x i8] c"hello\00", align 1 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 return: ; preds = %0 ret void } -define private void @initialize() !dbg !17 { - %1 = alloca %"Point", align 8, !dbg !18 - %"Point.data" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !18 - %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !18 - %2 = call %Integer @integer_from_i64(i64 0), !dbg !19 - store %Integer %2, ptr %"Point.x", align 8, !dbg !19 - %"Point.y" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 1, !dbg !19 - %3 = call %Integer @integer_from_i64(i64 0), !dbg !20 - store %Integer %3, ptr %"Point.y", align 8, !dbg !20 - %4 = load %"Point", ptr %1, align 8, !dbg !20 - %5 = call %Integer @"x of <:Point>"(%"Point" %4), !dbg !20 - store %Integer %5, ptr @x, align 8, !dbg !20 - br label %return, !dbg !20 +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 return: ; preds = %0 ret void } -define private %Integer @"x of <:Point>"(%"Point" %0) !dbg !21 { +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !20 + call void @initialize.2(), !dbg !21 + call void @initialize.3(), !dbg !22 + call void @initialize.4(), !dbg !23 + %1 = call %Integer @clone_integer(ptr @x), !dbg !24 + %2 = call %Integer @integer_from_i64(i64 0), !dbg !25 + %3 = call i1 @integer_eq_integer(%Integer %1, %Integer %2), !dbg !25 + call void @"println <:Bool>"(i1 %3), !dbg !25 + %4 = call %Integer @integer_from_i64(i64 1), !dbg !26 + %5 = call %Integer @"id <:Integer>"(%Integer %4), !dbg !26 + %6 = call %Integer @integer_from_i64(i64 1), !dbg !27 + %7 = call i1 @integer_eq_integer(%Integer %5, %Integer %6), !dbg !27 + call void @"println <:Bool>"(i1 %7), !dbg !27 + %8 = call %String @string_from_c_string_and_length(ptr @4, i64 5), !dbg !28 + %9 = call %String @"id <:String>"(%String %8), !dbg !28 + call void @"println <:String>"(%String %9), !dbg !28 + %10 = alloca %"Point", align 8, !dbg !29 + %"Point.x" = getelementptr inbounds %"Point", ptr %10, i32 0, i32 0, !dbg !29 + %11 = call %Integer @integer_from_i64(i64 0), !dbg !30 + store %Integer %11, ptr %"Point.x", align 8, !dbg !30 + %"Point.y" = getelementptr inbounds %"Point", ptr %10, i32 0, i32 1, !dbg !30 + %12 = call %Integer @integer_from_i64(i64 0), !dbg !31 + store %Integer %12, ptr %"Point.y", align 8, !dbg !31 + %13 = load %"Point", ptr %10, align 8, !dbg !31 + %14 = call %"Point" @"id <:Point>"(%"Point" %13), !dbg !31 + call void @destroy_integer(ptr @x), !dbg !22 + br label %return, !dbg !22 + +return: ; preds = %0 + ret void +} + +define private void @initialize.4() !dbg !32 { + %1 = alloca %"Point", align 8, !dbg !33 + %"Point.x" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !33 + %2 = call %Integer @integer_from_i64(i64 0), !dbg !34 + store %Integer %2, ptr %"Point.x", align 8, !dbg !34 + %"Point.y" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 1, !dbg !34 + %3 = call %Integer @integer_from_i64(i64 0), !dbg !35 + store %Integer %3, ptr %"Point.y", align 8, !dbg !35 + %4 = load %"Point", ptr %1, align 8, !dbg !35 + %5 = call %Integer @"x of <:Point>"(%"Point" %4), !dbg !35 + store %Integer %5, ptr @x, align 8, !dbg !35 + br label %return, !dbg !35 + +return: ; preds = %0 + ret void +} + +define private %Integer @"x of <:Point>"(%"Point" %0) !dbg !36 { %return_value = alloca %Integer, align 8 %p = alloca %"Point", align 8 store %"Point" %0, ptr %p, align 8 - %2 = getelementptr inbounds %"Point", ptr %p, i32 0, i32 0, !dbg !22 - %x = getelementptr inbounds %"PointImpl", ptr %2, i32 0, i32 0, !dbg !22 - %3 = load %Integer, ptr %x, align 8, !dbg !22 - store %Integer %3, ptr %return_value, align 8, !dbg !22 - br label %return, !dbg !22 + %x = getelementptr inbounds %"Point", ptr %p, i32 0, i32 0, !dbg !37 + %2 = load %Integer, ptr %x, align 8, !dbg !37 + store %Integer %2, ptr %return_value, align 8, !dbg !37 + br label %return, !dbg !37 return: ; preds = %1 - %4 = load %Integer, ptr %return_value, align 8 - ret %Integer %4 + %3 = load %Integer, ptr %return_value, align 8 + ret %Integer %3 } -declare %Integer @integer_from_i64(i64) - -define private void @"println <:Bool>"(i1 %0) !dbg !23 { +define private void @"println <:Bool>"(i1 %0) !dbg !38 { %x = alloca i1, align 1 store i1 %0, ptr %x, align 1 - %2 = load i1, ptr %x, align 1, !dbg !24 - %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !24 - call void @"println <:String>"(%String %3), !dbg !24 - br label %return, !dbg !25 + %2 = load i1, ptr %x, align 1, !dbg !39 + %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !39 + call void @"println <:String>"(%String %3), !dbg !39 + br label %return, !dbg !40 return: ; preds = %1 ret void @@ -99,41 +177,39 @@ declare i1 @integer_eq_integer(%Integer, %Integer) declare %Integer @clone_integer(ptr) -define private %Integer @"id <:Integer>"(%Integer %0) !dbg !26 { +define private %Integer @"id <:Integer>"(%Integer %0) !dbg !41 { %return_value = alloca %Integer, align 8 %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !27 - store %Integer %2, ptr %return_value, align 8, !dbg !27 - br label %return, !dbg !27 + %2 = load %Integer, ptr %x, align 8, !dbg !42 + store %Integer %2, ptr %return_value, align 8, !dbg !42 + br label %return, !dbg !42 return: ; preds = %1 %3 = load %Integer, ptr %return_value, align 8 ret %Integer %3 } -define private %String @"id <:String>"(%String %0) !dbg !28 { +define private %String @"id <:String>"(%String %0) !dbg !43 { %return_value = alloca %String, align 8 %x = alloca %String, align 8 store %String %0, ptr %x, align 8 - %2 = load %String, ptr %x, align 8, !dbg !29 - store %String %2, ptr %return_value, align 8, !dbg !29 - br label %return, !dbg !29 + %2 = load %String, ptr %x, align 8, !dbg !44 + store %String %2, ptr %return_value, align 8, !dbg !44 + br label %return, !dbg !44 return: ; preds = %1 %3 = load %String, ptr %return_value, align 8 ret %String %3 } -declare %String @string_from_c_string_and_length(ptr, i64) - -define private %"Point" @"id <:Point>"(%"Point" %0) !dbg !30 { +define private %"Point" @"id <:Point>"(%"Point" %0) !dbg !45 { %return_value = alloca %"Point", align 8 %x = alloca %"Point", align 8 store %"Point" %0, ptr %x, align 8 - %2 = load %"Point", ptr %x, align 8, !dbg !31 - store %"Point" %2, ptr %return_value, align 8, !dbg !31 - br label %return, !dbg !31 + %2 = load %"Point", ptr %x, align 8, !dbg !46 + store %"Point" %2, ptr %return_value, align 8, !dbg !46 + br label %return, !dbg !46 return: ; preds = %1 %3 = load %"Point", ptr %return_value, align 8 @@ -148,32 +224,47 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 10, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 5, column: 8, scope: !3) -!8 = !DILocation(line: 6, column: 8, scope: !3) -!9 = !DILocation(line: 6, column: 13, scope: !3) -!10 = !DILocation(line: 10, column: 12, scope: !3) -!11 = !DILocation(line: 10, column: 18, scope: !3) -!12 = !DILocation(line: 11, column: 12, scope: !3) -!13 = !DILocation(line: 12, column: 3, scope: !3) -!14 = !DILocation(line: 12, column: 14, scope: !3) -!15 = !DILocation(line: 12, column: 20, scope: !3) -!16 = !DILocation(line: 5, scope: !3) -!17 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!18 = !DILocation(line: 5, column: 13, scope: !17) -!19 = !DILocation(line: 5, column: 24, scope: !17) -!20 = !DILocation(line: 5, column: 30, scope: !17) -!21 = distinct !DISubprogram(name: "x of <:Point>", linkageName: "x of <:Point>", scope: !17, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!22 = !DILocation(line: 3, column: 28, scope: !21) -!23 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !3, file: !2, line: 11, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!24 = !DILocation(line: 13, scope: !23) -!25 = !DILocation(line: 12, column: 5, scope: !23) -!26 = distinct !DISubprogram(name: "id <:Integer>", linkageName: "id <:Integer>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!27 = !DILocation(line: 8, column: 19, scope: !26) -!28 = distinct !DISubprogram(name: "id <:String>", linkageName: "id <:String>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!29 = !DILocation(line: 8, column: 19, scope: !28) -!30 = distinct !DISubprogram(name: "id <:Point>", linkageName: "id <:Point>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!31 = !DILocation(line: 8, column: 19, scope: !30) +!7 = !DILocation(line: 10, column: 5, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 13, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 13, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 5, column: 5, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 5, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 10, column: 5, scope: !18) +!20 = !DILocation(line: 13, scope: !18) +!21 = !DILocation(line: 5, column: 5, scope: !18) +!22 = !DILocation(line: 5, scope: !18) +!23 = !DILocation(line: 5, column: 8, scope: !18) +!24 = !DILocation(line: 6, column: 8, scope: !18) +!25 = !DILocation(line: 6, column: 13, scope: !18) +!26 = !DILocation(line: 10, column: 12, scope: !18) +!27 = !DILocation(line: 10, column: 18, scope: !18) +!28 = !DILocation(line: 11, column: 12, scope: !18) +!29 = !DILocation(line: 12, column: 3, scope: !18) +!30 = !DILocation(line: 12, column: 14, scope: !18) +!31 = !DILocation(line: 12, column: 20, scope: !18) +!32 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !18, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!33 = !DILocation(line: 5, column: 13, scope: !32) +!34 = !DILocation(line: 5, column: 24, scope: !32) +!35 = !DILocation(line: 5, column: 30, scope: !32) +!36 = distinct !DISubprogram(name: "x of <:Point>", linkageName: "x of <:Point>", scope: !32, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!37 = !DILocation(line: 3, column: 28, scope: !36) +!38 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !18, file: !2, line: 11, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!39 = !DILocation(line: 13, scope: !38) +!40 = !DILocation(line: 12, column: 5, scope: !38) +!41 = distinct !DISubprogram(name: "id <:Integer>", linkageName: "id <:Integer>", scope: !18, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!42 = !DILocation(line: 8, column: 19, scope: !41) +!43 = distinct !DISubprogram(name: "id <:String>", linkageName: "id <:String>", scope: !18, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!44 = !DILocation(line: 8, column: 19, scope: !43) +!45 = distinct !DISubprogram(name: "id <:Point>", linkageName: "id <:Point>", scope: !18, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!46 = !DILocation(line: 8, column: 19, scope: !45) diff --git a/src/tests/snapshots/ppl__tests__import_all.ir.snap b/src/tests/snapshots/ppl__tests__import_all.ir.snap index d2f91541..939206cf 100644 --- a/src/tests/snapshots/ppl__tests__import_all.ir.snap +++ b/src/tests/snapshots/ppl__tests__import_all.ir.snap @@ -5,24 +5,109 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Integer = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } -define void @main.execute() !dbg !3 { - call void @"do nothing"(), !dbg !7 - call void @"println <:None>"(), !dbg !7 - %1 = call %Integer @"do something"(), !dbg !8 - call void @"println <:Integer>"(%Integer %1), !dbg !8 +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 br label %return, !dbg !8 return: ; preds = %0 ret void } -define private void @"println <:None>"() !dbg !9 { - %1 = call %String @"String from <:None>"(), !dbg !10 - call void @"println <:String>"(%String %1), !dbg !10 - br label %return, !dbg !10 +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !19 + call void @initialize.3(), !dbg !19 + call void @"do nothing"(), !dbg !20 + call void @"println <:None>"(), !dbg !20 + %1 = call %Integer @"do something"(), !dbg !21 + call void @"println <:Integer>"(%Integer %1), !dbg !21 + br label %return, !dbg !21 + +return: ; preds = %0 + ret void +} + +define private void @"println <:None>"() !dbg !22 { + %1 = call %String @"String from <:None>"(), !dbg !23 + call void @"println <:String>"(%String %1), !dbg !23 + br label %return, !dbg !23 return: ; preds = %0 ret void @@ -34,13 +119,13 @@ declare %String @"String from <:None>"() declare void @"do nothing"() -define private void @"println <:Integer>"(%Integer %0) !dbg !11 { +define private void @"println <:Integer>"(%Integer %0) !dbg !24 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !12 - %3 = call %String @integer_as_string(%Integer %2), !dbg !12 - call void @"println <:String>"(%String %3), !dbg !12 - br label %return, !dbg !12 + %2 = load %Integer, ptr %x, align 8, !dbg !25 + %3 = call %String @integer_as_string(%Integer %2), !dbg !25 + call void @"println <:String>"(%String %3), !dbg !25 + br label %return, !dbg !25 return: ; preds = %1 ret void @@ -56,13 +141,26 @@ declare %Integer @"do something"() !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 2, column: 9, scope: !3) -!8 = !DILocation(line: 3, column: 9, scope: !3) -!9 = distinct !DISubprogram(name: "println <:None>", linkageName: "println <:None>", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!7 = !DILocation(line: 3, column: 22, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) !10 = !DILocation(line: 3, column: 22, scope: !9) -!11 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!12 = !DILocation(line: 3, column: 22, scope: !11) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 3, column: 22, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 3, column: 22, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 3, column: 22, scope: !18) +!20 = !DILocation(line: 2, column: 9, scope: !18) +!21 = !DILocation(line: 3, column: 9, scope: !18) +!22 = distinct !DISubprogram(name: "println <:None>", linkageName: "println <:None>", scope: !18, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!23 = !DILocation(line: 3, column: 22, scope: !22) +!24 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !18, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!25 = !DILocation(line: 3, column: 22, scope: !24) diff --git a/src/tests/snapshots/ppl__tests__integer.hir.snap b/src/tests/snapshots/ppl__tests__integer.hir.snap index fb500dbf..dd0260e9 100644 --- a/src/tests/snapshots/ppl__tests__integer.hir.snap +++ b/src/tests/snapshots/ppl__tests__integer.hir.snap @@ -2,7 +2,7 @@ source: src/tests/mod.rs expression: hir --- -`println <:Integer>`(`default <:Type>`(Type { name: "Integer", size: 8 })) +`println <:Integer>`(`default <:Type>`((Type:Type))) `println <:Integer>`(`+ <:Integer>`(1)) `println <:Integer>`(`- <:Integer>`(2)) `println <:Integer>`(`<:Integer> + <:Integer>`(2, 1)) diff --git a/src/tests/snapshots/ppl__tests__integer.ir.snap b/src/tests/snapshots/ppl__tests__integer.ir.snap index 8ea555fc..7fe8e5e3 100644 --- a/src/tests/snapshots/ppl__tests__integer.ir.snap +++ b/src/tests/snapshots/ppl__tests__integer.ir.snap @@ -5,65 +5,158 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } +%"Type" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } %Rational = type { ptr } -@0 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 - -define void @main.execute() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 7), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@4 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - %5 = call %Integer @"default <:Type>"(%"Type" %4), !dbg !8 - call void @"println <:Integer>"(%Integer %5), !dbg !8 - %6 = call %Integer @integer_from_i64(i64 1), !dbg !9 - %7 = call %Integer @"+ <:Integer>"(%Integer %6), !dbg !9 - call void @"println <:Integer>"(%Integer %7), !dbg !9 - %8 = call %Integer @integer_from_i64(i64 2), !dbg !10 - %9 = call %Integer @minus_integer(%Integer %8), !dbg !10 - call void @"println <:Integer>"(%Integer %9), !dbg !10 - %10 = call %Integer @integer_from_i64(i64 2), !dbg !11 - %11 = call %Integer @integer_from_i64(i64 1), !dbg !12 - %12 = call %Integer @integer_plus_integer(%Integer %10, %Integer %11), !dbg !12 - call void @"println <:Integer>"(%Integer %12), !dbg !12 - %13 = call %Integer @integer_from_i64(i64 2), !dbg !13 - %14 = call %Integer @integer_from_i64(i64 2), !dbg !14 - %15 = call %Integer @integer_power_integer(%Integer %13, %Integer %14), !dbg !14 - call void @"println <:Integer>"(%Integer %15), !dbg !14 - %16 = call %Integer @integer_from_i64(i64 5), !dbg !15 - %17 = call %Integer @integer_from_i64(i64 0), !dbg !16 - %18 = call %Integer @"<:Integer> - <:Integer>"(%Integer %16, %Integer %17), !dbg !16 - call void @"println <:Integer>"(%Integer %18), !dbg !16 - %19 = call %Integer @integer_from_i64(i64 2), !dbg !17 - %20 = call %Integer @integer_from_i64(i64 3), !dbg !18 - %21 = call %Integer @integer_star_integer(%Integer %19, %Integer %20), !dbg !18 - call void @"println <:Integer>"(%Integer %21), !dbg !18 - %22 = call %Integer @integer_from_i64(i64 14), !dbg !19 - %23 = call %Integer @integer_from_i64(i64 2), !dbg !20 - %24 = call %Rational @integer_slash_integer(%Integer %22, %Integer %23), !dbg !20 - call void @"println <:Rational>"(%Rational %24), !dbg !20 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define private void @initialize.4() !dbg !18 { + %1 = alloca %"Type", align 8, !dbg !19 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !19 + %2 = call %String @string_from_c_string_and_length(ptr @4, i64 7), !dbg !20 + store %String %2, ptr %"Type.name", align 8, !dbg !20 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !20 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !20 + store %Integer %3, ptr %"Type.size", align 8, !dbg !20 + %4 = load %"Type", ptr %1, align 8, !dbg !20 + store %"Type" %4, ptr @"Type", align 8, !dbg !20 br label %return, !dbg !20 return: ; preds = %0 ret void } -define private void @"println <:Integer>"(%Integer %0) !dbg !21 { +define void @main.execute() !dbg !21 { + call void @initialize(), !dbg !22 + call void @initialize.1(), !dbg !22 + call void @initialize.2(), !dbg !23 + call void @initialize.3(), !dbg !24 + call void @initialize.4(), !dbg !25 + %1 = load %"Type", ptr @"Type", align 8, !dbg !25 + %2 = call %Integer @"default <:Type>"(%"Type" %1), !dbg !25 + call void @"println <:Integer>"(%Integer %2), !dbg !25 + %3 = call %Integer @integer_from_i64(i64 1), !dbg !26 + %4 = call %Integer @"+ <:Integer>"(%Integer %3), !dbg !26 + call void @"println <:Integer>"(%Integer %4), !dbg !26 + %5 = call %Integer @integer_from_i64(i64 2), !dbg !27 + %6 = call %Integer @minus_integer(%Integer %5), !dbg !27 + call void @"println <:Integer>"(%Integer %6), !dbg !27 + %7 = call %Integer @integer_from_i64(i64 2), !dbg !28 + %8 = call %Integer @integer_from_i64(i64 1), !dbg !29 + %9 = call %Integer @integer_plus_integer(%Integer %7, %Integer %8), !dbg !29 + call void @"println <:Integer>"(%Integer %9), !dbg !29 + %10 = call %Integer @integer_from_i64(i64 2), !dbg !30 + %11 = call %Integer @integer_from_i64(i64 2), !dbg !31 + %12 = call %Integer @integer_power_integer(%Integer %10, %Integer %11), !dbg !31 + call void @"println <:Integer>"(%Integer %12), !dbg !31 + %13 = call %Integer @integer_from_i64(i64 5), !dbg !32 + %14 = call %Integer @integer_from_i64(i64 0), !dbg !33 + %15 = call %Integer @"<:Integer> - <:Integer>"(%Integer %13, %Integer %14), !dbg !33 + call void @"println <:Integer>"(%Integer %15), !dbg !33 + %16 = call %Integer @integer_from_i64(i64 2), !dbg !34 + %17 = call %Integer @integer_from_i64(i64 3), !dbg !35 + %18 = call %Integer @integer_star_integer(%Integer %16, %Integer %17), !dbg !35 + call void @"println <:Integer>"(%Integer %18), !dbg !35 + %19 = call %Integer @integer_from_i64(i64 14), !dbg !36 + %20 = call %Integer @integer_from_i64(i64 2), !dbg !37 + %21 = call %Rational @integer_slash_integer(%Integer %19, %Integer %20), !dbg !37 + call void @"println <:Rational>"(%Rational %21), !dbg !37 + br label %return, !dbg !37 + +return: ; preds = %0 + ret void +} + +define private void @"println <:Integer>"(%Integer %0) !dbg !38 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !22 - %3 = call %String @integer_as_string(%Integer %2), !dbg !22 - call void @"println <:String>"(%String %3), !dbg !22 - br label %return, !dbg !22 + %2 = load %Integer, ptr %x, align 8, !dbg !39 + %3 = call %String @integer_as_string(%Integer %2), !dbg !39 + call void @"println <:String>"(%String %3), !dbg !39 + br label %return, !dbg !39 return: ; preds = %1 ret void @@ -75,10 +168,6 @@ declare %String @integer_as_string(%Integer) declare %Integer @"default <:Type>"(%"Type") -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - declare %Integer @"+ <:Integer>"(%Integer) declare %Integer @minus_integer(%Integer) @@ -91,13 +180,13 @@ declare %Integer @"<:Integer> - <:Integer>"(%Integer, %Integer) declare %Integer @integer_star_integer(%Integer, %Integer) -define private void @"println <:Rational>"(%Rational %0) !dbg !23 { +define private void @"println <:Rational>"(%Rational %0) !dbg !40 { %x = alloca %Rational, align 8 store %Rational %0, ptr %x, align 8 - %2 = load %Rational, ptr %x, align 8, !dbg !24 - %3 = call %String @rational_as_string(%Rational %2), !dbg !24 - call void @"println <:String>"(%String %3), !dbg !24 - br label %return, !dbg !24 + %2 = load %Rational, ptr %x, align 8, !dbg !41 + %3 = call %String @rational_as_string(%Rational %2), !dbg !41 + call void @"println <:String>"(%String %3), !dbg !41 + br label %return, !dbg !41 return: ; preds = %1 ret void @@ -113,25 +202,42 @@ declare %Rational @integer_slash_integer(%Integer, %Integer) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 17, scope: !3) +!7 = !DILocation(line: 7, column: 14, scope: !3) !8 = !DILocation(line: 0, scope: !3) -!9 = !DILocation(line: 1, column: 9, scope: !3) -!10 = !DILocation(line: 2, column: 9, scope: !3) -!11 = !DILocation(line: 3, column: 8, scope: !3) -!12 = !DILocation(line: 3, column: 12, scope: !3) -!13 = !DILocation(line: 4, column: 8, scope: !3) -!14 = !DILocation(line: 4, column: 12, scope: !3) -!15 = !DILocation(line: 5, column: 8, scope: !3) -!16 = !DILocation(line: 5, column: 12, scope: !3) -!17 = !DILocation(line: 6, column: 8, scope: !3) -!18 = !DILocation(line: 6, column: 12, scope: !3) -!19 = !DILocation(line: 7, column: 8, scope: !3) -!20 = !DILocation(line: 7, column: 13, scope: !3) -!21 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 7, column: 14, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 4, column: 1, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 3, column: 10, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 0, column: 17, scope: !18) +!20 = !DILocation(line: 0, scope: !18) +!21 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !22 = !DILocation(line: 7, column: 14, scope: !21) -!23 = distinct !DISubprogram(name: "println <:Rational>", linkageName: "println <:Rational>", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!24 = !DILocation(line: 7, column: 14, scope: !23) +!23 = !DILocation(line: 4, column: 1, scope: !21) +!24 = !DILocation(line: 3, column: 10, scope: !21) +!25 = !DILocation(line: 0, column: 17, scope: !21) +!26 = !DILocation(line: 1, column: 9, scope: !21) +!27 = !DILocation(line: 2, column: 9, scope: !21) +!28 = !DILocation(line: 3, column: 8, scope: !21) +!29 = !DILocation(line: 3, column: 12, scope: !21) +!30 = !DILocation(line: 4, column: 8, scope: !21) +!31 = !DILocation(line: 4, column: 12, scope: !21) +!32 = !DILocation(line: 5, column: 8, scope: !21) +!33 = !DILocation(line: 5, column: 12, scope: !21) +!34 = !DILocation(line: 6, column: 8, scope: !21) +!35 = !DILocation(line: 6, column: 12, scope: !21) +!36 = !DILocation(line: 7, column: 8, scope: !21) +!37 = !DILocation(line: 7, column: 13, scope: !21) +!38 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !21, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!39 = !DILocation(line: 7, column: 14, scope: !38) +!40 = distinct !DISubprogram(name: "println <:Rational>", linkageName: "println <:Rational>", scope: !21, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!41 = !DILocation(line: 7, column: 14, scope: !40) diff --git a/src/tests/snapshots/ppl__tests__memory.hir.snap b/src/tests/snapshots/ppl__tests__memory.hir.snap index 28c35cd6..7a3f8be6 100644 --- a/src/tests/snapshots/ppl__tests__memory.hir.snap +++ b/src/tests/snapshots/ppl__tests__memory.hir.snap @@ -2,8 +2,8 @@ source: src/tests/mod.rs expression: hir --- -let address: MemoryAddress = `allocate <:Integer> <:Type>`(1, Type { name: "Integer", size: 8 }) -let x: ReferenceMut = `<:Type> at <:Reference>`(Type { name: "Integer", size: 8 }, (&address:Reference)) +let address: MemoryAddress = `allocate <:Integer> <:Type>`(1, (Type:Type)) +let x: ReferenceMut = `<:Type> at <:Reference>`((Type:Type), (&address:Reference)) (x:ReferenceMut) = 0 `println <:Integer>`(`clone <:Reference>`((*x:Integer))) (x:ReferenceMut) = 1 @@ -13,14 +13,14 @@ let x: ReferenceMut = `<:Type> at <:Reference>` fn size of > -> Integer: - let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4426:Integer) + let $tmp@4582: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4582:Integer) fn allocate <$arg1: Type> -> MemoryAddress: - let $tmp@760: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`(Type { name: "Integer", size: 8 }))) + let $tmp@825: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`((Type:Type)))) `destroy <:ReferenceMut>`((n:Integer)) - return ($tmp@760:MemoryAddress) + return ($tmp@825:MemoryAddress) @mangle_as("read_memory") diff --git a/src/tests/snapshots/ppl__tests__memory.ir.snap b/src/tests/snapshots/ppl__tests__memory.ir.snap index 3105689c..5decea5b 100644 --- a/src/tests/snapshots/ppl__tests__memory.ir.snap +++ b/src/tests/snapshots/ppl__tests__memory.ir.snap @@ -5,87 +5,170 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%MemoryAddress = type { ptr } -%Integer = type { ptr } -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } +%"Type" = type { %String, %Integer } %String = type { ptr } +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%MemoryAddress = type { %Integer } +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@4 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 @address = global %MemoryAddress zeroinitializer -@0 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 -@1 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 @x = global ptr null -@2 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 - -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - call void @initialize.1(), !dbg !8 - %1 = load ptr, ptr @x, align 8, !dbg !9 - %2 = call %Integer @integer_from_i64(i64 0), !dbg !10 - store %Integer %2, ptr %1, align 8, !dbg !10 - %3 = load ptr, ptr @x, align 8, !dbg !11 - %4 = call %Integer @clone_integer(ptr %3), !dbg !11 - call void @"println <:Integer>"(%Integer %4), !dbg !11 - %5 = load ptr, ptr @x, align 8, !dbg !12 - %6 = call %Integer @integer_from_i64(i64 1), !dbg !13 - store %Integer %6, ptr %5, align 8, !dbg !13 - %7 = load ptr, ptr @x, align 8, !dbg !14 - %8 = call %Integer @clone_integer(ptr %7), !dbg !14 - call void @"println <:Integer>"(%Integer %8), !dbg !14 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 br label %return, !dbg !14 return: ; preds = %0 ret void } -define private void @initialize() !dbg !15 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !16 - %2 = alloca %"Type", align 8, !dbg !17 - %"Type.data" = getelementptr inbounds %"Type", ptr %2, i32 0, i32 0, !dbg !17 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !17 - %3 = call %String @string_from_c_string_and_length(ptr @1, i64 7), !dbg !18 - store %String %3, ptr %"Type.name", align 8, !dbg !18 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !18 - %4 = call %Integer @integer_from_i64(i64 8), !dbg !18 - store %Integer %4, ptr %"Type.size", align 8, !dbg !18 - %5 = load %"Type", ptr %2, align 8, !dbg !18 - %6 = call %MemoryAddress @"allocate <:Integer> <:Type>"(%Integer %1, %"Type" %5), !dbg !18 - store %MemoryAddress %6, ptr @address, align 8, !dbg !18 - br label %return, !dbg !18 +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define private void @initialize.4() !dbg !18 { + %1 = alloca %"Type", align 8, !dbg !19 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !19 + %2 = call %String @string_from_c_string_and_length(ptr @4, i64 7), !dbg !20 + store %String %2, ptr %"Type.name", align 8, !dbg !20 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !20 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !20 + store %Integer %3, ptr %"Type.size", align 8, !dbg !20 + %4 = load %"Type", ptr %1, align 8, !dbg !20 + store %"Type" %4, ptr @"Type", align 8, !dbg !20 + br label %return, !dbg !20 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !21 { + call void @initialize(), !dbg !22 + call void @initialize.1(), !dbg !22 + call void @initialize.2(), !dbg !23 + call void @initialize.3(), !dbg !24 + call void @initialize.4(), !dbg !25 + call void @initialize.5(), !dbg !26 + call void @initialize.6(), !dbg !27 + %1 = load ptr, ptr @x, align 8, !dbg !28 + %2 = call %Integer @integer_from_i64(i64 0), !dbg !29 + store %Integer %2, ptr %1, align 8, !dbg !29 + %3 = load ptr, ptr @x, align 8, !dbg !30 + %4 = call %Integer @clone_integer(ptr %3), !dbg !30 + call void @"println <:Integer>"(%Integer %4), !dbg !30 + %5 = load ptr, ptr @x, align 8, !dbg !31 + %6 = call %Integer @integer_from_i64(i64 1), !dbg !32 + store %Integer %6, ptr %5, align 8, !dbg !32 + %7 = load ptr, ptr @x, align 8, !dbg !33 + %8 = call %Integer @clone_integer(ptr %7), !dbg !33 + call void @"println <:Integer>"(%Integer %8), !dbg !33 + br label %return, !dbg !33 return: ; preds = %0 ret void } -define private %MemoryAddress @"allocate <:Integer> <:Type>"(%Integer %0, %"Type" %1) !dbg !19 { +define private void @initialize.5() !dbg !34 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !35 + %2 = load %"Type", ptr @"Type", align 8, !dbg !36 + %3 = call %MemoryAddress @"allocate <:Integer> <:Type>"(%Integer %1, %"Type" %2), !dbg !36 + store %MemoryAddress %3, ptr @address, align 8, !dbg !36 + br label %return, !dbg !36 + +return: ; preds = %0 + ret void +} + +define private %MemoryAddress @"allocate <:Integer> <:Type>"(%Integer %0, %"Type" %1) !dbg !37 { %return_value = alloca %MemoryAddress, align 8 %n = alloca %Integer, align 8 store %Integer %0, ptr %n, align 8 %"$arg1" = alloca %"Type", align 8 store %"Type" %1, ptr %"$arg1", align 8 - %3 = call %Integer @clone_integer(ptr %n), !dbg !20 - %4 = alloca %"Type", align 8, !dbg !20 - %"Type.data" = getelementptr inbounds %"Type", ptr %4, i32 0, i32 0, !dbg !20 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !20 - %5 = call %String @string_from_c_string_and_length(ptr @0, i64 7), !dbg !21 - store %String %5, ptr %"Type.name", align 8, !dbg !21 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !21 - %6 = call %Integer @integer_from_i64(i64 8), !dbg !21 - store %Integer %6, ptr %"Type.size", align 8, !dbg !21 - %7 = load %"Type", ptr %4, align 8, !dbg !21 - %8 = call %Integer @"size of <:Type>"(%"Type" %7), !dbg !21 - %9 = call %Integer @integer_star_integer(%Integer %3, %Integer %8), !dbg !21 - %10 = call %MemoryAddress @allocate_n_bytes(%Integer %9), !dbg !21 - %"$tmp@760" = alloca %MemoryAddress, align 8, !dbg !21 - store %MemoryAddress %10, ptr %"$tmp@760", align 8, !dbg !21 - call void @destroy_integer(ptr %n), !dbg !20 - %11 = load %MemoryAddress, ptr %"$tmp@760", align 8, !dbg !20 - store %MemoryAddress %11, ptr %return_value, align 8, !dbg !20 - br label %return, !dbg !20 + %3 = call %Integer @clone_integer(ptr %n), !dbg !38 + %4 = load %"Type", ptr @"Type", align 8, !dbg !38 + %5 = call %Integer @"size of <:Type>"(%"Type" %4), !dbg !38 + %6 = call %Integer @integer_star_integer(%Integer %3, %Integer %5), !dbg !38 + %7 = call %MemoryAddress @allocate_n_bytes(%Integer %6), !dbg !38 + %"$tmp@825" = alloca %MemoryAddress, align 8, !dbg !38 + store %MemoryAddress %7, ptr %"$tmp@825", align 8, !dbg !38 + call void @destroy_integer(ptr %n), !dbg !38 + %8 = load %MemoryAddress, ptr %"$tmp@825", align 8, !dbg !38 + store %MemoryAddress %8, ptr %return_value, align 8, !dbg !38 + br label %return, !dbg !38 return: ; preds = %2 - %12 = load %MemoryAddress, ptr %return_value, align 8 - ret %MemoryAddress %12 + %9 = load %MemoryAddress, ptr %return_value, align 8 + ret %MemoryAddress %9 } declare %MemoryAddress @allocate_n_bytes(%Integer) @@ -94,43 +177,30 @@ declare %Integer @integer_star_integer(%Integer, %Integer) declare %Integer @clone_integer(ptr) -define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !22 { +define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !39 { %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !23 - %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !23 - %3 = call %Integer @clone_integer(ptr %size), !dbg !23 - %"$tmp@4426" = alloca %Integer, align 8, !dbg !23 - store %Integer %3, ptr %"$tmp@4426", align 8, !dbg !23 - %4 = load %Integer, ptr %"$tmp@4426", align 8, !dbg !23 - store %Integer %4, ptr %return_value, align 8, !dbg !23 - br label %return, !dbg !23 + %size = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 1, !dbg !40 + %2 = call %Integer @clone_integer(ptr %size), !dbg !40 + %"$tmp@4582" = alloca %Integer, align 8, !dbg !40 + store %Integer %2, ptr %"$tmp@4582", align 8, !dbg !40 + %3 = load %Integer, ptr %"$tmp@4582", align 8, !dbg !40 + store %Integer %3, ptr %return_value, align 8, !dbg !40 + br label %return, !dbg !40 return: ; preds = %1 - %5 = load %Integer, ptr %return_value, align 8 - ret %Integer %5 + %4 = load %Integer, ptr %return_value, align 8 + ret %Integer %4 } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - declare void @destroy_integer(ptr) -define private void @initialize.1() !dbg !24 { - %1 = alloca %"Type", align 8, !dbg !25 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !25 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !25 - %2 = call %String @string_from_c_string_and_length(ptr @2, i64 7), !dbg !26 - store %String %2, ptr %"Type.name", align 8, !dbg !26 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !26 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !26 - store %Integer %3, ptr %"Type.size", align 8, !dbg !26 - %4 = load %"Type", ptr %1, align 8, !dbg !26 - %5 = call ptr @read_memory(%"Type" %4, ptr @address), !dbg !27 - store ptr %5, ptr @x, align 8, !dbg !27 - br label %return, !dbg !27 +define private void @initialize.6() !dbg !41 { + %1 = load %"Type", ptr @"Type", align 8, !dbg !42 + %2 = call ptr @read_memory(%"Type" %1, ptr @address), !dbg !43 + store ptr %2, ptr @x, align 8, !dbg !43 + br label %return, !dbg !43 return: ; preds = %0 ret void @@ -138,13 +208,13 @@ return: ; preds = %0 declare ptr @read_memory(%"Type", ptr) -define private void @"println <:Integer>"(%Integer %0) !dbg !28 { +define private void @"println <:Integer>"(%Integer %0) !dbg !44 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !29 - %3 = call %String @integer_as_string(%Integer %2), !dbg !29 - call void @"println <:String>"(%String %3), !dbg !29 - br label %return, !dbg !29 + %2 = load %Integer, ptr %x, align 8, !dbg !45 + %3 = call %String @integer_as_string(%Integer %2), !dbg !45 + call void @"println <:String>"(%String %3), !dbg !45 + br label %return, !dbg !45 return: ; preds = %1 ret void @@ -160,30 +230,46 @@ declare %String @integer_as_string(%Integer) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 14, scope: !3) -!8 = !DILocation(line: 1, column: 8, scope: !3) -!9 = !DILocation(line: 2, scope: !3) -!10 = !DILocation(line: 2, column: 4, scope: !3) -!11 = !DILocation(line: 3, column: 8, scope: !3) -!12 = !DILocation(line: 4, scope: !3) -!13 = !DILocation(line: 4, column: 4, scope: !3) -!14 = !DILocation(line: 5, column: 8, scope: !3) -!15 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!16 = !DILocation(line: 0, column: 23, scope: !15) -!17 = !DILocation(line: 0, column: 25, scope: !15) -!18 = !DILocation(line: 0, scope: !15) -!19 = distinct !DISubprogram(name: "allocate <:Integer> <:Type>", linkageName: "allocate <:Integer> <:Type>", scope: !15, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!20 = !DILocation(line: 5, column: 9, scope: !19) -!21 = !DILocation(line: 0, scope: !19) -!22 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !19, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!23 = !DILocation(line: 5, column: 9, scope: !22) -!24 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!25 = !DILocation(line: 1, column: 8, scope: !24) -!26 = !DILocation(line: 0, scope: !24) -!27 = !DILocation(line: 1, column: 19, scope: !24) -!28 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!29 = !DILocation(line: 5, column: 9, scope: !28) +!7 = !DILocation(line: 5, column: 9, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 5, column: 9, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 2, column: 3, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 1, column: 25, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 0, column: 25, scope: !18) +!20 = !DILocation(line: 0, scope: !18) +!21 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!22 = !DILocation(line: 5, column: 9, scope: !21) +!23 = !DILocation(line: 2, column: 3, scope: !21) +!24 = !DILocation(line: 1, column: 25, scope: !21) +!25 = !DILocation(line: 0, column: 25, scope: !21) +!26 = !DILocation(line: 0, column: 14, scope: !21) +!27 = !DILocation(line: 1, column: 8, scope: !21) +!28 = !DILocation(line: 2, scope: !21) +!29 = !DILocation(line: 2, column: 4, scope: !21) +!30 = !DILocation(line: 3, column: 8, scope: !21) +!31 = !DILocation(line: 4, scope: !21) +!32 = !DILocation(line: 4, column: 4, scope: !21) +!33 = !DILocation(line: 5, column: 8, scope: !21) +!34 = distinct !DISubprogram(name: "initialize.5", linkageName: "initialize.5", scope: !21, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!35 = !DILocation(line: 0, column: 23, scope: !34) +!36 = !DILocation(line: 0, column: 25, scope: !34) +!37 = distinct !DISubprogram(name: "allocate <:Integer> <:Type>", linkageName: "allocate <:Integer> <:Type>", scope: !34, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!38 = !DILocation(line: 5, column: 9, scope: !37) +!39 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !37, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!40 = !DILocation(line: 5, column: 9, scope: !39) +!41 = distinct !DISubprogram(name: "initialize.6", linkageName: "initialize.6", scope: !21, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!42 = !DILocation(line: 1, column: 8, scope: !41) +!43 = !DILocation(line: 1, column: 19, scope: !41) +!44 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !21, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!45 = !DILocation(line: 5, column: 9, scope: !44) diff --git a/src/tests/snapshots/ppl__tests__monomorphize.ir.snap b/src/tests/snapshots/ppl__tests__monomorphize.ir.snap index f9b7853b..4fa28dae 100644 --- a/src/tests/snapshots/ppl__tests__monomorphize.ir.snap +++ b/src/tests/snapshots/ppl__tests__monomorphize.ir.snap @@ -5,65 +5,145 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Point" = type { ptr } -%Integer = type { ptr } -%"PointImpl" = type { %Integer, %Integer } +%"Type" = type { %String, %Integer } %String = type { ptr } - +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Point" = type { %Integer, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 @p = global %"Point" zeroinitializer @x = global %Integer zeroinitializer -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - call void @initialize.1(), !dbg !8 - %1 = call %Integer @clone_integer(ptr @x), !dbg !9 - %2 = call %Integer @integer_from_i64(i64 1), !dbg !10 - %3 = call i1 @integer_eq_integer(%Integer %1, %Integer %2), !dbg !10 - call void @"println <:Bool>"(i1 %3), !dbg !10 - call void @destroy_integer(ptr @x), !dbg !11 - br label %return, !dbg !11 +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 return: ; preds = %0 ret void } -define private void @initialize() !dbg !12 { - %1 = alloca %"Point", align 8, !dbg !13 - %"Point.data" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !13 - %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !13 - %2 = call %Integer @integer_from_i64(i64 1), !dbg !14 - store %Integer %2, ptr %"Point.x", align 8, !dbg !14 - %"Point.y" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 1, !dbg !14 - %3 = call %Integer @integer_from_i64(i64 2), !dbg !15 - store %Integer %3, ptr %"Point.y", align 8, !dbg !15 - %4 = load %"Point", ptr %1, align 8, !dbg !15 - store %"Point" %4, ptr @p, align 8, !dbg !15 - br label %return, !dbg !15 +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 return: ; preds = %0 ret void } -declare %Integer @integer_from_i64(i64) +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 -define private void @initialize.1() !dbg !16 { - %1 = call %Integer @clone_integer(ptr @p), !dbg !17 - store %Integer %1, ptr @x, align 8, !dbg !17 +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 br label %return, !dbg !17 return: ; preds = %0 ret void } +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !20 + call void @initialize.3(), !dbg !21 + call void @initialize.4(), !dbg !22 + call void @initialize.5(), !dbg !23 + %1 = call %Integer @clone_integer(ptr @x), !dbg !24 + %2 = call %Integer @integer_from_i64(i64 1), !dbg !25 + %3 = call i1 @integer_eq_integer(%Integer %1, %Integer %2), !dbg !25 + call void @"println <:Bool>"(i1 %3), !dbg !25 + call void @destroy_integer(ptr @x), !dbg !26 + br label %return, !dbg !26 + +return: ; preds = %0 + ret void +} + +define private void @initialize.4() !dbg !27 { + %1 = alloca %"Point", align 8, !dbg !28 + %"Point.x" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !28 + %2 = call %Integer @integer_from_i64(i64 1), !dbg !29 + store %Integer %2, ptr %"Point.x", align 8, !dbg !29 + %"Point.y" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 1, !dbg !29 + %3 = call %Integer @integer_from_i64(i64 2), !dbg !30 + store %Integer %3, ptr %"Point.y", align 8, !dbg !30 + %4 = load %"Point", ptr %1, align 8, !dbg !30 + store %"Point" %4, ptr @p, align 8, !dbg !30 + br label %return, !dbg !30 + +return: ; preds = %0 + ret void +} + +define private void @initialize.5() !dbg !31 { + %1 = call %Integer @clone_integer(ptr @p), !dbg !32 + store %Integer %1, ptr @x, align 8, !dbg !32 + br label %return, !dbg !32 + +return: ; preds = %0 + ret void +} + declare %Integer @clone_integer(ptr) -define private void @"println <:Bool>"(i1 %0) !dbg !18 { +define private void @"println <:Bool>"(i1 %0) !dbg !33 { %x = alloca i1, align 1 store i1 %0, ptr %x, align 1 - %2 = load i1, ptr %x, align 1, !dbg !19 - %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !19 - call void @"println <:String>"(%String %3), !dbg !19 - br label %return, !dbg !19 + %2 = load i1, ptr %x, align 1, !dbg !34 + %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !34 + call void @"println <:String>"(%String %3), !dbg !34 + br label %return, !dbg !34 return: ; preds = %1 ret void @@ -83,20 +163,35 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 3, column: 8, scope: !3) -!8 = !DILocation(line: 4, column: 8, scope: !3) -!9 = !DILocation(line: 5, column: 8, scope: !3) -!10 = !DILocation(line: 5, column: 13, scope: !3) -!11 = !DILocation(line: 4, scope: !3) -!12 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 3, column: 8, scope: !12) -!14 = !DILocation(line: 3, column: 19, scope: !12) -!15 = !DILocation(line: 3, column: 25, scope: !12) -!16 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!17 = !DILocation(line: 4, column: 8, scope: !16) -!18 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !3, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!7 = !DILocation(line: 5, column: 14, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 5, column: 14, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 4, column: 9, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 4, column: 4, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !19 = !DILocation(line: 5, column: 14, scope: !18) +!20 = !DILocation(line: 4, column: 9, scope: !18) +!21 = !DILocation(line: 4, column: 4, scope: !18) +!22 = !DILocation(line: 3, column: 8, scope: !18) +!23 = !DILocation(line: 4, column: 8, scope: !18) +!24 = !DILocation(line: 5, column: 8, scope: !18) +!25 = !DILocation(line: 5, column: 13, scope: !18) +!26 = !DILocation(line: 4, scope: !18) +!27 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !18, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!28 = !DILocation(line: 3, column: 8, scope: !27) +!29 = !DILocation(line: 3, column: 19, scope: !27) +!30 = !DILocation(line: 3, column: 25, scope: !27) +!31 = distinct !DISubprogram(name: "initialize.5", linkageName: "initialize.5", scope: !18, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!32 = !DILocation(line: 4, column: 8, scope: !31) +!33 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !18, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!34 = !DILocation(line: 5, column: 14, scope: !33) diff --git a/src/tests/snapshots/ppl__tests__monomorphize_predeclared.ir.snap b/src/tests/snapshots/ppl__tests__monomorphize_predeclared.ir.snap index 824d1a12..8b8a8dcd 100644 --- a/src/tests/snapshots/ppl__tests__monomorphize_predeclared.ir.snap +++ b/src/tests/snapshots/ppl__tests__monomorphize_predeclared.ir.snap @@ -5,34 +5,118 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Integer = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@4 = private unnamed_addr constant [19 x i8] c"called predeclared\00", align 1 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 -@0 = private unnamed_addr constant [19 x i8] c"called predeclared\00", align 1 +return: ; preds = %0 + ret void +} -define void @main.execute() !dbg !3 { - call void @"call predeclared"(), !dbg !7 - br label %return, !dbg !7 +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !20 + call void @initialize.3(), !dbg !21 + call void @"call predeclared"(), !dbg !22 + br label %return, !dbg !22 return: ; preds = %0 ret void } -define void @"call predeclared"() !dbg !8 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !9 - call void @"predeclared <:Integer>"(%Integer %1), !dbg !9 - br label %return, !dbg !9 +define void @"call predeclared"() !dbg !23 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !24 + call void @"predeclared <:Integer>"(%Integer %1), !dbg !24 + br label %return, !dbg !24 return: ; preds = %0 ret void } -define private void @"predeclared <:Integer>"(%Integer %0) !dbg !10 { +define private void @"predeclared <:Integer>"(%Integer %0) !dbg !25 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 18), !dbg !11 - call void @"println <:String>"(%String %2), !dbg !11 - br label %return, !dbg !11 + %2 = call %String @string_from_c_string_and_length(ptr @4, i64 18), !dbg !26 + call void @"println <:String>"(%String %2), !dbg !26 + br label %return, !dbg !26 return: ; preds = %1 ret void @@ -40,22 +124,33 @@ return: ; preds = %1 declare void @"println <:String>"(%String) -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - !llvm.module.flags = !{!0} !llvm.dbg.cu = !{!1} !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 6, scope: !3) -!8 = distinct !DISubprogram(name: "call predeclared", linkageName: "call predeclared", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!9 = !DILocation(line: 1, column: 13, scope: !8) -!10 = distinct !DISubprogram(name: "predeclared <:Integer>", linkageName: "predeclared <:Integer>", scope: !8, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!11 = !DILocation(line: 4, column: 9, scope: !10) +!7 = !DILocation(line: 6, column: 16, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 6, column: 16, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 4, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 3, column: 21, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 6, column: 16, scope: !18) +!20 = !DILocation(line: 4, scope: !18) +!21 = !DILocation(line: 3, column: 21, scope: !18) +!22 = !DILocation(line: 6, scope: !18) +!23 = distinct !DISubprogram(name: "call predeclared", linkageName: "call predeclared", scope: !18, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!24 = !DILocation(line: 1, column: 13, scope: !23) +!25 = distinct !DISubprogram(name: "predeclared <:Integer>", linkageName: "predeclared <:Integer>", scope: !23, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!26 = !DILocation(line: 4, column: 9, scope: !25) diff --git a/src/tests/snapshots/ppl__tests__multifile.ir.snap b/src/tests/snapshots/ppl__tests__multifile.ir.snap index c2b1c07d..b7c7f67e 100644 --- a/src/tests/snapshots/ppl__tests__multifile.ir.snap +++ b/src/tests/snapshots/ppl__tests__multifile.ir.snap @@ -5,31 +5,127 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" +%"Type" = type { %String, %Integer } %String = type { ptr } +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } -@0 = private unnamed_addr constant [6 x i8] c"World\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@4 = private unnamed_addr constant [6 x i8] c"World\00", align 1 -define void @main.execute() !dbg !3 { - %1 = call %String @string_from_c_string_and_length(ptr @0, i64 5), !dbg !7 - call void @"greet <:String>"(%String %1), !dbg !7 - br label %return, !dbg !7 +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 return: ; preds = %0 ret void } -declare void @"greet <:String>"(%String) - declare %String @string_from_c_string_and_length(ptr, i64) +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !19 + call void @initialize.3(), !dbg !19 + %1 = call %String @string_from_c_string_and_length(ptr @4, i64 5), !dbg !20 + call void @"greet <:String>"(%String %1), !dbg !20 + br label %return, !dbg !20 + +return: ; preds = %0 + ret void +} + +declare void @"greet <:String>"(%String) + !llvm.module.flags = !{!0} !llvm.dbg.cu = !{!1} !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 2, column: 6, scope: !3) +!7 = !DILocation(line: 2, column: 13, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 2, column: 13, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 2, column: 13, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 2, column: 13, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 2, column: 13, scope: !18) +!20 = !DILocation(line: 2, column: 6, scope: !18) diff --git a/src/tests/snapshots/ppl__tests__plus_assign.ir.snap b/src/tests/snapshots/ppl__tests__plus_assign.ir.snap index 6fb2b731..438efd9f 100644 --- a/src/tests/snapshots/ppl__tests__plus_assign.ir.snap +++ b/src/tests/snapshots/ppl__tests__plus_assign.ir.snap @@ -5,28 +5,35 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%Rational = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } -%"TypeImpl" = type { %String, %Integer } %Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%Rational = type { ptr } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 @value = global %Rational zeroinitializer -@1 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@2 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@4 = private unnamed_addr constant [2 x i8] c"0\00", align 1 +@5 = private unnamed_addr constant [2 x i8] c"1\00", align 1 @str = global %String zeroinitializer -@3 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1 -@4 = private unnamed_addr constant [8 x i8] c" World!\00", align 1 +@6 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1 +@7 = private unnamed_addr constant [8 x i8] c" World!\00", align 1 define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 @@ -41,32 +48,83 @@ declare %String @string_from_c_string_and_length(ptr, i64) declare %Integer @integer_from_i64(i64) -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @initialize.1(), !dbg !11 - %1 = call %Rational @clone_rational(ptr @value), !dbg !12 - call void @"println <:Rational>"(%Rational %1), !dbg !12 - %2 = call %Rational @rational_from_c_string(ptr @2), !dbg !13 - call void @"<:ReferenceMut> += <:Rational>"(ptr @value, %Rational %2), !dbg !13 - %3 = call %Rational @clone_rational(ptr @value), !dbg !14 - call void @"println <:Rational>"(%Rational %3), !dbg !14 - call void @initialize.2(), !dbg !15 - %4 = call %String @string_from_c_string_and_length(ptr @4, i64 7), !dbg !16 - call void @"<:ReferenceMut> += <:String>"(ptr @str, %String %4), !dbg !16 - %5 = call %String @clone_string(ptr @str), !dbg !17 - call void @"println <:String>"(%String %5), !dbg !17 - call void @destroy_rational(ptr @value), !dbg !18 - call void @destroy_string(ptr @str), !dbg !19 - br label %return, !dbg !19 +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !20 + call void @initialize.3(), !dbg !21 + call void @initialize.4(), !dbg !22 + %1 = call %Rational @clone_rational(ptr @value), !dbg !23 + call void @"println <:Rational>"(%Rational %1), !dbg !23 + %2 = call %Rational @rational_from_c_string(ptr @5), !dbg !24 + call void @"<:ReferenceMut> += <:Rational>"(ptr @value, %Rational %2), !dbg !24 + %3 = call %Rational @clone_rational(ptr @value), !dbg !25 + call void @"println <:Rational>"(%Rational %3), !dbg !25 + call void @initialize.5(), !dbg !26 + %4 = call %String @string_from_c_string_and_length(ptr @7, i64 7), !dbg !27 + call void @"<:ReferenceMut> += <:String>"(ptr @str, %String %4), !dbg !27 + %5 = call %String @clone_string(ptr @str), !dbg !28 + call void @"println <:String>"(%String %5), !dbg !28 + call void @destroy_rational(ptr @value), !dbg !29 + call void @destroy_string(ptr @str), !dbg !30 + br label %return, !dbg !30 return: ; preds = %0 ret void } -define private void @initialize.1() !dbg !20 { - %1 = call %Rational @rational_from_c_string(ptr @1), !dbg !21 - store %Rational %1, ptr @value, align 8, !dbg !21 - br label %return, !dbg !21 +define private void @initialize.4() !dbg !31 { + %1 = call %Rational @rational_from_c_string(ptr @4), !dbg !32 + store %Rational %1, ptr @value, align 8, !dbg !32 + br label %return, !dbg !32 return: ; preds = %0 ret void @@ -74,13 +132,13 @@ return: ; preds = %0 declare %Rational @rational_from_c_string(ptr) -define private void @"println <:Rational>"(%Rational %0) !dbg !22 { +define private void @"println <:Rational>"(%Rational %0) !dbg !33 { %x = alloca %Rational, align 8 store %Rational %0, ptr %x, align 8 - %2 = load %Rational, ptr %x, align 8, !dbg !23 - %3 = call %String @rational_as_string(%Rational %2), !dbg !23 - call void @"println <:String>"(%String %3), !dbg !23 - br label %return, !dbg !23 + %2 = load %Rational, ptr %x, align 8, !dbg !34 + %3 = call %String @rational_as_string(%Rational %2), !dbg !34 + call void @"println <:String>"(%String %3), !dbg !34 + br label %return, !dbg !34 return: ; preds = %1 ret void @@ -92,18 +150,18 @@ declare %String @rational_as_string(%Rational) declare %Rational @clone_rational(ptr) -define private void @"<:ReferenceMut> += <:Rational>"(ptr %0, %Rational %1) !dbg !24 { +define private void @"<:ReferenceMut> += <:Rational>"(ptr %0, %Rational %1) !dbg !35 { %self = alloca ptr, align 8 store ptr %0, ptr %self, align 8 %other = alloca %Rational, align 8 store %Rational %1, ptr %other, align 8 - %3 = load ptr, ptr %self, align 8, !dbg !25 - %4 = load ptr, ptr %self, align 8, !dbg !25 - %5 = load %Rational, ptr %4, align 8, !dbg !25 - %6 = load %Rational, ptr %other, align 8, !dbg !25 - %7 = call %Rational @rational_plus_rational(%Rational %5, %Rational %6), !dbg !25 - store %Rational %7, ptr %3, align 8, !dbg !25 - br label %return, !dbg !25 + %3 = load ptr, ptr %self, align 8, !dbg !36 + %4 = load ptr, ptr %self, align 8, !dbg !36 + %5 = load %Rational, ptr %4, align 8, !dbg !36 + %6 = load %Rational, ptr %other, align 8, !dbg !36 + %7 = call %Rational @rational_plus_rational(%Rational %5, %Rational %6), !dbg !36 + store %Rational %7, ptr %3, align 8, !dbg !36 + br label %return, !dbg !36 return: ; preds = %2 ret void @@ -111,27 +169,27 @@ return: ; preds = %2 declare %Rational @rational_plus_rational(%Rational, %Rational) -define private void @initialize.2() !dbg !26 { - %1 = call %String @string_from_c_string_and_length(ptr @3, i64 5), !dbg !27 - store %String %1, ptr @str, align 8, !dbg !27 - br label %return, !dbg !27 +define private void @initialize.5() !dbg !37 { + %1 = call %String @string_from_c_string_and_length(ptr @6, i64 5), !dbg !38 + store %String %1, ptr @str, align 8, !dbg !38 + br label %return, !dbg !38 return: ; preds = %0 ret void } -define private void @"<:ReferenceMut> += <:String>"(ptr %0, %String %1) !dbg !28 { +define private void @"<:ReferenceMut> += <:String>"(ptr %0, %String %1) !dbg !39 { %self = alloca ptr, align 8 store ptr %0, ptr %self, align 8 %other = alloca %String, align 8 store %String %1, ptr %other, align 8 - %3 = load ptr, ptr %self, align 8, !dbg !29 - %4 = load ptr, ptr %self, align 8, !dbg !29 - %5 = load %String, ptr %4, align 8, !dbg !29 - %6 = load %String, ptr %other, align 8, !dbg !29 - %7 = call %String @string_plus_string(%String %5, %String %6), !dbg !29 - store %String %7, ptr %3, align 8, !dbg !29 - br label %return, !dbg !29 + %3 = load ptr, ptr %self, align 8, !dbg !40 + %4 = load ptr, ptr %self, align 8, !dbg !40 + %5 = load %String, ptr %4, align 8, !dbg !40 + %6 = load %String, ptr %other, align 8, !dbg !40 + %7 = call %String @string_plus_string(%String %5, %String %6), !dbg !40 + store %String %7, ptr %3, align 8, !dbg !40 + br label %return, !dbg !40 return: ; preds = %2 ret void @@ -157,24 +215,35 @@ declare void @destroy_string(ptr) !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) !7 = !DILocation(line: 7, column: 11, scope: !3) !8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) !10 = !DILocation(line: 7, column: 11, scope: !9) -!11 = !DILocation(line: 0, column: 16, scope: !9) -!12 = !DILocation(line: 1, column: 8, scope: !9) -!13 = !DILocation(line: 2, column: 9, scope: !9) -!14 = !DILocation(line: 3, column: 8, scope: !9) -!15 = !DILocation(line: 5, column: 14, scope: !9) -!16 = !DILocation(line: 6, column: 7, scope: !9) -!17 = !DILocation(line: 7, column: 8, scope: !9) -!18 = !DILocation(line: 0, scope: !9) -!19 = !DILocation(line: 5, scope: !9) -!20 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !9, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!21 = !DILocation(line: 0, column: 16, scope: !20) -!22 = distinct !DISubprogram(name: "println <:Rational>", linkageName: "println <:Rational>", scope: !9, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!23 = !DILocation(line: 7, column: 11, scope: !22) -!24 = distinct !DISubprogram(name: "<:ReferenceMut> += <:Rational>", linkageName: "<:ReferenceMut> += <:Rational>", scope: !9, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!25 = !DILocation(line: 7, column: 11, scope: !24) -!26 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !9, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!27 = !DILocation(line: 5, column: 14, scope: !26) -!28 = distinct !DISubprogram(name: "<:ReferenceMut> += <:String>", linkageName: "<:ReferenceMut> += <:String>", scope: !9, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!29 = !DILocation(line: 7, column: 11, scope: !28) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 5, column: 1, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 3, column: 11, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 7, column: 11, scope: !18) +!20 = !DILocation(line: 5, column: 1, scope: !18) +!21 = !DILocation(line: 3, column: 11, scope: !18) +!22 = !DILocation(line: 0, column: 16, scope: !18) +!23 = !DILocation(line: 1, column: 8, scope: !18) +!24 = !DILocation(line: 2, column: 9, scope: !18) +!25 = !DILocation(line: 3, column: 8, scope: !18) +!26 = !DILocation(line: 5, column: 14, scope: !18) +!27 = !DILocation(line: 6, column: 7, scope: !18) +!28 = !DILocation(line: 7, column: 8, scope: !18) +!29 = !DILocation(line: 0, scope: !18) +!30 = !DILocation(line: 5, scope: !18) +!31 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !18, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!32 = !DILocation(line: 0, column: 16, scope: !31) +!33 = distinct !DISubprogram(name: "println <:Rational>", linkageName: "println <:Rational>", scope: !18, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!34 = !DILocation(line: 7, column: 11, scope: !33) +!35 = distinct !DISubprogram(name: "<:ReferenceMut> += <:Rational>", linkageName: "<:ReferenceMut> += <:Rational>", scope: !18, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!36 = !DILocation(line: 7, column: 11, scope: !35) +!37 = distinct !DISubprogram(name: "initialize.5", linkageName: "initialize.5", scope: !18, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!38 = !DILocation(line: 5, column: 14, scope: !37) +!39 = distinct !DISubprogram(name: "<:ReferenceMut> += <:String>", linkageName: "<:ReferenceMut> += <:String>", scope: !18, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!40 = !DILocation(line: 7, column: 11, scope: !39) diff --git a/src/tests/snapshots/ppl__tests__ppl.ir.snap b/src/tests/snapshots/ppl__tests__ppl.ir.snap index 843a1f23..b62520b8 100644 --- a/src/tests/snapshots/ppl__tests__ppl.ir.snap +++ b/src/tests/snapshots/ppl__tests__ppl.ir.snap @@ -5,8 +5,96 @@ expression: ir ; ModuleID = 'lib' source_filename = "/Users/gavrilikhin_d/Code/ppl/ppl/src/lib.ppl" -define void @lib.execute() !dbg !3 { - br label %return +%"Type" = type { %String, %Integer } +%String = type { ptr } +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @lib.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !20 + call void @initialize.3(), !dbg !21 + br label %return, !dbg !21 return: ; preds = %0 ret void @@ -18,7 +106,22 @@ return: ; preds = %0 !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "/Users/gavrilikhin_d/Code/ppl/ppl/src/lib.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "lib.execute", linkageName: "lib.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) +!7 = !DILocation(line: 9, column: 15, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 9, column: 15, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 6, column: 6, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 6, column: 1, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "lib.execute", linkageName: "lib.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 9, column: 15, scope: !18) +!20 = !DILocation(line: 6, column: 6, scope: !18) +!21 = !DILocation(line: 6, column: 1, scope: !18) diff --git a/src/tests/snapshots/ppl__tests__predeclare_function.ir.snap b/src/tests/snapshots/ppl__tests__predeclare_function.ir.snap index 5a13c513..b73f5475 100644 --- a/src/tests/snapshots/ppl__tests__predeclare_function.ir.snap +++ b/src/tests/snapshots/ppl__tests__predeclare_function.ir.snap @@ -5,54 +5,139 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Integer = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} -define void @main.execute() !dbg !3 { - %1 = call %Integer @integer_from_i64(i64 2), !dbg !7 - %2 = call %Integer @"<:Integer> plus two"(%Integer %1), !dbg !7 - call void @"println <:Integer>"(%Integer %2), !dbg !7 - br label %return, !dbg !7 +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !20 + call void @initialize.3(), !dbg !21 + %1 = call %Integer @integer_from_i64(i64 2), !dbg !22 + %2 = call %Integer @"<:Integer> plus two"(%Integer %1), !dbg !22 + call void @"println <:Integer>"(%Integer %2), !dbg !22 + br label %return, !dbg !22 return: ; preds = %0 ret void } -define %Integer @"<:Integer> plus two"(%Integer %0) !dbg !8 { +define %Integer @"<:Integer> plus two"(%Integer %0) !dbg !23 { %return_value = alloca %Integer, align 8 %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = call %Integer @clone_integer(ptr %x), !dbg !9 - %3 = call %Integer @integer_from_i64(i64 2), !dbg !10 - %4 = call %Integer @"sum <:Integer> <:Integer>"(%Integer %2, %Integer %3), !dbg !10 - %"$tmp@28" = alloca %Integer, align 8, !dbg !10 - store %Integer %4, ptr %"$tmp@28", align 8, !dbg !10 - call void @destroy_integer(ptr %x), !dbg !11 - %5 = load %Integer, ptr %"$tmp@28", align 8, !dbg !12 - store %Integer %5, ptr %return_value, align 8, !dbg !12 - br label %return, !dbg !12 + %2 = call %Integer @clone_integer(ptr %x), !dbg !24 + %3 = call %Integer @integer_from_i64(i64 2), !dbg !25 + %4 = call %Integer @"sum <:Integer> <:Integer>"(%Integer %2, %Integer %3), !dbg !25 + %"$tmp@28" = alloca %Integer, align 8, !dbg !25 + store %Integer %4, ptr %"$tmp@28", align 8, !dbg !25 + call void @destroy_integer(ptr %x), !dbg !26 + %5 = load %Integer, ptr %"$tmp@28", align 8, !dbg !27 + store %Integer %5, ptr %return_value, align 8, !dbg !27 + br label %return, !dbg !27 return: ; preds = %1 %6 = load %Integer, ptr %return_value, align 8 ret %Integer %6 } -define %Integer @"sum <:Integer> <:Integer>"(%Integer %0, %Integer %1) !dbg !13 { +define %Integer @"sum <:Integer> <:Integer>"(%Integer %0, %Integer %1) !dbg !28 { %return_value = alloca %Integer, align 8 %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 %y = alloca %Integer, align 8 store %Integer %1, ptr %y, align 8 - %3 = call %Integer @clone_integer(ptr %x), !dbg !14 - %4 = call %Integer @clone_integer(ptr %y), !dbg !15 - %5 = call %Integer @integer_plus_integer(%Integer %3, %Integer %4), !dbg !15 - %"$tmp@84" = alloca %Integer, align 8, !dbg !15 - store %Integer %5, ptr %"$tmp@84", align 8, !dbg !15 - call void @destroy_integer(ptr %x), !dbg !16 - call void @destroy_integer(ptr %y), !dbg !17 - %6 = load %Integer, ptr %"$tmp@84", align 8, !dbg !14 - store %Integer %6, ptr %return_value, align 8, !dbg !14 - br label %return, !dbg !14 + %3 = call %Integer @clone_integer(ptr %x), !dbg !29 + %4 = call %Integer @clone_integer(ptr %y), !dbg !30 + %5 = call %Integer @integer_plus_integer(%Integer %3, %Integer %4), !dbg !30 + %"$tmp@84" = alloca %Integer, align 8, !dbg !30 + store %Integer %5, ptr %"$tmp@84", align 8, !dbg !30 + call void @destroy_integer(ptr %x), !dbg !31 + call void @destroy_integer(ptr %y), !dbg !32 + %6 = load %Integer, ptr %"$tmp@84", align 8, !dbg !29 + store %Integer %6, ptr %return_value, align 8, !dbg !29 + br label %return, !dbg !29 return: ; preds = %2 %7 = load %Integer, ptr %return_value, align 8 @@ -61,21 +146,19 @@ return: ; preds = %2 declare %Integer @clone_integer(ptr) -declare %Integer @integer_from_i64(i64) - declare void @destroy_integer(ptr) -declare %Integer @"sum <:Integer> <:Integer>.1"(%Integer, %Integer) +declare %Integer @"sum <:Integer> <:Integer>.4"(%Integer, %Integer) declare %Integer @integer_plus_integer(%Integer, %Integer) -define private void @"println <:Integer>"(%Integer %0) !dbg !18 { +define private void @"println <:Integer>"(%Integer %0) !dbg !33 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !19 - %3 = call %String @integer_as_string(%Integer %2), !dbg !19 - call void @"println <:String>"(%String %3), !dbg !19 - br label %return, !dbg !19 + %2 = load %Integer, ptr %x, align 8, !dbg !34 + %3 = call %String @integer_as_string(%Integer %2), !dbg !34 + call void @"println <:String>"(%String %3), !dbg !34 + br label %return, !dbg !34 return: ; preds = %1 ret void @@ -91,20 +174,35 @@ declare %String @integer_as_string(%Integer) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 4, column: 9, scope: !3) -!8 = distinct !DISubprogram(name: "<:Integer> plus two", linkageName: "<:Integer> plus two", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!9 = !DILocation(line: 0, column: 32, scope: !8) -!10 = !DILocation(line: 0, column: 34, scope: !8) -!11 = !DILocation(line: 0, column: 3, scope: !8) -!12 = !DILocation(line: 0, column: 28, scope: !8) -!13 = distinct !DISubprogram(name: "sum <:Integer> <:Integer>", linkageName: "sum <:Integer> <:Integer>", scope: !3, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!14 = !DILocation(line: 2, column: 47, scope: !13) -!15 = !DILocation(line: 2, column: 51, scope: !13) -!16 = !DILocation(line: 2, column: 7, scope: !13) -!17 = !DILocation(line: 2, column: 20, scope: !13) -!18 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!7 = !DILocation(line: 4, column: 20, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 4, column: 20, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 2, column: 26, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 2, column: 21, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !19 = !DILocation(line: 4, column: 20, scope: !18) +!20 = !DILocation(line: 2, column: 26, scope: !18) +!21 = !DILocation(line: 2, column: 21, scope: !18) +!22 = !DILocation(line: 4, column: 9, scope: !18) +!23 = distinct !DISubprogram(name: "<:Integer> plus two", linkageName: "<:Integer> plus two", scope: !18, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!24 = !DILocation(line: 0, column: 32, scope: !23) +!25 = !DILocation(line: 0, column: 34, scope: !23) +!26 = !DILocation(line: 0, column: 3, scope: !23) +!27 = !DILocation(line: 0, column: 28, scope: !23) +!28 = distinct !DISubprogram(name: "sum <:Integer> <:Integer>", linkageName: "sum <:Integer> <:Integer>", scope: !18, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!29 = !DILocation(line: 2, column: 47, scope: !28) +!30 = !DILocation(line: 2, column: 51, scope: !28) +!31 = !DILocation(line: 2, column: 7, scope: !28) +!32 = !DILocation(line: 2, column: 20, scope: !28) +!33 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !18, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!34 = !DILocation(line: 4, column: 20, scope: !33) diff --git a/src/tests/snapshots/ppl__tests__predeclare_vars.ir.snap b/src/tests/snapshots/ppl__tests__predeclare_vars.ir.snap index 1f8b972d..19fe39ee 100644 --- a/src/tests/snapshots/ppl__tests__predeclare_vars.ir.snap +++ b/src/tests/snapshots/ppl__tests__predeclare_vars.ir.snap @@ -5,44 +5,126 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Integer = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } - +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 @x = global %Integer zeroinitializer @y = global %Integer zeroinitializer -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - call void @initialize.1(), !dbg !8 - %1 = call %Integer @clone_integer(ptr @y), !dbg !9 - call void @"println <:Integer>"(%Integer %1), !dbg !9 - call void @destroy_integer(ptr @x), !dbg !10 - call void @destroy_integer(ptr @y), !dbg !11 +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 br label %return, !dbg !11 return: ; preds = %0 ret void } -define private void @initialize() !dbg !12 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !13 - store %Integer %1, ptr @x, align 8, !dbg !13 - br label %return, !dbg !13 +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 return: ; preds = %0 ret void } -declare %Integer @integer_from_i64(i64) +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !19 + call void @initialize.3(), !dbg !20 + call void @initialize.4(), !dbg !21 + call void @initialize.5(), !dbg !22 + %1 = call %Integer @clone_integer(ptr @y), !dbg !23 + call void @"println <:Integer>"(%Integer %1), !dbg !23 + call void @destroy_integer(ptr @x), !dbg !24 + call void @destroy_integer(ptr @y), !dbg !25 + br label %return, !dbg !25 + +return: ; preds = %0 + ret void +} + +define private void @initialize.4() !dbg !26 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !27 + store %Integer %1, ptr @x, align 8, !dbg !27 + br label %return, !dbg !27 -define %Integer @"get x"() !dbg !14 { +return: ; preds = %0 + ret void +} + +define %Integer @"get x"() !dbg !28 { %return_value = alloca %Integer, align 8 - %1 = call %Integer @clone_integer(ptr @x), !dbg !15 - %"$tmp@22" = alloca %Integer, align 8, !dbg !15 - store %Integer %1, ptr %"$tmp@22", align 8, !dbg !15 - %2 = load %Integer, ptr %"$tmp@22", align 8, !dbg !15 - store %Integer %2, ptr %return_value, align 8, !dbg !15 - br label %return, !dbg !15 + %1 = call %Integer @clone_integer(ptr @x), !dbg !29 + %"$tmp@22" = alloca %Integer, align 8, !dbg !29 + store %Integer %1, ptr %"$tmp@22", align 8, !dbg !29 + %2 = load %Integer, ptr %"$tmp@22", align 8, !dbg !29 + store %Integer %2, ptr %return_value, align 8, !dbg !29 + br label %return, !dbg !29 return: ; preds = %0 %3 = load %Integer, ptr %return_value, align 8 @@ -51,36 +133,36 @@ return: ; preds = %0 declare %Integer @clone_integer(ptr) -define private void @initialize.1() !dbg !16 { - %1 = call %Integer @"get x"(), !dbg !17 - store %Integer %1, ptr @y, align 8, !dbg !17 - br label %return, !dbg !17 +define private void @initialize.5() !dbg !30 { + %1 = call %Integer @"get x"(), !dbg !31 + store %Integer %1, ptr @y, align 8, !dbg !31 + br label %return, !dbg !31 return: ; preds = %0 ret void } -define %Integer @"get y"() !dbg !18 { +define %Integer @"get y"() !dbg !32 { %return_value = alloca %Integer, align 8 - %1 = call %Integer @clone_integer(ptr @y), !dbg !19 - %"$tmp@51" = alloca %Integer, align 8, !dbg !19 - store %Integer %1, ptr %"$tmp@51", align 8, !dbg !19 - %2 = load %Integer, ptr %"$tmp@51", align 8, !dbg !19 - store %Integer %2, ptr %return_value, align 8, !dbg !19 - br label %return, !dbg !19 + %1 = call %Integer @clone_integer(ptr @y), !dbg !33 + %"$tmp@51" = alloca %Integer, align 8, !dbg !33 + store %Integer %1, ptr %"$tmp@51", align 8, !dbg !33 + %2 = load %Integer, ptr %"$tmp@51", align 8, !dbg !33 + store %Integer %2, ptr %return_value, align 8, !dbg !33 + br label %return, !dbg !33 return: ; preds = %0 %3 = load %Integer, ptr %return_value, align 8 ret %Integer %3 } -define private void @"println <:Integer>"(%Integer %0) !dbg !20 { +define private void @"println <:Integer>"(%Integer %0) !dbg !34 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !21 - %3 = call %String @integer_as_string(%Integer %2), !dbg !21 - call void @"println <:String>"(%String %3), !dbg !21 - br label %return, !dbg !21 + %2 = load %Integer, ptr %x, align 8, !dbg !35 + %3 = call %String @integer_as_string(%Integer %2), !dbg !35 + call void @"println <:String>"(%String %3), !dbg !35 + br label %return, !dbg !35 return: ; preds = %1 ret void @@ -98,22 +180,36 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 8, scope: !3) -!8 = !DILocation(line: 3, column: 8, scope: !3) -!9 = !DILocation(line: 6, column: 8, scope: !3) -!10 = !DILocation(line: 0, scope: !3) -!11 = !DILocation(line: 3, scope: !3) -!12 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 0, column: 8, scope: !12) -!14 = distinct !DISubprogram(name: "get x", linkageName: "get x", scope: !3, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!15 = !DILocation(line: 1, column: 12, scope: !14) -!16 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!17 = !DILocation(line: 3, column: 8, scope: !16) -!18 = distinct !DISubprogram(name: "get y", linkageName: "get y", scope: !3, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!19 = !DILocation(line: 4, column: 12, scope: !18) -!20 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!21 = !DILocation(line: 6, column: 9, scope: !20) +!7 = !DILocation(line: 6, column: 9, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 6, column: 9, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 6, column: 9, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 6, column: 4, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 6, column: 9, scope: !18) +!20 = !DILocation(line: 6, column: 4, scope: !18) +!21 = !DILocation(line: 0, column: 8, scope: !18) +!22 = !DILocation(line: 3, column: 8, scope: !18) +!23 = !DILocation(line: 6, column: 8, scope: !18) +!24 = !DILocation(line: 0, scope: !18) +!25 = !DILocation(line: 3, scope: !18) +!26 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !18, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!27 = !DILocation(line: 0, column: 8, scope: !26) +!28 = distinct !DISubprogram(name: "get x", linkageName: "get x", scope: !18, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!29 = !DILocation(line: 1, column: 12, scope: !28) +!30 = distinct !DISubprogram(name: "initialize.5", linkageName: "initialize.5", scope: !18, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!31 = !DILocation(line: 3, column: 8, scope: !30) +!32 = distinct !DISubprogram(name: "get y", linkageName: "get y", scope: !18, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!33 = !DILocation(line: 4, column: 12, scope: !32) +!34 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !18, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!35 = !DILocation(line: 6, column: 9, scope: !34) diff --git a/src/tests/snapshots/ppl__tests__rational.ir.snap b/src/tests/snapshots/ppl__tests__rational.ir.snap index 06b07930..c0a813d2 100644 --- a/src/tests/snapshots/ppl__tests__rational.ir.snap +++ b/src/tests/snapshots/ppl__tests__rational.ir.snap @@ -5,109 +5,193 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Rational = type { ptr } -%Integer = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%Rational = type { ptr } -@0 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@1 = private unnamed_addr constant [2 x i8] c"1\00", align 1 -@2 = private unnamed_addr constant [2 x i8] c"2\00", align 1 -@3 = private unnamed_addr constant [2 x i8] c"1\00", align 1 -@4 = private unnamed_addr constant [2 x i8] c"2\00", align 1 -@5 = private unnamed_addr constant [2 x i8] c"5\00", align 1 -@6 = private unnamed_addr constant [2 x i8] c"1\00", align 1 -@7 = private unnamed_addr constant [4 x i8] c"5/2\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@4 = private unnamed_addr constant [2 x i8] c"0\00", align 1 +@5 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@6 = private unnamed_addr constant [2 x i8] c"2\00", align 1 +@7 = private unnamed_addr constant [2 x i8] c"1\00", align 1 @8 = private unnamed_addr constant [2 x i8] c"2\00", align 1 -@9 = private unnamed_addr constant [2 x i8] c"9\00", align 1 -@10 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@11 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@12 = private unnamed_addr constant [2 x i8] c"1\00", align 1 -@13 = private unnamed_addr constant [2 x i8] c"0\00", align 1 +@9 = private unnamed_addr constant [2 x i8] c"5\00", align 1 +@10 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@11 = private unnamed_addr constant [4 x i8] c"5/2\00", align 1 +@12 = private unnamed_addr constant [2 x i8] c"2\00", align 1 +@13 = private unnamed_addr constant [2 x i8] c"9\00", align 1 @14 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@15 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@15 = private unnamed_addr constant [2 x i8] c"0\00", align 1 @16 = private unnamed_addr constant [2 x i8] c"1\00", align 1 @17 = private unnamed_addr constant [2 x i8] c"0\00", align 1 @18 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@19 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@20 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@21 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@19 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@20 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@21 = private unnamed_addr constant [2 x i8] c"0\00", align 1 @22 = private unnamed_addr constant [2 x i8] c"0\00", align 1 @23 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@24 = private unnamed_addr constant [2 x i8] c"1\00", align 1 -@25 = private unnamed_addr constant [2 x i8] c"0\00", align 1 - -define void @main.execute() !dbg !3 { - %1 = call %Rational @rational_from_c_string(ptr @0), !dbg !7 - call void @"println <:Rational>"(%Rational %1), !dbg !7 - %2 = call %Rational @rational_from_c_string(ptr @1), !dbg !8 - %3 = call %Rational @"+ <:Rational>"(%Rational %2), !dbg !8 - call void @"println <:Rational>"(%Rational %3), !dbg !8 - %4 = call %Rational @rational_from_c_string(ptr @2), !dbg !9 - %5 = call %Rational @minus_rational(%Rational %4), !dbg !9 - call void @"println <:Rational>"(%Rational %5), !dbg !9 - %6 = call %Rational @rational_from_c_string(ptr @3), !dbg !10 - %7 = call %Rational @rational_from_c_string(ptr @4), !dbg !11 - %8 = call %Rational @rational_plus_rational(%Rational %6, %Rational %7), !dbg !11 - call void @"println <:Rational>"(%Rational %8), !dbg !11 - %9 = call %Rational @rational_from_c_string(ptr @5), !dbg !12 - %10 = call %Rational @rational_from_c_string(ptr @6), !dbg !13 - %11 = call %Rational @"<:Rational> - <:Rational>"(%Rational %9, %Rational %10), !dbg !13 - call void @"println <:Rational>"(%Rational %11), !dbg !13 - %12 = call %Rational @rational_from_c_string(ptr @7), !dbg !14 - %13 = call %Rational @rational_from_c_string(ptr @8), !dbg !15 - %14 = call %Rational @rational_star_rational(%Rational %12, %Rational %13), !dbg !15 - call void @"println <:Rational>"(%Rational %14), !dbg !15 - %15 = call %Rational @rational_from_c_string(ptr @9), !dbg !16 - %16 = call %Integer @integer_from_i64(i64 3), !dbg !17 - %17 = call %Integer @integer_from_i64(i64 2), !dbg !18 - %18 = call %Rational @integer_slash_integer(%Integer %16, %Integer %17), !dbg !18 - %19 = call %Rational @rational_slash_rational(%Rational %15, %Rational %18), !dbg !18 - call void @"println <:Rational>"(%Rational %19), !dbg !18 - %20 = call %Rational @rational_from_c_string(ptr @10), !dbg !19 - %21 = call %Rational @rational_from_c_string(ptr @11), !dbg !20 - %22 = call i1 @rational_eq_rational(%Rational %20, %Rational %21), !dbg !20 - call void @"println <:Bool>"(i1 %22), !dbg !20 - %23 = call %Rational @rational_from_c_string(ptr @12), !dbg !21 - %24 = call %Rational @rational_from_c_string(ptr @13), !dbg !22 - %25 = call i1 @"<:Rational> != <:Rational>"(%Rational %23, %Rational %24), !dbg !22 - call void @"println <:Bool>"(i1 %25), !dbg !22 - %26 = call %Rational @rational_from_c_string(ptr @14), !dbg !23 - %27 = call %Rational @rational_from_c_string(ptr @15), !dbg !24 - %28 = call i1 @rational_less_rational(%Rational %26, %Rational %27), !dbg !24 - call void @"println <:Bool>"(i1 %28), !dbg !24 - %29 = call %Rational @rational_from_c_string(ptr @16), !dbg !25 - %30 = call %Rational @rational_from_c_string(ptr @17), !dbg !26 - %31 = call i1 @"<:Rational> > <:Rational>"(%Rational %29, %Rational %30), !dbg !26 - call void @"println <:Bool>"(i1 %31), !dbg !26 - %32 = call %Rational @rational_from_c_string(ptr @18), !dbg !27 - %33 = call %Rational @rational_from_c_string(ptr @19), !dbg !28 - %34 = call i1 @"<:Rational> <= <:Rational>"(%Rational %32, %Rational %33), !dbg !28 - call void @"println <:Bool>"(i1 %34), !dbg !28 - %35 = call %Rational @rational_from_c_string(ptr @20), !dbg !29 - %36 = call %Rational @rational_from_c_string(ptr @21), !dbg !30 - %37 = call i1 @"<:Rational> <= <:Rational>"(%Rational %35, %Rational %36), !dbg !30 - call void @"println <:Bool>"(i1 %37), !dbg !30 - %38 = call %Rational @rational_from_c_string(ptr @22), !dbg !31 - %39 = call %Rational @rational_from_c_string(ptr @23), !dbg !32 - %40 = call i1 @"<:Rational> >= <:Rational>"(%Rational %38, %Rational %39), !dbg !32 - call void @"println <:Bool>"(i1 %40), !dbg !32 - %41 = call %Rational @rational_from_c_string(ptr @24), !dbg !33 - %42 = call %Rational @rational_from_c_string(ptr @25), !dbg !34 - %43 = call i1 @"<:Rational> >= <:Rational>"(%Rational %41, %Rational %42), !dbg !34 - call void @"println <:Bool>"(i1 %43), !dbg !34 - br label %return, !dbg !34 +@24 = private unnamed_addr constant [2 x i8] c"0\00", align 1 +@25 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@26 = private unnamed_addr constant [2 x i8] c"0\00", align 1 +@27 = private unnamed_addr constant [2 x i8] c"0\00", align 1 +@28 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@29 = private unnamed_addr constant [2 x i8] c"0\00", align 1 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 return: ; preds = %0 ret void } -define private void @"println <:Rational>"(%Rational %0) !dbg !35 { +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !20 + call void @initialize.2(), !dbg !21 + call void @initialize.3(), !dbg !22 + %1 = call %Rational @rational_from_c_string(ptr @4), !dbg !23 + call void @"println <:Rational>"(%Rational %1), !dbg !23 + %2 = call %Rational @rational_from_c_string(ptr @5), !dbg !24 + %3 = call %Rational @"+ <:Rational>"(%Rational %2), !dbg !24 + call void @"println <:Rational>"(%Rational %3), !dbg !24 + %4 = call %Rational @rational_from_c_string(ptr @6), !dbg !25 + %5 = call %Rational @minus_rational(%Rational %4), !dbg !25 + call void @"println <:Rational>"(%Rational %5), !dbg !25 + %6 = call %Rational @rational_from_c_string(ptr @7), !dbg !26 + %7 = call %Rational @rational_from_c_string(ptr @8), !dbg !27 + %8 = call %Rational @rational_plus_rational(%Rational %6, %Rational %7), !dbg !27 + call void @"println <:Rational>"(%Rational %8), !dbg !27 + %9 = call %Rational @rational_from_c_string(ptr @9), !dbg !28 + %10 = call %Rational @rational_from_c_string(ptr @10), !dbg !29 + %11 = call %Rational @"<:Rational> - <:Rational>"(%Rational %9, %Rational %10), !dbg !29 + call void @"println <:Rational>"(%Rational %11), !dbg !29 + %12 = call %Rational @rational_from_c_string(ptr @11), !dbg !30 + %13 = call %Rational @rational_from_c_string(ptr @12), !dbg !31 + %14 = call %Rational @rational_star_rational(%Rational %12, %Rational %13), !dbg !31 + call void @"println <:Rational>"(%Rational %14), !dbg !31 + %15 = call %Rational @rational_from_c_string(ptr @13), !dbg !32 + %16 = call %Integer @integer_from_i64(i64 3), !dbg !33 + %17 = call %Integer @integer_from_i64(i64 2), !dbg !34 + %18 = call %Rational @integer_slash_integer(%Integer %16, %Integer %17), !dbg !34 + %19 = call %Rational @rational_slash_rational(%Rational %15, %Rational %18), !dbg !34 + call void @"println <:Rational>"(%Rational %19), !dbg !34 + %20 = call %Rational @rational_from_c_string(ptr @14), !dbg !35 + %21 = call %Rational @rational_from_c_string(ptr @15), !dbg !36 + %22 = call i1 @rational_eq_rational(%Rational %20, %Rational %21), !dbg !36 + call void @"println <:Bool>"(i1 %22), !dbg !36 + %23 = call %Rational @rational_from_c_string(ptr @16), !dbg !37 + %24 = call %Rational @rational_from_c_string(ptr @17), !dbg !38 + %25 = call i1 @"<:Rational> != <:Rational>"(%Rational %23, %Rational %24), !dbg !38 + call void @"println <:Bool>"(i1 %25), !dbg !38 + %26 = call %Rational @rational_from_c_string(ptr @18), !dbg !39 + %27 = call %Rational @rational_from_c_string(ptr @19), !dbg !40 + %28 = call i1 @rational_less_rational(%Rational %26, %Rational %27), !dbg !40 + call void @"println <:Bool>"(i1 %28), !dbg !40 + %29 = call %Rational @rational_from_c_string(ptr @20), !dbg !41 + %30 = call %Rational @rational_from_c_string(ptr @21), !dbg !42 + %31 = call i1 @"<:Rational> > <:Rational>"(%Rational %29, %Rational %30), !dbg !42 + call void @"println <:Bool>"(i1 %31), !dbg !42 + %32 = call %Rational @rational_from_c_string(ptr @22), !dbg !43 + %33 = call %Rational @rational_from_c_string(ptr @23), !dbg !44 + %34 = call i1 @"<:Rational> <= <:Rational>"(%Rational %32, %Rational %33), !dbg !44 + call void @"println <:Bool>"(i1 %34), !dbg !44 + %35 = call %Rational @rational_from_c_string(ptr @24), !dbg !45 + %36 = call %Rational @rational_from_c_string(ptr @25), !dbg !46 + %37 = call i1 @"<:Rational> <= <:Rational>"(%Rational %35, %Rational %36), !dbg !46 + call void @"println <:Bool>"(i1 %37), !dbg !46 + %38 = call %Rational @rational_from_c_string(ptr @26), !dbg !47 + %39 = call %Rational @rational_from_c_string(ptr @27), !dbg !48 + %40 = call i1 @"<:Rational> >= <:Rational>"(%Rational %38, %Rational %39), !dbg !48 + call void @"println <:Bool>"(i1 %40), !dbg !48 + %41 = call %Rational @rational_from_c_string(ptr @28), !dbg !20 + %42 = call %Rational @rational_from_c_string(ptr @29), !dbg !49 + %43 = call i1 @"<:Rational> >= <:Rational>"(%Rational %41, %Rational %42), !dbg !49 + call void @"println <:Bool>"(i1 %43), !dbg !49 + br label %return, !dbg !49 + +return: ; preds = %0 + ret void +} + +define private void @"println <:Rational>"(%Rational %0) !dbg !50 { %x = alloca %Rational, align 8 store %Rational %0, ptr %x, align 8 - %2 = load %Rational, ptr %x, align 8, !dbg !36 - %3 = call %String @rational_as_string(%Rational %2), !dbg !36 - call void @"println <:String>"(%String %3), !dbg !36 - br label %return, !dbg !37 + %2 = load %Rational, ptr %x, align 8, !dbg !51 + %3 = call %String @rational_as_string(%Rational %2), !dbg !51 + call void @"println <:String>"(%String %3), !dbg !51 + br label %return, !dbg !52 return: ; preds = %1 ret void @@ -133,15 +217,13 @@ declare %Rational @rational_slash_rational(%Rational, %Rational) declare %Rational @integer_slash_integer(%Integer, %Integer) -declare %Integer @integer_from_i64(i64) - -define private void @"println <:Bool>"(i1 %0) !dbg !38 { +define private void @"println <:Bool>"(i1 %0) !dbg !53 { %x = alloca i1, align 1 store i1 %0, ptr %x, align 1 - %2 = load i1, ptr %x, align 1, !dbg !39 - %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !39 - call void @"println <:String>"(%String %3), !dbg !39 - br label %return, !dbg !40 + %2 = load i1, ptr %x, align 1, !dbg !54 + %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !54 + call void @"println <:String>"(%String %3), !dbg !54 + br label %return, !dbg !55 return: ; preds = %1 ret void @@ -151,21 +233,21 @@ declare %String @"String from <:Bool>"(i1) declare i1 @rational_eq_rational(%Rational, %Rational) -define private i1 @"<:Rational> != <:Rational>"(%Rational %0, %Rational %1) !dbg !41 { +define private i1 @"<:Rational> != <:Rational>"(%Rational %0, %Rational %1) !dbg !56 { %return_value = alloca i1, align 1 %x = alloca %Rational, align 8 store %Rational %0, ptr %x, align 8 %y = alloca %Rational, align 8 store %Rational %1, ptr %y, align 8 - %3 = load %Rational, ptr %x, align 8, !dbg !42 - %4 = load %Rational, ptr %y, align 8, !dbg !42 - %5 = call i1 @rational_eq_rational(%Rational %3, %Rational %4), !dbg !42 - %6 = call i1 @"not <:Bool>"(i1 %5), !dbg !42 - %"$tmp@776" = alloca i1, align 1, !dbg !42 - store i1 %6, ptr %"$tmp@776", align 1, !dbg !42 - %7 = load i1, ptr %"$tmp@776", align 1, !dbg !42 - store i1 %7, ptr %return_value, align 1, !dbg !42 - br label %return, !dbg !42 + %3 = load %Rational, ptr %x, align 8, !dbg !57 + %4 = load %Rational, ptr %y, align 8, !dbg !57 + %5 = call i1 @rational_eq_rational(%Rational %3, %Rational %4), !dbg !57 + %6 = call i1 @"not <:Bool>"(i1 %5), !dbg !57 + %"$tmp@776" = alloca i1, align 1, !dbg !57 + store i1 %6, ptr %"$tmp@776", align 1, !dbg !57 + %7 = load i1, ptr %"$tmp@776", align 1, !dbg !57 + store i1 %7, ptr %return_value, align 1, !dbg !57 + br label %return, !dbg !57 return: ; preds = %2 %8 = load i1, ptr %return_value, align 1 @@ -176,62 +258,62 @@ declare i1 @"not <:Bool>"(i1) declare i1 @rational_less_rational(%Rational, %Rational) -define private i1 @"<:Rational> > <:Rational>"(%Rational %0, %Rational %1) !dbg !43 { +define private i1 @"<:Rational> > <:Rational>"(%Rational %0, %Rational %1) !dbg !58 { %return_value = alloca i1, align 1 %x = alloca %Rational, align 8 store %Rational %0, ptr %x, align 8 %y = alloca %Rational, align 8 store %Rational %1, ptr %y, align 8 - %3 = load %Rational, ptr %y, align 8, !dbg !44 - %4 = load %Rational, ptr %x, align 8, !dbg !44 - %5 = call i1 @rational_less_rational(%Rational %3, %Rational %4), !dbg !44 - %"$tmp@1032" = alloca i1, align 1, !dbg !44 - store i1 %5, ptr %"$tmp@1032", align 1, !dbg !44 - %6 = load i1, ptr %"$tmp@1032", align 1, !dbg !44 - store i1 %6, ptr %return_value, align 1, !dbg !44 - br label %return, !dbg !44 + %3 = load %Rational, ptr %y, align 8, !dbg !59 + %4 = load %Rational, ptr %x, align 8, !dbg !59 + %5 = call i1 @rational_less_rational(%Rational %3, %Rational %4), !dbg !59 + %"$tmp@1032" = alloca i1, align 1, !dbg !59 + store i1 %5, ptr %"$tmp@1032", align 1, !dbg !59 + %6 = load i1, ptr %"$tmp@1032", align 1, !dbg !59 + store i1 %6, ptr %return_value, align 1, !dbg !59 + br label %return, !dbg !59 return: ; preds = %2 %7 = load i1, ptr %return_value, align 1 ret i1 %7 } -define private i1 @"<:Rational> <= <:Rational>"(%Rational %0, %Rational %1) !dbg !45 { +define private i1 @"<:Rational> <= <:Rational>"(%Rational %0, %Rational %1) !dbg !60 { %return_value = alloca i1, align 1 %x = alloca %Rational, align 8 store %Rational %0, ptr %x, align 8 %y = alloca %Rational, align 8 store %Rational %1, ptr %y, align 8 - %3 = load %Rational, ptr %x, align 8, !dbg !46 - %4 = load %Rational, ptr %y, align 8, !dbg !46 - %5 = call i1 @"<:Rational> > <:Rational>"(%Rational %3, %Rational %4), !dbg !46 - %6 = call i1 @"not <:Bool>"(i1 %5), !dbg !46 - %"$tmp@1068" = alloca i1, align 1, !dbg !46 - store i1 %6, ptr %"$tmp@1068", align 1, !dbg !46 - %7 = load i1, ptr %"$tmp@1068", align 1, !dbg !46 - store i1 %7, ptr %return_value, align 1, !dbg !46 - br label %return, !dbg !46 + %3 = load %Rational, ptr %x, align 8, !dbg !61 + %4 = load %Rational, ptr %y, align 8, !dbg !61 + %5 = call i1 @"<:Rational> > <:Rational>"(%Rational %3, %Rational %4), !dbg !61 + %6 = call i1 @"not <:Bool>"(i1 %5), !dbg !61 + %"$tmp@1068" = alloca i1, align 1, !dbg !61 + store i1 %6, ptr %"$tmp@1068", align 1, !dbg !61 + %7 = load i1, ptr %"$tmp@1068", align 1, !dbg !61 + store i1 %7, ptr %return_value, align 1, !dbg !61 + br label %return, !dbg !61 return: ; preds = %2 %8 = load i1, ptr %return_value, align 1 ret i1 %8 } -define private i1 @"<:Rational> >= <:Rational>"(%Rational %0, %Rational %1) !dbg !47 { +define private i1 @"<:Rational> >= <:Rational>"(%Rational %0, %Rational %1) !dbg !62 { %return_value = alloca i1, align 1 %x = alloca %Rational, align 8 store %Rational %0, ptr %x, align 8 %y = alloca %Rational, align 8 store %Rational %1, ptr %y, align 8 - %3 = load %Rational, ptr %x, align 8, !dbg !48 - %4 = load %Rational, ptr %y, align 8, !dbg !48 - %5 = call i1 @rational_less_rational(%Rational %3, %Rational %4), !dbg !48 - %6 = call i1 @"not <:Bool>"(i1 %5), !dbg !48 - %"$tmp@1110" = alloca i1, align 1, !dbg !48 - store i1 %6, ptr %"$tmp@1110", align 1, !dbg !48 - %7 = load i1, ptr %"$tmp@1110", align 1, !dbg !48 - store i1 %7, ptr %return_value, align 1, !dbg !48 - br label %return, !dbg !48 + %3 = load %Rational, ptr %x, align 8, !dbg !63 + %4 = load %Rational, ptr %y, align 8, !dbg !63 + %5 = call i1 @rational_less_rational(%Rational %3, %Rational %4), !dbg !63 + %6 = call i1 @"not <:Bool>"(i1 %5), !dbg !63 + %"$tmp@1110" = alloca i1, align 1, !dbg !63 + store i1 %6, ptr %"$tmp@1110", align 1, !dbg !63 + %7 = load i1, ptr %"$tmp@1110", align 1, !dbg !63 + store i1 %7, ptr %return_value, align 1, !dbg !63 + br label %return, !dbg !63 return: ; preds = %2 %8 = load i1, ptr %return_value, align 1 @@ -244,49 +326,64 @@ return: ; preds = %2 !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 8, scope: !3) -!8 = !DILocation(line: 1, column: 9, scope: !3) -!9 = !DILocation(line: 2, column: 9, scope: !3) -!10 = !DILocation(line: 3, column: 8, scope: !3) -!11 = !DILocation(line: 3, column: 14, scope: !3) -!12 = !DILocation(line: 4, column: 8, scope: !3) -!13 = !DILocation(line: 4, column: 14, scope: !3) -!14 = !DILocation(line: 5, column: 8, scope: !3) -!15 = !DILocation(line: 5, column: 14, scope: !3) -!16 = !DILocation(line: 6, column: 8, scope: !3) -!17 = !DILocation(line: 6, column: 15, scope: !3) -!18 = !DILocation(line: 6, column: 19, scope: !3) -!19 = !DILocation(line: 7, column: 8, scope: !3) -!20 = !DILocation(line: 7, column: 15, scope: !3) -!21 = !DILocation(line: 8, column: 8, scope: !3) -!22 = !DILocation(line: 8, column: 15, scope: !3) -!23 = !DILocation(line: 9, column: 8, scope: !3) -!24 = !DILocation(line: 9, column: 14, scope: !3) -!25 = !DILocation(line: 10, column: 8, scope: !3) -!26 = !DILocation(line: 10, column: 14, scope: !3) -!27 = !DILocation(line: 11, column: 8, scope: !3) -!28 = !DILocation(line: 11, column: 15, scope: !3) -!29 = !DILocation(line: 12, column: 8, scope: !3) -!30 = !DILocation(line: 12, column: 15, scope: !3) -!31 = !DILocation(line: 13, column: 8, scope: !3) -!32 = !DILocation(line: 13, column: 15, scope: !3) -!33 = !DILocation(line: 14, column: 8, scope: !3) -!34 = !DILocation(line: 14, column: 15, scope: !3) -!35 = distinct !DISubprogram(name: "println <:Rational>", linkageName: "println <:Rational>", scope: !3, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!36 = !DILocation(line: 11, column: 9, scope: !35) -!37 = !DILocation(line: 10, column: 6, scope: !35) -!38 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !3, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!39 = !DILocation(line: 11, column: 9, scope: !38) -!40 = !DILocation(line: 10, column: 6, scope: !38) -!41 = distinct !DISubprogram(name: "<:Rational> != <:Rational>", linkageName: "<:Rational> != <:Rational>", scope: !3, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!42 = !DILocation(line: 14, column: 18, scope: !41) -!43 = distinct !DISubprogram(name: "<:Rational> > <:Rational>", linkageName: "<:Rational> > <:Rational>", scope: !3, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!44 = !DILocation(line: 14, column: 18, scope: !43) -!45 = distinct !DISubprogram(name: "<:Rational> <= <:Rational>", linkageName: "<:Rational> <= <:Rational>", scope: !3, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!46 = !DILocation(line: 14, column: 18, scope: !45) -!47 = distinct !DISubprogram(name: "<:Rational> >= <:Rational>", linkageName: "<:Rational> >= <:Rational>", scope: !3, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!48 = !DILocation(line: 14, column: 18, scope: !47) +!7 = !DILocation(line: 8, column: 2, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 14, column: 8, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 4, column: 7, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 4, column: 2, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 8, column: 2, scope: !18) +!20 = !DILocation(line: 14, column: 8, scope: !18) +!21 = !DILocation(line: 4, column: 7, scope: !18) +!22 = !DILocation(line: 4, column: 2, scope: !18) +!23 = !DILocation(line: 0, column: 8, scope: !18) +!24 = !DILocation(line: 1, column: 9, scope: !18) +!25 = !DILocation(line: 2, column: 9, scope: !18) +!26 = !DILocation(line: 3, column: 8, scope: !18) +!27 = !DILocation(line: 3, column: 14, scope: !18) +!28 = !DILocation(line: 4, column: 8, scope: !18) +!29 = !DILocation(line: 4, column: 14, scope: !18) +!30 = !DILocation(line: 5, column: 8, scope: !18) +!31 = !DILocation(line: 5, column: 14, scope: !18) +!32 = !DILocation(line: 6, column: 8, scope: !18) +!33 = !DILocation(line: 6, column: 15, scope: !18) +!34 = !DILocation(line: 6, column: 19, scope: !18) +!35 = !DILocation(line: 7, column: 8, scope: !18) +!36 = !DILocation(line: 7, column: 15, scope: !18) +!37 = !DILocation(line: 8, column: 8, scope: !18) +!38 = !DILocation(line: 8, column: 15, scope: !18) +!39 = !DILocation(line: 9, column: 8, scope: !18) +!40 = !DILocation(line: 9, column: 14, scope: !18) +!41 = !DILocation(line: 10, column: 8, scope: !18) +!42 = !DILocation(line: 10, column: 14, scope: !18) +!43 = !DILocation(line: 11, column: 8, scope: !18) +!44 = !DILocation(line: 11, column: 15, scope: !18) +!45 = !DILocation(line: 12, column: 8, scope: !18) +!46 = !DILocation(line: 12, column: 15, scope: !18) +!47 = !DILocation(line: 13, column: 8, scope: !18) +!48 = !DILocation(line: 13, column: 15, scope: !18) +!49 = !DILocation(line: 14, column: 15, scope: !18) +!50 = distinct !DISubprogram(name: "println <:Rational>", linkageName: "println <:Rational>", scope: !18, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!51 = !DILocation(line: 11, column: 9, scope: !50) +!52 = !DILocation(line: 10, column: 6, scope: !50) +!53 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !18, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!54 = !DILocation(line: 11, column: 9, scope: !53) +!55 = !DILocation(line: 10, column: 6, scope: !53) +!56 = distinct !DISubprogram(name: "<:Rational> != <:Rational>", linkageName: "<:Rational> != <:Rational>", scope: !18, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!57 = !DILocation(line: 14, column: 18, scope: !56) +!58 = distinct !DISubprogram(name: "<:Rational> > <:Rational>", linkageName: "<:Rational> > <:Rational>", scope: !18, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!59 = !DILocation(line: 14, column: 18, scope: !58) +!60 = distinct !DISubprogram(name: "<:Rational> <= <:Rational>", linkageName: "<:Rational> <= <:Rational>", scope: !18, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!61 = !DILocation(line: 14, column: 18, scope: !60) +!62 = distinct !DISubprogram(name: "<:Rational> >= <:Rational>", linkageName: "<:Rational> >= <:Rational>", scope: !18, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!63 = !DILocation(line: 14, column: 18, scope: !62) diff --git a/src/tests/snapshots/ppl__tests__reference_mut.hir.snap b/src/tests/snapshots/ppl__tests__reference_mut.hir.snap index 24ef65f0..1d339d6f 100644 --- a/src/tests/snapshots/ppl__tests__reference_mut.hir.snap +++ b/src/tests/snapshots/ppl__tests__reference_mut.hir.snap @@ -14,8 +14,8 @@ let y: ReferenceMut = `reference to mutable <:ReferenceMut>`(( fn reference to mutable > -> ReferenceMut: - let mut $tmp@4774: ReferenceMut = (ref:ReferenceMut) - return ($tmp@4774:ReferenceMut) + let mut $tmp@4930: ReferenceMut = (ref:ReferenceMut) + return ($tmp@4930:ReferenceMut) @mangle_as("integer_as_string") diff --git a/src/tests/snapshots/ppl__tests__reference_mut.ir.snap b/src/tests/snapshots/ppl__tests__reference_mut.ir.snap index 697da767..7ed0de7b 100644 --- a/src/tests/snapshots/ppl__tests__reference_mut.ir.snap +++ b/src/tests/snapshots/ppl__tests__reference_mut.ir.snap @@ -5,76 +5,158 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Integer = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } - +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 @x = global %Integer zeroinitializer @y = global ptr null -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - call void @initialize.1(), !dbg !8 - %1 = load ptr, ptr @y, align 8, !dbg !9 - %2 = call %Integer @clone_integer(ptr %1), !dbg !9 - call void @"println <:Integer>"(%Integer %2), !dbg !9 - %3 = load ptr, ptr @y, align 8, !dbg !10 - %4 = call %Integer @integer_from_i64(i64 2), !dbg !11 - store %Integer %4, ptr %3, align 8, !dbg !11 - %5 = load ptr, ptr @y, align 8, !dbg !12 - %6 = call %Integer @clone_integer(ptr %5), !dbg !12 - call void @"println <:Integer>"(%Integer %6), !dbg !12 - %7 = call %Integer @clone_integer(ptr @x), !dbg !13 - call void @"println <:Integer>"(%Integer %7), !dbg !13 - call void @destroy_integer(ptr @x), !dbg !14 +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 br label %return, !dbg !14 return: ; preds = %0 ret void } -define private void @initialize() !dbg !15 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !16 - store %Integer %1, ptr @x, align 8, !dbg !16 - br label %return, !dbg !16 +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 return: ; preds = %0 ret void } -declare %Integer @integer_from_i64(i64) +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !20 + call void @initialize.3(), !dbg !21 + call void @initialize.4(), !dbg !22 + call void @initialize.5(), !dbg !23 + %1 = load ptr, ptr @y, align 8, !dbg !24 + %2 = call %Integer @clone_integer(ptr %1), !dbg !24 + call void @"println <:Integer>"(%Integer %2), !dbg !24 + %3 = load ptr, ptr @y, align 8, !dbg !25 + %4 = call %Integer @integer_from_i64(i64 2), !dbg !26 + store %Integer %4, ptr %3, align 8, !dbg !26 + %5 = load ptr, ptr @y, align 8, !dbg !27 + %6 = call %Integer @clone_integer(ptr %5), !dbg !27 + call void @"println <:Integer>"(%Integer %6), !dbg !27 + %7 = call %Integer @clone_integer(ptr @x), !dbg !28 + call void @"println <:Integer>"(%Integer %7), !dbg !28 + call void @destroy_integer(ptr @x), !dbg !29 + br label %return, !dbg !29 + +return: ; preds = %0 + ret void +} + +define private void @initialize.4() !dbg !30 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !31 + store %Integer %1, ptr @x, align 8, !dbg !31 + br label %return, !dbg !31 + +return: ; preds = %0 + ret void +} -define private void @initialize.1() !dbg !17 { - %1 = call ptr @"reference to mutable <:ReferenceMut>"(ptr @x), !dbg !18 - store ptr %1, ptr @y, align 8, !dbg !18 - br label %return, !dbg !18 +define private void @initialize.5() !dbg !32 { + %1 = call ptr @"reference to mutable <:ReferenceMut>"(ptr @x), !dbg !33 + store ptr %1, ptr @y, align 8, !dbg !33 + br label %return, !dbg !33 return: ; preds = %0 ret void } -define private ptr @"reference to mutable <:ReferenceMut>"(ptr %0) !dbg !19 { +define private ptr @"reference to mutable <:ReferenceMut>"(ptr %0) !dbg !34 { %return_value = alloca ptr, align 8 %ref = alloca ptr, align 8 store ptr %0, ptr %ref, align 8 - %2 = load ptr, ptr %ref, align 8, !dbg !20 - %"$tmp@4774" = alloca ptr, align 8, !dbg !20 - store ptr %2, ptr %"$tmp@4774", align 8, !dbg !20 - %3 = load ptr, ptr %"$tmp@4774", align 8, !dbg !20 - store ptr %3, ptr %return_value, align 8, !dbg !20 - br label %return, !dbg !20 + %2 = load ptr, ptr %ref, align 8, !dbg !35 + %"$tmp@4930" = alloca ptr, align 8, !dbg !35 + store ptr %2, ptr %"$tmp@4930", align 8, !dbg !35 + %3 = load ptr, ptr %"$tmp@4930", align 8, !dbg !35 + store ptr %3, ptr %return_value, align 8, !dbg !35 + br label %return, !dbg !35 return: ; preds = %1 %4 = load ptr, ptr %return_value, align 8 ret ptr %4 } -define private void @"println <:Integer>"(%Integer %0) !dbg !21 { +define private void @"println <:Integer>"(%Integer %0) !dbg !36 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !22 - %3 = call %String @integer_as_string(%Integer %2), !dbg !22 - call void @"println <:String>"(%String %3), !dbg !22 - br label %return, !dbg !22 + %2 = load %Integer, ptr %x, align 8, !dbg !37 + %3 = call %String @integer_as_string(%Integer %2), !dbg !37 + call void @"println <:String>"(%String %3), !dbg !37 + br label %return, !dbg !37 return: ; preds = %1 ret void @@ -94,23 +176,38 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 12, scope: !3) -!8 = !DILocation(line: 1, column: 8, scope: !3) -!9 = !DILocation(line: 2, column: 8, scope: !3) -!10 = !DILocation(line: 3, scope: !3) -!11 = !DILocation(line: 3, column: 4, scope: !3) -!12 = !DILocation(line: 4, column: 8, scope: !3) -!13 = !DILocation(line: 5, column: 8, scope: !3) -!14 = !DILocation(line: 0, scope: !3) -!15 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!16 = !DILocation(line: 0, column: 12, scope: !15) -!17 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!18 = !DILocation(line: 1, column: 29, scope: !17) -!19 = distinct !DISubprogram(name: "reference to mutable <:ReferenceMut>", linkageName: "reference to mutable <:ReferenceMut>", scope: !17, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!20 = !DILocation(line: 6, scope: !19) -!21 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!22 = !DILocation(line: 6, scope: !21) +!7 = !DILocation(line: 6, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 6, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 4, column: 2, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 3, column: 3, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 6, scope: !18) +!20 = !DILocation(line: 4, column: 2, scope: !18) +!21 = !DILocation(line: 3, column: 3, scope: !18) +!22 = !DILocation(line: 0, column: 12, scope: !18) +!23 = !DILocation(line: 1, column: 8, scope: !18) +!24 = !DILocation(line: 2, column: 8, scope: !18) +!25 = !DILocation(line: 3, scope: !18) +!26 = !DILocation(line: 3, column: 4, scope: !18) +!27 = !DILocation(line: 4, column: 8, scope: !18) +!28 = !DILocation(line: 5, column: 8, scope: !18) +!29 = !DILocation(line: 0, scope: !18) +!30 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !18, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!31 = !DILocation(line: 0, column: 12, scope: !30) +!32 = distinct !DISubprogram(name: "initialize.5", linkageName: "initialize.5", scope: !18, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!33 = !DILocation(line: 1, column: 29, scope: !32) +!34 = distinct !DISubprogram(name: "reference to mutable <:ReferenceMut>", linkageName: "reference to mutable <:ReferenceMut>", scope: !32, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!35 = !DILocation(line: 6, scope: !34) +!36 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !18, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!37 = !DILocation(line: 6, scope: !36) diff --git a/src/tests/snapshots/ppl__tests__reference_to_literal.ir.snap b/src/tests/snapshots/ppl__tests__reference_to_literal.ir.snap index aa740263..3502afc4 100644 --- a/src/tests/snapshots/ppl__tests__reference_to_literal.ir.snap +++ b/src/tests/snapshots/ppl__tests__reference_to_literal.ir.snap @@ -5,40 +5,124 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Integer = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } - +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 @"$tmp@39" = global %Integer zeroinitializer -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - call void @"foo <:Reference>"(ptr @"$tmp@39"), !dbg !7 - call void @destroy_integer(ptr @"$tmp@39"), !dbg !7 - br label %return, !dbg !7 +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 return: ; preds = %0 ret void } -define void @"foo <:Reference>"(ptr %0) !dbg !8 { +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !19 + call void @initialize.3(), !dbg !19 + call void @initialize.4(), !dbg !20 + call void @"foo <:Reference>"(ptr @"$tmp@39"), !dbg !20 + call void @destroy_integer(ptr @"$tmp@39"), !dbg !20 + br label %return, !dbg !20 + +return: ; preds = %0 + ret void +} + +define void @"foo <:Reference>"(ptr %0) !dbg !21 { %x = alloca ptr, align 8 store ptr %0, ptr %x, align 8 - %2 = load ptr, ptr %x, align 8, !dbg !9 - %3 = call %Integer @clone_integer(ptr %2), !dbg !9 - call void @"println <:Integer>"(%Integer %3), !dbg !9 - br label %return, !dbg !10 + %2 = load ptr, ptr %x, align 8, !dbg !22 + %3 = call %Integer @clone_integer(ptr %2), !dbg !22 + call void @"println <:Integer>"(%Integer %3), !dbg !22 + br label %return, !dbg !23 return: ; preds = %1 ret void } -define private void @"println <:Integer>"(%Integer %0) !dbg !11 { +define private void @"println <:Integer>"(%Integer %0) !dbg !24 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !12 - %3 = call %String @integer_as_string(%Integer %2), !dbg !12 - call void @"println <:String>"(%String %3), !dbg !12 - br label %return, !dbg !12 + %2 = load %Integer, ptr %x, align 8, !dbg !25 + %3 = call %String @integer_as_string(%Integer %2), !dbg !25 + call void @"println <:String>"(%String %3), !dbg !25 + br label %return, !dbg !25 return: ; preds = %1 ret void @@ -50,17 +134,15 @@ declare %String @integer_as_string(%Integer) declare %Integer @clone_integer(ptr) -define private void @initialize() !dbg !13 { - %1 = call %Integer @integer_from_i64(i64 42), !dbg !14 - store %Integer %1, ptr @"$tmp@39", align 8, !dbg !14 - br label %return, !dbg !14 +define private void @initialize.4() !dbg !26 { + %1 = call %Integer @integer_from_i64(i64 42), !dbg !27 + store %Integer %1, ptr @"$tmp@39", align 8, !dbg !27 + br label %return, !dbg !27 return: ; preds = %0 ret void } -declare %Integer @integer_from_i64(i64) - declare void @destroy_integer(ptr) !llvm.module.flags = !{!0} @@ -69,15 +151,28 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 2, column: 4, scope: !3) -!8 = distinct !DISubprogram(name: "foo <:Reference>", linkageName: "foo <:Reference>", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!9 = !DILocation(line: 0, column: 32, scope: !8) -!10 = !DILocation(line: 0, column: 24, scope: !8) -!11 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !8, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!12 = !DILocation(line: 2, column: 6, scope: !11) -!13 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!14 = !DILocation(line: 2, column: 4, scope: !13) +!7 = !DILocation(line: 2, column: 6, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 2, column: 6, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 2, column: 6, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 2, column: 6, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 2, column: 6, scope: !18) +!20 = !DILocation(line: 2, column: 4, scope: !18) +!21 = distinct !DISubprogram(name: "foo <:Reference>", linkageName: "foo <:Reference>", scope: !18, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!22 = !DILocation(line: 0, column: 32, scope: !21) +!23 = !DILocation(line: 0, column: 24, scope: !21) +!24 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !21, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!25 = !DILocation(line: 2, column: 6, scope: !24) +!26 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !18, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!27 = !DILocation(line: 2, column: 4, scope: !26) diff --git a/src/tests/snapshots/ppl__tests__reference_to_none.ir.snap b/src/tests/snapshots/ppl__tests__reference_to_none.ir.snap index 036716b5..d5350a8d 100644 --- a/src/tests/snapshots/ppl__tests__reference_to_none.ir.snap +++ b/src/tests/snapshots/ppl__tests__reference_to_none.ir.snap @@ -5,34 +5,117 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" +%"Type" = type { %String, %Integer } %String = type { ptr } +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } -@0 = private unnamed_addr constant [4 x i8] c"foo\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@4 = private unnamed_addr constant [4 x i8] c"foo\00", align 1 -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - call void @"foo <:Reference>"(), !dbg !8 +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 br label %return, !dbg !8 return: ; preds = %0 ret void } -define void @"foo <:Reference>"() !dbg !9 { - %1 = call %String @string_from_c_string_and_length(ptr @0, i64 3), !dbg !10 - call void @"println <:String>"(%String %1), !dbg !10 +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 br label %return, !dbg !11 return: ; preds = %0 ret void } -declare void @"println <:String>"(%String) +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 -declare %String @string_from_c_string_and_length(ptr, i64) +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !19 + call void @initialize.3(), !dbg !19 + call void @initialize.4(), !dbg !20 + call void @"foo <:Reference>"(), !dbg !21 + br label %return, !dbg !21 + +return: ; preds = %0 + ret void +} + +define void @"foo <:Reference>"() !dbg !22 { + %1 = call %String @string_from_c_string_and_length(ptr @4, i64 3), !dbg !23 + call void @"println <:String>"(%String %1), !dbg !23 + br label %return, !dbg !24 + +return: ; preds = %0 + ret void +} + +declare void @"println <:String>"(%String) -define private void @initialize() !dbg !12 { - br label %return, !dbg !13 +define private void @initialize.4() !dbg !25 { + br label %return, !dbg !26 return: ; preds = %0 ret void @@ -44,14 +127,27 @@ return: ; preds = %0 !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 2, column: 8, scope: !3) -!8 = !DILocation(line: 3, column: 4, scope: !3) -!9 = distinct !DISubprogram(name: "foo <:Reference>", linkageName: "foo <:Reference>", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 0, column: 27, scope: !9) -!11 = !DILocation(line: 0, column: 19, scope: !9) -!12 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 2, column: 8, scope: !12) +!7 = !DILocation(line: 3, column: 5, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 3, column: 5, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 3, column: 5, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 3, column: 5, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 3, column: 5, scope: !18) +!20 = !DILocation(line: 2, column: 8, scope: !18) +!21 = !DILocation(line: 3, column: 4, scope: !18) +!22 = distinct !DISubprogram(name: "foo <:Reference>", linkageName: "foo <:Reference>", scope: !18, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!23 = !DILocation(line: 0, column: 27, scope: !22) +!24 = !DILocation(line: 0, column: 19, scope: !22) +!25 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !18, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!26 = !DILocation(line: 2, column: 8, scope: !25) diff --git a/src/tests/snapshots/ppl__tests__references.hir.snap b/src/tests/snapshots/ppl__tests__references.hir.snap index 269b58d0..c598b83f 100644 --- a/src/tests/snapshots/ppl__tests__references.hir.snap +++ b/src/tests/snapshots/ppl__tests__references.hir.snap @@ -2,9 +2,9 @@ source: src/tests/mod.rs expression: hir --- -let n: Integer = `size of <:Type>`(Type { name: "I32", size: 4 }) +let n: Integer = `size of <:Type>`((Type:Type)) let address: MemoryAddress = `allocate <:Integer> bytes`(`clone <:Reference>`((n:Integer))) -let value: ReferenceMut = `<:Type> at <:Reference>`(Type { name: "I32", size: 4 }, (&address:Reference)) +let value: ReferenceMut = `<:Type> at <:Reference>`((Type:Type), (&address:Reference)) (value:ReferenceMut) = `<:Integer> as I32`(0) `println <:I32>`((*value:I32)) (value:ReferenceMut) = `<:Integer> as I32`(1) @@ -16,8 +16,8 @@ let value: ReferenceMut = `<:Type> at <:Reference>`(Typ fn size of > -> Integer: - let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4426:Integer) + let $tmp@4582: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4582:Integer) @mangle_as("read_memory") diff --git a/src/tests/snapshots/ppl__tests__references.ir.snap b/src/tests/snapshots/ppl__tests__references.ir.snap index 2f0982d7..42f69e44 100644 --- a/src/tests/snapshots/ppl__tests__references.ir.snap +++ b/src/tests/snapshots/ppl__tests__references.ir.snap @@ -5,91 +5,158 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Integer = type { ptr } -%MemoryAddress = type { ptr } -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } +%"Type" = type { %String, %Integer } %String = type { ptr } - +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%MemoryAddress = type { %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 @n = global %Integer zeroinitializer -@0 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 @address = global %MemoryAddress zeroinitializer @value = global ptr null -@1 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 - -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - call void @initialize.1(), !dbg !8 - call void @initialize.2(), !dbg !9 - %1 = load ptr, ptr @value, align 8, !dbg !10 - %2 = call %Integer @integer_from_i64(i64 0), !dbg !11 - %3 = call i32 @integer_as_i32(%Integer %2), !dbg !11 - store i32 %3, ptr %1, align 4, !dbg !11 - %4 = load ptr, ptr @value, align 8, !dbg !12 - %5 = load i32, ptr %4, align 4, !dbg !12 - call void @"println <:I32>"(i32 %5), !dbg !12 - %6 = load ptr, ptr @value, align 8, !dbg !13 - %7 = call %Integer @integer_from_i64(i64 1), !dbg !14 - %8 = call i32 @integer_as_i32(%Integer %7), !dbg !14 - store i32 %8, ptr %6, align 4, !dbg !14 - %9 = load ptr, ptr @value, align 8, !dbg !15 - %10 = load i32, ptr %9, align 4, !dbg !15 - call void @"println <:I32>"(i32 %10), !dbg !15 - call void @free_memory(ptr @address), !dbg !16 - call void @destroy_integer(ptr @n), !dbg !17 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 br label %return, !dbg !17 return: ; preds = %0 ret void } -define private void @initialize() !dbg !18 { - %1 = alloca %"Type", align 8, !dbg !19 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !19 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !19 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 3), !dbg !20 - store %String %2, ptr %"Type.name", align 8, !dbg !20 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !20 - %3 = call %Integer @integer_from_i64(i64 4), !dbg !20 - store %Integer %3, ptr %"Type.size", align 8, !dbg !20 - %4 = load %"Type", ptr %1, align 8, !dbg !20 - %5 = call %Integer @"size of <:Type>"(%"Type" %4), !dbg !20 - store %Integer %5, ptr @n, align 8, !dbg !20 - br label %return, !dbg !20 +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !20 + call void @initialize.2(), !dbg !21 + call void @initialize.3(), !dbg !22 + call void @initialize.4(), !dbg !23 + call void @initialize.5(), !dbg !24 + call void @initialize.6(), !dbg !25 + %1 = load ptr, ptr @value, align 8, !dbg !26 + %2 = call %Integer @integer_from_i64(i64 0), !dbg !27 + %3 = call i32 @integer_as_i32(%Integer %2), !dbg !27 + store i32 %3, ptr %1, align 4, !dbg !27 + %4 = load ptr, ptr @value, align 8, !dbg !28 + %5 = load i32, ptr %4, align 4, !dbg !28 + call void @"println <:I32>"(i32 %5), !dbg !28 + %6 = load ptr, ptr @value, align 8, !dbg !29 + %7 = call %Integer @integer_from_i64(i64 1), !dbg !30 + %8 = call i32 @integer_as_i32(%Integer %7), !dbg !30 + store i32 %8, ptr %6, align 4, !dbg !30 + %9 = load ptr, ptr @value, align 8, !dbg !31 + %10 = load i32, ptr %9, align 4, !dbg !31 + call void @"println <:I32>"(i32 %10), !dbg !31 + call void @free_memory(ptr @address), !dbg !32 + call void @destroy_integer(ptr @n), !dbg !33 + br label %return, !dbg !33 + +return: ; preds = %0 + ret void +} + +define private void @initialize.4() !dbg !34 { + %1 = load %"Type", ptr @"Type", align 8, !dbg !35 + %2 = call %Integer @"size of <:Type>"(%"Type" %1), !dbg !35 + store %Integer %2, ptr @n, align 8, !dbg !35 + br label %return, !dbg !35 return: ; preds = %0 ret void } -define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !21 { +define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !36 { %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !22 - %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !22 - %3 = call %Integer @clone_integer(ptr %size), !dbg !22 - %"$tmp@4426" = alloca %Integer, align 8, !dbg !22 - store %Integer %3, ptr %"$tmp@4426", align 8, !dbg !22 - %4 = load %Integer, ptr %"$tmp@4426", align 8, !dbg !22 - store %Integer %4, ptr %return_value, align 8, !dbg !22 - br label %return, !dbg !22 + %size = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 1, !dbg !37 + %2 = call %Integer @clone_integer(ptr %size), !dbg !37 + %"$tmp@4582" = alloca %Integer, align 8, !dbg !37 + store %Integer %2, ptr %"$tmp@4582", align 8, !dbg !37 + %3 = load %Integer, ptr %"$tmp@4582", align 8, !dbg !37 + store %Integer %3, ptr %return_value, align 8, !dbg !37 + br label %return, !dbg !37 return: ; preds = %1 - %5 = load %Integer, ptr %return_value, align 8 - ret %Integer %5 + %4 = load %Integer, ptr %return_value, align 8 + ret %Integer %4 } declare %Integer @clone_integer(ptr) -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define private void @initialize.1() !dbg !23 { - %1 = call %Integer @clone_integer(ptr @n), !dbg !24 - %2 = call %MemoryAddress @allocate_n_bytes(%Integer %1), !dbg !24 - store %MemoryAddress %2, ptr @address, align 8, !dbg !24 - br label %return, !dbg !24 +define private void @initialize.5() !dbg !38 { + %1 = call %Integer @clone_integer(ptr @n), !dbg !39 + %2 = call %MemoryAddress @allocate_n_bytes(%Integer %1), !dbg !39 + store %MemoryAddress %2, ptr @address, align 8, !dbg !39 + br label %return, !dbg !39 return: ; preds = %0 ret void @@ -97,19 +164,11 @@ return: ; preds = %0 declare %MemoryAddress @allocate_n_bytes(%Integer) -define private void @initialize.2() !dbg !25 { - %1 = alloca %"Type", align 8, !dbg !26 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !26 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !26 - %2 = call %String @string_from_c_string_and_length(ptr @1, i64 3), !dbg !27 - store %String %2, ptr %"Type.name", align 8, !dbg !27 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !27 - %3 = call %Integer @integer_from_i64(i64 4), !dbg !27 - store %Integer %3, ptr %"Type.size", align 8, !dbg !27 - %4 = load %"Type", ptr %1, align 8, !dbg !27 - %5 = call ptr @read_memory(%"Type" %4, ptr @address), !dbg !28 - store ptr %5, ptr @value, align 8, !dbg !28 - br label %return, !dbg !28 +define private void @initialize.6() !dbg !40 { + %1 = load %"Type", ptr @"Type", align 8, !dbg !41 + %2 = call ptr @read_memory(%"Type" %1, ptr @address), !dbg !42 + store ptr %2, ptr @value, align 8, !dbg !42 + br label %return, !dbg !42 return: ; preds = %0 ret void @@ -119,13 +178,13 @@ declare ptr @read_memory(%"Type", ptr) declare i32 @integer_as_i32(%Integer) -define private void @"println <:I32>"(i32 %0) !dbg !29 { +define private void @"println <:I32>"(i32 %0) !dbg !43 { %x = alloca i32, align 4 store i32 %0, ptr %x, align 4 - %2 = load i32, ptr %x, align 4, !dbg !30 - %3 = call %String @i32_as_string(i32 %2), !dbg !30 - call void @"println <:String>"(%String %3), !dbg !30 - br label %return, !dbg !31 + %2 = load i32, ptr %x, align 4, !dbg !44 + %3 = call %String @i32_as_string(i32 %2), !dbg !44 + call void @"println <:String>"(%String %3), !dbg !44 + br label %return, !dbg !45 return: ; preds = %1 ret void @@ -145,32 +204,46 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 8, scope: !3) -!8 = !DILocation(line: 2, column: 14, scope: !3) -!9 = !DILocation(line: 3, column: 12, scope: !3) -!10 = !DILocation(line: 4, scope: !3) -!11 = !DILocation(line: 4, column: 8, scope: !3) -!12 = !DILocation(line: 5, column: 8, scope: !3) -!13 = !DILocation(line: 6, scope: !3) -!14 = !DILocation(line: 6, column: 8, scope: !3) -!15 = !DILocation(line: 7, column: 8, scope: !3) -!16 = !DILocation(line: 8, column: 5, scope: !3) -!17 = !DILocation(line: 0, scope: !3) -!18 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!19 = !DILocation(line: 0, column: 16, scope: !18) -!20 = !DILocation(line: 0, scope: !18) -!21 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !18, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!22 = !DILocation(line: 8, column: 12, scope: !21) -!23 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!24 = !DILocation(line: 2, column: 23, scope: !23) -!25 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!26 = !DILocation(line: 3, column: 12, scope: !25) -!27 = !DILocation(line: 0, scope: !25) -!28 = !DILocation(line: 3, column: 19, scope: !25) -!29 = distinct !DISubprogram(name: "println <:I32>", linkageName: "println <:I32>", scope: !3, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!30 = !DILocation(line: 8, column: 12, scope: !29) -!31 = !DILocation(line: 8, column: 3, scope: !29) +!7 = !DILocation(line: 5, column: 7, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 8, column: 12, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 2, column: 10, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 2, column: 5, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 5, column: 7, scope: !18) +!20 = !DILocation(line: 8, column: 12, scope: !18) +!21 = !DILocation(line: 2, column: 10, scope: !18) +!22 = !DILocation(line: 2, column: 5, scope: !18) +!23 = !DILocation(line: 0, column: 8, scope: !18) +!24 = !DILocation(line: 2, column: 14, scope: !18) +!25 = !DILocation(line: 3, column: 12, scope: !18) +!26 = !DILocation(line: 4, scope: !18) +!27 = !DILocation(line: 4, column: 8, scope: !18) +!28 = !DILocation(line: 5, column: 8, scope: !18) +!29 = !DILocation(line: 6, scope: !18) +!30 = !DILocation(line: 6, column: 8, scope: !18) +!31 = !DILocation(line: 7, column: 8, scope: !18) +!32 = !DILocation(line: 8, column: 5, scope: !18) +!33 = !DILocation(line: 0, scope: !18) +!34 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !18, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!35 = !DILocation(line: 0, column: 16, scope: !34) +!36 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !34, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!37 = !DILocation(line: 8, column: 12, scope: !36) +!38 = distinct !DISubprogram(name: "initialize.5", linkageName: "initialize.5", scope: !18, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!39 = !DILocation(line: 2, column: 23, scope: !38) +!40 = distinct !DISubprogram(name: "initialize.6", linkageName: "initialize.6", scope: !18, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!41 = !DILocation(line: 3, column: 12, scope: !40) +!42 = !DILocation(line: 3, column: 19, scope: !40) +!43 = distinct !DISubprogram(name: "println <:I32>", linkageName: "println <:I32>", scope: !18, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!44 = !DILocation(line: 8, column: 12, scope: !43) +!45 = !DILocation(line: 8, column: 3, scope: !43) diff --git a/src/tests/snapshots/ppl__tests__references.run.snap b/src/tests/snapshots/ppl__tests__references.run.snap index a3ce206a..72969f69 100644 --- a/src/tests/snapshots/ppl__tests__references.run.snap +++ b/src/tests/snapshots/ppl__tests__references.run.snap @@ -2,26 +2,5 @@ source: src/tests/mod.rs expression: run_log --- -AddressSanitizer:DEADLYSIGNAL -================================================================= -==4961==ERROR: AddressSanitizer: SEGV on unknown address 0xd10103ffd5032383 (pc 0x00010133253c bp 0x00016effe480 sp 0x00016effe470 T0) -==4961==The signal is caused by a READ memory access. - #0 0x10133253c in rug::ext::xmpz64::fits_u64::h0cb5d3d34e870f0a xmpz64.rs:232 - #1 0x101330900 in rug::integer::casts::_$LT$impl$u20$az..CheckedCast$LT$u64$GT$$u20$for$u20$$RF$rug..integer..big..Integer$GT$::checked_cast::ha1d2fd6891399af0 casts.rs:57 - #2 0x101330264 in rug::integer::big::Integer::to_u64::hd87aea55d6ded3ae big.rs:1367 - #3 0x10132e51c in runtime::memory::read_memory_impl::h6ec466adc51af51c memory.rs:78 - #4 0x10132e4b0 in read_memory memory.rs:72 - #5 0x100e03b74 (references.out:arm64+0x100003b74) - -==4961==Register values: - x[0] = 0xd10103ffd503237f x[1] = 0x0000000100e081c0 x[2] = 0x0000000195152ca8 x[3] = 0x0000603000001c50 - x[4] = 0x0000603000001c50 x[5] = 0x0000000000000001 x[6] = 0x000000016e804000 x[7] = 0x0000000000000001 - x[8] = 0xd10103ffd503237f x[9] = 0x000000016effe488 x[10] = 0x0000603000001c30 x[11] = 0x0000000000000000 -x[12] = 0xffffffffffffffff x[13] = 0x0000000000000000 x[14] = 0x00007fffffffffff x[15] = 0x000010700001ffff -x[16] = 0x000000010132e484 x[17] = 0x00000002071cf638 x[18] = 0x0000000000000000 x[19] = 0x0000000101215ff0 -x[20] = 0x0000000100e03bb8 x[21] = 0x000000016effe600 x[22] = 0x0000000101215910 x[23] = 0x000000016effe680 -x[24] = 0x000000016effe6c0 x[25] = 0x0000000194e422db x[26] = 0x0000000000000000 x[27] = 0x0000000000000000 -x[28] = 0x0000000000000000 fp = 0x000000016effe480 lr = 0x000000010133253c sp = 0x000000016effe470 -AddressSanitizer can not provide additional info. -SUMMARY: AddressSanitizer: SEGV xmpz64.rs:232 in rug::ext::xmpz64::fits_u64::h0cb5d3d34e870f0a -==4961==ABORTING +0 +1 diff --git a/src/tests/snapshots/ppl__tests__star.ir.snap b/src/tests/snapshots/ppl__tests__star.ir.snap index 9e056135..59bbd317 100644 --- a/src/tests/snapshots/ppl__tests__star.ir.snap +++ b/src/tests/snapshots/ppl__tests__star.ir.snap @@ -5,29 +5,114 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Integer = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} -define void @main.execute() !dbg !3 { - %1 = call %Integer @integer_from_i64(i64 2), !dbg !7 - %2 = call %Integer @integer_from_i64(i64 2), !dbg !8 - %3 = call %Integer @integer_from_i64(i64 2), !dbg !9 - %4 = call %Integer @integer_star_integer(%Integer %2, %Integer %3), !dbg !9 - %5 = call %Integer @integer_plus_integer(%Integer %1, %Integer %4), !dbg !9 - call void @"println <:Integer>"(%Integer %5), !dbg !9 - br label %return, !dbg !9 +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 return: ; preds = %0 ret void } -define private void @"println <:Integer>"(%Integer %0) !dbg !10 { +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !19 + call void @initialize.3(), !dbg !19 + %1 = call %Integer @integer_from_i64(i64 2), !dbg !20 + %2 = call %Integer @integer_from_i64(i64 2), !dbg !21 + %3 = call %Integer @integer_from_i64(i64 2), !dbg !22 + %4 = call %Integer @integer_star_integer(%Integer %2, %Integer %3), !dbg !22 + %5 = call %Integer @integer_plus_integer(%Integer %1, %Integer %4), !dbg !22 + call void @"println <:Integer>"(%Integer %5), !dbg !22 + br label %return, !dbg !22 + +return: ; preds = %0 + ret void +} + +define private void @"println <:Integer>"(%Integer %0) !dbg !23 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !11 - %3 = call %String @integer_as_string(%Integer %2), !dbg !11 - call void @"println <:String>"(%String %3), !dbg !11 - br label %return, !dbg !11 + %2 = load %Integer, ptr %x, align 8, !dbg !24 + %3 = call %String @integer_as_string(%Integer %2), !dbg !24 + call void @"println <:String>"(%String %3), !dbg !24 + br label %return, !dbg !24 return: ; preds = %1 ret void @@ -39,8 +124,6 @@ declare %String @integer_as_string(%Integer) declare %Integer @integer_plus_integer(%Integer, %Integer) -declare %Integer @integer_from_i64(i64) - declare %Integer @integer_star_integer(%Integer, %Integer) !llvm.module.flags = !{!0} @@ -49,12 +132,25 @@ declare %Integer @integer_star_integer(%Integer, %Integer) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 8, scope: !3) -!8 = !DILocation(line: 0, column: 12, scope: !3) -!9 = !DILocation(line: 0, column: 16, scope: !3) -!10 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!11 = !DILocation(line: 0, column: 17, scope: !10) +!7 = !DILocation(line: 0, column: 17, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 0, column: 17, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 0, column: 17, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 0, column: 17, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 0, column: 17, scope: !18) +!20 = !DILocation(line: 0, column: 8, scope: !18) +!21 = !DILocation(line: 0, column: 12, scope: !18) +!22 = !DILocation(line: 0, column: 16, scope: !18) +!23 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !18, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!24 = !DILocation(line: 0, column: 17, scope: !23) diff --git a/src/tests/snapshots/ppl__tests__string.hir.snap b/src/tests/snapshots/ppl__tests__string.hir.snap index 96bfe6d6..eb0e3ff3 100644 --- a/src/tests/snapshots/ppl__tests__string.hir.snap +++ b/src/tests/snapshots/ppl__tests__string.hir.snap @@ -8,17 +8,17 @@ expression: hir `println <:String>`(`String from <:Bool>`(true)) `println <:String>`(`String from <:Integer>`(0)) `println <:String>`(`String from <:Rational>`(0.0)) -`println <:String>`(`String from <:Type>`(Type { name: "Integer", size: 8 })) -`println <:String>`(`String from <:Type>>`(Type> { name: "Array", size: 8 })) +`println <:String>`(`String from <:Type>`((Type:Type))) +`println <:String>`(`String from <:Type>>`((Type>:Type>))) ==MONOMORPHIZED== fn String from > -> String: - let $tmp@4358: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4358:String) + let $tmp@4514: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4514:String) fn> String from >> -> String: - let $tmp@4358: String = `clone <:Reference>`((ty:Type>).name) - return ($tmp@4358:String) + let $tmp@4514: String = `clone <:Reference>`((ty:Type>).name) + return ($tmp@4514:String) diff --git a/src/tests/snapshots/ppl__tests__string.ir.snap b/src/tests/snapshots/ppl__tests__string.ir.snap index 1be3464d..132b9acc 100644 --- a/src/tests/snapshots/ppl__tests__string.ir.snap +++ b/src/tests/snapshots/ppl__tests__string.ir.snap @@ -5,63 +5,165 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" +%"Type" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type>" = type { %String, %Integer } %Rational = type { ptr } -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%"Type>" = type { ptr } -%"Type>Impl" = type { %String, %Integer } - -@0 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1 -@1 = private unnamed_addr constant [2 x i8] c" \00", align 1 -@2 = private unnamed_addr constant [7 x i8] c"World!\00", align 1 -@3 = private unnamed_addr constant [2 x i8] c"0\00", align 1 + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@"Type" = private global %"Type" zeroinitializer @4 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 +@"Type>" = private global %"Type>" zeroinitializer @5 = private unnamed_addr constant [15 x i8] c"Array\00", align 1 +@6 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1 +@7 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@8 = private unnamed_addr constant [7 x i8] c"World!\00", align 1 +@9 = private unnamed_addr constant [2 x i8] c"0\00", align 1 + +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} -define void @main.execute() !dbg !3 { - %1 = call %String @string_from_c_string_and_length(ptr @0, i64 5), !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @1, i64 1), !dbg !8 - %3 = call %String @string_plus_string(%String %1, %String %2), !dbg !8 - %4 = call %String @string_from_c_string_and_length(ptr @2, i64 6), !dbg !9 - %5 = call %String @string_plus_string(%String %3, %String %4), !dbg !9 - call void @"println <:String>"(%String %5), !dbg !9 - %6 = call %String @"String from <:None>"(), !dbg !10 - call void @"println <:String>"(%String %6), !dbg !10 - %7 = call %String @"String from <:Bool>"(i1 false), !dbg !11 - call void @"println <:String>"(%String %7), !dbg !11 - %8 = call %String @"String from <:Bool>"(i1 true), !dbg !12 - call void @"println <:String>"(%String %8), !dbg !12 - %9 = call %Integer @integer_from_i64(i64 0), !dbg !13 - %10 = call %String @integer_as_string(%Integer %9), !dbg !13 - call void @"println <:String>"(%String %10), !dbg !13 - %11 = call %Rational @rational_from_c_string(ptr @3), !dbg !14 - %12 = call %String @rational_as_string(%Rational %11), !dbg !14 - call void @"println <:String>"(%String %12), !dbg !14 - %13 = alloca %"Type", align 8, !dbg !15 - %"Type.data" = getelementptr inbounds %"Type", ptr %13, i32 0, i32 0, !dbg !15 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !15 - %14 = call %String @string_from_c_string_and_length(ptr @4, i64 7), !dbg !16 - store %String %14, ptr %"Type.name", align 8, !dbg !16 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !16 - %15 = call %Integer @integer_from_i64(i64 8), !dbg !16 - store %Integer %15, ptr %"Type.size", align 8, !dbg !16 - %16 = load %"Type", ptr %13, align 8, !dbg !16 - %17 = call %String @"String from <:Type>"(%"Type" %16), !dbg !16 - call void @"println <:String>"(%String %17), !dbg !16 - %18 = alloca %"Type>", align 8, !dbg !17 - %"Type>.data" = getelementptr inbounds %"Type>", ptr %18, i32 0, i32 0, !dbg !17 - %"Type>.name" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 0, !dbg !17 - %19 = call %String @string_from_c_string_and_length(ptr @5, i64 14), !dbg !16 - store %String %19, ptr %"Type>.name", align 8, !dbg !16 - %"Type>.size" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 1, !dbg !16 - %20 = call %Integer @integer_from_i64(i64 8), !dbg !16 - store %Integer %20, ptr %"Type>.size", align 8, !dbg !16 - %21 = load %"Type>", ptr %18, align 8, !dbg !16 - %22 = call %String @"String from <:Type>>"(%"Type>" %21), !dbg !16 - call void @"println <:String>"(%String %22), !dbg !16 - br label %return, !dbg !16 +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define private void @initialize.4() !dbg !18 { + %1 = alloca %"Type", align 8, !dbg !19 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !19 + %2 = call %String @string_from_c_string_and_length(ptr @4, i64 7), !dbg !20 + store %String %2, ptr %"Type.name", align 8, !dbg !20 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !20 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !20 + store %Integer %3, ptr %"Type.size", align 8, !dbg !20 + %4 = load %"Type", ptr %1, align 8, !dbg !20 + store %"Type" %4, ptr @"Type", align 8, !dbg !20 + br label %return, !dbg !20 + +return: ; preds = %0 + ret void +} + +define private void @initialize.5() !dbg !21 { + %1 = alloca %"Type>", align 8, !dbg !22 + %"Type>.name" = getelementptr inbounds %"Type>", ptr %1, i32 0, i32 0, !dbg !22 + %2 = call %String @string_from_c_string_and_length(ptr @5, i64 14), !dbg !23 + store %String %2, ptr %"Type>.name", align 8, !dbg !23 + %"Type>.size" = getelementptr inbounds %"Type>", ptr %1, i32 0, i32 1, !dbg !23 + %3 = call %Integer @integer_from_i64(i64 24), !dbg !23 + store %Integer %3, ptr %"Type>.size", align 8, !dbg !23 + %4 = load %"Type>", ptr %1, align 8, !dbg !23 + store %"Type>" %4, ptr @"Type>", align 8, !dbg !23 + br label %return, !dbg !23 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !24 { + call void @initialize(), !dbg !25 + call void @initialize.1(), !dbg !26 + call void @initialize.2(), !dbg !27 + call void @initialize.3(), !dbg !28 + call void @initialize.4(), !dbg !29 + call void @initialize.5(), !dbg !30 + %1 = call %String @string_from_c_string_and_length(ptr @6, i64 5), !dbg !31 + %2 = call %String @string_from_c_string_and_length(ptr @7, i64 1), !dbg !32 + %3 = call %String @string_plus_string(%String %1, %String %2), !dbg !32 + %4 = call %String @string_from_c_string_and_length(ptr @8, i64 6), !dbg !33 + %5 = call %String @string_plus_string(%String %3, %String %4), !dbg !33 + call void @"println <:String>"(%String %5), !dbg !33 + %6 = call %String @"String from <:None>"(), !dbg !34 + call void @"println <:String>"(%String %6), !dbg !34 + %7 = call %String @"String from <:Bool>"(i1 false), !dbg !35 + call void @"println <:String>"(%String %7), !dbg !35 + %8 = call %String @"String from <:Bool>"(i1 true), !dbg !36 + call void @"println <:String>"(%String %8), !dbg !36 + %9 = call %Integer @integer_from_i64(i64 0), !dbg !37 + %10 = call %String @integer_as_string(%Integer %9), !dbg !37 + call void @"println <:String>"(%String %10), !dbg !37 + %11 = call %Rational @rational_from_c_string(ptr @9), !dbg !38 + %12 = call %String @rational_as_string(%Rational %11), !dbg !38 + call void @"println <:String>"(%String %12), !dbg !38 + %13 = load %"Type", ptr @"Type", align 8, !dbg !29 + %14 = call %String @"String from <:Type>"(%"Type" %13), !dbg !29 + call void @"println <:String>"(%String %14), !dbg !29 + %15 = load %"Type>", ptr @"Type>", align 8, !dbg !30 + %16 = call %String @"String from <:Type>>"(%"Type>" %15), !dbg !30 + call void @"println <:String>"(%String %16), !dbg !30 + br label %return, !dbg !30 return: ; preds = %0 ret void @@ -71,56 +173,50 @@ declare void @"println <:String>"(%String) declare %String @string_plus_string(%String, %String) -declare %String @string_from_c_string_and_length(ptr, i64) - declare %String @"String from <:None>"() declare %String @"String from <:Bool>"(i1) declare %String @integer_as_string(%Integer) -declare %Integer @integer_from_i64(i64) - declare %String @rational_as_string(%Rational) declare %Rational @rational_from_c_string(ptr) -define private %String @"String from <:Type>"(%"Type" %0) !dbg !18 { +define private %String @"String from <:Type>"(%"Type" %0) !dbg !39 { %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !19 - %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !19 - %3 = call %String @clone_string(ptr %name), !dbg !19 - %"$tmp@4358" = alloca %String, align 8, !dbg !19 - store %String %3, ptr %"$tmp@4358", align 8, !dbg !19 - %4 = load %String, ptr %"$tmp@4358", align 8, !dbg !19 - store %String %4, ptr %return_value, align 8, !dbg !19 - br label %return, !dbg !19 + %name = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !40 + %2 = call %String @clone_string(ptr %name), !dbg !40 + %"$tmp@4514" = alloca %String, align 8, !dbg !40 + store %String %2, ptr %"$tmp@4514", align 8, !dbg !40 + %3 = load %String, ptr %"$tmp@4514", align 8, !dbg !40 + store %String %3, ptr %return_value, align 8, !dbg !40 + br label %return, !dbg !40 return: ; preds = %1 - %5 = load %String, ptr %return_value, align 8 - ret %String %5 + %4 = load %String, ptr %return_value, align 8 + ret %String %4 } declare %String @clone_string(ptr) -define private %String @"String from <:Type>>"(%"Type>" %0) !dbg !20 { +define private %String @"String from <:Type>>"(%"Type>" %0) !dbg !41 { %return_value = alloca %String, align 8 %ty = alloca %"Type>", align 8 store %"Type>" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type>", ptr %ty, i32 0, i32 0, !dbg !21 - %name = getelementptr inbounds %"Type>Impl", ptr %2, i32 0, i32 0, !dbg !21 - %3 = call %String @clone_string(ptr %name), !dbg !21 - %"$tmp@4358" = alloca %String, align 8, !dbg !21 - store %String %3, ptr %"$tmp@4358", align 8, !dbg !21 - %4 = load %String, ptr %"$tmp@4358", align 8, !dbg !21 - store %String %4, ptr %return_value, align 8, !dbg !21 - br label %return, !dbg !21 + %name = getelementptr inbounds %"Type>", ptr %ty, i32 0, i32 0, !dbg !42 + %2 = call %String @clone_string(ptr %name), !dbg !42 + %"$tmp@4514" = alloca %String, align 8, !dbg !42 + store %String %2, ptr %"$tmp@4514", align 8, !dbg !42 + %3 = load %String, ptr %"$tmp@4514", align 8, !dbg !42 + store %String %3, ptr %return_value, align 8, !dbg !42 + br label %return, !dbg !42 return: ; preds = %1 - %5 = load %String, ptr %return_value, align 8 - ret %String %5 + %4 = load %String, ptr %return_value, align 8 + ret %String %4 } !llvm.module.flags = !{!0} @@ -129,22 +225,43 @@ return: ; preds = %1 !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 8, scope: !3) -!8 = !DILocation(line: 0, column: 18, scope: !3) -!9 = !DILocation(line: 0, column: 24, scope: !3) -!10 = !DILocation(line: 1, column: 21, scope: !3) -!11 = !DILocation(line: 2, column: 21, scope: !3) -!12 = !DILocation(line: 3, column: 21, scope: !3) -!13 = !DILocation(line: 4, column: 21, scope: !3) -!14 = !DILocation(line: 5, column: 21, scope: !3) -!15 = !DILocation(line: 6, column: 21, scope: !3) -!16 = !DILocation(line: 0, scope: !3) -!17 = !DILocation(line: 7, column: 21, scope: !3) -!18 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!19 = !DILocation(line: 7, column: 36, scope: !18) -!20 = distinct !DISubprogram(name: "String from <:Type>>", linkageName: "String from <:Type>>", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!21 = !DILocation(line: 7, column: 36, scope: !20) +!7 = !DILocation(line: 4, column: 20, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 7, column: 36, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 2, column: 3, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 1, column: 25, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 6, column: 21, scope: !18) +!20 = !DILocation(line: 0, scope: !18) +!21 = distinct !DISubprogram(name: "initialize.5", linkageName: "initialize.5", scope: !2, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!22 = !DILocation(line: 7, column: 21, scope: !21) +!23 = !DILocation(line: 0, scope: !21) +!24 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!25 = !DILocation(line: 4, column: 20, scope: !24) +!26 = !DILocation(line: 7, column: 36, scope: !24) +!27 = !DILocation(line: 2, column: 3, scope: !24) +!28 = !DILocation(line: 1, column: 25, scope: !24) +!29 = !DILocation(line: 6, column: 21, scope: !24) +!30 = !DILocation(line: 7, column: 21, scope: !24) +!31 = !DILocation(line: 0, column: 8, scope: !24) +!32 = !DILocation(line: 0, column: 18, scope: !24) +!33 = !DILocation(line: 0, column: 24, scope: !24) +!34 = !DILocation(line: 1, column: 21, scope: !24) +!35 = !DILocation(line: 2, column: 21, scope: !24) +!36 = !DILocation(line: 3, column: 21, scope: !24) +!37 = !DILocation(line: 4, column: 21, scope: !24) +!38 = !DILocation(line: 5, column: 21, scope: !24) +!39 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !24, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!40 = !DILocation(line: 7, column: 36, scope: !39) +!41 = distinct !DISubprogram(name: "String from <:Type>>", linkageName: "String from <:Type>>", scope: !24, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!42 = !DILocation(line: 7, column: 36, scope: !41) diff --git a/src/tests/snapshots/ppl__tests__supertraits.ir.snap b/src/tests/snapshots/ppl__tests__supertraits.ir.snap index a365e88f..854ba37f 100644 --- a/src/tests/snapshots/ppl__tests__supertraits.ir.snap +++ b/src/tests/snapshots/ppl__tests__supertraits.ir.snap @@ -5,36 +5,119 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" +%"Type" = type { %String, %Integer } %String = type { ptr } +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } -@0 = private unnamed_addr constant [4 x i8] c"foo\00", align 1 -@1 = private unnamed_addr constant [4 x i8] c"bar\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@4 = private unnamed_addr constant [4 x i8] c"foo\00", align 1 +@5 = private unnamed_addr constant [4 x i8] c"bar\00", align 1 -define void @main.execute() !dbg !3 { - call void @"foobar <:None>"(), !dbg !7 - br label %return, !dbg !7 +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 return: ; preds = %0 ret void } -define void @"foo <:None>"() !dbg !8 { - %1 = call %String @string_from_c_string_and_length(ptr @0, i64 3), !dbg !9 - call void @print_string(%String %1), !dbg !9 - br label %return, !dbg !10 +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 return: ; preds = %0 ret void } -declare void @print_string(%String) +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 -declare %String @string_from_c_string_and_length(ptr, i64) +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !20 + call void @initialize.2(), !dbg !21 + call void @initialize.3(), !dbg !22 + call void @"foobar <:None>"(), !dbg !23 + br label %return, !dbg !23 + +return: ; preds = %0 + ret void +} + +define void @"foo <:None>"() !dbg !24 { + %1 = call %String @string_from_c_string_and_length(ptr @4, i64 3), !dbg !25 + call void @print_string(%String %1), !dbg !25 + br label %return, !dbg !26 + +return: ; preds = %0 + ret void +} + +declare void @print_string(%String) -define void @"bar <:None>"() !dbg !11 { - %1 = call %String @string_from_c_string_and_length(ptr @1, i64 3), !dbg !12 - call void @"println <:String>"(%String %1), !dbg !12 - br label %return, !dbg !13 +define void @"bar <:None>"() !dbg !27 { + %1 = call %String @string_from_c_string_and_length(ptr @5, i64 3), !dbg !28 + call void @"println <:String>"(%String %1), !dbg !28 + br label %return, !dbg !29 return: ; preds = %0 ret void @@ -42,10 +125,10 @@ return: ; preds = %0 declare void @"println <:String>"(%String) -define private void @"foobar <:None>"() !dbg !14 { - call void @"foo <:None>"(), !dbg !15 - call void @"bar <:None>"(), !dbg !16 - br label %return, !dbg !16 +define private void @"foobar <:None>"() !dbg !30 { + call void @"foo <:None>"(), !dbg !31 + call void @"bar <:None>"(), !dbg !32 + br label %return, !dbg !32 return: ; preds = %0 ret void @@ -57,17 +140,33 @@ return: ; preds = %0 !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 15, column: 7, scope: !3) -!8 = distinct !DISubprogram(name: "foo <:None>", linkageName: "foo <:None>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!9 = !DILocation(line: 8, column: 24, scope: !8) -!10 = !DILocation(line: 8, column: 18, scope: !8) -!11 = distinct !DISubprogram(name: "bar <:None>", linkageName: "bar <:None>", scope: !3, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!12 = !DILocation(line: 9, column: 26, scope: !11) -!13 = !DILocation(line: 9, column: 18, scope: !11) -!14 = distinct !DISubprogram(name: "foobar <:None>", linkageName: "foobar <:None>", scope: !3, file: !2, line: 11, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!15 = !DILocation(line: 12, column: 5, scope: !14) -!16 = !DILocation(line: 13, column: 5, scope: !14) +!7 = !DILocation(line: 9, column: 24, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 15, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 15, column: 11, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 6, column: 7, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 6, column: 2, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 9, column: 24, scope: !18) +!20 = !DILocation(line: 15, column: 11, scope: !18) +!21 = !DILocation(line: 6, column: 7, scope: !18) +!22 = !DILocation(line: 6, column: 2, scope: !18) +!23 = !DILocation(line: 15, column: 7, scope: !18) +!24 = distinct !DISubprogram(name: "foo <:None>", linkageName: "foo <:None>", scope: !18, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!25 = !DILocation(line: 8, column: 24, scope: !24) +!26 = !DILocation(line: 8, column: 18, scope: !24) +!27 = distinct !DISubprogram(name: "bar <:None>", linkageName: "bar <:None>", scope: !18, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!28 = !DILocation(line: 9, column: 26, scope: !27) +!29 = !DILocation(line: 9, column: 18, scope: !27) +!30 = distinct !DISubprogram(name: "foobar <:None>", linkageName: "foobar <:None>", scope: !18, file: !2, line: 11, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!31 = !DILocation(line: 12, column: 5, scope: !30) +!32 = !DILocation(line: 13, column: 5, scope: !30) diff --git a/src/tests/snapshots/ppl__tests__trait_with_ref.ir.snap b/src/tests/snapshots/ppl__tests__trait_with_ref.ir.snap index 35c09b44..44c0d87f 100644 --- a/src/tests/snapshots/ppl__tests__trait_with_ref.ir.snap +++ b/src/tests/snapshots/ppl__tests__trait_with_ref.ir.snap @@ -5,28 +5,112 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Integer = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } - -@0 = private unnamed_addr constant [12 x i8] c"foo integer\00", align 1 +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@4 = private unnamed_addr constant [12 x i8] c"foo integer\00", align 1 @x = global %Integer zeroinitializer -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - call void @"bar <:Reference>"(ptr @x), !dbg !8 - call void @destroy_integer(ptr @x), !dbg !9 - br label %return, !dbg !9 +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 return: ; preds = %0 ret void } -define void @"foo <:Reference>"(ptr %0) !dbg !10 { +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !19 + call void @initialize.2(), !dbg !20 + call void @initialize.3(), !dbg !21 + call void @initialize.4(), !dbg !22 + call void @"bar <:Reference>"(ptr @x), !dbg !23 + call void @destroy_integer(ptr @x), !dbg !24 + br label %return, !dbg !24 + +return: ; preds = %0 + ret void +} + +define void @"foo <:Reference>"(ptr %0) !dbg !25 { %"$arg0" = alloca ptr, align 8 store ptr %0, ptr %"$arg0", align 8 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 11), !dbg !11 - call void @"println <:String>"(%String %2), !dbg !11 - br label %return, !dbg !12 + %2 = call %String @string_from_c_string_and_length(ptr @4, i64 11), !dbg !26 + call void @"println <:String>"(%String %2), !dbg !26 + br label %return, !dbg !27 return: ; preds = %1 ret void @@ -34,24 +118,20 @@ return: ; preds = %1 declare void @"println <:String>"(%String) -declare %String @string_from_c_string_and_length(ptr, i64) - -define private void @initialize() !dbg !13 { - %1 = call %Integer @integer_from_i64(i64 0), !dbg !14 - store %Integer %1, ptr @x, align 8, !dbg !14 - br label %return, !dbg !14 +define private void @initialize.4() !dbg !28 { + %1 = call %Integer @integer_from_i64(i64 0), !dbg !29 + store %Integer %1, ptr @x, align 8, !dbg !29 + br label %return, !dbg !29 return: ; preds = %0 ret void } -declare %Integer @integer_from_i64(i64) - -define private void @"bar <:Reference>"(ptr %0) !dbg !15 { +define private void @"bar <:Reference>"(ptr %0) !dbg !30 { %x = alloca ptr, align 8 store ptr %0, ptr %x, align 8 - call void @"foo <:Reference>"(ptr %x), !dbg !16 - br label %return, !dbg !16 + call void @"foo <:Reference>"(ptr %x), !dbg !31 + br label %return, !dbg !31 return: ; preds = %1 ret void @@ -65,17 +145,32 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 7, column: 8, scope: !3) -!8 = !DILocation(line: 8, column: 4, scope: !3) -!9 = !DILocation(line: 7, scope: !3) -!10 = distinct !DISubprogram(name: "foo <:Reference>", linkageName: "foo <:Reference>", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!11 = !DILocation(line: 3, column: 30, scope: !10) -!12 = !DILocation(line: 3, column: 22, scope: !10) -!13 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!14 = !DILocation(line: 7, column: 8, scope: !13) -!15 = distinct !DISubprogram(name: "bar <:Reference>", linkageName: "bar <:Reference>", scope: !3, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!16 = !DILocation(line: 5, column: 30, scope: !15) +!7 = !DILocation(line: 8, column: 5, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 8, column: 5, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 3, column: 34, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 3, column: 29, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 8, column: 5, scope: !18) +!20 = !DILocation(line: 3, column: 34, scope: !18) +!21 = !DILocation(line: 3, column: 29, scope: !18) +!22 = !DILocation(line: 7, column: 8, scope: !18) +!23 = !DILocation(line: 8, column: 4, scope: !18) +!24 = !DILocation(line: 7, scope: !18) +!25 = distinct !DISubprogram(name: "foo <:Reference>", linkageName: "foo <:Reference>", scope: !18, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!26 = !DILocation(line: 3, column: 30, scope: !25) +!27 = !DILocation(line: 3, column: 22, scope: !25) +!28 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !18, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!29 = !DILocation(line: 7, column: 8, scope: !28) +!30 = distinct !DISubprogram(name: "bar <:Reference>", linkageName: "bar <:Reference>", scope: !18, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!31 = !DILocation(line: 5, column: 30, scope: !30) diff --git a/src/tests/snapshots/ppl__tests__traits.ir.snap b/src/tests/snapshots/ppl__tests__traits.ir.snap index 54184139..54b14ef5 100644 --- a/src/tests/snapshots/ppl__tests__traits.ir.snap +++ b/src/tests/snapshots/ppl__tests__traits.ir.snap @@ -5,27 +5,111 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%Integer = type { ptr } +%"Type" = type { %String, %Integer } %String = type { ptr } - +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 @res = global %Integer zeroinitializer -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - %1 = call %Integer @clone_integer(ptr @res), !dbg !8 - call void @"println <:Integer>"(%Integer %1), !dbg !8 - call void @destroy_integer(ptr @res), !dbg !9 - br label %return, !dbg !9 +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 return: ; preds = %0 ret void } -define void @"required <:Integer>"(%Integer %0) !dbg !10 { +define void @main.execute() !dbg !18 { + call void @initialize(), !dbg !19 + call void @initialize.1(), !dbg !20 + call void @initialize.2(), !dbg !21 + call void @initialize.3(), !dbg !22 + call void @initialize.4(), !dbg !23 + %1 = call %Integer @clone_integer(ptr @res), !dbg !24 + call void @"println <:Integer>"(%Integer %1), !dbg !24 + call void @destroy_integer(ptr @res), !dbg !25 + br label %return, !dbg !25 + +return: ; preds = %0 + ret void +} + +define void @"required <:Integer>"(%Integer %0) !dbg !26 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - call void @destroy_integer(ptr %x), !dbg !11 - br label %return, !dbg !12 + call void @destroy_integer(ptr %x), !dbg !27 + br label %return, !dbg !28 return: ; preds = %1 ret void @@ -33,38 +117,36 @@ return: ; preds = %1 declare void @destroy_integer(ptr) -define private void @initialize() !dbg !13 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !14 - %2 = call %Integer @"default <:Integer>"(%Integer %1), !dbg !14 - store %Integer %2, ptr @res, align 8, !dbg !14 - br label %return, !dbg !14 +define private void @initialize.4() !dbg !29 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !30 + %2 = call %Integer @"default <:Integer>"(%Integer %1), !dbg !30 + store %Integer %2, ptr @res, align 8, !dbg !30 + br label %return, !dbg !30 return: ; preds = %0 ret void } -define private %Integer @"default <:Integer>"(%Integer %0) !dbg !15 { +define private %Integer @"default <:Integer>"(%Integer %0) !dbg !31 { %return_value = alloca %Integer, align 8 %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !16 - store %Integer %2, ptr %return_value, align 8, !dbg !16 - br label %return, !dbg !16 + %2 = load %Integer, ptr %x, align 8, !dbg !32 + store %Integer %2, ptr %return_value, align 8, !dbg !32 + br label %return, !dbg !32 return: ; preds = %1 %3 = load %Integer, ptr %return_value, align 8 ret %Integer %3 } -declare %Integer @integer_from_i64(i64) - -define private void @"println <:Integer>"(%Integer %0) !dbg !17 { +define private void @"println <:Integer>"(%Integer %0) !dbg !33 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !18 - %3 = call %String @integer_as_string(%Integer %2), !dbg !18 - call void @"println <:String>"(%String %3), !dbg !18 - br label %return, !dbg !18 + %2 = load %Integer, ptr %x, align 8, !dbg !34 + %3 = call %String @integer_as_string(%Integer %2), !dbg !34 + call void @"println <:String>"(%String %3), !dbg !34 + br label %return, !dbg !34 return: ; preds = %1 ret void @@ -82,19 +164,35 @@ declare %Integer @clone_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 9, column: 10, scope: !3) -!8 = !DILocation(line: 10, column: 8, scope: !3) -!9 = !DILocation(line: 9, scope: !3) -!10 = distinct !DISubprogram(name: "required <:Integer>", linkageName: "required <:Integer>", scope: !3, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!11 = !DILocation(line: 6, column: 12, scope: !10) -!12 = !DILocation(line: 6, column: 28, scope: !10) -!13 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!14 = !DILocation(line: 9, column: 18, scope: !13) -!15 = distinct !DISubprogram(name: "default <:Integer>", linkageName: "default <:Integer>", scope: !13, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!16 = !DILocation(line: 3, column: 25, scope: !15) -!17 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 10, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!18 = !DILocation(line: 10, column: 11, scope: !17) +!7 = !DILocation(line: 9, column: 4, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 10, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 10, column: 11, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 5, column: 1, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 3, column: 24, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 9, column: 4, scope: !18) +!20 = !DILocation(line: 10, column: 11, scope: !18) +!21 = !DILocation(line: 5, column: 1, scope: !18) +!22 = !DILocation(line: 3, column: 24, scope: !18) +!23 = !DILocation(line: 9, column: 10, scope: !18) +!24 = !DILocation(line: 10, column: 8, scope: !18) +!25 = !DILocation(line: 9, scope: !18) +!26 = distinct !DISubprogram(name: "required <:Integer>", linkageName: "required <:Integer>", scope: !18, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!27 = !DILocation(line: 6, column: 12, scope: !26) +!28 = !DILocation(line: 6, column: 28, scope: !26) +!29 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !18, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!30 = !DILocation(line: 9, column: 18, scope: !29) +!31 = distinct !DISubprogram(name: "default <:Integer>", linkageName: "default <:Integer>", scope: !29, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!32 = !DILocation(line: 3, column: 25, scope: !31) +!33 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !18, file: !2, line: 10, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!34 = !DILocation(line: 10, column: 11, scope: !33) diff --git a/src/tests/snapshots/ppl__tests__type_as_value.hir.snap b/src/tests/snapshots/ppl__tests__type_as_value.hir.snap index cd637419..577cfe8d 100644 --- a/src/tests/snapshots/ppl__tests__type_as_value.hir.snap +++ b/src/tests/snapshots/ppl__tests__type_as_value.hir.snap @@ -2,22 +2,22 @@ source: src/tests/mod.rs expression: hir --- -`println <:Bool>`(`<:Integer> == <:Integer>`(`size of <:Type>`(Type { name: "None", size: 0 }), 0)) -`println <:Bool>`(`<:Integer> == <:Integer>`(`size of <:Type>`(Type { name: "Bool", size: 1 }), 1)) -`println <:String>`(`String from <:Type>`(Type { name: "None", size: 0 })) -`println <:String>`(`String from <:Type>>`(Type> { name: "Type", size: 8 })) -let x: Type = Type { name: "Integer", size: 8 } -let y: Integer = `clone <:Reference>`(Type { name: "Integer", size: 8 }.size) -`println <:Bool>`(`<:Integer> == <:Integer>`(`clone <:Reference>`((y:Integer)), `size of <:Type>`(Type { name: "Integer", size: 8 }))) -`println <:Type>`(Type { name: "Integer", size: 8 }) +`println <:Bool>`(`<:Integer> == <:Integer>`(`size of <:Type>`((Type:Type)), 0)) +`println <:Bool>`(`<:Integer> == <:Integer>`(`size of <:Type>`((Type:Type)), 1)) +`println <:String>`(`String from <:Type>`((Type:Type))) +`println <:String>`(`String from <:Type>>`((Type>:Type>))) +let x: Type = (Type:Type) +let y: Integer = `clone <:Reference>`((Type:Type).size) +`println <:Bool>`(`<:Integer> == <:Integer>`(`clone <:Reference>`((y:Integer)), `size of <:Type>`((Type:Type)))) +`println <:Type>`((Type:Type)) `destroy <:ReferenceMut>`((y:Integer)) ==MONOMORPHIZED== fn size of > -> Integer: - let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4426:Integer) + let $tmp@4582: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4582:Integer) fn String from -> String: @@ -36,8 +36,8 @@ fn println -> None: fn size of > -> Integer: - let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4426:Integer) + let $tmp@4582: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4582:Integer) fn String from -> String: @@ -56,18 +56,18 @@ fn println -> None: fn String from > -> String: - let $tmp@4358: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4358:String) + let $tmp@4514: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4514:String) fn> String from >> -> String: - let $tmp@4358: String = `clone <:Reference>`((ty:Type>).name) - return ($tmp@4358:String) + let $tmp@4514: String = `clone <:Reference>`((ty:Type>).name) + return ($tmp@4514:String) fn size of > -> Integer: - let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4426:Integer) + let $tmp@4582: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4582:Integer) fn String from -> String: @@ -86,8 +86,8 @@ fn println -> None: fn String from > -> String: - let $tmp@4358: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4358:String) + let $tmp@4514: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4514:String) fn println > -> None: diff --git a/src/tests/snapshots/ppl__tests__type_as_value.ir.snap b/src/tests/snapshots/ppl__tests__type_as_value.ir.snap index a222fc0f..cb779d26 100644 --- a/src/tests/snapshots/ppl__tests__type_as_value.ir.snap +++ b/src/tests/snapshots/ppl__tests__type_as_value.ir.snap @@ -5,116 +5,216 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%Integer = type { ptr } -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } +%"Type" = type { %String, %Integer } %String = type { ptr } -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%"Type>" = type { ptr } -%"Type>Impl" = type { %String, %Integer } -%"TypeImpl" = type { %String, %Integer } - -@0 = private unnamed_addr constant [5 x i8] c"None\00", align 1 -@1 = private unnamed_addr constant [5 x i8] c"Bool\00", align 1 -@2 = private unnamed_addr constant [5 x i8] c"None\00", align 1 -@3 = private unnamed_addr constant [14 x i8] c"Type\00", align 1 +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type>" = type { %String, %Integer } +%"Type" = type { %String, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@4 = private unnamed_addr constant [5 x i8] c"None\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@5 = private unnamed_addr constant [5 x i8] c"Bool\00", align 1 +@"Type>" = private global %"Type>" zeroinitializer +@6 = private unnamed_addr constant [14 x i8] c"Type\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@7 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 @x = global %"Type" zeroinitializer -@4 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 @y = global %Integer zeroinitializer -@5 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 -@6 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 -@7 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 -define void @main.execute() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 4), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 0), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - %5 = call %Integer @"size of <:Type>"(%"Type" %4), !dbg !8 - %6 = call %Integer @integer_from_i64(i64 0), !dbg !9 - %7 = call i1 @integer_eq_integer(%Integer %5, %Integer %6), !dbg !9 - call void @"println <:Bool>"(i1 %7), !dbg !9 - %8 = alloca %"Type", align 8, !dbg !10 - %"Type.data" = getelementptr inbounds %"Type", ptr %8, i32 0, i32 0, !dbg !10 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 - %9 = call %String @string_from_c_string_and_length(ptr @1, i64 4), !dbg !8 - store %String %9, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %10 = call %Integer @integer_from_i64(i64 1), !dbg !8 - store %Integer %10, ptr %"Type.size", align 8, !dbg !8 - %11 = load %"Type", ptr %8, align 8, !dbg !8 - %12 = call %Integer @"size of <:Type>"(%"Type" %11), !dbg !8 - %13 = call %Integer @integer_from_i64(i64 1), !dbg !11 - %14 = call i1 @integer_eq_integer(%Integer %12, %Integer %13), !dbg !11 - call void @"println <:Bool>"(i1 %14), !dbg !11 - %15 = alloca %"Type", align 8, !dbg !12 - %"Type.data1" = getelementptr inbounds %"Type", ptr %15, i32 0, i32 0, !dbg !12 - %"Type.name2" = getelementptr inbounds %"TypeImpl", ptr %"Type.data1", i32 0, i32 0, !dbg !12 - %16 = call %String @string_from_c_string_and_length(ptr @2, i64 4), !dbg !8 - store %String %16, ptr %"Type.name2", align 8, !dbg !8 - %"Type.size3" = getelementptr inbounds %"TypeImpl", ptr %"Type.data1", i32 0, i32 1, !dbg !8 - %17 = call %Integer @integer_from_i64(i64 0), !dbg !8 - store %Integer %17, ptr %"Type.size3", align 8, !dbg !8 - %18 = load %"Type", ptr %15, align 8, !dbg !8 - %19 = call %String @"String from <:Type>"(%"Type" %18), !dbg !8 - call void @"println <:String>"(%String %19), !dbg !8 - %20 = alloca %"Type>", align 8, !dbg !13 - %"Type>.data" = getelementptr inbounds %"Type>", ptr %20, i32 0, i32 0, !dbg !13 - %"Type>.name" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 0, !dbg !13 - %21 = call %String @string_from_c_string_and_length(ptr @3, i64 13), !dbg !8 - store %String %21, ptr %"Type>.name", align 8, !dbg !8 - %"Type>.size" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 1, !dbg !8 - %22 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %22, ptr %"Type>.size", align 8, !dbg !8 - %23 = load %"Type>", ptr %20, align 8, !dbg !8 - %24 = call %String @"String from <:Type>>"(%"Type>" %23), !dbg !8 - call void @"println <:String>"(%String %24), !dbg !8 - call void @initialize(), !dbg !14 - call void @initialize.1(), !dbg !15 - %25 = call %Integer @clone_integer(ptr @y), !dbg !16 - %26 = alloca %"Type", align 8, !dbg !17 - %"Type.data" = getelementptr inbounds %"Type", ptr %26, i32 0, i32 0, !dbg !17 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !17 - %27 = call %String @string_from_c_string_and_length(ptr @6, i64 7), !dbg !8 - store %String %27, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %28 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %28, ptr %"Type.size", align 8, !dbg !8 - %29 = load %"Type", ptr %26, align 8, !dbg !8 - %30 = call %Integer @"size of <:Type>"(%"Type" %29), !dbg !8 - %31 = call i1 @integer_eq_integer(%Integer %25, %Integer %30), !dbg !8 - call void @"println <:Bool>"(i1 %31), !dbg !8 - %32 = alloca %"Type", align 8, !dbg !18 - %"Type.data4" = getelementptr inbounds %"Type", ptr %32, i32 0, i32 0, !dbg !18 - %"Type.name5" = getelementptr inbounds %"TypeImpl", ptr %"Type.data4", i32 0, i32 0, !dbg !18 - %33 = call %String @string_from_c_string_and_length(ptr @7, i64 7), !dbg !8 - store %String %33, ptr %"Type.name5", align 8, !dbg !8 - %"Type.size6" = getelementptr inbounds %"TypeImpl", ptr %"Type.data4", i32 0, i32 1, !dbg !8 - %34 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %34, ptr %"Type.size6", align 8, !dbg !8 - %35 = load %"Type", ptr %32, align 8, !dbg !8 - call void @"println <:Type>"(%"Type" %35), !dbg !8 - call void @destroy_integer(ptr @y), !dbg !19 - br label %return, !dbg !19 +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 + br label %return, !dbg !8 + +return: ; preds = %0 + ret void +} + +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define private void @initialize.4() !dbg !18 { + %1 = alloca %"Type", align 8, !dbg !19 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !19 + %2 = call %String @string_from_c_string_and_length(ptr @4, i64 4), !dbg !20 + store %String %2, ptr %"Type.name", align 8, !dbg !20 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !20 + %3 = call %Integer @integer_from_i64(i64 0), !dbg !20 + store %Integer %3, ptr %"Type.size", align 8, !dbg !20 + %4 = load %"Type", ptr %1, align 8, !dbg !20 + store %"Type" %4, ptr @"Type", align 8, !dbg !20 + br label %return, !dbg !20 + +return: ; preds = %0 + ret void +} + +define private void @initialize.5() !dbg !21 { + %1 = alloca %"Type", align 8, !dbg !22 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !22 + %2 = call %String @string_from_c_string_and_length(ptr @5, i64 4), !dbg !23 + store %String %2, ptr %"Type.name", align 8, !dbg !23 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !23 + %3 = call %Integer @integer_from_i64(i64 1), !dbg !23 + store %Integer %3, ptr %"Type.size", align 8, !dbg !23 + %4 = load %"Type", ptr %1, align 8, !dbg !23 + store %"Type" %4, ptr @"Type", align 8, !dbg !23 + br label %return, !dbg !23 + +return: ; preds = %0 + ret void +} + +define private void @initialize.6() !dbg !24 { + %1 = alloca %"Type>", align 8, !dbg !25 + %"Type>.name" = getelementptr inbounds %"Type>", ptr %1, i32 0, i32 0, !dbg !25 + %2 = call %String @string_from_c_string_and_length(ptr @6, i64 13), !dbg !26 + store %String %2, ptr %"Type>.name", align 8, !dbg !26 + %"Type>.size" = getelementptr inbounds %"Type>", ptr %1, i32 0, i32 1, !dbg !26 + %3 = call %Integer @integer_from_i64(i64 16), !dbg !26 + store %Integer %3, ptr %"Type>.size", align 8, !dbg !26 + %4 = load %"Type>", ptr %1, align 8, !dbg !26 + store %"Type>" %4, ptr @"Type>", align 8, !dbg !26 + br label %return, !dbg !26 return: ; preds = %0 ret void } -define private void @"println <:Bool>"(i1 %0) !dbg !20 { +define private void @initialize.7() !dbg !27 { + %1 = alloca %"Type", align 8, !dbg !28 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !28 + %2 = call %String @string_from_c_string_and_length(ptr @7, i64 7), !dbg !29 + store %String %2, ptr %"Type.name", align 8, !dbg !29 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !29 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !29 + store %Integer %3, ptr %"Type.size", align 8, !dbg !29 + %4 = load %"Type", ptr %1, align 8, !dbg !29 + store %"Type" %4, ptr @"Type", align 8, !dbg !29 + br label %return, !dbg !29 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !30 { + call void @initialize(), !dbg !31 + call void @initialize.1(), !dbg !32 + call void @initialize.2(), !dbg !33 + call void @initialize.3(), !dbg !34 + call void @initialize.4(), !dbg !35 + call void @initialize.5(), !dbg !36 + call void @initialize.6(), !dbg !37 + call void @initialize.7(), !dbg !38 + %1 = load %"Type", ptr @"Type", align 8, !dbg !35 + %2 = call %Integer @"size of <:Type>"(%"Type" %1), !dbg !35 + %3 = call %Integer @integer_from_i64(i64 0), !dbg !39 + %4 = call i1 @integer_eq_integer(%Integer %2, %Integer %3), !dbg !39 + call void @"println <:Bool>"(i1 %4), !dbg !39 + %5 = load %"Type", ptr @"Type", align 8, !dbg !36 + %6 = call %Integer @"size of <:Type>"(%"Type" %5), !dbg !36 + %7 = call %Integer @integer_from_i64(i64 1), !dbg !40 + %8 = call i1 @integer_eq_integer(%Integer %6, %Integer %7), !dbg !40 + call void @"println <:Bool>"(i1 %8), !dbg !40 + %9 = load %"Type", ptr @"Type", align 8, !dbg !41 + %10 = call %String @"String from <:Type>"(%"Type" %9), !dbg !41 + call void @"println <:String>"(%String %10), !dbg !41 + %11 = load %"Type>", ptr @"Type>", align 8, !dbg !37 + %12 = call %String @"String from <:Type>>"(%"Type>" %11), !dbg !37 + call void @"println <:String>"(%String %12), !dbg !37 + call void @initialize.8(), !dbg !38 + call void @initialize.9(), !dbg !42 + %13 = call %Integer @clone_integer(ptr @y), !dbg !43 + %14 = load %"Type", ptr @"Type", align 8, !dbg !44 + %15 = call %Integer @"size of <:Type>"(%"Type" %14), !dbg !44 + %16 = call i1 @integer_eq_integer(%Integer %13, %Integer %15), !dbg !44 + call void @"println <:Bool>"(i1 %16), !dbg !44 + %17 = load %"Type", ptr @"Type", align 8, !dbg !45 + call void @"println <:Type>"(%"Type" %17), !dbg !45 + call void @destroy_integer(ptr @y), !dbg !46 + br label %return, !dbg !46 + +return: ; preds = %0 + ret void +} + +define private void @"println <:Bool>"(i1 %0) !dbg !47 { %x = alloca i1, align 1 store i1 %0, ptr %x, align 1 - %2 = load i1, ptr %x, align 1, !dbg !21 - %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !21 - call void @"println <:String>"(%String %3), !dbg !21 - br label %return, !dbg !22 + %2 = load i1, ptr %x, align 1, !dbg !48 + %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !48 + call void @"println <:String>"(%String %3), !dbg !48 + br label %return, !dbg !49 return: ; preds = %1 ret void @@ -126,168 +226,140 @@ declare %String @"String from <:Bool>"(i1) declare i1 @integer_eq_integer(%Integer, %Integer) -define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !23 { +define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !50 { %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !24 - %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !24 - %3 = call %Integer @clone_integer(ptr %size), !dbg !24 - %"$tmp@4426" = alloca %Integer, align 8, !dbg !24 - store %Integer %3, ptr %"$tmp@4426", align 8, !dbg !24 - %4 = load %Integer, ptr %"$tmp@4426", align 8, !dbg !24 - store %Integer %4, ptr %return_value, align 8, !dbg !24 - br label %return, !dbg !24 + %size = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 1, !dbg !51 + %2 = call %Integer @clone_integer(ptr %size), !dbg !51 + %"$tmp@4582" = alloca %Integer, align 8, !dbg !51 + store %Integer %2, ptr %"$tmp@4582", align 8, !dbg !51 + %3 = load %Integer, ptr %"$tmp@4582", align 8, !dbg !51 + store %Integer %3, ptr %return_value, align 8, !dbg !51 + br label %return, !dbg !51 return: ; preds = %1 - %5 = load %Integer, ptr %return_value, align 8 - ret %Integer %5 + %4 = load %Integer, ptr %return_value, align 8 + ret %Integer %4 } declare %Integer @clone_integer(ptr) -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !25 { +define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !52 { %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !26 - %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !26 - %3 = call %Integer @clone_integer(ptr %size), !dbg !26 - %"$tmp@4426" = alloca %Integer, align 8, !dbg !26 - store %Integer %3, ptr %"$tmp@4426", align 8, !dbg !26 - %4 = load %Integer, ptr %"$tmp@4426", align 8, !dbg !26 - store %Integer %4, ptr %return_value, align 8, !dbg !26 - br label %return, !dbg !26 + %size = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 1, !dbg !53 + %2 = call %Integer @clone_integer(ptr %size), !dbg !53 + %"$tmp@4582" = alloca %Integer, align 8, !dbg !53 + store %Integer %2, ptr %"$tmp@4582", align 8, !dbg !53 + %3 = load %Integer, ptr %"$tmp@4582", align 8, !dbg !53 + store %Integer %3, ptr %return_value, align 8, !dbg !53 + br label %return, !dbg !53 return: ; preds = %1 - %5 = load %Integer, ptr %return_value, align 8 - ret %Integer %5 + %4 = load %Integer, ptr %return_value, align 8 + ret %Integer %4 } -define private %String @"String from <:Type>"(%"Type" %0) !dbg !27 { +define private %String @"String from <:Type>"(%"Type" %0) !dbg !54 { %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !28 - %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !28 - %3 = call %String @clone_string(ptr %name), !dbg !28 - %"$tmp@4358" = alloca %String, align 8, !dbg !28 - store %String %3, ptr %"$tmp@4358", align 8, !dbg !28 - %4 = load %String, ptr %"$tmp@4358", align 8, !dbg !28 - store %String %4, ptr %return_value, align 8, !dbg !28 - br label %return, !dbg !28 + %name = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !55 + %2 = call %String @clone_string(ptr %name), !dbg !55 + %"$tmp@4514" = alloca %String, align 8, !dbg !55 + store %String %2, ptr %"$tmp@4514", align 8, !dbg !55 + %3 = load %String, ptr %"$tmp@4514", align 8, !dbg !55 + store %String %3, ptr %return_value, align 8, !dbg !55 + br label %return, !dbg !55 return: ; preds = %1 - %5 = load %String, ptr %return_value, align 8 - ret %String %5 + %4 = load %String, ptr %return_value, align 8 + ret %String %4 } declare %String @clone_string(ptr) -define private %String @"String from <:Type>>"(%"Type>" %0) !dbg !29 { +define private %String @"String from <:Type>>"(%"Type>" %0) !dbg !56 { %return_value = alloca %String, align 8 %ty = alloca %"Type>", align 8 store %"Type>" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type>", ptr %ty, i32 0, i32 0, !dbg !30 - %name = getelementptr inbounds %"Type>Impl", ptr %2, i32 0, i32 0, !dbg !30 - %3 = call %String @clone_string(ptr %name), !dbg !30 - %"$tmp@4358" = alloca %String, align 8, !dbg !30 - store %String %3, ptr %"$tmp@4358", align 8, !dbg !30 - %4 = load %String, ptr %"$tmp@4358", align 8, !dbg !30 - store %String %4, ptr %return_value, align 8, !dbg !30 - br label %return, !dbg !30 + %name = getelementptr inbounds %"Type>", ptr %ty, i32 0, i32 0, !dbg !57 + %2 = call %String @clone_string(ptr %name), !dbg !57 + %"$tmp@4514" = alloca %String, align 8, !dbg !57 + store %String %2, ptr %"$tmp@4514", align 8, !dbg !57 + %3 = load %String, ptr %"$tmp@4514", align 8, !dbg !57 + store %String %3, ptr %return_value, align 8, !dbg !57 + br label %return, !dbg !57 return: ; preds = %1 - %5 = load %String, ptr %return_value, align 8 - ret %String %5 + %4 = load %String, ptr %return_value, align 8 + ret %String %4 } -define private void @initialize() !dbg !31 { - %1 = alloca %"Type", align 8, !dbg !32 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !32 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !32 - %2 = call %String @string_from_c_string_and_length(ptr @4, i64 7), !dbg !33 - store %String %2, ptr %"Type.name", align 8, !dbg !33 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !33 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !33 - store %Integer %3, ptr %"Type.size", align 8, !dbg !33 - %4 = load %"Type", ptr %1, align 8, !dbg !33 - store %"Type" %4, ptr @x, align 8, !dbg !33 - br label %return, !dbg !33 +define private void @initialize.8() !dbg !58 { + %1 = load %"Type", ptr @"Type", align 8, !dbg !59 + store %"Type" %1, ptr @x, align 8, !dbg !59 + br label %return, !dbg !59 return: ; preds = %0 ret void } -define private void @initialize.1() !dbg !34 { - %1 = alloca %"Type", align 8, !dbg !35 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !35 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !35 - %2 = call %String @string_from_c_string_and_length(ptr @5, i64 7), !dbg !36 - store %String %2, ptr %"Type.name", align 8, !dbg !36 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !36 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !36 - store %Integer %3, ptr %"Type.size", align 8, !dbg !36 - %4 = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !36 - %size = getelementptr inbounds %"TypeImpl", ptr %4, i32 0, i32 1, !dbg !36 - %5 = call %Integer @clone_integer(ptr %size), !dbg !36 - store %Integer %5, ptr @y, align 8, !dbg !36 - br label %return, !dbg !36 +define private void @initialize.9() !dbg !60 { + %1 = call %Integer @clone_integer(ptr getelementptr inbounds (%"Type", ptr @"Type", i32 0, i32 1)), !dbg !61 + store %Integer %1, ptr @y, align 8, !dbg !61 + br label %return, !dbg !61 return: ; preds = %0 ret void } -define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !37 { +define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !62 { %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !38 - %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !38 - %3 = call %Integer @clone_integer(ptr %size), !dbg !38 - %"$tmp@4426" = alloca %Integer, align 8, !dbg !38 - store %Integer %3, ptr %"$tmp@4426", align 8, !dbg !38 - %4 = load %Integer, ptr %"$tmp@4426", align 8, !dbg !38 - store %Integer %4, ptr %return_value, align 8, !dbg !38 - br label %return, !dbg !38 + %size = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 1, !dbg !63 + %2 = call %Integer @clone_integer(ptr %size), !dbg !63 + %"$tmp@4582" = alloca %Integer, align 8, !dbg !63 + store %Integer %2, ptr %"$tmp@4582", align 8, !dbg !63 + %3 = load %Integer, ptr %"$tmp@4582", align 8, !dbg !63 + store %Integer %3, ptr %return_value, align 8, !dbg !63 + br label %return, !dbg !63 return: ; preds = %1 - %5 = load %Integer, ptr %return_value, align 8 - ret %Integer %5 + %4 = load %Integer, ptr %return_value, align 8 + ret %Integer %4 } -define private void @"println <:Type>"(%"Type" %0) !dbg !39 { +define private void @"println <:Type>"(%"Type" %0) !dbg !64 { %x = alloca %"Type", align 8 store %"Type" %0, ptr %x, align 8 - %2 = load %"Type", ptr %x, align 8, !dbg !40 - %3 = call %String @"String from <:Type>"(%"Type" %2), !dbg !40 - call void @"println <:String>"(%String %3), !dbg !40 - br label %return, !dbg !41 + %2 = load %"Type", ptr %x, align 8, !dbg !65 + %3 = call %String @"String from <:Type>"(%"Type" %2), !dbg !65 + call void @"println <:String>"(%String %3), !dbg !65 + br label %return, !dbg !66 return: ; preds = %1 ret void } -define private %String @"String from <:Type>"(%"Type" %0) !dbg !42 { +define private %String @"String from <:Type>"(%"Type" %0) !dbg !67 { %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !43 - %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !43 - %3 = call %String @clone_string(ptr %name), !dbg !43 - %"$tmp@4358" = alloca %String, align 8, !dbg !43 - store %String %3, ptr %"$tmp@4358", align 8, !dbg !43 - %4 = load %String, ptr %"$tmp@4358", align 8, !dbg !43 - store %String %4, ptr %return_value, align 8, !dbg !43 - br label %return, !dbg !43 + %name = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !68 + %2 = call %String @clone_string(ptr %name), !dbg !68 + %"$tmp@4514" = alloca %String, align 8, !dbg !68 + store %String %2, ptr %"$tmp@4514", align 8, !dbg !68 + %3 = load %String, ptr %"$tmp@4514", align 8, !dbg !68 + store %String %3, ptr %return_value, align 8, !dbg !68 + br label %return, !dbg !68 return: ; preds = %1 - %5 = load %String, ptr %return_value, align 8 - ret %String %5 + %4 = load %String, ptr %return_value, align 8 + ret %String %4 } declare void @destroy_integer(ptr) @@ -298,44 +370,69 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 17, scope: !3) +!7 = !DILocation(line: 5, column: 15, scope: !3) !8 = !DILocation(line: 0, scope: !3) -!9 = !DILocation(line: 0, column: 26, scope: !3) -!10 = !DILocation(line: 1, column: 17, scope: !3) -!11 = !DILocation(line: 1, column: 26, scope: !3) -!12 = !DILocation(line: 2, column: 21, scope: !3) -!13 = !DILocation(line: 3, column: 21, scope: !3) -!14 = !DILocation(line: 5, column: 8, scope: !3) -!15 = !DILocation(line: 6, column: 8, scope: !3) -!16 = !DILocation(line: 7, column: 8, scope: !3) -!17 = !DILocation(line: 7, column: 22, scope: !3) -!18 = !DILocation(line: 8, column: 8, scope: !3) -!19 = !DILocation(line: 6, scope: !3) -!20 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !3, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!21 = !DILocation(line: 8, column: 9, scope: !20) -!22 = !DILocation(line: 7, column: 19, scope: !20) -!23 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!24 = !DILocation(line: 8, column: 15, scope: !23) -!25 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!26 = !DILocation(line: 8, column: 15, scope: !25) -!27 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!28 = !DILocation(line: 8, column: 15, scope: !27) -!29 = distinct !DISubprogram(name: "String from <:Type>>", linkageName: "String from <:Type>>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!30 = !DILocation(line: 8, column: 15, scope: !29) -!31 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!32 = !DILocation(line: 5, column: 8, scope: !31) -!33 = !DILocation(line: 0, scope: !31) -!34 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!35 = !DILocation(line: 6, column: 8, scope: !34) -!36 = !DILocation(line: 0, scope: !34) -!37 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!38 = !DILocation(line: 8, column: 15, scope: !37) -!39 = distinct !DISubprogram(name: "println <:Type>", linkageName: "println <:Type>", scope: !3, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!40 = !DILocation(line: 8, column: 9, scope: !39) -!41 = !DILocation(line: 7, column: 19, scope: !39) -!42 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !39, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!43 = !DILocation(line: 8, column: 15, scope: !42) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 8, column: 15, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 2, column: 7, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 2, column: 2, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 0, column: 17, scope: !18) +!20 = !DILocation(line: 0, scope: !18) +!21 = distinct !DISubprogram(name: "initialize.5", linkageName: "initialize.5", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!22 = !DILocation(line: 1, column: 17, scope: !21) +!23 = !DILocation(line: 0, scope: !21) +!24 = distinct !DISubprogram(name: "initialize.6", linkageName: "initialize.6", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!25 = !DILocation(line: 3, column: 21, scope: !24) +!26 = !DILocation(line: 0, scope: !24) +!27 = distinct !DISubprogram(name: "initialize.7", linkageName: "initialize.7", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!28 = !DILocation(line: 5, column: 8, scope: !27) +!29 = !DILocation(line: 0, scope: !27) +!30 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!31 = !DILocation(line: 5, column: 15, scope: !30) +!32 = !DILocation(line: 8, column: 15, scope: !30) +!33 = !DILocation(line: 2, column: 7, scope: !30) +!34 = !DILocation(line: 2, column: 2, scope: !30) +!35 = !DILocation(line: 0, column: 17, scope: !30) +!36 = !DILocation(line: 1, column: 17, scope: !30) +!37 = !DILocation(line: 3, column: 21, scope: !30) +!38 = !DILocation(line: 5, column: 8, scope: !30) +!39 = !DILocation(line: 0, column: 26, scope: !30) +!40 = !DILocation(line: 1, column: 26, scope: !30) +!41 = !DILocation(line: 2, column: 21, scope: !30) +!42 = !DILocation(line: 6, column: 8, scope: !30) +!43 = !DILocation(line: 7, column: 8, scope: !30) +!44 = !DILocation(line: 7, column: 22, scope: !30) +!45 = !DILocation(line: 8, column: 8, scope: !30) +!46 = !DILocation(line: 6, scope: !30) +!47 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !30, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!48 = !DILocation(line: 8, column: 9, scope: !47) +!49 = !DILocation(line: 7, column: 19, scope: !47) +!50 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !30, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!51 = !DILocation(line: 8, column: 15, scope: !50) +!52 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !30, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!53 = !DILocation(line: 8, column: 15, scope: !52) +!54 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !30, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!55 = !DILocation(line: 8, column: 15, scope: !54) +!56 = distinct !DISubprogram(name: "String from <:Type>>", linkageName: "String from <:Type>>", scope: !30, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!57 = !DILocation(line: 8, column: 15, scope: !56) +!58 = distinct !DISubprogram(name: "initialize.8", linkageName: "initialize.8", scope: !30, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!59 = !DILocation(line: 5, column: 8, scope: !58) +!60 = distinct !DISubprogram(name: "initialize.9", linkageName: "initialize.9", scope: !30, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!61 = !DILocation(line: 6, column: 8, scope: !60) +!62 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !30, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!63 = !DILocation(line: 8, column: 15, scope: !62) +!64 = distinct !DISubprogram(name: "println <:Type>", linkageName: "println <:Type>", scope: !30, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!65 = !DILocation(line: 8, column: 9, scope: !64) +!66 = !DILocation(line: 7, column: 19, scope: !64) +!67 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !64, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!68 = !DILocation(line: 8, column: 15, scope: !67) diff --git a/src/tests/snapshots/ppl__tests__type_of.hir.snap b/src/tests/snapshots/ppl__tests__type_of.hir.snap index 93b50338..aed9f7cf 100644 --- a/src/tests/snapshots/ppl__tests__type_of.hir.snap +++ b/src/tests/snapshots/ppl__tests__type_of.hir.snap @@ -9,13 +9,13 @@ let ty: Type = `type of <:Integer>`(1) fn type of <$arg0: Integer> -> Type: - let $tmp@4483: Type = Type { name: "Integer", size: 8 } - return ($tmp@4483:Type) + let $tmp@4639: Type = (Type:Type) + return ($tmp@4639:Type) fn String from > -> String: - let $tmp@4358: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4358:String) + let $tmp@4514: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4514:String) fn println > -> None: diff --git a/src/tests/snapshots/ppl__tests__type_of.ir.snap b/src/tests/snapshots/ppl__tests__type_of.ir.snap index 3c67dccd..6731c376 100644 --- a/src/tests/snapshots/ppl__tests__type_of.ir.snap +++ b/src/tests/snapshots/ppl__tests__type_of.ir.snap @@ -5,69 +5,158 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%Integer = type { ptr } -%"TypeImpl" = type { %String, %Integer } +%"Type" = type { %String, %Integer } %String = type { ptr } - +%Integer = type { ptr } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } +%"Type" = type { %String, %Integer } + +@"Type" = private global %"Type" zeroinitializer +@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@1 = private unnamed_addr constant [14 x i8] c"MemoryAddress\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@2 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@3 = private unnamed_addr constant [4 x i8] c"F64\00", align 1 +@"Type" = private global %"Type" zeroinitializer +@4 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 @ty = global %"Type" zeroinitializer -@0 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 -define void @main.execute() !dbg !3 { - call void @initialize(), !dbg !7 - %1 = load %"Type", ptr @ty, align 8, !dbg !8 - call void @"println <:Type>"(%"Type" %1), !dbg !8 +define private void @initialize() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + store %"Type" %4, ptr @"Type", align 8, !dbg !8 br label %return, !dbg !8 return: ; preds = %0 ret void } -define private void @initialize() !dbg !9 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !10 - %2 = call %"Type" @"type of <:Integer>"(%Integer %1), !dbg !10 - store %"Type" %2, ptr @ty, align 8, !dbg !10 - br label %return, !dbg !10 +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !9 { + %1 = alloca %"Type", align 8, !dbg !10 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 13), !dbg !11 + store %String %2, ptr %"Type.name", align 8, !dbg !11 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 + store %Integer %3, ptr %"Type.size", align 8, !dbg !11 + %4 = load %"Type", ptr %1, align 8, !dbg !11 + store %"Type" %4, ptr @"Type", align 8, !dbg !11 + br label %return, !dbg !11 + +return: ; preds = %0 + ret void +} + +define private void @initialize.2() !dbg !12 { + %1 = alloca %"Type", align 8, !dbg !13 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !14 + store %String %2, ptr %"Type.name", align 8, !dbg !14 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !14 + store %Integer %3, ptr %"Type.size", align 8, !dbg !14 + %4 = load %"Type", ptr %1, align 8, !dbg !14 + store %"Type" %4, ptr @"Type", align 8, !dbg !14 + br label %return, !dbg !14 + +return: ; preds = %0 + ret void +} + +define private void @initialize.3() !dbg !15 { + %1 = alloca %"Type", align 8, !dbg !16 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @3, i64 3), !dbg !17 + store %String %2, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !17 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %3, ptr %"Type.size", align 8, !dbg !17 + %4 = load %"Type", ptr %1, align 8, !dbg !17 + store %"Type" %4, ptr @"Type", align 8, !dbg !17 + br label %return, !dbg !17 + +return: ; preds = %0 + ret void +} + +define private void @initialize.4() !dbg !18 { + %1 = alloca %"Type", align 8, !dbg !19 + %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !19 + %2 = call %String @string_from_c_string_and_length(ptr @4, i64 7), !dbg !20 + store %String %2, ptr %"Type.name", align 8, !dbg !20 + %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !20 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !20 + store %Integer %3, ptr %"Type.size", align 8, !dbg !20 + %4 = load %"Type", ptr %1, align 8, !dbg !20 + store %"Type" %4, ptr @"Type", align 8, !dbg !20 + br label %return, !dbg !20 + +return: ; preds = %0 + ret void +} + +define void @main.execute() !dbg !21 { + call void @initialize(), !dbg !22 + call void @initialize.1(), !dbg !22 + call void @initialize.2(), !dbg !22 + call void @initialize.3(), !dbg !22 + call void @initialize.4(), !dbg !22 + call void @initialize.5(), !dbg !23 + %1 = load %"Type", ptr @ty, align 8, !dbg !24 + call void @"println <:Type>"(%"Type" %1), !dbg !24 + br label %return, !dbg !24 return: ; preds = %0 ret void } -define private %"Type" @"type of <:Integer>"(%Integer %0) !dbg !11 { +define private void @initialize.5() !dbg !25 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !26 + %2 = call %"Type" @"type of <:Integer>"(%Integer %1), !dbg !26 + store %"Type" %2, ptr @ty, align 8, !dbg !26 + br label %return, !dbg !26 + +return: ; preds = %0 + ret void +} + +define private %"Type" @"type of <:Integer>"(%Integer %0) !dbg !27 { %return_value = alloca %"Type", align 8 %"$arg0" = alloca %Integer, align 8 store %Integer %0, ptr %"$arg0", align 8 - %2 = alloca %"Type", align 8, !dbg !12 - %"Type.data" = getelementptr inbounds %"Type", ptr %2, i32 0, i32 0, !dbg !12 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !12 - %3 = call %String @string_from_c_string_and_length(ptr @0, i64 7), !dbg !13 - store %String %3, ptr %"Type.name", align 8, !dbg !13 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !13 - %4 = call %Integer @integer_from_i64(i64 8), !dbg !13 - store %Integer %4, ptr %"Type.size", align 8, !dbg !13 - %5 = load %"Type", ptr %2, align 8, !dbg !13 - %"$tmp@4483" = alloca %"Type", align 8, !dbg !13 - store %"Type" %5, ptr %"$tmp@4483", align 8, !dbg !13 - %6 = load %"Type", ptr %"$tmp@4483", align 8, !dbg !12 - store %"Type" %6, ptr %return_value, align 8, !dbg !12 - br label %return, !dbg !12 + %2 = load %"Type", ptr @"Type", align 8, !dbg !28 + %"$tmp@4639" = alloca %"Type", align 8, !dbg !28 + store %"Type" %2, ptr %"$tmp@4639", align 8, !dbg !28 + %3 = load %"Type", ptr %"$tmp@4639", align 8, !dbg !28 + store %"Type" %3, ptr %return_value, align 8, !dbg !28 + br label %return, !dbg !28 return: ; preds = %1 - %7 = load %"Type", ptr %return_value, align 8 - ret %"Type" %7 + %4 = load %"Type", ptr %return_value, align 8 + ret %"Type" %4 } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define private void @"println <:Type>"(%"Type" %0) !dbg !14 { +define private void @"println <:Type>"(%"Type" %0) !dbg !29 { %x = alloca %"Type", align 8 store %"Type" %0, ptr %x, align 8 - %2 = load %"Type", ptr %x, align 8, !dbg !15 - %3 = call %String @"String from <:Type>"(%"Type" %2), !dbg !15 - call void @"println <:String>"(%String %3), !dbg !15 - br label %return, !dbg !15 + %2 = load %"Type", ptr %x, align 8, !dbg !30 + %3 = call %String @"String from <:Type>"(%"Type" %2), !dbg !30 + call void @"println <:String>"(%String %3), !dbg !30 + br label %return, !dbg !30 return: ; preds = %1 ret void @@ -75,22 +164,21 @@ return: ; preds = %1 declare void @"println <:String>"(%String) -define private %String @"String from <:Type>"(%"Type" %0) !dbg !16 { +define private %String @"String from <:Type>"(%"Type" %0) !dbg !31 { %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !17 - %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !17 - %3 = call %String @clone_string(ptr %name), !dbg !17 - %"$tmp@4358" = alloca %String, align 8, !dbg !17 - store %String %3, ptr %"$tmp@4358", align 8, !dbg !17 - %4 = load %String, ptr %"$tmp@4358", align 8, !dbg !17 - store %String %4, ptr %return_value, align 8, !dbg !17 - br label %return, !dbg !17 + %name = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !32 + %2 = call %String @clone_string(ptr %name), !dbg !32 + %"$tmp@4514" = alloca %String, align 8, !dbg !32 + store %String %2, ptr %"$tmp@4514", align 8, !dbg !32 + %3 = load %String, ptr %"$tmp@4514", align 8, !dbg !32 + store %String %3, ptr %return_value, align 8, !dbg !32 + br label %return, !dbg !32 return: ; preds = %1 - %5 = load %String, ptr %return_value, align 8 - ret %String %5 + %4 = load %String, ptr %return_value, align 8 + ret %String %4 } declare %String @clone_string(ptr) @@ -101,18 +189,33 @@ declare %String @clone_string(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 9, scope: !3) -!8 = !DILocation(line: 1, column: 8, scope: !3) -!9 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 0, column: 19, scope: !9) -!11 = distinct !DISubprogram(name: "type of <:Integer>", linkageName: "type of <:Integer>", scope: !9, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!12 = !DILocation(line: 1, column: 10, scope: !11) -!13 = !DILocation(line: 0, scope: !11) -!14 = distinct !DISubprogram(name: "println <:Type>", linkageName: "println <:Type>", scope: !3, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!15 = !DILocation(line: 1, column: 10, scope: !14) -!16 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !14, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!17 = !DILocation(line: 1, column: 10, scope: !16) +!7 = !DILocation(line: 1, column: 10, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 1, column: 10, scope: !9) +!11 = !DILocation(line: 0, scope: !9) +!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 1, column: 10, scope: !12) +!14 = !DILocation(line: 0, scope: !12) +!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 1, column: 10, scope: !15) +!17 = !DILocation(line: 0, scope: !15) +!18 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 1, column: 10, scope: !18) +!20 = !DILocation(line: 0, scope: !18) +!21 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!22 = !DILocation(line: 1, column: 10, scope: !21) +!23 = !DILocation(line: 0, column: 9, scope: !21) +!24 = !DILocation(line: 1, column: 8, scope: !21) +!25 = distinct !DISubprogram(name: "initialize.5", linkageName: "initialize.5", scope: !21, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!26 = !DILocation(line: 0, column: 19, scope: !25) +!27 = distinct !DISubprogram(name: "type of <:Integer>", linkageName: "type of <:Integer>", scope: !25, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!28 = !DILocation(line: 1, column: 10, scope: !27) +!29 = distinct !DISubprogram(name: "println <:Type>", linkageName: "println <:Type>", scope: !21, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!30 = !DILocation(line: 1, column: 10, scope: !29) +!31 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !29, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!32 = !DILocation(line: 1, column: 10, scope: !31)