Create an Add Instruction in LLVM IR - llvm-ir

I want to create an add instruction that takes two constant operands at the LLVM IR level. I use the IRBuilder class, but nothing happens. Here is part of the runOnFunction() method of my function pass:
LLVMContext &Context = F.getContext();
IRBuilder<> builder(&Instruction);
Value *Lef = ConstantInt::get(Type::getInt32Ty(Context), 4);
Value *Rig = ConstantInt::get(Type::getInt32Ty(Context), 5);
Value *Result = builder.CreateAdd(Lef, Rig);
It seems that the problem is with the ConstantInt::get() function. Any idea?

Related

GMS2 returns instance_create_layer :: specified layer "text_layer" does not exist even though the layer exists how do i fix this?

heres the code
var _obj;
if (instance_exists(obj_text)) _obj = obj_txt_queued; else _obj = obj_text;
with (instance_create_layer(0, 0, "text_layer", _obj))
{
msg = argument[0];
if (instance_exists(other)) originInstance = other.id else originInstance = noone;
if (argument_count > 1) background = argument[1]; else background = 1;
}
with (obj_phae)
{ if (state != scr_player_state_lock)
{
lastState = state;
state = scr_player_state_lock;
}
}
[layers](https://i.stack.imgur.com/9u9tD.png)
I tried removing any extra rooms that were not needed and I tried changing the layer name to something else.
I also tried using var instance_create_layer() but that obviously didn't work
I'm a bit confused at this part:
with (instance_create_layer(0, 0, "text_layer", _obj))
Especially the with(), as that function will go through every object in the room if it sees an object within the parameter, since you suggested to create a new object with it, I'm surprised it doesn't create an infinite loop. Maybe it works, I've never tried it myself, but I think there's a more logical way to assign variables from one object to a newly created object.
Assuming you want to use the With() statement to address the variables within the _obj, I think you can manage something similair through this function:
var object = instance_create_layer(0, 0, "text_layer", _obj)
object.msg = argument[0];
object.originInstance = id
if (argument_count > 1) object.background = argument[1]; else object.background = 1;
It's probably a given at this point, but double-check that this part of code can only run if it's in the same room that has a layer called "text_layer"
In the worst case, you may also try out instance_create_depth() and use the build-in depth variable from the object instead of the layer names. Using depth is more flexible, but less organised than layers.

Metalkit: MTLBuffer and pointers in swift 3

I started with Metalkit and I have a very simple kernel as a test case.
kernel void compute(device float* outData [[ buffer(0) ]])
{
outData[0] = 234.5;
outData[3] = 345.6;
}
This "computed" data is stored in a MTLBuffer.
var buffer : MTLBuffer?
...
buffer = device.makeBuffer(length: MemoryLayout<Float>.size * 5, options: [])
...
commandBuffer.waitUntilCompleted()
At this point the kernel has written some test data to the MTLBuffer.
Question is how I should access that data from my main program?
I get a unsafeMutableRawPointer from buffer.contents(). How do I get a swift array of values that I can use everywhere else (displaying on screen, writing to file,...)?
These snippets work in this very simple app, but I am not sure if they are correct:
let raw = buffer.contents()
let b = raw.bindMemory(to: Float.self, capacity: 5)
print(b.advanced(by: 3).pointee)
let a = raw.assumingMemoryBound(to: Float.self)
print(a.advanced(by: 3).pointee)
let bufferPointer = UnsafeBufferPointer(start: b, count: 5)
let values = Array(bufferPointer)
print(values)
let value = raw.load(fromByteOffset: MemoryLayout<Float>.size * 3, as: Float.self)
print(value)
Both bindMemory and assumingMemoryBound work. Though assumingMemoryBound assumes the underlying bytes are already typed and bindMemory doesn't. I think that one of either should work, but not both. Which one should it be and why?
I use the code presented below to load to arrays, but I can't decide if mine or your version is best.
let count = 16
var array = [Float]()
array.reserveCapacity(count)
for i in 0..<count {
array.append(buffer.contents().load(fromByteOffset: MemoryLayout<Float>.size * i, as: Float.self))
}

Moq SetupSet on property

i am trying to learn to use Moq (4) to test the C# code below. I was hoping that by setting
mockTimer.SetupSet(m => m.Interval = It.IsInRange(
interval - shorter, interval + longer, Range.Inclusive));
before calling the method which assigns the interval property a value (ageService.AddParticipant method), the test would throw when an incorrect value was assigned. However, even when a value well outside the specified range is assigned to the Interval property within the AddParticipant method, the test passes. I also find timer.Interval has a value of 0 after executing the AddParticipant method, even though I can see this property being assigned a non-zero value when stepping through the AddParticipant method.
[TestMethod]
public void TestAgeUpdatingStartOnAdd()
{
var mockTimer = new Mock<IDispatcherTimer>();
mockTimer.SetupProperty(m => m.Interval);
mockTimer.Setup(m => m.Start());
mockTimer.Setup(m => m.Stop());
IDispatcherTimer timer = mockTimer.Object;
var ageService = new AgeUpdatingService(timer);
TimeSpan interval = TimeSpan.FromMinutes(10);
TimeSpan tolerance = TimeSpan.FromMilliseconds(100)
mockTimer.SetupSet(m => m.Interval = It.IsInRange(
interval - tolerance, interval + tolerance, Range.Inclusive));
ageService.AddParticipant(new Participant{ DOB = DateTime.Now + interval });
What am I doing wrong? Am I missing the point of the SetupSet method all together (and therefore should just stick to examining the properties on the timer object after executing the function, which seemed to work prior to placing the SetupSet method in the code)? If so, could you please explain what SetupSet exists for. Thank you.
Since you're creating your mock with new Mock<IDispatcherTimer>(), it defaults to Loose mock behavior. This means that the mock object will not complain when it is used in a way that was not specified via a Setup method. Using the constructor overload that accepts a MockBehavior enumeration and specifying Strict will make the code behave like you'd expect. It looks like that's how you're expecting to use it judging by the Setup calls; they would be unnecessary if you were using loose mocks.
Alternatively you can keep the loose mock and change the SetupSet for the Interval to be a VerifySet after you expect it to be set. I.e.:
var ageService = new AgeUpdatingService(timer);
TimeSpan interval = TimeSpan.FromMinutes(10);
TimeSpan tolerance = TimeSpan.FromMilliseconds(100)
ageService.AddParticipant(new Participant{ DOB = DateTime.Now + interval });
mockTimer.VerifySet(m => m.Interval = It.IsInRange(
interval - tolerance, interval + tolerance, Range.Inclusive));
This is like a test assertion, meaning if a set of the Interval property never happened when this is invoked, it would throw a MoqException and fail the test.
SetupSet can be used to setup a property setter - it is fairly unusual to need this, as arguments passed to Set typically don't need to be captured, as the calls to the Setter can be verified with a VerifySet after the "Act" step.
Here's a way to achieve what you want:
var mockTimer = new Mock<ITimer>();
// Simulate the actions of the Sut with the Mock
mockTimer.Object.Interval = 6;
mockTimer.Object.Interval = 7;
mockTimer.Object.Interval = 999;
// Ensure the mock was called in-band
mockTimer.VerifySet(m => m.Interval = It.IsInRange(5, 10, Range.Inclusive),
Times.Exactly(2));
// Ensure the mock was not called out of band
mockTimer.VerifySet(m => m.Interval = It.Is<int>(i => i < 5 || i > 10),
Times.Never);
Another, less elegant approach would be to use SetupSet to detect invalid invocations directly:
mockTimer.SetupSet(m => m.Interval = It.Is<int>(i => i < 5 || i > 10))
.Throws(new ArgumentOutOfRangeException());

Autofetch behavior with firehose cursor, when SQL_SOPT_SS_CURSOR_OPTIONS option is set to SQL_CO_FIREHOSE_AF

On firehose cursor, when statement attribute SQL_SOPT_SS_CURSOR_OPTIONS is set to SQL_CO_FIREHOSE_AF, and the statement is executed, observed different behavior for autofetch which are mentioned below:
1) When SQLExecute is called first time it does not autofetch.
2) When SQLExecute is called second time on the same stament handle, after closing cursor using SQLFreestmt(hstmt, SQL_CLOSE), it autofetch 1 row with SQLExecute.
So what is the expected behavior, whether it should autofetch or not ? This seems to be bug in SQL Native client drivers.
Also I didn't see documentation for SQL_CO_FIREHOSE_AF but it is listed in sqlncli.h ?
code snippet with comments:
rc = SQLSetStmtAttr(hstmt1, (UWORD) SQL_SOPT_SS_CURSOR_OPTIONS, (SQLPOINTER) SQL_CO_FIREHOSE_AF, 0);
...
rc = SQLSetStmtAttr(hstmt1, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)1, 0);
// Execute first statement
rc = SQLExecute(hstmt1); // it does not autofetch the data.
...
rc = SQLFreeStmt(hstmt1, SQL_CLOSE);
...
rc = SQLSetStmtAttr(hstmt1, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)1, 0);
// Execute first statement
rc = SQLExecute(hstmt1); // it autofetch 1 record.
Thanks,
Mukesh

