mirror of
https://github.com/Zenithsiz/dcb.git
synced 2026-02-05 00:39:31 +00:00
Moved dcb_exe::exe::inst to crate::inst.
This commit is contained in:
parent
b41bd32fbd
commit
1e2f059895
@ -13,6 +13,7 @@ members = [
|
||||
"dcb-pak",
|
||||
"dcb-tools/dcb-extractor",
|
||||
"dcb-tools/dcb-decompiler",
|
||||
"dcb-tools/dcb-compiler",
|
||||
"dcb-tools/dcb-undrv",
|
||||
"dcb-tools/dcb-mkdrv",
|
||||
"dcb-tools/dcb-unpak",
|
||||
|
||||
@ -8,7 +8,6 @@ pub mod data;
|
||||
pub mod error;
|
||||
pub mod func;
|
||||
pub mod header;
|
||||
pub mod inst;
|
||||
pub mod iter;
|
||||
pub mod pos;
|
||||
|
||||
@ -23,6 +22,8 @@ pub use pos::Pos;
|
||||
use dcb_bytes::{ByteArray, Bytes};
|
||||
use std::{convert::TryFrom, io, ops::Range};
|
||||
|
||||
use crate::inst;
|
||||
|
||||
/// The game executable
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Exe {
|
||||
|
||||
@ -38,8 +38,10 @@ pub use target::InstTarget;
|
||||
|
||||
// Imports
|
||||
use self::{basic::Decodable as _, directive::DecodeWithDataError, pseudo::Decodable as _};
|
||||
use super::{Data, DataTable, FuncTable};
|
||||
use crate::Pos;
|
||||
use crate::{
|
||||
exe::{Data, DataTable, FuncTable},
|
||||
Pos,
|
||||
};
|
||||
|
||||
/// An assembler instruction.
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||
@ -18,7 +18,7 @@ pub mod sys;
|
||||
|
||||
// Imports
|
||||
use super::InstSize;
|
||||
use crate::exe::inst::InstFmt;
|
||||
use crate::inst::InstFmt;
|
||||
|
||||
/// Raw instruction
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||
@ -5,7 +5,7 @@ pub mod imm;
|
||||
pub mod reg;
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt,
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
//! Alu immediate instructions
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt, Register,
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
//! Alu register instructions
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt, Register,
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
//! Co-processor instructions
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt, Register,
|
||||
};
|
||||
@ -3,7 +3,7 @@
|
||||
//! Lui instruction
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt, Register,
|
||||
};
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
// Imports
|
||||
use crate::{
|
||||
exe::inst::{
|
||||
inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstTarget, InstTargetFmt, Register,
|
||||
},
|
||||
@ -5,7 +5,7 @@ pub mod imm;
|
||||
pub mod reg;
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt,
|
||||
};
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
// Imports
|
||||
use crate::{
|
||||
exe::inst::{
|
||||
inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstTarget, InstTargetFmt,
|
||||
},
|
||||
@ -1,7 +1,7 @@
|
||||
//! Jump register instructions
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt, Register,
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
//! Load instructions
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt, Register,
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
//! Lui instruction
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt, Register,
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
//! Multiplications
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt, Register,
|
||||
};
|
||||
@ -6,7 +6,7 @@ pub mod imm;
|
||||
pub mod reg;
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt,
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
//! Shift immediate instructions
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt, Register,
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
//! Shift register instructions
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt, Register,
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
//! Store instructions
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt, Register,
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
//! System calls
|
||||
|
||||
// Imports
|
||||
use crate::exe::inst::{
|
||||
use crate::inst::{
|
||||
basic::{Decodable, Encodable},
|
||||
InstFmt,
|
||||
};
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
// Imports
|
||||
use crate::{
|
||||
exe::inst::{basic, InstSize, InstTarget, InstTargetFmt, Register},
|
||||
inst::{basic, InstSize, InstTarget, InstTargetFmt, Register},
|
||||
Pos,
|
||||
};
|
||||
use int_conv::{Join, SignExtended, Signed};
|
||||
@ -3,7 +3,7 @@
|
||||
// Imports
|
||||
use super::Decodable;
|
||||
use crate::{
|
||||
exe::inst::{basic, InstFmt, InstSize, InstTargetFmt, Register},
|
||||
inst::{basic, InstFmt, InstSize, InstTargetFmt, Register},
|
||||
Pos,
|
||||
};
|
||||
use dcb_util::SignedHex;
|
||||
@ -4,7 +4,7 @@
|
||||
use std::convert::TryInto;
|
||||
|
||||
use super::Decodable;
|
||||
use crate::exe::inst::{basic, InstFmt, InstSize, Register};
|
||||
use crate::inst::{basic, InstFmt, InstSize, Register};
|
||||
|
||||
/// Move register instruction
|
||||
///
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
// Imports
|
||||
use super::Decodable;
|
||||
use crate::exe::inst::{basic, InstFmt, InstSize, Register};
|
||||
use crate::inst::{basic, InstFmt, InstSize, Register};
|
||||
|
||||
/// No-op
|
||||
///
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
// Imports
|
||||
use crate::{
|
||||
exe::inst::{basic, InstSize, InstTarget, InstTargetFmt, Register},
|
||||
inst::{basic, InstSize, InstTarget, InstTargetFmt, Register},
|
||||
Pos,
|
||||
};
|
||||
use int_conv::{Join, SignExtended, Signed};
|
||||
@ -75,6 +75,7 @@
|
||||
|
||||
// Modules
|
||||
pub mod exe;
|
||||
pub mod inst;
|
||||
|
||||
// Exports
|
||||
pub use exe::{Exe, Header, Pos};
|
||||
|
||||
35
dcb-tools/dcb-compiler/Cargo.toml
Normal file
35
dcb-tools/dcb-compiler/Cargo.toml
Normal file
@ -0,0 +1,35 @@
|
||||
[package]
|
||||
name = "dcb-compiler"
|
||||
version = "0.1.0"
|
||||
authors = ["Filipe Rodrigues <filipejacintorodrigues1@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
# Dcb
|
||||
dcb = { path = "../../dcb" }
|
||||
dcb-exe = { path = "../../dcb-exe" }
|
||||
dcb-util = { path = "../../dcb-util" }
|
||||
|
||||
# Text
|
||||
ascii = "1.0"
|
||||
|
||||
# Helpers
|
||||
int-conv = "0.1"
|
||||
byteorder = "1.3"
|
||||
|
||||
# Cmd
|
||||
clap = "2.33"
|
||||
|
||||
# Logging
|
||||
log = "0.4"
|
||||
simplelog = "0.8"
|
||||
|
||||
# Error handling
|
||||
anyhow = "1.0"
|
||||
|
||||
# Derives
|
||||
derive_more = "0.99"
|
||||
|
||||
# Serde
|
||||
serde = "1.0"
|
||||
serde_yaml = "0.8"
|
||||
57
dcb-tools/dcb-compiler/src/cli.rs
Normal file
57
dcb-tools/dcb-compiler/src/cli.rs
Normal file
@ -0,0 +1,57 @@
|
||||
//! Command line arguments
|
||||
|
||||
// Imports
|
||||
use clap::{App as ClapApp, Arg as ClapArg};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Command line data
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
pub struct CliData {
|
||||
/// The input file
|
||||
pub input_path: PathBuf,
|
||||
|
||||
/// Output file
|
||||
pub output_file_path: PathBuf,
|
||||
}
|
||||
|
||||
impl CliData {
|
||||
/// Constructs all of the cli data given and returns it
|
||||
pub fn new() -> Self {
|
||||
const INPUT_FILE_STR: &str = "input-file";
|
||||
const OUTPUT_FILE_STR: &str = "output-file";
|
||||
|
||||
// Get all matches from cli
|
||||
let matches = ClapApp::new("Dcb Decompiler")
|
||||
.version("0.0")
|
||||
.author("Filipe [...] <[...]@gmail.com>")
|
||||
.about("Compiles code from assembly")
|
||||
.arg(
|
||||
ClapArg::with_name(INPUT_FILE_STR)
|
||||
.help("Sets the input file to use")
|
||||
.required(true)
|
||||
.index(1),
|
||||
)
|
||||
.arg(ClapArg::with_name(OUTPUT_FILE_STR).long("output").short("o").help("Sets the output file"))
|
||||
.get_matches();
|
||||
|
||||
// Get the input filename
|
||||
// Note: required
|
||||
let input_path = matches
|
||||
.value_of(INPUT_FILE_STR)
|
||||
.map(Path::new)
|
||||
.map(Path::to_path_buf)
|
||||
.expect("Unable to get required argument `input-file`");
|
||||
|
||||
// Get the output directory, or just use `a.out`
|
||||
let output_file_path = match matches.value_of(OUTPUT_FILE_STR) {
|
||||
Some(path) => PathBuf::from(path),
|
||||
None => PathBuf::from("a.out"),
|
||||
};
|
||||
|
||||
// Return the cli data
|
||||
Self {
|
||||
input_path,
|
||||
output_file_path,
|
||||
}
|
||||
}
|
||||
}
|
||||
31
dcb-tools/dcb-compiler/src/main.rs
Normal file
31
dcb-tools/dcb-compiler/src/main.rs
Normal file
@ -0,0 +1,31 @@
|
||||
//! Compiler
|
||||
|
||||
#![feature(box_syntax, backtrace, panic_info_message, array_chunks, format_args_capture, bindings_after_at)]
|
||||
|
||||
// Modules
|
||||
mod cli;
|
||||
|
||||
// Imports
|
||||
use anyhow::Context;
|
||||
|
||||
fn main() -> Result<(), anyhow::Error> {
|
||||
// Initialize the logger
|
||||
simplelog::TermLogger::init(log::LevelFilter::Info, simplelog::Config::default(), simplelog::TerminalMode::Stderr)
|
||||
.expect("Unable to initialize logger");
|
||||
|
||||
// Get all data from cli
|
||||
let cli = cli::CliData::new();
|
||||
|
||||
// Open the input and output file
|
||||
let _input_file = std::fs::File::open(&cli.input_path).context("Unable to open input file")?;
|
||||
let _output_file = std::fs::File::open(&cli.output_file_path).context("Unable to open output file")?;
|
||||
|
||||
// Read the executable
|
||||
/*
|
||||
let exe = Exe::new();
|
||||
|
||||
exe.serialize(&mut input_file).context("Unable to parse game executable")?;
|
||||
*/
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -8,11 +8,8 @@ mod cli;
|
||||
// Imports
|
||||
use anyhow::Context;
|
||||
use dcb_exe::{
|
||||
exe::{
|
||||
inst::{basic, pseudo, Directive, Inst, InstFmt, InstTarget, InstTargetFmt},
|
||||
iter::ExeItem,
|
||||
Func,
|
||||
},
|
||||
exe::{iter::ExeItem, Func},
|
||||
inst::{basic, pseudo, Directive, Inst, InstFmt, InstTarget, InstTargetFmt},
|
||||
Exe, Pos,
|
||||
};
|
||||
use std::fmt;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user