module volta.interfaces

Code Map

module volta.interfaces;


//! Each of these listed platforms corresponds to a Version identifier.
enum CRuntime
{
	None,
	MinGW,
	Glibc,
	Darwin,
	Microsoft,
}

//! Each of these listed platforms corresponds to a Version identifier.
enum Platform
{
	MinGW,
	MSVC,
	Linux,
	OSX,
	Metal,
}

//! Each of these listed architectures corresponds to a Version identifier.
enum Arch
{
	X86,
	X86_64,
	ARMHF,
	AArch64,
}

//! What kind of exception handling should the backend implement.
enum ExceptionHandlingType
{
	None,
	Posix,
	Windows,
}

//! Interface for communicating error conditions to the user.
interface ErrorSink
{
public:
	fn onWarning(msg: string, file: string, line: i32);
	fn onWarning(loc: const(ir.Location), msg: string, file: string, line: i32);
	fn onError(msg: string, file: string, line: i32);
	fn onError(loc: const(ir.Location), msg: string, file: string, line: i32);
	fn onPanic(msg: string, file: string, line: i32);
	fn onPanic(loc: const(ir.Location), msg: string, file: string, line: i32);
}

//! The part of the compiler that takes user supplied code and turns it
//! into IR.
interface Frontend
{
public:
	//! Free resources.
	fn close();
	//! Parse a module and all its children from the given source. Filename is
	//! the file from which file the source was loaded from.
	fn parseNewFile(source: string, filename: string) ir.Module;
	//! Parse a BlockStatement from a list of tokens.
	fn parseBlockStatement(tokens: ir.Token[], magicFlagD: bool) ir.BlockStatement;
	//! Parse a zero or more statements from a string, does not need to start
	//! with '{' or end with a '}'.
	fn parseStatements(source: string, loc: Location) ir.Node[];
}

//! Interface implemented by transformation, debug and/or validation
//! passes.
interface Pass
{
public:
	//! Free resources.
	fn close();
	//! Run the pass on the given module.
	fn transform(m: ir.Module);
}

//! Interface implemented by PostParse code, allows running certain
//! operations out of band from the normal transform entire module type.
interface PostParsePass
{
public:
	//! Resume the post-parsing process on the given Function.
	fn transformChildBlocks(func: ir.Function);
}

//! Holds information about the target that we are compiling to.
class TargetInfo
{
public:
	struct Alignments
	{
	public:
		int1: size_t;
		int8: size_t;
		int16: size_t;
		int32: size_t;
		int64: size_t;
		float32: size_t;
		float64: size_t;
		ptr: size_t;
		aggregate: size_t;
	}


public:
	arch: Arch;
	platform: Platform;
	cRuntime: CRuntime;
	ptrSize: size_t;
	alignment: Alignments;
	isP64: bool;
	ehType: ExceptionHandlingType;
	llvmIntrinsicVersion: i32;


public:
	this() { }
}

//! A set of version/debug identifiers.
class VersionSet
{
public:
	//! These are always set
	enum defaultVersions;
	enum reservedVersions;


public:
	debugEnabled: bool;


public:
	this() { }
	//! Throws: Exception if ident is reserved.
	fn setVersionIdentifierIfNotReserved(ident: string) bool { }
	//! Doesn't throw on ident reserve.
	fn overwriteVersionIdentifier(ident: string) { }
	//! Doesn't throw, debug identifiers can't be reserved.
	fn setDebugIdentifier(ident: string) { }
	//! Check if a given version identifier is set. Params: ident = the
	//! identifier to check. Returns: true if set, false otherwise.
	fn isVersionSet(ident: string) bool { }
	//! Check if a given debug identifier is set. Params: ident = the identifier
	//! to check. Returns: true if set, false otherwise.
	fn isDebugSet(ident: string) bool { }
	//! Set the correct version identifiers for the given arch, platform, and
	//! runtime.
	fn set(arch: Arch, platform: Platform, cRuntime: CRuntime, llvmIntrinsicVersion: i32) { }
	//! Quick helpers to get version flags.
	fn isP64() bool { }
}
interface ErrorSink