How can I pass controls as reference in Bada?

In the big picture I want to create a frame based application in Bada that has a single UI control - a label. So far so good, but I want it to display a number of my choosing and decrement it repeatedly every X seconds. The threading is fine (I think), but I can't pass the label pointer as a class variable.
//MyTask.h
//...
result Construct(Label* pLabel, int seconds);
//...
Label* pLabel;
//MyTask.cpp
//...
result
MyTask::Construct(Label* pLabel, int seconds) {
result r = E_SUCCESS;
r = Thread::Construct(THREAD_TYPE_EVENT_DRIVEN);
AppLog("I'm in da constructor");
this->pLabel = pLabel;
this->seconds = seconds;
return r;
}
//...
bool
Threading::OnAppInitializing(AppRegistry& appRegistry)
{
// ...
Label* pLabel = new Label();
pLabel = static_cast<Label*>(pForm->GetControl(L"IDC_LABEL1"));
MyTask* task = new MyTask();
task->Construct(&pLabel); // HERE IS THE ERROR no matching for Label**
task->Start();
// ...
}
The problem is that I have tried every possible combination of *, &, and just plain pLabel, known in Combinatorics...
It is not extremely important that I get this (it is just for training) but I am dying to understand how to solve the problem.
Have you tried:
task->Construct(pLabel, 0);
And by that I want to point out that you are missing the second parameter for MyTask::Construct.
No, I haven't. I don't know of a second parameter. But this problem is solved. If I declare a variable Object* __pVar, then the constructor should be Init(Object* pVar), and if I want to initialize an instance variable I should write
Object* pVar = new Object();
MyClass* mClass = new MyClass();
mClass->Construct(pVar);

Resources