Skip to content

Commit

Permalink
Replace all tabs by spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
julien.hamaide committed May 3, 2012
1 parent ca9197e commit e30fcdd
Show file tree
Hide file tree
Showing 11 changed files with 535 additions and 535 deletions.
38 changes: 19 additions & 19 deletions src/_manifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

return {

-- language
"language/types.lua",
"language/intrinsics.lua",
"language/input.lua",
"language/output.lua",
"language/technique.lua",
"language/texture.lua",
"language/constant.lua",
-- Intermediate representation
"ir/ast_to_ir.lua",
-- Printer
"printer/hlsl_printer.lua",
"utilities/output.lua"
-- language
"language/types.lua",
"language/intrinsics.lua",
"language/input.lua",
"language/output.lua",
"language/technique.lua",
"language/texture.lua",
"language/constant.lua",
-- Intermediate representation
"ir/ast_to_ir.lua",
-- Printer
"printer/hlsl_printer.lua",
"utilities/output.lua"

}
34 changes: 17 additions & 17 deletions src/_shader_shaker_main.lua
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
function _shader_shaker_main(script_path, output_file)

-- if running off the disk (in debug mode), load everything
-- listed in _manifest.lua; the list divisions make sure
-- everything gets initialized in the proper order.
if script_path then
local scripts = dofile(script_path .. "/_manifest.lua")
for _,v in ipairs(scripts) do
dofile(script_path .. "/" .. v)
end
end
if output_file ~= nil then
InitializeOutputFile( output_file )
else
InitializeOutputPrint()
end
-- if running off the disk (in debug mode), load everything
-- listed in _manifest.lua; the list divisions make sure
-- everything gets initialized in the proper order.
if script_path then
local scripts = dofile(script_path .. "/_manifest.lua")
for _,v in ipairs(scripts) do
dofile(script_path .. "/" .. v)
end
end
if output_file ~= nil then
InitializeOutputFile( output_file )
else
InitializeOutputPrint()
end

end
190 changes: 95 additions & 95 deletions src/ir/ast_to_ir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,141 +3,141 @@
Ir = Ir or {}

