Vuo  2.3.2
VuoCompilerEventPort.cc
Go to the documentation of this file.
1 
11 #include "VuoCompilerData.hh"
12 #include "VuoCompilerDataClass.hh"
13 #include "VuoCompilerEventPort.hh"
15 #include "VuoCompilerType.hh"
16 #include "VuoPort.hh"
17 #include "VuoType.hh"
18 
23  : VuoCompilerPort(basePort)
24 {
25  data = NULL;
26  VuoCompilerDataClass *dataClass = ((VuoCompilerEventPortClass *)getBase()->getClass()->getCompiler())->getDataClass();
27  if (dataClass)
28  data = dataClass->newData();
29 }
30 
36 Value * VuoCompilerEventPort::generateCreatePortContext(Module *module, BasicBlock *block)
37 {
39  VuoCompilerType *dataType = (data ? getDataVuoType()->getCompiler() : NULL);
40  return VuoCompilerCodeGenUtilities::generateCreatePortContext(module, block, dataType, false, "");
41 }
42 
48 Value * VuoCompilerEventPort::generateLoadEvent(Module *module, BasicBlock *block, Value *nodeContextValue, Value *portContextValue)
49 {
50  if (! portContextValue)
51  portContextValue = generateGetPortContext(module, block, nodeContextValue);
52  Value *eventValue = VuoCompilerCodeGenUtilities::generateGetPortContextEvent(module, block, portContextValue);
53  return new TruncInst(eventValue, IntegerType::get(block->getContext(), 1), "", block);
54 }
55 
59 void VuoCompilerEventPort::generateStoreEvent(Module *module, BasicBlock *block, Value *nodeContextValue, Value *eventValue, Value *portContextValue)
60 {
61  unsigned valueBitWidth = ((IntegerType *)eventValue->getType())->getBitWidth();
62  unsigned variableBitWidth = 64;
63  if (valueBitWidth < variableBitWidth)
64  eventValue = new ZExtInst(eventValue, IntegerType::get(block->getContext(), variableBitWidth), "", block);
65 
66  if (! portContextValue)
67  portContextValue = generateGetPortContext(module, block, nodeContextValue);
68  VuoCompilerCodeGenUtilities::generateSetPortContextEvent(module, block, portContextValue, eventValue);
69 }
70 
74 void VuoCompilerEventPort::generateStoreEvent(Module *module, BasicBlock *block, Value *nodeContextValue, bool event, Value *portContextValue)
75 {
76  if (! portContextValue)
77  portContextValue = generateGetPortContext(module, block, nodeContextValue);
78  Value *eventValue = ConstantInt::get(IntegerType::get(module->getContext(), 64), event ? 1 : 0);
79  VuoCompilerCodeGenUtilities::generateSetPortContextEvent(module, block, portContextValue, eventValue);
80 }
81 
85 Value * VuoCompilerEventPort::generateRetrieveData(Module *module, BasicBlock *block, Value *nodeContextValue, Value *portContextValue)
86 {
87  if (! portContextValue)
88  portContextValue = generateGetPortContext(module, block, nodeContextValue);
89  return VuoCompilerCodeGenUtilities::generateGetPortContextDataVariable(module, block, portContextValue, getDataType());
90 }
91 
95 void VuoCompilerEventPort::generateReplaceData(Module *module, BasicBlock *block, Value *nodeContextValue, Value *dataPointer, Value *portContextValue)
96 {
97  if (! portContextValue)
98  portContextValue = generateGetPortContext(module, block, nodeContextValue);
99 
100  Value *oldDataPointer = VuoCompilerCodeGenUtilities::generateGetPortContextDataVariable(module, block, portContextValue, getDataType());
101 
102  VuoCompilerType *type = getDataType();
103  type->generateRetainCall(module, block, dataPointer);
104  type->generateReleaseCall(module, block, oldDataPointer);
106 
107  Value *dataValue = new LoadInst(dataPointer, "", false, block);
108  VuoCompilerCodeGenUtilities::generateSetPortContextData(module, block, portContextValue, dataValue, type);
109 }
110 
115 {
117  if (data)
118  {
119  VuoCompilerDataClass *dataClass = static_cast<VuoCompilerDataClass *>(data->getBase()->getClass()->getCompiler());
120  return dataClass->getVuoType()->getCompiler();
121  }
122 
123  return NULL;
124 }