HIP Source Backend

HIP Backend for CrossGL Translator

HIP AST Node definitions

class crosstl.backend.HIP.HipAst.AtomicOperationNode(operation, args)[source]

Bases: FunctionCallNode

Node representing a HIP atomic operation

class crosstl.backend.HIP.HipAst.ConstantMemoryNode(vtype, name, value=None)[source]

Bases: VariableNode

Node representing constant memory variable declaration

class crosstl.backend.HIP.HipAst.HipBuiltinNode(builtin_name, component=None)[source]

Bases: ASTNode

Node representing HIP built-in variables (threadIdx, hipThreadIdx_x, etc.)

class crosstl.backend.HIP.HipAst.HipDevicePropertyNode(property_name, device_id=None)[source]

Bases: ASTNode

Node representing HIP device property access

class crosstl.backend.HIP.HipAst.HipErrorHandlingNode(error_type, error_expr)[source]

Bases: ASTNode

Node representing HIP error handling (hipError_t, hipGetErrorString, etc.)

class crosstl.backend.HIP.HipAst.KernelLaunchNode(kernel_name, blocks, threads, shared_mem=None, stream=None, args=None)[source]

Bases: ASTNode

Node representing a kernel launch: kernel<<<blocks, threads>>>(args)

class crosstl.backend.HIP.HipAst.KernelNode(return_type, name, params, body, attributes=None)[source]

Bases: FunctionNode

Node representing a HIP kernel function (marked with __global__)

class crosstl.backend.HIP.HipAst.SharedMemoryNode(vtype, name, size=None)[source]

Bases: VariableNode

Node representing shared memory variable declaration

class crosstl.backend.HIP.HipAst.TextureAccessNode(texture_name, coordinates)[source]

Bases: ASTNode

Node representing texture memory access

Lexer for importing HIP source into CrossGL Translator.

class crosstl.backend.HIP.HipLexer.HipLexer(code)[source]

Bases: object

Tokenize HIP source for the HIP backend parser.

tokenize()[source]

Return the full HIP token stream with source locations.

Return type:

List[Token]

class crosstl.backend.HIP.HipLexer.Token(token_type, value, line=1, column=1)[source]

Bases: object

Token object carrying HIP token type, text, and source location.

crosstl.backend.HIP.HipLexer.parse_hip_code(code)[source]

Parse HIP source text and return the backend AST.

HIP Parser for converting HIP tokens to AST

class crosstl.backend.HIP.HipParser.HipParser(tokens)[source]

Bases: object

Parse HIP tokens into the HIP backend AST.

advance()[source]

Advance to the next token or mark the parser as finished.

consume(expected_type)[source]

Consume and return the current token when its type matches.

error(message)[source]

Raise a syntax error annotated with the current token.

match(*token_types)[source]

Return whether the current token type is one of token_types.

Return type:

bool

parse()[source]

Parse the entire HIP program into a HipProgramNode.

parse_class()[source]

Parse class definitions (treat similar to struct for now)

parse_preprocessor()[source]

Parse preprocessor directives

parse_statement()[source]

Parse a single statement

peek(offset=1)[source]

Look ahead at the next token without advancing

skip_newlines()[source]

Advance past newline tokens between declarations/statements.

class crosstl.backend.HIP.HipParser.HipProgramNode(statements=None)[source]

Bases: ASTNode

Root node representing a complete HIP program

crosstl.backend.HIP.HipParser.parse_hip_code(code)[source]

Parse HIP source text and return the backend AST.

Return type:

HipProgramNode

HIP to CrossGL Code Generator

class crosstl.backend.HIP.HipCrossGLCodeGen.HipToCrossGLConverter[source]

Bases: object

Serialize HIP backend AST nodes back into CrossGL source.

convert(node)[source]

Legacy convert method for compatibility

convert_hip_builtin_function(func_name)[source]

Convert HIP built-in functions to CrossGL equivalents.

convert_hip_pointer_type(hip_type)[source]

Convert a HIP pointer type into nested CrossGL pointer syntax.

convert_hip_type_to_crossgl(hip_type)[source]

Map a HIP type name to the closest CrossGL type name.

emit(code)[source]

Append a line of CrossGL output using the current indentation level.

emit_statement(stmt)[source]

Render and append one converted statement.

generate(ast_node)[source]

Generate complete CrossGL source from a parsed HIP AST.

generic_visit(node)[source]

Fallback converter for primitive values, lists, and unknown nodes.

visit(node)[source]

Dispatch a HIP backend AST node to its converter method.

visit_FunctionNode(node)[source]

Render a HIP function node as a CrossGL function.

visit_HipProgramNode(node)[source]

Render a HIP program AST as a CrossGL shader block.

visit_kernel_as_compute_shader(kernel)[source]

Render a HIP kernel as a CrossGL compute shader block.

crosstl.backend.HIP.HipCrossGLCodeGen.hip_to_crossgl(hip_ast)[source]

Convert HIP AST to CrossGL code string

Return type:

str