79
81
ENDobjDebugPrint(vmprg)
84
/* This function is similar to DebugPrint, but does not send its output to
85
* the debug log but instead to a caller-provided string. The idea here is that
86
* we can use this string to get a textual representation of a bytecode program.
87
* Among others, this is useful for creating testbenches, our first use case for
88
* it. Here, it enables simple comparison of the resulting program to a
89
* reference program by simple string compare.
90
* Note that the caller must initialize the string object. We always add
91
* data to it. So, it can be easily combined into a chain of methods
92
* to generate the final string.
93
* rgerhards, 2008-07-04
96
Obj2Str(vmprg_t *pThis, cstr_t *pstrPrg)
104
ISOBJ_TYPE_assert(pThis, vmprg);
105
assert(pstrPrg != NULL);
106
i = 0; /* "program counter" */
107
for(pOp = pThis->vmopRoot ; pOp != NULL ; pOp = pOp->pNext) {
108
lenAddr = snprintf((char*)szAddr, sizeof(szAddr), "%8.8d: ", i++);
109
CHKiRet(rsCStrAppendStrWithLen(pstrPrg, szAddr, lenAddr));
110
vmop.Obj2Str(pOp, pstrPrg);
82
118
/* add an operation (instruction) to the end of the current program. This
83
119
* function is expected to be called while creating the program, but never
84
120
* again after this is done and it is being executed. Results are undefined if
146
182
* work here (if we can support an older interface version - that,
147
183
* of course, also affects the "if" above).
149
//xxxpIf->oID = OBJvmprg;
151
185
pIf->Construct = vmprgConstruct;
152
186
pIf->ConstructFinalize = vmprgConstructFinalize;
153
187
pIf->Destruct = vmprgDestruct;
154
188
pIf->DebugPrint = vmprgDebugPrint;
189
pIf->Obj2Str = Obj2Str;
155
190
pIf->AddOperation = vmprgAddOperation;
156
191
pIf->AddVarOperation = vmprgAddVarOperation;