Esempio n. 1
0
static void
lto_read_body (struct lto_file_decl_data *file_data, tree fn_decl,
        const char *data, enum lto_section_type section_type)
{
  struct data_in *data_in;
  struct lto_input_block ib_main;
  input_function (fn_decl, data_in, &ib_main);
}
Esempio n. 2
0
int main(int argc, char *argv[]) {
  if (argc == 1)
    fp = stdin;
  else {
    fp = fopen(argv[1],"r");
    if (fp == NULL) {
      printf("No File: %s\n",argv[1]);
      return 1;
    }
  }
  root = NULL;
  input_function();
  printf("Exiting\n");
  return 0; 
}
Esempio n. 3
0
/*****************************************************************************************
 *  Advance the state of this FMU from the current communication point to that point plus
 *  the specified step size.
 *  @param c The FMU.
 *  @param currentCommunicationPoint The time at the start of the step interval.
 *  @param communicationStepSize The width of the step interval.
 *  @param noSetFMUStatePriorToCurrentPoint True to assert that the master will not subsequently
 *   restore the state of this FMU or call fmiDoStep with a communication point less than the
 *   current one. An FMU may use this to determine that it is safe to take actions that have side
 *   effects, such as printing outputs. This FMU ignores this argument.
 *  @return fmi2Discard if the FMU rejects the step size, otherwise fmi2OK.
 */
fmi2Status fmiDoStep(fmi2Component c, fmi2Real currentCommunicationPoint,
                fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) {
        ModelInstance* component = (ModelInstance *) c;

        // If current time is greater than period * (value + 1), then it is
        // time for another increment.
        double endOfStepTime = currentCommunicationPoint + communicationStepSize;
        double targetTime = TICK_PERIOD * (component->currentCount + 1);
        if (endOfStepTime >= targetTime - EPSILON) {
                // It is time for an increment.
                // Is it too late for the increment?
                if (endOfStepTime > targetTime + EPSILON) {
                        // Indicate that the last successful time is
                        // at the target time.
                        component->lastSuccessfulTime = targetTime;
                        fflush(stdout);
                        return fmi2Discard;
                }
                // We are at the target time. Are we
                // ready for the increment yet? Have to have already
                // completed one firing at this time.
                if (component->atBreakpoint) {
                        // Not the first firing. Go ahead an increment.
                        component->currentCount++;

                        input_function(component->controller,component->input,component->dInput);

                        transition_function(component->controller);

                        output_function(component->controller,component->output);
                        // Reset the indicator that the increment is needed.
                        component->atBreakpoint = fmi2False;
                } else {
                        // This will complete the first firing at the target time.
                        // We don't want to increment yet, but we set an indicator
                        // that we have had a firing at this time.
                        fflush(stdout);
                        component->atBreakpoint = fmi2True;
                }
        }
        component->lastSuccessfulTime = endOfStepTime;
        fflush(stdout);
        return fmi2OK;
}
Esempio n. 4
0
//process the current window, and advance to the next one.
//Returns a negative number on a failure, a zero when there are still more windows to go, and a 1 when done.
static inline int process_window(ctr_crypto_interface *io, write_window *window, size_t sector_size, size_t block_size, void (*input_function)(void *io, void *buffer, uint64_t block, size_t block_count), void (*output_function)(void *io, void *buffer, uint64_t block, size_t block_count))
{
	//FIXME what if we try to read more than there is disk? Return zeros?
	size_t sectors_to_read = (window->window_size - window->window_offset) / sector_size;
	int res = ctr_io_read_sector(io->lower_io, window->window + window->window_offset, window->window_size - window->window_offset, window->current_sector, sectors_to_read);
	if (res)
		return -1;

	size_t block_start_offset = window->block_offset;
	uint8_t *pos = window->window + block_start_offset;

	size_t amount_to_copy = window->window_size - window->window_offset;
	if (amount_to_copy > window->buffer_size - window->buffer_offset)
		amount_to_copy = window->buffer_size - window->buffer_offset;

	//In the case that blocks are aligned to sectors, this is not necessary... FIXME
	//only process parts that won't be overwritten completely
	//	from block_start_offset to window->window_offset
	size_t blocks_to_process = CEIL(window->window_offset - block_start_offset, block_size);
	if (!blocks_to_process) blocks_to_process = 1;
	output_function(io, pos, window->block, blocks_to_process);

	//now copy data from buffer
	memcpy(window->window + window->window_offset, window->buffer + window->buffer_offset, amount_to_copy);
	window->buffer_offset += amount_to_copy;

	blocks_to_process = CEIL(amount_to_copy + window->window_offset - block_start_offset, block_size);
	input_function(io, pos, window->block, blocks_to_process);

	//We need to write out the full blocks processed actually, not just the sectors
	size_t sectors_processed = (amount_to_copy + window->window_offset) / sector_size;
	size_t sectors_to_copy = CEIL(blocks_to_process * block_size, sector_size);
	res = ctr_io_write_sector(io->lower_io, window->window, sectors_to_copy * sector_size, window->sector);
	if (res)
		return -2;

	//Copy sector that contain part of next block
	update_window(window, sectors_processed);

	return window->buffer_offset >= window->buffer_size;
}