Skip to content

Commit

Permalink
ir: Initial API stubs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mewmew committed Oct 13, 2014
1 parent ea91536 commit 563ab54
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 4 deletions.
12 changes: 12 additions & 0 deletions ir/basicblock.go
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions ir/doc.go
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions ir/function.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions ir/global.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ir

type Global struct {
}
4 changes: 4 additions & 0 deletions ir/instruction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ir

type Instruction interface {
}
4 changes: 0 additions & 4 deletions ir/ir.go

This file was deleted.

4 changes: 4 additions & 0 deletions ir/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ir

type Metadata struct {
}
27 changes: 27 additions & 0 deletions ir/module.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions ir/type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ir

type Type struct {
}

0 comments on commit 563ab54

Please sign in to comment.