Clean up warnings and formatting.
This commit is contained in:
@@ -118,7 +118,7 @@ impl<Annotation> Expression<Annotation> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum Primitive {
|
pub enum Primitive {
|
||||||
Plus,
|
Plus,
|
||||||
Minus,
|
Minus,
|
||||||
@@ -141,7 +141,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Value {
|
pub enum Value {
|
||||||
Number(Option<u8>, i128),
|
Number(Option<u8>, i128),
|
||||||
}
|
}
|
||||||
@@ -172,7 +172,7 @@ where
|
|||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
struct CommaSep {}
|
struct CommaSep {}
|
||||||
|
|
||||||
impl<'a, 'b, D, A> Pretty<'a, D, A> for CommaSep
|
impl<'a, D, A> Pretty<'a, D, A> for CommaSep
|
||||||
where
|
where
|
||||||
A: 'a,
|
A: 'a,
|
||||||
D: ?Sized + DocAllocator<'a, A>,
|
D: ?Sized + DocAllocator<'a, A>,
|
||||||
|
|||||||
@@ -10,10 +10,7 @@ pub struct Program<Annotation> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<Annotation> Program<Annotation> {
|
impl<Annotation> Program<Annotation> {
|
||||||
pub fn pretty<'a, A, D>(
|
pub fn pretty<'a, A, D>(&self, allocator: &'a D) -> DocBuilder<'a, D, A>
|
||||||
&self,
|
|
||||||
allocator: &'a D,
|
|
||||||
) -> DocBuilder<'a, D, A>
|
|
||||||
where
|
where
|
||||||
A: 'a,
|
A: 'a,
|
||||||
D: ?Sized + DocAllocator<'a, A>,
|
D: ?Sized + DocAllocator<'a, A>,
|
||||||
@@ -71,13 +68,16 @@ impl<Annotation> Statement<Annotation> {
|
|||||||
.append(prim.pretty(variable_map, allocator))
|
.append(prim.pretty(variable_map, allocator))
|
||||||
}
|
}
|
||||||
|
|
||||||
Statement::Print(_, idx, var) => {
|
Statement::Print(_, idx, _var) => {
|
||||||
let name = strings.get(idx).cloned().unwrap_or_else(||"<unknown>".to_string());
|
let name = strings
|
||||||
|
.get(idx)
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or_else(|| "<unknown>".to_string());
|
||||||
|
|
||||||
allocator
|
allocator
|
||||||
.text("print")
|
.text("print")
|
||||||
.append(allocator.space())
|
.append(allocator.space())
|
||||||
.append(allocator.text(name.to_string()))
|
.append(allocator.text(name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,12 @@ use codespan_reporting::diagnostic::Diagnostic;
|
|||||||
use codespan_reporting::files::SimpleFiles;
|
use codespan_reporting::files::SimpleFiles;
|
||||||
use codespan_reporting::term;
|
use codespan_reporting::term;
|
||||||
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
|
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
|
||||||
use cranelift_codegen::ir::{types, AbiParam, Signature};
|
|
||||||
use cranelift_codegen::isa::CallConv;
|
|
||||||
use cranelift_codegen::{isa, settings, CodegenError};
|
use cranelift_codegen::{isa, settings, CodegenError};
|
||||||
use cranelift_module::{default_libcall_names, Linkage, Module, ModuleError};
|
use cranelift_module::{default_libcall_names, ModuleError};
|
||||||
use cranelift_object::{object, ObjectBuilder, ObjectModule};
|
use cranelift_object::{object, ObjectBuilder, ObjectModule};
|
||||||
use ngr::asts::lil;
|
use ngr::asts::lil;
|
||||||
use ngr::passes::{run_front_end, BackendError};
|
use ngr::passes::{run_front_end, BackendError};
|
||||||
use ngr::runtime::RuntimeFunctions;
|
use ngr::runtime::RuntimeFunctions;
|
||||||
use pretty::Arena;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use target_lexicon::Triple;
|
use target_lexicon::Triple;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
@@ -78,7 +75,7 @@ fn main() -> Result<(), MainError> {
|
|||||||
|
|
||||||
if let Some((hil_tree, variable_map)) = hil_conversion_result.result {
|
if let Some((hil_tree, variable_map)) = hil_conversion_result.result {
|
||||||
//let arena = Arena::new();
|
//let arena = Arena::new();
|
||||||
let lil_tree = lil::Program::convert(hil_tree, variable_map.clone());
|
let lil_tree = lil::Program::convert(hil_tree, variable_map);
|
||||||
|
|
||||||
let isa = isa::lookup(Triple::host())?.finish(settings::Flags::new(settings::builder()))?;
|
let isa = isa::lookup(Triple::host())?.finish(settings::Flags::new(settings::builder()))?;
|
||||||
let object_builder = ObjectBuilder::new(isa, "example", default_libcall_names())?;
|
let object_builder = ObjectBuilder::new(isa, "example", default_libcall_names())?;
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
use std::string;
|
|
||||||
|
|
||||||
use crate::asts::hil;
|
use crate::asts::hil;
|
||||||
use crate::asts::lil;
|
use crate::asts::lil;
|
||||||
use crate::variable_map::VariableMap;
|
use crate::variable_map::VariableMap;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
impl<Annotation: Clone> lil::Program<Annotation> {
|
impl<Annotation: Clone> lil::Program<Annotation> {
|
||||||
pub fn convert(hil_program: hil::Program<Annotation>, mut variable_map: VariableMap) -> Self {
|
pub fn convert(hil_program: hil::Program<Annotation>, mut variable_map: VariableMap) -> Self {
|
||||||
@@ -30,7 +28,7 @@ impl<Annotation: Clone> lil::Statement<Annotation> {
|
|||||||
fn convert(
|
fn convert(
|
||||||
hil_statement: hil::Statement<Annotation>,
|
hil_statement: hil::Statement<Annotation>,
|
||||||
variable_map: &mut VariableMap,
|
variable_map: &mut VariableMap,
|
||||||
strings: &mut HashMap<usize, String>
|
strings: &mut HashMap<usize, String>,
|
||||||
) -> Vec<Self> {
|
) -> Vec<Self> {
|
||||||
match hil_statement {
|
match hil_statement {
|
||||||
hil::Statement::Binding(annotation, var, expr) => match expr {
|
hil::Statement::Binding(annotation, var, expr) => match expr {
|
||||||
@@ -111,9 +109,9 @@ impl<Annotation: Clone> lil::Statement<Annotation> {
|
|||||||
hil::Statement::Print(annotation, var) => {
|
hil::Statement::Print(annotation, var) => {
|
||||||
let string_idx = strings.keys().max().unwrap_or(&1) + 1;
|
let string_idx = strings.keys().max().unwrap_or(&1) + 1;
|
||||||
let zero_termed = format!("{}\0", variable_map.get_name(var).unwrap());
|
let zero_termed = format!("{}\0", variable_map.get_name(var).unwrap());
|
||||||
strings.insert(string_idx,zero_termed);
|
strings.insert(string_idx, zero_termed);
|
||||||
vec![lil::Statement::Print(annotation, string_idx, var)]
|
vec![lil::Statement::Print(annotation, string_idx, var)]
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use cranelift_codegen::ir::{entities, types, Function, InstBuilder, Signature, U
|
|||||||
use cranelift_codegen::isa::CallConv;
|
use cranelift_codegen::isa::CallConv;
|
||||||
use cranelift_codegen::Context;
|
use cranelift_codegen::Context;
|
||||||
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
|
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
|
||||||
use cranelift_module::{FuncId, Linkage, Module, ModuleCompiledFunction, ModuleError, DataContext};
|
use cranelift_module::{DataContext, Linkage, Module, ModuleCompiledFunction, ModuleError};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
@@ -22,7 +22,7 @@ pub enum BackendError {
|
|||||||
|
|
||||||
impl<Annotation> Program<Annotation> {
|
impl<Annotation> Program<Annotation> {
|
||||||
pub fn into_cranelift<M: Module>(
|
pub fn into_cranelift<M: Module>(
|
||||||
&self,
|
mut self,
|
||||||
module: &mut M,
|
module: &mut M,
|
||||||
rtfuns: &RuntimeFunctions,
|
rtfuns: &RuntimeFunctions,
|
||||||
) -> Result<ModuleCompiledFunction, BackendError> {
|
) -> Result<ModuleCompiledFunction, BackendError> {
|
||||||
@@ -38,7 +38,7 @@ impl<Annotation> Program<Annotation> {
|
|||||||
Function::with_name_signature(UserFuncName::user(0, func_id.as_u32()), basic_signature);
|
Function::with_name_signature(UserFuncName::user(0, func_id.as_u32()), basic_signature);
|
||||||
let mut variable_name_global_values = HashMap::new();
|
let mut variable_name_global_values = HashMap::new();
|
||||||
|
|
||||||
for (index, value) in self.strings.iter() {
|
for (index, value) in self.strings.drain() {
|
||||||
let global_id = module.declare_data(
|
let global_id = module.declare_data(
|
||||||
&format!("local-string-{}", index),
|
&format!("local-string-{}", index),
|
||||||
Linkage::Local,
|
Linkage::Local,
|
||||||
@@ -47,7 +47,7 @@ impl<Annotation> Program<Annotation> {
|
|||||||
)?;
|
)?;
|
||||||
let mut data_context = DataContext::new();
|
let mut data_context = DataContext::new();
|
||||||
data_context.set_align(8);
|
data_context.set_align(8);
|
||||||
data_context.define(value.to_owned().into_boxed_str().into_boxed_bytes());
|
data_context.define(value.into_boxed_str().into_boxed_bytes());
|
||||||
module.define_data(global_id, &data_context)?;
|
module.define_data(global_id, &data_context)?;
|
||||||
let local_data = module.declare_data_in_func(global_id, &mut ctx.func);
|
let local_data = module.declare_data_in_func(global_id, &mut ctx.func);
|
||||||
variable_name_global_values.insert(index, local_data);
|
variable_name_global_values.insert(index, local_data);
|
||||||
@@ -60,17 +60,17 @@ impl<Annotation> Program<Annotation> {
|
|||||||
let main_block = builder.create_block();
|
let main_block = builder.create_block();
|
||||||
builder.switch_to_block(main_block);
|
builder.switch_to_block(main_block);
|
||||||
|
|
||||||
for stmt in self.statements.iter() {
|
for stmt in self.statements.drain(..) {
|
||||||
match stmt {
|
match stmt {
|
||||||
Statement::Print(_ann, name_idx, var) => {
|
Statement::Print(_ann, name_idx, var) => {
|
||||||
let local_data = *variable_name_global_values.get(name_idx).unwrap();
|
let local_data = *variable_name_global_values.get(&name_idx).unwrap();
|
||||||
let var_name = builder.ins().symbol_value(types::I64, local_data);
|
let var_name = builder.ins().symbol_value(types::I64, local_data);
|
||||||
let val = builder.use_var(Variable::new(*var));
|
let val = builder.use_var(Variable::new(var));
|
||||||
builder.ins().call(print_func_ref, &[var_name, val]);
|
builder.ins().call(print_func_ref, &[var_name, val]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Statement::ResultBinding(_, varnum, value) => {
|
Statement::ResultBinding(_, varnum, value) => {
|
||||||
let var = Variable::new(*varnum);
|
let var = Variable::new(varnum);
|
||||||
builder.declare_var(var, types::I64);
|
builder.declare_var(var, types::I64);
|
||||||
|
|
||||||
let val = match value {
|
let val = match value {
|
||||||
@@ -102,7 +102,7 @@ impl<Annotation> Program<Annotation> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Statement::VariableBinding(_, varnum, exp) => {
|
Statement::VariableBinding(_, varnum, exp) => {
|
||||||
let var = Variable::new(*varnum);
|
let var = Variable::new(varnum);
|
||||||
builder.declare_var(var, types::I64);
|
builder.declare_var(var, types::I64);
|
||||||
let val = exp.into_cranelift(&mut builder);
|
let val = exp.into_cranelift(&mut builder);
|
||||||
builder.def_var(var, val);
|
builder.def_var(var, val);
|
||||||
@@ -119,13 +119,13 @@ impl<Annotation> Program<Annotation> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<Annotation> SimpleExpression<Annotation> {
|
impl<Annotation> SimpleExpression<Annotation> {
|
||||||
fn into_cranelift(&self, builder: &mut FunctionBuilder) -> entities::Value {
|
fn into_cranelift(self, builder: &mut FunctionBuilder) -> entities::Value {
|
||||||
match self {
|
match self {
|
||||||
SimpleExpression::Constant(_, value) => match value {
|
SimpleExpression::Constant(_, value) => match value {
|
||||||
Value::Number(_base, numval) => builder.ins().iconst(types::I64, *numval as i64),
|
Value::Number(_base, numval) => builder.ins().iconst(types::I64, numval as i64),
|
||||||
},
|
},
|
||||||
|
|
||||||
SimpleExpression::Reference(_, num) => builder.use_var(Variable::new(*num)),
|
SimpleExpression::Reference(_, num) => builder.use_var(Variable::new(num)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
use cranelift_codegen::ir::{
|
use cranelift_codegen::ir::{types, AbiParam, FuncRef, Function, Signature};
|
||||||
types, AbiParam, ArgumentExtension, ArgumentPurpose, FuncRef, Function, Signature,
|
|
||||||
};
|
|
||||||
use cranelift_codegen::isa::CallConv;
|
use cranelift_codegen::isa::CallConv;
|
||||||
use cranelift_module::{FuncId, Linkage, Module, ModuleResult};
|
use cranelift_module::{FuncId, Linkage, Module, ModuleResult};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Value {
|
pub enum Value {
|
||||||
Number(Option<u8>, i128),
|
Number(Option<u8>, i128),
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ where
|
|||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
struct CommaSep {}
|
struct CommaSep {}
|
||||||
|
|
||||||
impl<'a, 'b, D, A> Pretty<'a, D, A> for CommaSep
|
impl<'a, D, A> Pretty<'a, D, A> for CommaSep
|
||||||
where
|
where
|
||||||
A: 'a,
|
A: 'a,
|
||||||
D: ?Sized + DocAllocator<'a, A>,
|
D: ?Sized + DocAllocator<'a, A>,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ impl<'s> TokenStream<'s> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum Location {
|
pub enum Location {
|
||||||
InFile(usize, usize),
|
InFile(usize, usize),
|
||||||
Manufactured,
|
Manufactured,
|
||||||
@@ -44,7 +44,7 @@ impl Default for Location {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error, PartialEq)]
|
#[derive(Debug, Error, PartialEq, Eq)]
|
||||||
pub enum LexerError {
|
pub enum LexerError {
|
||||||
#[error("Failed lexing at {0}")]
|
#[error("Failed lexing at {0}")]
|
||||||
LexFailure(Location),
|
LexFailure(Location),
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use logos::{Lexer, Logos};
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
|
|
||||||
#[derive(Logos, Clone, Debug, PartialEq)]
|
#[derive(Logos, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum Token {
|
pub enum Token {
|
||||||
#[token("=")]
|
#[token("=")]
|
||||||
Equals,
|
Equals,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::syntax::Location;
|
use crate::syntax::Location;
|
||||||
use codespan_reporting::diagnostic::{Diagnostic, Label};
|
use codespan_reporting::diagnostic::{Diagnostic, Label};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Warning {
|
pub enum Warning {
|
||||||
ShadowedVariable(Location, Location, String),
|
ShadowedVariable(Location, Location, String),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user