From 893eaaa8654c4123ac47a8306b451a3dc4cff538 Mon Sep 17 00:00:00 2001 From: sofia Date: Sun, 20 Jul 2025 22:36:38 +0300 Subject: [PATCH] Clean up and fix some warnings --- README.md | 1 + reid-llvm-lib/src/compile.rs | 2 +- reid-llvm-lib/src/debug_information.rs | 14 +++----------- reid-llvm-lib/src/{debug.rs => fmt.rs} | 7 ++----- reid-llvm-lib/src/lib.rs | 4 ++-- reid/src/codegen.rs | 13 ++++++------- reid/src/mir/{display.rs => fmt.rs} | 0 reid/src/mir/impl.rs | 4 ---- reid/src/mir/mod.rs | 2 +- reid/src/mir/typeinference.rs | 12 ++---------- 10 files changed, 18 insertions(+), 41 deletions(-) rename reid-llvm-lib/src/{debug.rs => fmt.rs} (96%) rename reid/src/mir/{display.rs => fmt.rs} (100%) diff --git a/README.md b/README.md index 429e244..3cb6e90 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Currently missing relevant features (TODOs) are: Smaller features: - Easier way to initialize arrays with a single value +- Lexical scopes for Debug Information ### Why "Reid" diff --git a/reid-llvm-lib/src/compile.rs b/reid-llvm-lib/src/compile.rs index 7d1ef92..3ca93c5 100644 --- a/reid-llvm-lib/src/compile.rs +++ b/reid-llvm-lib/src/compile.rs @@ -1029,7 +1029,7 @@ impl ConstValue { ConstValue::U32(val) => LLVMConstInt(t, *val as u64, 1), ConstValue::U64(val) => LLVMConstInt(t, *val as u64, 1), ConstValue::U128(val) => LLVMConstInt(t, *val as u64, 1), - ConstValue::StringPtr(val) => LLVMBuildGlobalStringPtr( + ConstValue::StringPtr(val) => LLVMBuildGlobalString( module.builder_ref, into_cstring(val).as_ptr(), c"string".as_ptr(), diff --git a/reid-llvm-lib/src/debug_information.rs b/reid-llvm-lib/src/debug_information.rs index 1bf22ad..575fc35 100644 --- a/reid-llvm-lib/src/debug_information.rs +++ b/reid-llvm-lib/src/debug_information.rs @@ -47,7 +47,7 @@ pub struct DebugTypeHolder { #[derive(Debug, Clone)] pub struct DebugSubprogramHolder { - pub(crate) value: DebugProgramValue, + pub(crate) _value: DebugProgramValue, pub(crate) data: DebugSubprogramData, } @@ -151,19 +151,11 @@ impl DebugInformation { value } - fn check_metadata(&self, scope: &DebugScopeValue, metadata: &DebugMetadata) { - match &metadata { - DebugMetadata::ParamVar(debug_param_variable) => todo!(), - DebugMetadata::LocalVar(debug_local_variable) => todo!(), - DebugMetadata::VarAssignment => todo!(), - } - } - pub fn subprogram(&self, kind: DebugSubprogramData) -> DebugProgramValue { let mut subprogram = self.programs.borrow_mut(); let value = DebugProgramValue(subprogram.len() + 1); subprogram.push(DebugSubprogramHolder { - value: value.clone(), + _value: value.clone(), data: kind, }); value @@ -185,7 +177,7 @@ impl DebugInformation { self.types.clone() } - pub fn get_locations(&self) -> Rc>> { + pub(crate) fn get_locations(&self) -> Rc>> { self.locations.clone() } diff --git a/reid-llvm-lib/src/debug.rs b/reid-llvm-lib/src/fmt.rs similarity index 96% rename from reid-llvm-lib/src/debug.rs rename to reid-llvm-lib/src/fmt.rs index f6dd478..24b9b94 100644 --- a/reid-llvm-lib/src/debug.rs +++ b/reid-llvm-lib/src/fmt.rs @@ -10,9 +10,8 @@ use crate::{ builder::*, debug_information::{ DebugArrayType, DebugBasicType, DebugFieldType, DebugLocation, DebugLocationValue, - DebugMetadataHolder, DebugMetadataValue, DebugPointerType, DebugProgramValue, - DebugScopeValue, DebugStructType, DebugSubprogramType, DebugTypeData, DebugTypeHolder, - DebugTypeValue, + DebugMetadataValue, DebugPointerType, DebugProgramValue, DebugScopeValue, DebugStructType, + DebugSubprogramType, DebugTypeData, DebugTypeHolder, DebugTypeValue, }, }; @@ -244,8 +243,6 @@ impl Debug for DebugTypeHolder { impl Debug for DebugTypeData { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - DebugTypeData::Basic(ty) => Debug::fmt(ty, f), - DebugTypeData::Subprogram(ty) => Debug::fmt(ty, f), DebugTypeData::Basic(ty) => Debug::fmt(ty, f), DebugTypeData::Subprogram(ty) => Debug::fmt(ty, f), DebugTypeData::Pointer(ty) => Debug::fmt(ty, f), diff --git a/reid-llvm-lib/src/lib.rs b/reid-llvm-lib/src/lib.rs index 03140a5..16827c9 100644 --- a/reid-llvm-lib/src/lib.rs +++ b/reid-llvm-lib/src/lib.rs @@ -5,17 +5,17 @@ use std::{fmt::Debug, marker::PhantomData}; use builder::{BlockValue, Builder, FunctionValue, InstructionValue, ModuleValue, TypeValue}; -use debug::PrintableModule; use debug_information::{ DebugFileData, DebugInformation, DebugLocationValue, DebugMetadataValue, DebugProgramValue, InstructionDebugRecordData, }; +use fmt::PrintableModule; use util::match_types; pub mod builder; pub mod compile; -mod debug; pub mod debug_information; +mod fmt; mod util; #[derive(Debug)] diff --git a/reid/src/codegen.rs b/reid/src/codegen.rs index 63ee507..dbf4c64 100644 --- a/reid/src/codegen.rs +++ b/reid/src/codegen.rs @@ -1,14 +1,14 @@ -use std::{array, collections::HashMap, fmt::format, mem}; +use std::{collections::HashMap, mem}; use reid_lib::{ builder::{InstructionValue, TypeValue}, compile::CompiledModule, debug_information::{ DebugArrayType, DebugBasicType, DebugFieldType, DebugFileData, DebugInformation, - DebugLocalVariable, DebugLocation, DebugMetadata, DebugMetadataValue, DebugParamVariable, - DebugPointerType, DebugProgramValue, DebugRecordKind, DebugScopeValue, DebugStructType, - DebugSubprogramData, DebugSubprogramOptionals, DebugSubprogramType, DebugTypeData, - DebugTypeValue, DwarfEncoding, DwarfFlags, InstructionDebugRecordData, + DebugLocalVariable, DebugLocation, DebugMetadata, DebugParamVariable, DebugPointerType, + DebugProgramValue, DebugRecordKind, DebugStructType, DebugSubprogramData, + DebugSubprogramOptionals, DebugSubprogramType, DebugTypeData, DebugTypeValue, + DwarfEncoding, DwarfFlags, InstructionDebugRecordData, }, Block, CmpPredicate, ConstValue, Context, CustomTypeKind, Function, FunctionFlags, Instr, Module, NamedStruct, TerminatorKind as Term, Type, @@ -130,6 +130,7 @@ impl StackValueKind { } } + #[allow(dead_code)] fn map(&self, lambda: F) -> StackValueKind where F: FnOnce(InstructionValue) -> InstructionValue, @@ -478,7 +479,6 @@ impl mir::Statement { mir::StmtKind::Let(NamedVariableRef(ty, name, _), mutable, expression) => { let value = expression.codegen(scope, &state).unwrap(); - dbg!(&name); let alloca = scope .block .build( @@ -664,7 +664,6 @@ impl mir::Expression { .functions .get(&call.name) .expect("function not found!"); - dbg!(&self, &callee.ir.value()); let val = scope .block diff --git a/reid/src/mir/display.rs b/reid/src/mir/fmt.rs similarity index 100% rename from reid/src/mir/display.rs rename to reid/src/mir/fmt.rs diff --git a/reid/src/mir/impl.rs b/reid/src/mir/impl.rs index 5864e82..aeae147 100644 --- a/reid/src/mir/impl.rs +++ b/reid/src/mir/impl.rs @@ -1,7 +1,3 @@ -use reid_lib::debug_information::{ - DebugBasicType, DebugLocation, DebugTypeData, DwarfEncoding, DwarfFlags, -}; - use super::{typecheck::ErrorKind, typerefs::TypeRefs, VagueType as Vague, *}; #[derive(Debug, Clone)] diff --git a/reid/src/mir/mod.rs b/reid/src/mir/mod.rs index afb0270..2eb8320 100644 --- a/reid/src/mir/mod.rs +++ b/reid/src/mir/mod.rs @@ -9,7 +9,7 @@ use crate::{ token_stream::TokenRange, }; -mod display; +mod fmt; pub mod r#impl; pub mod linker; pub mod pass; diff --git a/reid/src/mir/typeinference.rs b/reid/src/mir/typeinference.rs index f524679..5e02dc0 100644 --- a/reid/src/mir/typeinference.rs +++ b/reid/src/mir/typeinference.rs @@ -144,8 +144,6 @@ impl Block { let mut ret_type_ref = outer_refs.from_type(&ty).unwrap(); // Narow return type to declared type if hard return - dbg!(&kind, ty); - if kind == ReturnKind::Hard { if let Some(hint) = &state.scope.return_type_hint { ret_type_ref.narrow(&mut outer_refs.from_type(&hint).unwrap()); @@ -394,16 +392,10 @@ impl Expression { var.0 = hint.as_type(); } - dbg!(&var.0); - dbg!(&var.0.resolve_weak(type_refs.types)); - let a = match &var.0.resolve_weak(type_refs.types) { + match &var.0.resolve_weak(type_refs.types) { Borrow(type_kind) => Ok(type_refs.from_type(&type_kind).unwrap()), _ => Err(ErrorKind::AttemptedDerefNonBorrow(var.1.clone())), - }; - - dbg!(&a); - - a + } } } }