|
|
|
@ -3,7 +3,6 @@ mod tests;
|
|
|
|
|
|
|
|
|
|
use crate::compiler::{Instruction, Module};
|
|
|
|
|
use std::fmt;
|
|
|
|
|
use std::fmt::Write;
|
|
|
|
|
|
|
|
|
|
use super::StorageClass;
|
|
|
|
|
|
|
|
|
@ -149,7 +148,7 @@ fn fix_name(name: &String) -> String {
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn has_id(name: String, ops: &Vec<(Option<String>, Vec<String>)>) -> bool {
|
|
|
|
|
fn has_id<T>(name: String, ops: &Vec<(Option<String>, T)>) -> bool {
|
|
|
|
|
for op in ops {
|
|
|
|
|
if op.0.is_some() && op.0.clone().unwrap() == name {
|
|
|
|
|
return true;
|
|
|
|
@ -158,8 +157,7 @@ fn has_id(name: String, ops: &Vec<(Option<String>, Vec<String>)>) -> bool {
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn spirv_meta(module: Module) -> String {
|
|
|
|
|
let mut spirv_asm = String::new();
|
|
|
|
|
pub fn spirv_meta(module: &mut Module) -> Vec<(Option<String>, Vec<String>)> {
|
|
|
|
|
let mut ops: Vec<(Option<String>, Vec<String>)> = Vec::new();
|
|
|
|
|
|
|
|
|
|
let capabilities: Vec<String> = module
|
|
|
|
@ -192,7 +190,7 @@ pub fn spirv_meta(module: Module) -> String {
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
for entry in module.entry_points {
|
|
|
|
|
for entry in module.entry_points.clone() {
|
|
|
|
|
let exec_model = match entry.execution_model {
|
|
|
|
|
crate::compiler::ExecutionModel::Fragment => "Fragment",
|
|
|
|
|
crate::compiler::ExecutionModel::Vertex => "Vertex",
|
|
|
|
@ -226,7 +224,7 @@ pub fn spirv_meta(module: Module) -> String {
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for global in module.globals {
|
|
|
|
|
for global in module.globals.clone() {
|
|
|
|
|
let name = fix_name(&global.name);
|
|
|
|
|
let _typ = global.typ;
|
|
|
|
|
let storage_class = match global.storage_class {
|
|
|
|
@ -265,8 +263,8 @@ pub fn spirv_meta(module: Module) -> String {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for fun in module.functions {
|
|
|
|
|
let name = fix_name(&fun.name);
|
|
|
|
|
for fun in module.functions.clone() {
|
|
|
|
|
let name = fix_name(&format!("l_{}", fun.name));
|
|
|
|
|
let return_type = fix_name(&fun.return_type);
|
|
|
|
|
let mut type_ops = Vec::new();
|
|
|
|
|
emit_type(parse_type(&fun.return_type), &mut type_ops);
|
|
|
|
@ -283,16 +281,17 @@ pub fn spirv_meta(module: Module) -> String {
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for op in ops {
|
|
|
|
|
if op.0.is_some() {
|
|
|
|
|
write!(spirv_asm, "{} = ", op.0.unwrap()).unwrap();
|
|
|
|
|
}
|
|
|
|
|
for arg in op.1 {
|
|
|
|
|
write!(spirv_asm, "{} ", arg).unwrap();
|
|
|
|
|
}
|
|
|
|
|
writeln!(spirv_asm).unwrap();
|
|
|
|
|
}
|
|
|
|
|
spirv_asm
|
|
|
|
|
// for op in ops {
|
|
|
|
|
// if op.0.is_some() {
|
|
|
|
|
// write!(spirv_asm, "{} = ", op.0.unwrap()).unwrap();
|
|
|
|
|
// }
|
|
|
|
|
// for arg in op.1 {
|
|
|
|
|
// write!(spirv_asm, "{} ", arg).unwrap();
|
|
|
|
|
// }
|
|
|
|
|
// writeln!(spirv_asm).unwrap();
|
|
|
|
|
// }
|
|
|
|
|
// spirv_asm
|
|
|
|
|
ops
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum Number {
|
|
|
|
@ -475,7 +474,7 @@ pub fn compile_ast_ssa(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn compile_fun_ssa(module: &mut Module) {
|
|
|
|
|
pub fn compile_fun_ssa(module: &mut Module, ops: &Vec<(Option<String>, String)>) {
|
|
|
|
|
for fun in module.functions.iter_mut() {
|
|
|
|
|
assert!(fun.ast.is_some());
|
|
|
|
|
let ast = fun.ast.as_mut().unwrap();
|
|
|
|
@ -501,6 +500,12 @@ pub fn compile_fun_ssa(module: &mut Module) {
|
|
|
|
|
let mut out_pre = vec![];
|
|
|
|
|
for t in &types {
|
|
|
|
|
let typ = parse_type(t);
|
|
|
|
|
if has_id(fix_name(&typ.to_string()), ops) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if has_id(fix_name(&typ.to_string()), &out_pre) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
let mut type_ops = vec![];
|
|
|
|
|
emit_type(typ, &mut type_ops);
|
|
|
|
|
for type_op in type_ops {
|
|
|
|
|