mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Add more glsl-new handling of funcs and types (#110)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::{Arena, FastHashMap, Function, Handle};
|
||||
use crate::{Arena, FastHashMap, Function, Handle, Type};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Program {
|
||||
@@ -7,6 +7,8 @@ pub struct Program {
|
||||
pub ext_decls: Vec<ExtDecl>,
|
||||
pub lookup_function: FastHashMap<String, Handle<Function>>,
|
||||
pub functions: Arena<Function>,
|
||||
pub lookup_type: FastHashMap<String, Handle<Type>>,
|
||||
pub types: Arena<Type>,
|
||||
}
|
||||
|
||||
impl Program {
|
||||
@@ -17,6 +19,8 @@ impl Program {
|
||||
ext_decls: vec![],
|
||||
lookup_function: FastHashMap::default(),
|
||||
functions: Arena::<Function>::new(),
|
||||
lookup_type: FastHashMap::default(),
|
||||
types: Arena::<Type>::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ pub fn parse_str(source: &str, entry: String, stage: ShaderStage) -> Result<Modu
|
||||
|
||||
let mut module = Module::generate_empty();
|
||||
module.functions = program.functions;
|
||||
module.types = program.types;
|
||||
|
||||
// find entry point
|
||||
if let Some(entry_handle) = program.lookup_function.get(&entry) {
|
||||
|
||||
@@ -6,7 +6,8 @@ pomelo! {
|
||||
//%verbose;
|
||||
%include {
|
||||
use super::super::{error::ErrorKind, token::*, ast::*};
|
||||
use crate::{Arena, Expression, Function, LocalVariable};
|
||||
use crate::{Arena, Expression, Function, Handle, LocalVariable, ScalarKind,
|
||||
Type, TypeInner, VectorSize};
|
||||
}
|
||||
%token #[derive(Debug)] pub enum Token {};
|
||||
%parser pub struct Parser<'a> {};
|
||||
@@ -38,8 +39,18 @@ pomelo! {
|
||||
%type DoubleConstant f64;
|
||||
%type String String;
|
||||
%type arg_list Vec<String>;
|
||||
|
||||
%type function_prototype Function;
|
||||
%type function_declarator Function;
|
||||
%type function_header Function;
|
||||
|
||||
%type function_definition Function;
|
||||
|
||||
%type fully_specified_type Option<Handle<Type>>;
|
||||
%type type_specifier Option<Handle<Type>>;
|
||||
%type type_specifier_nonarray Option<Type>;
|
||||
|
||||
|
||||
root ::= version_pragma translation_unit;
|
||||
version_pragma ::= Version IntConstant(V) Identifier?(P) {
|
||||
match V.1 {
|
||||
@@ -178,16 +189,44 @@ pomelo! {
|
||||
|
||||
|
||||
// function
|
||||
function_prototype ::= function_declarator RightParen;
|
||||
function_prototype ::= function_declarator(f) RightParen {f}
|
||||
function_declarator ::= function_header;
|
||||
function_header ::= fully_specified_type Identifier LeftParen;
|
||||
function_header ::= fully_specified_type(t) Identifier(n) LeftParen {
|
||||
Function {
|
||||
name: Some(n.1),
|
||||
parameter_types: vec![],
|
||||
return_type: t,
|
||||
global_usage: vec![],
|
||||
local_variables: Arena::<LocalVariable>::new(),
|
||||
expressions: Arena::<Expression>::new(),
|
||||
body: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
// type
|
||||
fully_specified_type ::= type_specifier;
|
||||
type_specifier ::= type_specifier_nonarray;
|
||||
type_specifier ::= type_specifier_nonarray(t) {
|
||||
t.map(|t| {
|
||||
let name = t.name.clone();
|
||||
let handle = extra.types.fetch_or_append(t);
|
||||
if let Some(name) = name {
|
||||
extra.lookup_type.insert(name, handle);
|
||||
}
|
||||
handle
|
||||
})
|
||||
}
|
||||
|
||||
type_specifier_nonarray ::= Void;
|
||||
type_specifier_nonarray ::= Vec4;
|
||||
type_specifier_nonarray ::= Void { None }
|
||||
type_specifier_nonarray ::= Vec4 {
|
||||
Some(Type {
|
||||
name: None,
|
||||
inner: TypeInner::Vector {
|
||||
size: VectorSize::Quad,
|
||||
kind: ScalarKind::Float,
|
||||
width: 16,
|
||||
}
|
||||
})
|
||||
}
|
||||
//TODO: remaining types
|
||||
|
||||
// misc
|
||||
@@ -202,16 +241,8 @@ pomelo! {
|
||||
}
|
||||
}
|
||||
|
||||
function_definition ::= function_prototype compound_statement_no_new_scope {
|
||||
Function {
|
||||
name: Some(String::from("main")),
|
||||
parameter_types: vec![],
|
||||
return_type: None,
|
||||
global_usage: vec![],
|
||||
local_variables: Arena::<LocalVariable>::new(),
|
||||
expressions: Arena::<Expression>::new(),
|
||||
body: vec![],
|
||||
}
|
||||
function_definition ::= function_prototype(f) compound_statement_no_new_scope {
|
||||
f
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user