Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Commit

Permalink
LLVM: Use tagua/llvm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Nov 1, 2016
1 parent ba75974 commit 6db179c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Expand Up @@ -51,6 +51,5 @@ debug-assertions = true
codegen-units = 1 codegen-units = 1


[dependencies] [dependencies]
libc = "~0.2.7" tagua-llvm = {git = "https://github.com/tagua-vm/llvm", rev = "master"}
llvm-sys = "~0.3.9"
tagua-parser = {git = "https://github.com/tagua-vm/parser", rev = "master"} tagua-parser = {git = "https://github.com/tagua-vm/parser", rev = "master"}
26 changes: 13 additions & 13 deletions source/language/compiler/vm.rs
Expand Up @@ -31,35 +31,35 @@


//! Transform an AST to VM intermediate representation. //! Transform an AST to VM intermediate representation.


use llvm::native_type::VMRepresentation;
use llvm;
use parser::ast; use parser::ast;
use super::super::super::vm::native_type::VMRepresentation;
use super::super::super::vm;


/// Compile an AST to VM intermediate representation. /// Compile an AST to VM intermediate representation.
pub fn compile(ast: ast::Addition) { pub fn compile(ast: ast::Addition) {
let context = vm::context::Context::new(); let context = llvm::context::Context::new();
let mut module = vm::module::Module::new("foobar", &context); let mut module = llvm::module::Module::new("foobar", &context);
let mut builder = vm::builder::Builder::new(&context); let mut builder = llvm::builder::Builder::new(&context);
let function = vm::function::Function::new( let function = llvm::function::Function::new(
&module, &module,
"f", "f",
&mut [], &mut [],
vm::native_type::int64_type(&context) llvm::native_type::int64_type(&context)
); );
let basic_block = function.new_basic_block("entry"); let basic_block = function.new_basic_block("entry");
builder.move_to_end(basic_block); builder.move_to_end(basic_block);
let addition = builder.add( let addition = builder.add(
ast.a.t.to_vm_representation(&context), 7u64.to_vm_representation(&context),
ast.b.t.to_vm_representation(&context), 42u64.to_vm_representation(&context),
"addition" "addition"
); );
builder.return_value(addition); builder.return_value(addition);


let engine_result = vm::engine::Engine::new( let engine_result = llvm::engine::Engine::new(
&mut module, &mut module,
&vm::engine::Options { &llvm::engine::Options {
level : vm::engine::OptimizationLevel::NoOptimizations, level : llvm::engine::OptimizationLevel::NoOptimizations,
code_model: vm::engine::CodeModel::Default code_model: llvm::engine::CodeModel::Default
} }
); );


Expand Down
4 changes: 1 addition & 3 deletions source/lib.rs
Expand Up @@ -40,10 +40,8 @@
//! This library is the fundation of the VM. It contains the language (with the lexer, parser and //! This library is the fundation of the VM. It contains the language (with the lexer, parser and
//! compiler) and the virtual machine. //! compiler) and the virtual machine.


extern crate libc; extern crate tagua_llvm as llvm;
extern crate llvm_sys as llvm;
extern crate tagua_parser as parser; extern crate tagua_parser as parser;


pub mod language; pub mod language;
pub mod shared; pub mod shared;
pub mod vm;

0 comments on commit 6db179c

Please sign in to comment.