[glsl-new] store int constants in module (#111)

This commit is contained in:
Pelle Johnsen
2020-07-20 16:56:10 +02:00
committed by GitHub
parent 56e78e47ac
commit 41ca3834f5
3 changed files with 21 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
use crate::{Arena, FastHashMap, Function, Handle, Type};
use crate::{Arena, Constant, FastHashMap, Function, Handle, Type};
#[derive(Debug)]
pub struct Program {
@@ -9,6 +9,7 @@ pub struct Program {
pub functions: Arena<Function>,
pub lookup_type: FastHashMap<String, Handle<Type>>,
pub types: Arena<Type>,
pub constants: Arena<Constant>,
}
impl Program {
@@ -21,6 +22,7 @@ impl Program {
functions: Arena::<Function>::new(),
lookup_type: FastHashMap::default(),
types: Arena::<Type>::new(),
constants: Arena::<Constant>::new(),
}
}
}

View File

@@ -30,6 +30,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;
module.constants = program.constants;
// find entry point
if let Some(entry_handle) = program.lookup_function.get(&entry) {

View File

@@ -6,8 +6,8 @@ pomelo! {
//%verbose;
%include {
use super::super::{error::ErrorKind, token::*, ast::*};
use crate::{Arena, Expression, Function, Handle, LocalVariable, ScalarKind,
Type, TypeInner, VectorSize};
use crate::{Arena, Constant, ConstantInner, Expression, Function, Handle,
LocalVariable, ScalarKind, Type, TypeInner, VectorSize};
}
%token #[derive(Debug)] pub enum Token {};
%parser pub struct Parser<'a> {};
@@ -75,7 +75,21 @@ pomelo! {
variable_identifier ::= Identifier;
primary_expression ::= variable_identifier;
primary_expression ::= IntConstant;
primary_expression ::= IntConstant(i) {
let ty = extra.types.fetch_or_append(Type {
name: None,
inner: TypeInner::Scalar {
kind: ScalarKind::Sint,
width: 4,
}
});
let ch = extra.constants.fetch_or_append(Constant {
name: None,
specialization: None,
ty,
inner: ConstantInner::Sint(i.1)
});
}
primary_expression ::= UintConstant;
primary_expression ::= FloatConstant;
primary_expression ::= BoolConstant;