Clippy and warning clean-ups.
This commit is contained in:
@@ -4,12 +4,12 @@ use crate::backend::runtime::RuntimeFunctions;
|
||||
use crate::ir::{Expression, Primitive, Program, Statement, Value, ValueOrRef};
|
||||
use cranelift_codegen::entity::EntityRef;
|
||||
use cranelift_codegen::ir::{
|
||||
entities, types, Function, GlobalValue, InstBuilder, Signature, UserFuncName, MemFlags,
|
||||
entities, types, Function, GlobalValue, InstBuilder, MemFlags, Signature, UserFuncName,
|
||||
};
|
||||
use cranelift_codegen::isa::CallConv;
|
||||
use cranelift_codegen::Context;
|
||||
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
|
||||
use cranelift_module::{DataContext, FuncId, Linkage, Module, ModuleError, DataId};
|
||||
use cranelift_module::{DataContext, DataId, FuncId, Linkage, Module, ModuleError};
|
||||
use internment::ArcIntern;
|
||||
|
||||
use super::RuntimeFunctionError;
|
||||
@@ -45,10 +45,13 @@ impl Program {
|
||||
let mut variable_table = HashMap::new();
|
||||
let mut next_var_num = 1;
|
||||
let print_func_ref = rtfuns.include_runtime_function("print", module, &mut ctx.func)?;
|
||||
let pre_defined_symbols: HashMap<String, GlobalValue> = pre_defined_symbols.iter().map(|(k, v)| {
|
||||
let pre_defined_symbols: HashMap<String, GlobalValue> = pre_defined_symbols
|
||||
.iter()
|
||||
.map(|(k, v)| {
|
||||
let local_data = module.declare_data_in_func(*v, &mut ctx.func);
|
||||
(k.clone(), local_data)
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut fctx = FunctionBuilderContext::new();
|
||||
let mut builder = FunctionBuilder::new(&mut ctx.func, &mut fctx);
|
||||
@@ -60,7 +63,11 @@ impl Program {
|
||||
Statement::Print(ann, var) => {
|
||||
let local_name_ref = string_table.get(&var).unwrap();
|
||||
let name_ptr = builder.ins().symbol_value(types::I64, *local_name_ref);
|
||||
let val = ValueOrRef::Ref(ann, var).into_cranelift(&mut builder, &variable_table, &pre_defined_symbols)?;
|
||||
let val = ValueOrRef::Ref(ann, var).into_cranelift(
|
||||
&mut builder,
|
||||
&variable_table,
|
||||
&pre_defined_symbols,
|
||||
)?;
|
||||
builder.ins().call(print_func_ref, &[name_ptr, val]);
|
||||
}
|
||||
|
||||
@@ -76,14 +83,16 @@ impl Program {
|
||||
}
|
||||
|
||||
Expression::Primitive(_, prim, mut vals) => {
|
||||
let right = vals
|
||||
.pop()
|
||||
.unwrap()
|
||||
.into_cranelift(&mut builder, &variable_table, &pre_defined_symbols)?;
|
||||
let left = vals
|
||||
.pop()
|
||||
.unwrap()
|
||||
.into_cranelift(&mut builder, &variable_table, &pre_defined_symbols)?;
|
||||
let right = vals.pop().unwrap().into_cranelift(
|
||||
&mut builder,
|
||||
&variable_table,
|
||||
&pre_defined_symbols,
|
||||
)?;
|
||||
let left = vals.pop().unwrap().into_cranelift(
|
||||
&mut builder,
|
||||
&variable_table,
|
||||
&pre_defined_symbols,
|
||||
)?;
|
||||
|
||||
match prim {
|
||||
Primitive::Plus => builder.ins().iadd(left, right),
|
||||
@@ -175,7 +184,7 @@ impl ValueOrRef {
|
||||
|
||||
if let Some(global_id) = global_variables.get(name.as_str()) {
|
||||
let val_ptr = builder.ins().symbol_value(types::I64, *global_id);
|
||||
return Ok(builder.ins().load(types::I64, MemFlags::new(), val_ptr, 0))
|
||||
return Ok(builder.ins().load(types::I64, MemFlags::new(), val_ptr, 0));
|
||||
}
|
||||
|
||||
Err(ModuleError::Undeclared(name.to_string()))
|
||||
|
||||
@@ -7,7 +7,7 @@ use cranelift_codegen::{
|
||||
};
|
||||
use cranelift_jit::{JITBuilder, JITModule};
|
||||
use cranelift_module::{DataContext, DataId, Linkage, Module};
|
||||
use std::{collections::HashMap, ffi::{CString, CStr}};
|
||||
use std::{collections::HashMap, ffi::CStr};
|
||||
use target_lexicon::Triple;
|
||||
|
||||
const EMPTY_DATUM: [u8; 8] = [0; 8];
|
||||
@@ -20,7 +20,7 @@ pub struct JITEngine {
|
||||
defined_symbols: HashMap<String, DataId>,
|
||||
}
|
||||
|
||||
extern fn runtime_print(name: *const i8, value: u64) {
|
||||
extern "C" fn runtime_print(name: *const i8, value: u64) {
|
||||
let cstr = unsafe { CStr::from_ptr(name) };
|
||||
let reconstituted = cstr.to_string_lossy();
|
||||
println!("{} = {}", reconstituted, value);
|
||||
@@ -52,7 +52,9 @@ impl JITEngine {
|
||||
|
||||
pub fn define_string(&mut self, s: String) -> Result<(), JITError> {
|
||||
let name = format!("<string_constant>{}", s);
|
||||
let global_id = self.module.declare_data(&name, Linkage::Local, false, false)?;
|
||||
let global_id = self
|
||||
.module
|
||||
.declare_data(&name, Linkage::Local, false, false)?;
|
||||
let mut data_context = DataContext::new();
|
||||
data_context.set_align(8);
|
||||
data_context.define(s.as_str().to_owned().into_boxed_str().into_boxed_bytes());
|
||||
|
||||
@@ -6,7 +6,7 @@ mod location;
|
||||
mod simplify;
|
||||
mod tokens;
|
||||
lalrpop_mod!(
|
||||
#[allow(clippy::just_underscores_and_digits)]
|
||||
#[allow(clippy::just_underscores_and_digits, clippy::clone_on_copy)]
|
||||
parser,
|
||||
"/syntax/parser.rs"
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user