Interface for communicating error conditions to the user.

Methods may terminate.

class TargetInfo

Holds information about the target that we are compiling to.

enum CRuntime

Each of these listed platforms corresponds to a Version identifier.

Posix and Windows are not listed here as they they are available on multiple platforms.

Posix on Linux and OSX. Windows on MinGW and MSVC.

enum Platform

Each of these listed platforms corresponds to a Version identifier.

Posix and Windows are not listed here as they they are available on multiple platforms.

Posix on Linux and OSX. Windows on MinGW and MSVC.

enum Arch

Each of these listed architectures corresponds to a Version identifier.

enum ExceptionHandlingType

What kind of exception handling should the backend implement.

interface Frontend

The part of the compiler that takes user supplied code and turns it into IR.

fn close()

Free resources.

fn parseNewFile(source: string, filename: string) ir.Module

Parse a module and all its children from the given source. Filename is the file from which file the source was loaded from.

Parameters

source

The complete source of the module to be parsed.

filename

The path to the module, ir nodes locations gets gets tagged with this filename.

Return

The parsed module.

fn parseBlockStatement(tokens: ir.Token[], magicFlagD: bool) ir.BlockStatement

Parse a BlockStatement from a list of tokens.

Used to implement lazy parsing of functions.

Parameters

tokens

The list of tokens that comprise the body of the function. Starts with BEGIN {, and ends with } END tokens.

magicFlagD

Whether the tokens should use legacy parsing functionality, as if they had the magic D flag on top.

Return

The parsed BlockStatement.

fn parseStatements(source: string, loc: Location) ir.Node[]

Parse a zero or more statements from a string, does not need to start with '{' or end with a '}'.

Used for string mixins in functions.

Parameters

source

The source of the statements to be parsed.

loc

The location of the mixin that this originated from.

Return

The parsed statements.

class VersionSet

A set of version/debug identifiers.

enum defaultVersions

These are always set

fn setVersionIdentifierIfNotReserved(ident: string) bool

Throws: Exception if ident is reserved.

fn overwriteVersionIdentifier(ident: string)

Doesn't throw on ident reserve.

fn setDebugIdentifier(ident: string)

Doesn't throw, debug identifiers can't be reserved.

fn isVersionSet(ident: string) bool

Check if a given version identifier is set. Params: ident = the identifier to check. Returns: true if set, false otherwise.

fn isDebugSet(ident: string) bool

Check if a given debug identifier is set. Params: ident = the identifier to check. Returns: true if set, false otherwise.

fn set(arch: Arch, platform: Platform, cRuntime: CRuntime, llvmIntrinsicVersion: i32)

Set the correct version identifiers for the given arch, platform, and runtime.

fn isP64() bool

Quick helpers to get version flags.

fn reserveVersionIdentifier(ident: string)

Marks an identifier as unable to be set. Doesn't set the identifier.

interface Pass

Interface implemented by transformation, debug and/or validation passes.

Transformation passes often lowers high level Volt IR into something that is easier for backends to handle.

Validation passes validates the Volt IR, and reports errors, often halting compilation by throwing CompilerError.

fn close()

Free resources.

fn transform(m: ir.Module)

Run the pass on the given module.

interface PostParsePass

Interface implemented by PostParse code, allows running certain operations out of band from the normal transform entire module type.

fn transformChildBlocks(func: ir.Function)

Resume the post-parsing process on the given Function.

The parser will leave the blocks unparsed and leave it up to the SemanticPass to trigger a full parsing of the function body. This function does the post-parsing that would have been done if all of the ir.BlockStatement had been parsed up front.

The function must have been post-parsed before calling this method, so that it is inserted into a parent scope.