Ir.CreateVariable = function( representation, variable_type )
local variable_name = "temp" .. representation.variable_index
representation.variable_index = representation.variable_index + 1
representation.code[ #(representation.code) + 1 ] = { type = "Declaration", variable_type = variable_type, name = variable_name }
return variable_name
local variable_name = "temp" .. representation.variable_index
representation.variable_index = representation.variable_index + 1
representation.code[ #(representation.code) + 1 ] = { type = "Declaration", variable_type = variable_type, name = variable_name }
return variable_name

end

Ir.HandleOutput = function( node, representation )

for k,v in pairs( node.__variable ) do
local variable = Ir.HandleNode( v, representation )
local definition = node.__definition[ k ]
representation.code[ #(representation.code) + 1 ] = { type = "Assignment", variable = "output." .. k, value = variable }
representation.output[ k ] = { semantic = definition.semantic, type = definition.type }
end
for k,v in pairs( node.__variable ) do
local variable = Ir.HandleNode( v, representation )
local definition = node.__definition[ k ]
representation.code[ #(representation.code) + 1 ] = { type = "Assignment", variable = "output." .. k, value = variable }
representation.output[ k ] = { semantic = definition.semantic, type = definition.type }
end

end

Ir.HandleInput = function( node, representation )

representation.input[ node.value ] = { semantic = node.semantic, type = node.type }
return "input." .. node.value
representation.input[ node.value ] = { semantic = node.semantic, type = node.type }
return "input." .. node.value
end

Ir.HandleConstructor = function( node, representation )

local variable_table = {}
for i,v in ipairs( node.value ) do
if type( v ) == "number" then
variable_table[i] = v
else
variable_table[i] = Ir.HandleNode( v, representation )
end
end
local output_variable_name = Ir.CreateVariable( representation, node.type )
representation.code[ #(representation.code) + 1 ] = { type = "Constructor", constructor_type = node.type, arguments = variable_table, variable = output_variable_name }

return output_variable_name
local variable_table = {}
for i,v in ipairs( node.value ) do
if type( v ) == "number" then
variable_table[i] = v
else
variable_table[i] = Ir.HandleNode( v, representation )
end
end
local output_variable_name = Ir.CreateVariable( representation, node.type )
representation.code[ #(representation.code) + 1 ] = { type = "Constructor", constructor_type = node.type, arguments = variable_table, variable = output_variable_name }

return output_variable_name
end

Ir.HandleConstant = function( node, representation )
representation.constant[ node.name ] = { type = node.type }
return node.name
representation.constant[ node.name ] = { type = node.type }
return node.name
end

Ir.HandleSwizzle = function( node, representation )
local variable_name = Ir.CreateVariable( representation, node.type )
local source_variable_name = Ir.HandleNode( node.arguments[ 1 ], representation )
representation.variable[ node ] = variable_name
representation.code[ #(representation.code) + 1 ]
= { type = "Swizzle", variable_type = node.type, variable = variable_name, arguments = { source_variable_name, node.arguments[2] } }
return variable_name
local variable_name = Ir.CreateVariable( representation, node.type )
local source_variable_name = Ir.HandleNode( node.arguments[ 1 ], representation )
representation.variable[ node ] = variable_name
representation.code[ #(representation.code) + 1 ]
= { type = "Swizzle", variable_type = node.type, variable = variable_name, arguments = { source_variable_name, node.arguments[2] } }
return variable_name
end

Ir.HandleVariable = function( node, representation )
local value = rawget( node, "value" )
local variable_name
variable_name = Ir.CreateVariable( representation, node.type )
if type( value ) == "number" or value.type == nil then
representation.code[ #(representation.code) + 1 ] = { type = "Assignment", variable_type = node.type, variable = variable_name, value = value }
else
output_variable_name = Ir.HandleNode( value )
representation.code[ #(representation.code) + 1 ] = { type = "Assignment", variable_type = node.type, variable = variable_name, value = output_variable_name }
end
representation.variable[ node ] = variable_name
return variable_name
local value = rawget( node, "value" )
local variable_name
variable_name = Ir.CreateVariable( representation, node.type )
if type( value ) == "number" or value.type == nil then
representation.code[ #(representation.code) + 1 ] = { type = "Assignment", variable_type = node.type, variable = variable_name, value = value }
else
output_variable_name = Ir.HandleNode( value )
representation.code[ #(representation.code) + 1 ] = { type = "Assignment", variable_type = node.type, variable = variable_name, value = output_variable_name }
end
representation.variable[ node ] = variable_name
return variable_name
end

Ir.HandleTexture = function( node, representation )

representation.texture[ node.name ] = { type = node.type }
return { type = "Texture", name = node.name }
representation.texture[ node.name ] = { type = node.type }
return { type = "Texture", name = node.name }
end

Ir.HandleFunction = function( node, representation )
local variable_name_table = {}
for i,v in ipairs( node.arguments ) do
variable_name_table[i] = Ir.HandleNode( v, representation )
end
local output_variable_name = Ir.CreateVariable( representation, node.type )
representation.code[ #(representation.code) + 1 ] = { type = "CallFunction", name = node.name, arguments = variable_name_table, variable = output_variable_name }

return output_variable_name
local variable_name_table = {}
for i,v in ipairs( node.arguments ) do
variable_name_table[i] = Ir.HandleNode( v, representation )
end
local output_variable_name = Ir.CreateVariable( representation, node.type )
representation.code[ #(representation.code) + 1 ] = { type = "CallFunction", name = node.name, arguments = variable_name_table, variable = output_variable_name }

return output_variable_name
end

Ir.HandleOperation = function( node, representation )
local variable_name_table = {}
for i,v in ipairs( node.arguments ) do
variable_name_table[i] = Ir.HandleNode( v, representation )
end
local output_variable_name = Ir.CreateVariable( representation, node.type )
representation.code[ #(representation.code) + 1 ] = { type = "Operation", operation = node.operation, arguments = variable_name_table, variable = output_variable_name }

return output_variable_name
local variable_name_table = {}
for i,v in ipairs( node.arguments ) do
variable_name_table[i] = Ir.HandleNode( v, representation )
end
local output_variable_name = Ir.CreateVariable( representation, node.type )
representation.code[ #(representation.code) + 1 ] = { type = "Operation", operation = node.operation, arguments = variable_name_table, variable = output_variable_name }

return output_variable_name
end

Ir.HandleNode = function( ast_node, representation )

if type( ast_node ) == "number" then
local varname = Ir.CreateVariable( representation, "float" )
representation.code[ #(representation.code) + 1 ] = { type = "Assignment", variable_type = "float", variable = varname, value = ast_node }
return varname
end
if ast_node.node == nil then
print( ast_node )
print ( "ast_node : " .. table.tostring( ast_node ) )
error( "No node field found in ast_node", 2 )
end
local handle_function = Ir["Handle" .. ast_node.node];
if handle_function == nil then
error( "No handle function found for " .. ast_node.node, 2 )
end
return handle_function( ast_node, representation )
if type( ast_node ) == "number" then
local varname = Ir.CreateVariable( representation, "float" )
representation.code[ #(representation.code) + 1 ] = { type = "Assignment", variable_type = "float", variable = varname, value = ast_node }
return varname
end
if ast_node.node == nil then
print( ast_node )
print ( "ast_node : " .. table.tostring( ast_node ) )
error( "No node field found in ast_node", 2 )
end
local handle_function = Ir["Handle" .. ast_node.node];
if handle_function == nil then
error( "No handle function found for " .. ast_node.node, 2 )
end
return handle_function( ast_node, representation )
end

function AstToIR( ast )

local representation = { code={}, input={}, output={}, constant={}, texture={}, variable={}, variable_index = 0 }
local representation = { code={}, input={}, output={}, constant={}, texture={}, variable={}, variable_index = 0 }

Ir.HandleNode( ast, representation )
return representation
Ir.HandleNode( ast, representation )
return representation
end
32 changes: 16 additions & 16 deletions src/language/input.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@

function DefineInput()
input = { __semantic = {} }
input = { __semantic = {} }
end

function InputAttribute( name, type, semantic )

if input[ name ] ~= nil then
error( "An entry named '" .. name .."' already exists in the input structure", 2 )
end
if input.__semantic[ semantic ] ~= nil then
error( "An entry already have the semantic '" .. semantic .. "' in the input structure", 2 )
end
-- :TODO: Validate semantic and type value
local input_variable = { type = type, value = name, node = "Input", semantic = semantic }
input[ name ] = input_variable
input.__semantic[ semantic ] = input_variable
Language.AttachVectorMetatable( input_variable )
if input[ name ] ~= nil then
error( "An entry named '" .. name .."' already exists in the input structure", 2 )
end
if input.__semantic[ semantic ] ~= nil then
error( "An entry already have the semantic '" .. semantic .. "' in the input structure", 2 )
end
-- :TODO: Validate semantic and type value
local input_variable = { type = type, value = name, node = "Input", semantic = semantic }
input[ name ] = input_variable
input.__semantic[ semantic ] = input_variable
Language.AttachVectorMetatable( input_variable )
end

function EndInput()
-- :TODO: Validate structure
-- :TODO: Validate structure
end
Loading

0 comments on commit e30fcdd

Please sign in to comment.