Vuo  2.0.0
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 ? dataType->getType() : NULL, 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::generateLoadData(Module *module, BasicBlock *block, Value *nodeContextValue, Value *portContextValue)
86 {
87  if (! portContextValue)
88  portContextValue = generateGetPortContext(module, block, nodeContextValue);
89  return VuoCompilerCodeGenUtilities::generateGetPortContextData(module, block, portContextValue, getDataType()->getType());
90 }
91 
95 void VuoCompilerEventPort::generateStoreData(Module *module, BasicBlock *block, Value *nodeContextValue, Value *dataValue)
96 {
97  Value *portContextValue = generateGetPortContext(module, block, nodeContextValue);
98  VuoCompilerCodeGenUtilities::generateSetPortContextData(module, block, portContextValue, dataValue);
99 }
100 
104 void VuoCompilerEventPort::generateReplaceData(Module *module, BasicBlock *block, Value *nodeContextValue, Value *dataValue, Value *portContextValue)
105 {
106  if (! portContextValue)
107  portContextValue = generateGetPortContext(module, block, nodeContextValue);
108 
109  Value *oldDataValue = VuoCompilerCodeGenUtilities::generateGetPortContextData(module, block, portContextValue, getDataType()->getType());
110  VuoCompilerCodeGenUtilities::generateSetPortContextData(module, block, portContextValue, dataValue);
111 
112  VuoCompilerType *type = getDataType();
113  type->generateRetainCall(module, block, dataValue);
114  type->generateReleaseCall(module, block, oldDataValue);
115 }
116 
121 {
123  if (data)
124  {
125  VuoCompilerDataClass *dataClass = static_cast<VuoCompilerDataClass *>(data->getBase()->getClass()->getCompiler());
126  return dataClass->getVuoType()->getCompiler();
127  }
128 
129  return NULL;
130 }