From 563ab549e3801e694737e85f19d39df951fbee77 Mon Sep 17 00:00:00 2001 From: mewmew Date: Tue, 14 Oct 2014 01:43:24 +0200 Subject: [PATCH] ir: Initial API stubs. --- ir/basicblock.go | 12 ++++++++++++ ir/doc.go | 10 ++++++++++ ir/function.go | 12 ++++++++++++ ir/global.go | 4 ++++ ir/instruction.go | 4 ++++ ir/ir.go | 4 ---- ir/metadata.go | 4 ++++ ir/module.go | 27 +++++++++++++++++++++++++++ ir/type.go | 4 ++++ 9 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 ir/basicblock.go create mode 100644 ir/doc.go create mode 100644 ir/function.go create mode 100644 ir/global.go create mode 100644 ir/instruction.go delete mode 100644 ir/ir.go create mode 100644 ir/metadata.go create mode 100644 ir/module.go create mode 100644 ir/type.go diff --git a/ir/basicblock.go b/ir/basicblock.go new file mode 100644 index 00000000..800ab0d9 --- /dev/null +++ b/ir/basicblock.go @@ -0,0 +1,12 @@ +package ir + +// A BasicBlock is a sequence of non-branching instructions, terminated by a +// control flow instruction (such as br or ret) [1]. +// +// [1]: http://llvm.org/docs/LangRef.html#terminators +type BasicBlock struct { + // Parent function of the basic block. + Parent *Function + // Instructions. + Insts []Instruction +} diff --git a/ir/doc.go b/ir/doc.go new file mode 100644 index 00000000..f4d817a3 --- /dev/null +++ b/ir/doc.go @@ -0,0 +1,10 @@ +// Package ir declares the types used to represent the LLVM IR language [1]. +// +// LLVM code is organized into modules containing top-level definitions, such as +// functions and global variables. A function definition contains a set of basic +// blocks, which forms the nodes in a Control Flow Graph of the function. Each +// basic block consists of a sequence of non-branching instructions, terminated +// by a control flow instruction (such as br or ret). +// +// [1]: http://llvm.org/docs/LangRef.html +package ir diff --git a/ir/function.go b/ir/function.go new file mode 100644 index 00000000..34f5d6b0 --- /dev/null +++ b/ir/function.go @@ -0,0 +1,12 @@ +package ir + +// A Function definition contains a set of basic blocks, interconnected by +// control flow instructions (such as br), which forms the nodes in a Control +// Flow Graph of the function [1,2]. +// +// [1]: http://llvm.org/docs/LangRef.html#functions +// [2]: http://llvm.org/docs/LangRef.html#terminators +type Function struct { + // Basic blocks of the function. + Blocks []*BasicBlock +} diff --git a/ir/global.go b/ir/global.go new file mode 100644 index 00000000..7dd6405f --- /dev/null +++ b/ir/global.go @@ -0,0 +1,4 @@ +package ir + +type Global struct { +} diff --git a/ir/instruction.go b/ir/instruction.go new file mode 100644 index 00000000..ed8dc534 --- /dev/null +++ b/ir/instruction.go @@ -0,0 +1,4 @@ +package ir + +type Instruction interface { +} diff --git a/ir/ir.go b/ir/ir.go deleted file mode 100644 index ebf99281..00000000 --- a/ir/ir.go +++ /dev/null @@ -1,4 +0,0 @@ -// Package ir declares the types used to represent the LLVM IR language. -// -// ref: http://llvm.org/docs/LangRef.html -package ir diff --git a/ir/metadata.go b/ir/metadata.go new file mode 100644 index 00000000..605679a3 --- /dev/null +++ b/ir/metadata.go @@ -0,0 +1,4 @@ +package ir + +type Metadata struct { +} diff --git a/ir/module.go b/ir/module.go new file mode 100644 index 00000000..8dd8d534 --- /dev/null +++ b/ir/module.go @@ -0,0 +1,27 @@ +package ir + +// A Module contains top-level function definitions, external function +// declarations, global variables, type definitions, and metadata [1]. +// +// [1]: http://llvm.org/docs/LangRef.html#module-structure +type Module struct { + + // TODO(u): Add external function declarations, or let *Function handle + // function definitions without bodies. If *Function handles both, update the + // doc comment to: + // Function definitions and external function declarations (Blocks is nil). + + // Function definitions. + Funcs []*Function + + // TODO(u): Replace with any of the following? + // Globals []Value + // Globals []*Variable + + // Global variables. + Globals []*Global + // Type definitions. + Types []*Type + // Metadata. + Metadata []*Metadata +} diff --git a/ir/type.go b/ir/type.go new file mode 100644 index 00000000..3d9a9544 --- /dev/null +++ b/ir/type.go @@ -0,0 +1,4 @@ +package ir + +type Type struct { +}