Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Commits on Sep 25, 2011
@dubik Small cleanup b7082ad
Commits on Sep 26, 2011
@dubik Added AssemblySyntaxError exception which is raised when assembly can…
…'t be parsed by read_assembly() method.

Updated assembly source code in test_value exception since it doesn't compile by llvm 2.9 any more.
2335bbd
View
2  ext/llvm_function.cpp
@@ -33,8 +33,6 @@ llvm_function_inspect(VALUE self) {
strstrm << *f;
return rb_str_new2(str.c_str());
}
-#include <iostream>
-using namespace std;
VALUE
llvm_function_get_basic_block_list(VALUE self) {
View
22 ext/llvm_module.cpp
@@ -48,10 +48,13 @@ VALUE
llvm_module_get_function(VALUE self, VALUE name) {
Check_Type(name, T_STRING);
Module *m = LLVM_MODULE(self);
+
Function *f = NULL;
+
if(m)
- f = m->getFunction(StringValuePtr(name));
- return llvm_function_wrap(f);
+ f = m->getFunction(StringValuePtr(name));
+
+ return llvm_function_wrap(f);
}
VALUE
@@ -163,16 +166,25 @@ VALUE
llvm_module_read_assembly(VALUE self, VALUE assembly) {
Check_Type(assembly, T_STRING);
- SMDiagnostic e;
const char * asmString = StringValuePtr(assembly);
+ SMDiagnostic e;
Module *module = ParseAssemblyString(
asmString,
0,
e,
- getGlobalContext()
+ getGlobalContext()
);
- //TODO How do we handle errors?
+
+ if(!module) {
+ VALUE exception = rb_exc_new2(cLLVMAssemblySyntaxError, e.getMessage().c_str());
+ rb_iv_set(exception, "@line", INT2NUM(e.getLineNo()));
+ rb_iv_set(exception, "@column", INT2NUM(e.getColumnNo()));
+ rb_iv_set(exception, "@line_contents", rb_str_new2(e.getLineContents().c_str()));
+ rb_iv_set(exception, "@filename", rb_str_new2(""));
+ rb_exc_raise(exception);
+ }
+
return Data_Wrap_Struct(cLLVMModule, NULL, NULL, module);
}
View
8 ext/llvmruby.c
@@ -27,6 +27,7 @@ VALUE cLLVMPhi = Qnil;
VALUE cLLVMBinaryOps = Qnil;
VALUE cLLVMPassManager = Qnil;
VALUE cLLVMExecutionEngine = Qnil;
+VALUE cLLVMAssemblySyntaxError = Qnil;
#define HANDLE_TERM_INST(Num, Opcode, Klass) VALUE cLLVM##Klass;
#define HANDLE_MEMORY_INST(Num, Opcode, Klass) VALUE cLLVM##Klass;
@@ -192,6 +193,8 @@ void Init_llvmruby() {
cLLVMPassManager = rb_define_class_under(cLLVMRuby, "PassManager", rb_cObject);
cLLVMExecutionEngine = rb_define_class_under(cLLVMRuby, "ExecutionEngine", rb_cObject);
+ cLLVMAssemblySyntaxError = rb_define_class_under(cLLVMRuby, "AssemblySyntaxError", rb_eSyntaxError);
+
init_types();
rb_define_module_function(cLLVMType, "pointer", llvm_type_pointer, 1);
rb_define_module_function(cLLVMType, "struct", llvm_type_struct, 1);
@@ -308,6 +311,11 @@ void Init_llvmruby() {
rb_define_module_function(cLLVMExecutionEngine, "run_function", llvm_execution_engine_run_function, -1);
rb_define_module_function(cLLVMExecutionEngine, "run_autoconvert", llvm_execution_engine_run_autoconvert, 1);
+ rb_define_attr(cLLVMAssemblySyntaxError, "line", 1, 0);
+ rb_define_attr(cLLVMAssemblySyntaxError, "column", 1, 0);
+ rb_define_attr(cLLVMAssemblySyntaxError, "line_contents", 1, 0);
+ rb_define_attr(cLLVMAssemblySyntaxError, "filename", 1, 0);
+
/*
printf("sizeof long: %d\n", (int)sizeof(long));
printf("sizeof ptr: %d\n", (int)sizeof(long*));
View
1  ext/llvmruby.h
@@ -39,6 +39,7 @@ extern VALUE cLLVMFunctionType;
extern VALUE cLLVMInstruction;
extern VALUE cLLVMBinaryOperator;
extern VALUE cLLVMAllocationInst;
+extern VALUE cLLVMAssemblySyntaxError;
#define HANDLE_TERM_INST(Num, Opcode, Klass) extern VALUE cLLVM##Klass;
#define HANDLE_MEMORY_INST(Num, Opcode, Klass) extern VALUE cLLVM##Klass;
View
30 test/test_value.rb
@@ -7,31 +7,31 @@ class ValueTests < Test::Unit::TestCase
def setup
@assembly=<<-EOF
- ; ModuleID = 'constants.o'
- target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
- target triple = "i386-apple-darwin9"
- @CONST_PI = constant float 0x400921FA00000000 ; <float*> [#uses=0]
-
- define float @circle_area(float %radius) nounwind {
- entry:
- %tmp2 = mul float %radius, 0x400921FA00000000 ; <float> [#uses=1]
- %tmp4 = mul float %tmp2, %radius ; <float> [#uses=1]
- ret float %tmp4
+ ; ModuleID = '/tmp/webcompile/_14635_0.bc'
+ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+ target triple = "x86_64-unknown-linux-gnu"
+
+ @CONST_PI = constant float 0x400921FA00000000, align 4
+
+ define float @circle_area(float %radius) nounwind readnone {
+ %1 = fmul float %radius, 0x400921FA00000000
+ %2 = fmul float %1, %radius
+ ret float %2
}
- define i32 @add_42(i32 %x) nounwind {
- entry:
- %tmp2 = add i32 %x, 42 ; <i32> [#uses=1]
- ret i32 %tmp2
+ define i32 @add_42(i32 %x) nounwind readnone {
+ %1 = add nsw i32 %x, 42
+ ret i32 %1
}
EOF
- @m = LLVM::Module.read_assembly(@assembly)
+ @m = LLVM::Module.read_assembly(@assembly)
end
def test_check_value_is_constant
add42 = @m.get_function("add_42")
assert(add42)
+ assert_equal(2, add42.get_basic_block_list.count)
ins = add42.get_basic_block_list[0].get_instruction_list
add_ins = ins[0]
assert_equal(false,add_ins.get_operand(0).is_constant())

No commit comments for this range

Something went wrong with that request. Please try again.