Пример #1
0
void NewFormat::Program_Control (void)
{
	bool type_flag, flat_flag, time_flag;
	String key;

	//---- open the support files ----

	Data_Service::Program_Control ();

	if (Check_Control_Key (VERSION4_PLAN_FILE) && Check_Control_Key (TRIP_SORT_TYPE)) {
		Warning ("Plan Sorting is Limited to Version 5 Plan files");
		Show_Message (1);
	}	
	Print (2, String ("%s Control Keys:") % Program ());

	//---- copy existing fields ----

	copy_flag = Get_Control_Flag (COPY_EXISTING_FIELDS);

	if (copy_flag) {
		if (System_File_Flag (LOCATION) && System_File_Flag (NEW_LOCATION)) {
			Location_File *file = (Location_File *) System_File_Handle (LOCATION);
			new_loc_file = (Location_File *) System_File_Handle (NEW_LOCATION);
			new_loc_file->Add_User_Fields (file);
		}
		if (System_File_Flag (ZONE) && System_File_Flag (NEW_ZONE)) {
			Zone_File *file = (Zone_File *) System_File_Handle (ZONE);
			new_zone_file = (Zone_File *) System_File_Handle (NEW_ZONE);
			new_zone_file->Add_User_Fields (file);
		}
	}

	//---- copy existing configuration ----

	if (System_File_Flag (LINK_DELAY) && System_File_Flag (NEW_LINK_DELAY)) {
		Link_Delay_File *file = (Link_Delay_File *) System_File_Header (LINK_DELAY);
		if (file->Turn_Flag ()) {
			file = (Link_Delay_File *) System_File_Header (NEW_LINK_DELAY);
			file->Clear_Fields ();
			file->Turn_Flag (true);
			file->Set_Nesting (true);
			file->Create_Fields ();
			file->Write_Header ();
		}
	}
	if (System_File_Flag (PERFORMANCE) && System_File_Flag (NEW_PERFORMANCE)) {
		Performance_File *file = (Performance_File *) System_File_Header (PERFORMANCE);
		if (file->Turn_Flag ()) {
			file = (Performance_File *) System_File_Header (NEW_PERFORMANCE);
			file->Clear_Fields ();
			file->Turn_Flag (true);
			file->Set_Nesting (true);
			file->Create_Fields ();
			file->Write_Header ();
		}
	}
	
	//---- flatten output flag ----

	flat_flag = Get_Control_Flag (FLATTEN_OUTPUT_FLAG);

	if (flat_flag) {
		if (System_File_Flag (NEW_SHAPE)) {
			System_File_Header (NEW_SHAPE)->Flatten_File ();
		}
		if (System_File_Flag (NEW_PARKING)) {
			System_File_Header (NEW_PARKING)->Flatten_File ();
		}
		if (System_File_Flag (NEW_SIGNAL)) {
			System_File_Header (NEW_SIGNAL)->Flatten_File ();
		}
		if (System_File_Flag (NEW_TIMING_PLAN)) {
			System_File_Header (NEW_TIMING_PLAN)->Flatten_File ();
		}
		if (System_File_Flag (NEW_PHASING_PLAN)) {
			System_File_Header (NEW_PHASING_PLAN)->Flatten_File ();
		}
		if (System_File_Flag (NEW_TRANSIT_ROUTE)) {
			System_File_Header (NEW_TRANSIT_ROUTE)->Flatten_File ();
		}
		if (System_File_Flag (NEW_TRANSIT_SCHEDULE)) {
			System_File_Header (NEW_TRANSIT_SCHEDULE)->Flatten_File ();
		}
		if (System_File_Flag (NEW_TRANSIT_DRIVER)) {
			System_File_Header (NEW_TRANSIT_DRIVER)->Flatten_File ();
		}
		if (System_File_Flag (NEW_ROUTE_NODES)) {
			System_File_Header (NEW_ROUTE_NODES)->Flatten_File ();
		}
		if (System_File_Flag (NEW_HOUSEHOLD)) {
			System_File_Header (NEW_HOUSEHOLD)->Flatten_File ();
		}
		if (System_File_Flag (NEW_LINK_DELAY)) {
			System_File_Header (NEW_LINK_DELAY)->Flatten_File ();
		}
		if (System_File_Flag (NEW_PERFORMANCE)) {
			System_File_Header (NEW_PERFORMANCE)->Flatten_File ();
		}
		if (System_File_Flag (NEW_PLAN)) {
			System_File_Header (NEW_PLAN)->Flatten_File ();
		}
	}

	//---- toll file ----

	key = Get_Control_String (TOLL_FILE);

	if (!key.empty ()) {
		toll_file.Open (Project_Filename (key));
		toll_flag = true;
	}

	//---- activity file ----

	key = Get_Control_String (ACTIVITY_FILE);

	if (!key.empty ()) {
		activity_file.Open (Project_Filename (key));
		activity_flag = true;

		if (!System_File_Flag (NEW_TRIP)) {
			Error ("A New Trip file is required to convert an Activity File");
		}
		if (!System_File_Flag (VEHICLE)) {
			Error ("A Vehicle file is required to convert an Activity File");
		}
	}

	//---- person file ----

	key = Get_Control_String (PERSON_FILE);

	if (!key.empty ()) {
		person_file.Open (Project_Filename (key));
		person_flag = true;
	}

	//---- snapshot file ----

	key = Get_Control_String (SNAPSHOT_FILE);

	if (!key.empty ()) {
		Print (1);
		snap_file.Open (Project_Filename (key));
		snap_flag = true;
	}

	//---- new snapshot file ----

	key = Get_Control_String (NEW_SNAPSHOT_FILE);

	if (!key.empty ()) {
		new_snap_file.Compress_Flag (Set_Control_Flag (NEW_SNAPSHOT_COMPRESSION));

		if (new_snap_file.Compress_Flag ()) {
			new_snap_file.Dbase_Format (BINARY);
		} else {
			if (Check_Control_Key (NEW_SNAPSHOT_FORMAT)) {
				new_snap_file.Dbase_Format (Get_Control_String (NEW_SNAPSHOT_FORMAT));
			}
			new_snap_file.Location_Flag (snap_file.Location_Flag ());
			new_snap_file.Cell_Flag (snap_file.Cell_Flag ());
			new_snap_file.Status_Flag (snap_file.Status_Flag ());
		}
		new_snap_file.Create (Project_Filename (key));

		Get_Control_Flag (NEW_SNAPSHOT_COMPRESSION);
	} else if (snap_flag) {
		Error ("A New Snapshot File is required for Output");
	}

	//---- version 4 time format ----

	time_units = Units_Code (Get_Control_Text (VERSION4_TIME_FORMAT));
	time_flag = Check_Control_Key (VERSION4_TIME_FORMAT);

	if (time_flag) {
		int num;
		Field_Ptr fld_ptr;

		if (System_File_Flag (TRIP)) {
			Trip_File *file = (Trip_File *) System_File_Base (TRIP);
			if (file->Version () <= 40) {
				num = file->Optional_Field (START_FIELD_NAMES);
				if (num >= 0) {
					fld_ptr = file->Field (num);
					fld_ptr->Units (time_units);
				}
				num = file->Optional_Field (END_FIELD_NAMES);
				if (num >= 0) {
					fld_ptr = file->Field (num);
					fld_ptr->Units (time_units);
				}
				num = file->Optional_Field (DURATION_FIELD_NAMES);
				if (num >= 0) {
					fld_ptr = file->Field (num);
					fld_ptr->Units (time_units);
				}
			}
		}
		if (activity_flag) {
			num = activity_file.Optional_Field ("START_MIN", "START", "START_TIME", "STARTTIME");
			if (num >= 0) {
				fld_ptr = activity_file.Field (num);
				fld_ptr->Units (time_units);
			}
			num = activity_file.Optional_Field ("START_MAX", "START", "START_TIME", "STARTTIME");
			if (num >= 0) {
				fld_ptr = activity_file.Field (num);
				fld_ptr->Units (time_units);
			}
			num = activity_file.Optional_Field ("END_MIN", "END", "END_TIME", "ENDTIME");
			if (num >= 0) {
				fld_ptr = activity_file.Field (num);
				fld_ptr->Units (time_units);
			}
			num = activity_file.Optional_Field ("END_MAX", "END", "END_TIME", "ENDTIME");
			if (num >= 0) {
				fld_ptr = activity_file.Field (num);
				fld_ptr->Units (time_units);
			}
			num = activity_file.Optional_Field ("TIME_MIN", "DURATION");
			if (num >= 0) {
				fld_ptr = activity_file.Field (num);
				fld_ptr->Units (time_units);
			}
			num = activity_file.Optional_Field ("TIME_MAX", "DURATION");
			if (num >= 0) {
				fld_ptr = activity_file.Field (num);
				fld_ptr->Units (time_units);
			}
		}
	}

	//---- plan file ----

	if (Check_Control_Key (VERSION4_PLAN_FILE)) {
		if (System_File_Flag (PLAN)) {
			Error ("A plan file and Version 4 plan file must be processed separateley");
		}
		if (!System_File_Flag (NEW_PLAN)) {
			Error ("A new plan file is required to convert a Version 4 plan file");
		}
		Print (1);
		plan_flag = true;
		old_plan.File_Type ("Version4 Plan File");

		//---- get the list type ----

		key = Get_Control_String (NODE_LIST_PATHS);

		if (!key.empty ()) {
			type_flag = key.Bool ();
		} else {
			type_flag = true;
		}
		old_plan.Node_Based_Flag (type_flag);

		//---- get the traveler scale ----

		key = Get_Control_String (TRAVELER_SCALING_FACTOR);

		if (!key.empty ()) {
			scale = key.Integer ();

			if (scale < 2 || scale > 100) {
				Control_Key_Error (TRAVELER_SCALING_FACTOR, "(2..100)");
			}
			old_plan.Traveler_Scale (scale);
		}

		//---- get the file format ----

		if (Check_Control_Key (VERSION4_PLAN_FORMAT)) {
			old_plan.File_Format (Get_Control_String (VERSION4_PLAN_FORMAT));
		}

		//---- open the file and print the parameters ----

		if (!old_plan.Open (Project_Filename (Get_Control_String (VERSION4_PLAN_FILE)))) {
			File_Error ("Opening Version4 Plan File", old_plan.Filename ());
		}
		Get_Control_Text (VERSION4_PLAN_FORMAT);

		type_flag = old_plan.Node_Based_Flag ();

		if (type_flag) {
			Print (1, "Plan File contains Node List Paths");
			if (!System_File_Flag (NODE) || !System_File_Flag (LINK) || !System_File_Flag (PARKING)) {
				Error ("A Node, Link and Parking Files are Required for Node-Based Plan Files");
			}
			AB_Map_Flag (true);
		} else {
			Print (1, "Plan File contains Link List Paths");
		}
		Get_Control_Integer (TRAVELER_SCALING_FACTOR);

	} else if (snap_flag && snap_file.Version () <= 40) {

		//---- get the traveler scale ----

		scale= Get_Control_Integer (TRAVELER_SCALING_FACTOR);

		if (scale < 2 || scale > 100) {
			Control_Key_Error (TRAVELER_SCALING_FACTOR, "(2..100)");
		}
	}

	//---- Version 4 Route Header and Node files ----

	if (Check_Control_Key (VERSION4_ROUTE_HEADER)) {
		if (!System_File_Flag (NEW_ROUTE_NODES)) {
			Error ("A New Route Nodes File is Required");
		}
		int i, num;
		String field;
		Field_Ptr fld_ptr;

		if (!time_flag) time_units = MINUTES;

		Print (1);
		route_flag = true;

		Route_Nodes_File *file = (Route_Nodes_File *) System_File_Base (NEW_ROUTE_NODES);

		key = Get_Control_String (VERSION4_ROUTE_HEADER);

		route_header.File_Type ("Version4 Route Header");
		route_header.File_ID ("Header");

		route_header.Open (Project_Filename (key));

		for (i=1; i <= 24; i++) {
			field ("HEADWAY_%d") % i;
			num = route_header.Optional_Field (field.c_str ());
			if (num < 0) break;

			fld_ptr = route_header.Field (num);
			fld_ptr->Units (time_units);

			field ("OFFSET_%d") % i;
			num = route_header.Optional_Field (field.c_str ());
			if (num >= 0) {
				fld_ptr = route_header.Field (num);
				fld_ptr->Units (time_units);
			}
			field ("TTIME_%d") % i;
			num = route_header.Optional_Field (field.c_str ());
			if (num >= 0) {
				fld_ptr = route_header.Field (num);
				fld_ptr->Units (time_units);
			}
		}
		route_periods = i - 1;
		if (route_periods != file->Num_Periods ()) {
			file->Num_Periods (route_periods);
			file->Clear_Fields ();
			file->Create_Fields ();
			file->Write_Header ();
		}
		key = Get_Control_String (VERSION4_ROUTE_NODES);

		if (key.empty ()) {
			Error ("A Version4 Route Nodes file is Required");
		}
		route_nodes.File_Type ("Version4 Route Nodes");
		route_nodes.File_ID ("Nodes");

		route_nodes.Open (Project_Filename (key));
	}
}
Пример #2
0
void PerfPrep::Program_Control (void)
{
	String key;
	Strings list;
	Str_Itr str_itr;

	//---- open network files ----

	Data_Service::Program_Control ();
	
	Read_Select_Keys ();
	Read_Flow_Time_Keys ();

	Print (2, String ("%s Control Keys:") % Program ());

	new_file_flag = System_File_Flag (NEW_PERFORMANCE);

	//---- open the merge performance ----
	
	key = Get_Control_String (MERGE_PERFORMANCE_FILE);

	if (!key.empty ()) {
		merge_file.File_Type ("Merge Performance File");
		Print (1);

		if (Check_Control_Key (MERGE_PERFORMANCE_FORMAT)) {
			merge_file.Dbase_Format (Get_Control_String (MERGE_PERFORMANCE_FORMAT));
		}
		merge_file.Open (Project_Filename (key));
		merge_flag = true;

		if (!new_file_flag) {
			Error ("A New Performance File is required for Merge Processing");
		}
	}

	//---- open the base performance ----
	
	key = Get_Control_String (BASE_PERFORMANCE_FILE);

	if (!key.empty ()) {
		base_file.File_Type ("Base Performance File");
		Print (1);

		if (Check_Control_Key (BASE_PERFORMANCE_FORMAT)) {
			base_file.Dbase_Format (Get_Control_String (BASE_PERFORMANCE_FORMAT));
		}
		base_file.Open (Project_Filename (key));
		base_flag = true;

		if (!new_file_flag) {
			Error ("A New Performance File is required for Base Processing");
		}
	}

	//---- open the merge turn delay ----

	turn_flag = System_File_Flag (TURN_DELAY);

	if (turn_flag) {
		key = Get_Control_String (MERGE_TURN_DELAY_FILE);

		if (!key.empty ()) {
			turn_file.File_Type ("Merge Turn Delay File");
			Print (1);

			if (Check_Control_Key (MERGE_TURN_DELAY_FORMAT)) {
				turn_file.Dbase_Format (Get_Control_String (MERGE_TURN_DELAY_FORMAT));
			}
			turn_file.Open (Project_Filename (key));
			turn_merge_flag = true;

			if (!System_File_Flag (NEW_TURN_DELAY)) {
				Error ("A New Turn Delay File is required for Merge Processing");
			}
		}
	}

	//---- processing method ----

	Print (1);
	key = Get_Control_Text (PROCESSING_METHOD);

	if (!key.empty ()) {
		method = Combine_Code (key);

		if (method != UPDATE_TIMES) {
			if (merge_flag || turn_merge_flag) {
				if (method == WEIGHTED_LINK_AVG || method == REPLACE_AVERAGE) {

					//---- merge weighting factor ----

					factor = Get_Control_Double (MERGE_WEIGHTING_FACTOR);
				}
			} else {
				//Error (String ("Processing Method %s requires Merge Files") % key);
			}
		}
	}

	//---- read the smoothing parameters ----

	smooth_flag = smooth_data.Read_Control ();

	if (smooth_flag) {
		if (!smooth_data.Num_Input (time_periods.Num_Periods ())) {
			Error ("Smooth Parameters are Illogical");
		}
		if (!new_file_flag) {
			Error ("A New Performance File is required for Data Smoothing");
		}
	}

	//---- set min travel time ----

	min_time_flag = Get_Control_Flag (SET_MIN_TRAVEL_TIME);

	if (min_time_flag && !new_file_flag) {
		Error ("A New Performance File is required for Minimum Travel Times");
	}

	//---- set merge transit data ----

	key = Get_Control_Text (MERGE_TRANSIT_DATA);

	if (!key.empty ()) {
		transit_flag = true;

		if (!System_File_Flag (TRANSIT_STOP) || !System_File_Flag (TRANSIT_ROUTE) ||
			!System_File_Flag (TRANSIT_SCHEDULE) || !System_File_Flag (TRANSIT_DRIVER)) {

			Error ("Transit Network Files are Required for Transit Loading");
		}
		if (!new_file_flag) {
			Error ("A New Performance File is required to Merge Transit Data");
		}
		key.Parse (list);
		for (str_itr = list.begin (); str_itr != list.end (); str_itr++) {
			if (str_itr->Starts_With ("VEH")) {
				transit_veh_flag = true;
			} else if (str_itr->Starts_With ("PER")) {
				transit_person_flag = true;
			} else if (str_itr->Starts_With ("PCE") || str_itr->Starts_With ("CAR_EQ")) {
				transit_pce_flag = true;
			}
		}
		if (!System_File_Flag (VEHICLE_TYPE) && transit_pce_flag) {
			Warning ("Vehicle Type File is Required for Transit PCE Loading");
		}
		if (!System_File_Flag (RIDERSHIP) && transit_person_flag) {
			Warning ("Ridership File is Required for Transit Person Loading");
		}
		if (!merge_flag) {
			method = Combine_Code (Get_Control_Text (PROCESSING_METHOD));
		}
	}

	//---- open the time constraint file ----
	
	key = Get_Control_String (TIME_CONSTRAINT_FILE);

	if (!key.empty ()) {
		constraint_file.File_Type ("Time Constraint File");
		Print (1);

		if (Check_Control_Key (TIME_CONSTRAINT_FORMAT)) {
			constraint_file.Dbase_Format (Get_Control_String (TIME_CONSTRAINT_FORMAT));
		}
		constraint_file.Open (Project_Filename (key));
		constraint_flag = true;
	}

	//---- open the time ratio file ----
	
	key = Get_Control_String (NEW_TIME_RATIO_FILE);

	if (!key.empty ()) {
		time_ratio_file.File_Type ("New Time Ratio File");

		time_ratio_file.Create (Project_Filename (key));
		time_ratio_flag = true;
	}

	//---- open the deleted record file ----
	
	key = Get_Control_String (NEW_DELETED_RECORD_FILE);

	if (!key.empty ()) {
		deleted_file.File_Type ("New Deleted Record File");
		Print (1);

		if (Check_Control_Key (NEW_DELETED_RECORD_FORMAT)) {
			deleted_file.Dbase_Format (Get_Control_String (NEW_DELETED_RECORD_FORMAT));
		}
		deleted_file.Create (Project_Filename (key));
		del_file_flag = true;
	}

	List_Reports ();

	first_delete = deleted_flag = (Report_Flag (DELETED_RECORDS) || del_file_flag);
}
Пример #3
0
void print_warn_num(bool bFatalError)
{
  print_warn_count("note",nwarn_note);

  print_warn_count("warning",nwarn_warn);

  if (bFatalError && nwarn_warn > maxwarn) {
    gmx_fatal(FARGS,"Too many warnings (%d), %s terminated.\n"
	      "If you are sure all warnings are harmless, use the -maxwarn option.",nwarn_warn,Program());
  }
}
Пример #4
0
ConvertTours::ConvertTours (void) : Demand_Service ()
{
	Program ("ConvertTours");
	Version ("4.0.15");
	Title ("Tour Data Conversion Utility");

	Network_File required_network [] = {
		ACTIVITY_LOCATION, PROCESS_LINK, END_NETWORK
	};

	Network_File optional_network [] = {
		DIRECTORY, LINK, ZONE, END_NETWORK
	};

	Demand_File required_demand [] = {
		NEW_TRIP, NEW_HOUSEHOLD, NEW_POPULATION, NEW_VEHICLE, END_DEMAND
	};

	Demand_File optional_demand [] = {
		TRIP, HOUSEHOLD, POPULATION, VEHICLE, VEHICLE_TYPE, END_DEMAND
	};

	char *keys [] = {
		TOUR_DATA_FILE,
		TOUR_DATA_FORMAT,
		TOUR_HOUSEHOLD_FIELD,
		TOUR_PERSON_FIELD,
		TOUR_NUMBER_FIELD,
		TOUR_PURPOSE_FIELD,
		TOUR_MODE_FIELD,
		TOUR_ORIGIN_FIELD,
		TOUR_DESTINATION_FIELD,
		TOUR_STOP_OUT_FIELD,
		TOUR_STOP_IN_FIELD,
		TOUR_START_FIELD,
		TOUR_RETURN_FIELD,
		TOUR_GROUP_FIELD,
		TOUR_GROUP_SCRIPT,
		HOUSEHOLD_LIST,
		STARTING_HOUSEHOLD_ID,
		STARTING_VEHICLE_ID,
		TIME_OF_DAY_FORMAT,
		ADDITIONAL_TRAVEL_TIME,
		ZONE_LOCATION_MAP_FILE,
		RANDOM_NUMBER_SEED,
		ZONE_EQUIVALENCE_FILE,
		TRAVEL_TIME_FILE,
		NEW_DIURNAL_FILE,
		TRIP_TIME_FILE_x,
		TRIP_TIME_FORMAT_x,
		TRIP_TIME_FIELD_x,
		TIME_PERIOD_RANGE_x,
		TIME_CONTROL_POINT_x,
		ORIGIN_WEIGHT_FIELD_x,
		DESTINATION_WEIGHT_FIELD_x,
		DISTANCE_WEIGHT_FLAG_x,
		STOP_WEIGHT_FIELD_x,
		TRIP_PURPOSE_CODE_x,
		TRAVEL_MODE_CODE_x,
		TRIP_STOP_DURATION_x,
		AVERAGE_TRAVEL_SPEED_x,
		VEHICLE_TYPE_x,
		VEHICLE_SUBTYPE_x,
		TRIP_SCALING_FACTOR_x,
		TRIP_ADJUSTMENT_FACTORS_x,
		TRIP_ADJUSTMENT_FORMAT_x,
		TIME_PERIOD_EQUIVALENCE_x,
		NULL
	};
	char *reports [] = {
		"TOUR_GROUP_SCRIPT",
		"TOUR_GROUP_STACK",
		"PRINT_ZONE_EQUIVALENCIES",
		"TIME_PERIOD_EQUIVALENCE",
		NULL
	};

	Required_Network_Files (required_network);
	Optional_Network_Files (optional_network);
	Required_Demand_Files (required_demand);
	Optional_Demand_Files (optional_demand);

	Key_List (keys);
	Report_List (reports);

	equiv_flag = skim_flag = zone_flag = script_flag = diurnal_flag = zone_loc_flag = hhlist_flag = false;

	num_zone = 0;
	additional_time = 600;
	num_trip = tot_trips = tot_errors = nhhold = nperson = 0;
	tot_add = tot_del = 0.0;
	skim_ptr = NULL;

	trip_copy = hhold_copy = pop_copy = veh_copy = 0;
	max_hh_in = max_veh_in = max_hhlist = 0;

	location_array = (Location_Array *) new Convert_Location_Array ();
}
Пример #5
0
int main(int argc, const char * argv[]) {
    // Usage Message (TODO: Improve)
    if (argc < 3) {
        std::cerr << "Usage: " << argv[0] << " <FileName>\n"
                  << "Compiles the file given by <FileName>\n";
        return 1;
    }

    // Read in the file passed as the first argument
    std::ifstream fileStream;
    fileStream.open(argv[1]);

    // We'll output to the file passed in as the second argument
    std::error_code ec;
    auto openflags = llvm::sys::fs::F_None;
    auto out = std::make_unique<llvm::tool_output_file>(argv[2], ec, openflags);

    if (ec) {
        std::cerr << argv[0] << ": " << ec.message() << "\n";
        return 1;
    }

    // Parse it!
    auto lex = Lexer(&fileStream);
    auto stmts = parse(&lex);

    // std::cout << "Result of parsing: \n";
    // for (auto &stmt : stmts) {
    //     std::cout << *stmt << ";\n";
    // }

    auto prgm = Program();
    prgm.addItems(stmts);
    prgm.finalize();

    auto mod = prgm.module;

    /* DEBUG */
    // mod->dump();

    llvm::InitializeNativeTarget();
    llvm::InitializeNativeTargetAsmPrinter();
    llvm::InitializeNativeTargetAsmParser();

    llvm::PassRegistry *registry = llvm::PassRegistry::getPassRegistry();
    llvm::initializeCore(*registry);
    llvm::initializeCodeGen(*registry);
    llvm::initializeLoopStrengthReducePass(*registry);
    llvm::initializeLowerIntrinsicsPass(*registry);
    llvm::initializeUnreachableBlockElimPass(*registry);

    llvm::Triple targetTriple(mod->getTargetTriple());
    if (targetTriple.getTriple().empty()) {
        targetTriple.setTriple(llvm::sys::getDefaultTargetTriple());
    }

    std::cout << "Target Triple: " << targetTriple.getTriple() << "\n";

    std::string error;
    const llvm::Target *target = llvm::TargetRegistry::lookupTarget("", targetTriple, error);
    if (! target) {
        std::cerr << argv[0] << ": " << error;
        return 1;
    }

    auto optLvl = llvm::CodeGenOpt::Default;
    switch ('0') { // TEmporary
    default:
        std::cerr << argv[0] << ": invalid optimization level.\n";
        return 1;
    case ' ': break;
    case '0': optLvl = llvm::CodeGenOpt::None; break;
    case '1': optLvl = llvm::CodeGenOpt::Less; break;
    case '2': optLvl = llvm::CodeGenOpt::Default; break;
    case '3': optLvl = llvm::CodeGenOpt::Aggressive; break;
    }

    // llvm::TargetOptions options;
    // TODO: llc line 268

    std::unique_ptr<llvm::TargetMachine> targetMachine(target->createTargetMachine(targetTriple.getTriple(),
                                                                                   llvm::sys::getHostCPUName(),
                                                                                   "",
                                                                                   llvm::TargetOptions(),
                                                                                   llvm::Reloc::Default,
                                                                                   llvm::CodeModel::Default,
                                                                                   optLvl));
    assert(targetMachine && "Could not allocate target machine!");

    llvm::PassManager passmanager;
    llvm::TargetLibraryInfo *TLI = new llvm::TargetLibraryInfo(targetTriple);
    passmanager.add(TLI);

    if (const llvm::DataLayout *datalayout = targetMachine->getSubtargetImpl()->getDataLayout())
        mod->setDataLayout(datalayout);

    llvm::formatted_raw_ostream ostream(out->os());

    // Ask the target to add backend passes as necessary.
    if (targetMachine->addPassesToEmitFile(passmanager, ostream, llvm::TargetMachine::CGFT_ObjectFile)) {
        std::cerr << argv[0] << ": target does not support generation of this"
                  << " file type!\n";
        return 1;
    }

    passmanager.run(*mod);

    out->keep();

    return 0;
}
Пример #6
0
void Validate::Program_Control (void)
{
	int i, num;
	String key, record;
	Dtime low, high;
	Db_File label_file;
	Str_Map_Stat map_stat;

	//---- set equivalence flags ----

	line_flag = Report_Flag (LINE_GROUP);
	stop_flag = (Report_Flag (STOP_GROUP) || Report_Flag (BOARD_GROUP) || Report_Flag (ALIGHT_GROUP));

	Link_Equiv_Flag (Report_Flag (LINK_GROUP) || Report_Flag (GROUP_DETAILS));
	Zone_Equiv_Flag (Report_Flag (ZONE_GROUP));
	Stop_Equiv_Flag (stop_flag);
	Line_Equiv_Flag (line_flag);

	//---- open network files ----

	Data_Service::Program_Control ();
	
	Print (2, String ("%s Control Keys:") % Program ());	

	//---- check for traffic counts ----

	if (Check_Control_Key (TRAFFIC_COUNT_FILE)) {
		link_flag = true;

		if (Report_Flag (ZONE_GROUP)) {
			if (!System_File_Flag (ZONE)) {
				Error ("Zone File is Required for Zone Group Reports");
			}
			zone_flag = true;
		} else if (Report_Flag (AREA_TYPE)) {
			zone_flag = System_File_Flag (ZONE);
		}
	} else {
		if (Report_Flag (VOLUME_LEVEL) || Report_Flag (FACILITY_TYPE) ||
			Report_Flag (AREA_TYPE) || Report_Flag (ZONE_GROUP) ||
			Report_Flag (LINK_GROUP) || Report_Flag (GROUP_DETAILS)) {

			Error ("Traffic Count file is Required for Link-Based Reports");
		}
	}

	//---- check for turning movements ----

	if (Check_Control_Key (TURN_COUNT_FILE)) {
		if ((Report_Flag (TURN_MOVEMENT) || Report_Flag (TURN_LOS)) && 
			!System_File_Flag (CONNECTION)) {

			Error ("Connection File is Required for Turning Movement Reports");
		}
		if (Report_Flag (TURN_LOS) && !(System_File_Flag (SIGNAL) &&
			System_File_Flag (TIMING_PLAN) && System_File_Flag (PHASING_PLAN))) {

			Error ("Signal Data is Required for Turn Level of Service Analysis");
		}
		turn_flag = true;
	} else {
		if (Report_Flag (TURN_MOVEMENT) || Report_Flag (TURN_LOS)) {
			Error ("Turn Count File is Required for Turning Movement Reports");
		}
		System_File_False (POCKET);
		System_File_False (CONNECTION);
		System_File_False (SIGNAL);
		System_File_False (TIMING_PLAN);
		System_File_False (PHASING_PLAN);
	}

	//---- check for transit reports ----

	if (line_flag || stop_flag) {
		if (!System_File_Flag (TRANSIT_STOP) || !System_File_Flag (TRANSIT_ROUTE) ||
			!System_File_Flag (TRANSIT_SCHEDULE) || !System_File_Flag (TRANSIT_DRIVER) ||
			!System_File_Flag (RIDERSHIP)) {

			Error ("Transit Network and Ridership are Required for Transit Reports");
		}
		if (line_flag && !Check_Control_Key (LINE_EQUIVALENCE_FILE)) {
			Error ("Line Group Equivalance is Required for Line Group Reports");
		}
		if (line_flag && !Check_Control_Key (LINE_GROUP_COUNT_FILE)) {
			Error ("Line Group Counts are Required for Line Group Reports");
		}
		if (stop_flag && !Check_Control_Key (STOP_EQUIVALENCE_FILE)) {
			Error ("Stop Group Equivalance is Required for Stop Group Reports");
		}
		if (stop_flag && !Check_Control_Key (STOP_GROUP_COUNT_FILE)) {
			Error ("Stop Group Counts are Required for Stop Group Reports");
		}
	} else {
		System_File_False (TRANSIT_STOP);
		System_File_False (TRANSIT_ROUTE);
		System_File_False (TRANSIT_SCHEDULE);
		System_File_False (TRANSIT_DRIVER);
		System_File_False (RIDERSHIP);
	}

	//---- check for a link delay file ----

	if (!System_File_Flag (LINK_DELAY)) {

		//---- open the link volume file ----

		if (link_flag) {
			key = Get_Control_String (INPUT_VOLUME_FILE);

			if (key.empty ()) goto control_error;

			Print (1);
			volume_file.File_Type ("Input Volume File");

			volume_file.Open (Project_Filename (key));
		
			Print (1, "Number of Time Periods = ") << volume_file.Num_Periods ();
		}

		//---- open the turn movement file ----

		if (turn_flag) {
			key = Get_Control_String (TURN_VOLUME_FILE);

			if (key.empty ()) goto control_error;

			Print (1);
			turn_volume.File_Type ("Turn Volume File");

			turn_volume.Open (Project_Filename (key));
		}
	} else {
		delay_flag = true;
	}

	//---- open the traffic count file ----

	if (link_flag) {
		key = Get_Control_String (TRAFFIC_COUNT_FILE);

		Print (1);
		count_file.File_Type ("Traffic Count File");

		count_file.Open (Project_Filename (key));

		Print (1, "Number of Time Periods = ") << count_file.Num_Periods ();
	}

	//---- open the turn count file ----

	if (turn_flag) {
		key = Get_Control_String (TURN_COUNT_FILE);

		Print (1);
		turn_count.File_Type ("Turn Count File");

		turn_count.Open (Project_Filename (key));
	}

	//---- open the transit line group count file ----

	if (line_flag) {
		key = Get_Control_String (LINE_GROUP_COUNT_FILE);

		Print (1);
		line_count_file.File_Type ("Transit Line Group Count File");

		line_count_file.Open (Project_Filename (key));

		line_count_file.Required_Field ("GROUP", "LINE", "LINEGROUP", "LINEGRP", "ID");
		line_count_file.Required_Field ("COUNT", "RIDERS", "PASSENGERS", "TOTAL", "VOLUME");
	}

	//---- open the transit stop group count file ----

	if (stop_flag) {
		key = Get_Control_String (STOP_GROUP_COUNT_FILE);

		Print (1);
		stop_count_file.File_Type ("Transit Stop Group Count File");

		stop_count_file.Open (Project_Filename (key));

		stop_count_file.Required_Field ("GROUP", "STOP", "STOPGROUP", "STOPGRP", "ID");

		if (Report_Flag (STOP_GROUP)) {
			stop_count_file.Required_Field ("TOTAL",  "ONOFF", "ON_OFF", "PASSENGERS", "COUNT");
		}
		if (Report_Flag (BOARD_GROUP)) {
			stop_count_file.Required_Field ("BOARDINGS", "BOARD", "ON", "PASSENGERS", "COUNT");
		}
		if (Report_Flag (ALIGHT_GROUP)) {
			stop_count_file.Required_Field ("ALIGHTINGS", "ALIGHT", "OFF", "PASSENGERS", "COUNT");
		}
	}

	//---- create new volume file ----

	key = Get_Control_String (NEW_VOLUME_FILE);

	if (!key.empty ()) {
		if (!delay_flag && !link_flag) {
			Error ("Link Delay or Volume File is Required to Output Volume Data");
		}
		Print (1);
		output_file.File_Type ("New Volume File");

		output_file.Create (Project_Filename (key));
		output_flag = true;
	}

	//---- create new volume count file ----

	key = Get_Control_String (NEW_VOLUME_COUNT_FILE);

	if (!key.empty ()) {
		if (!delay_flag && !link_flag) {
			Error ("Volume and Count Files are Required to Output Volume Count Data");
		}
		Print (1);
		vol_cnt_file.File_Type ("New Volume Count File");

		vol_cnt_file.Create (Project_Filename (key));
		vc_flag = true;
	}

	//---- adjust the volume ranges ----

	hours = 24.0 * sum_periods.Range_Length () / Dtime (MIDNIGHT, SECONDS);

	if (hours < 12.0) {
		double adjust = (hours <= 4.0) ? 0.1 : 0.5;

		for (i=0; volume_level [i] > 0; i++) {
			volume_level [i] = (int) (volume_level [i] * adjust + 0.5);
		}
	}
	hours = hours / sum_periods.Num_Periods ();

	//---- check the data fields ----

	if (link_flag) {
		key = "Traffic Count";

		num = sum_periods.Num_Periods ();

		if (count_file.Num_Periods () < num) goto field_error;

		for (i=0; i < num; i++) {
			sum_periods.Period_Range (i, low, high);
			if (!count_file.In_Range (low) || !count_file.In_Range ((low + high) / 2)) goto field_error;
		}
		if (!delay_flag) {
			key = "Input Volume";

			if (volume_file.Num_Periods () < num) goto field_error;

			for (i=0; i < num; i++) {
				sum_periods.Period_Range (i, low, high);
				if (!volume_file.In_Range (low) || !volume_file.In_Range ((low + high) / 2)) goto field_error;
			}
		}
	}

	//---- read the analysis method ----

	key = Get_Control_Text (ANALYSIS_METHOD);

	if (!key.empty ()) {
		if (key.Equals ("VOLUME")) {
			method = false;
		} else if (key.Equals ("VMT")) {
			method = true;
		} else {
			Error (String ("Analysis Method = %s was Unrecognized") % key);
		}
	}
	header1 = String ("\n%29cNum.  ------%s------ ---Difference---  --Abs.Error--    Std.     %%     R   ----V/C----") %
				BLANK % ((method) ? "--VMT-" : "Volume") % FINISH;

	header2 = String ("    Obs.  Estimate  Observed   %6.6s      %%     Avg.     %%     Dev.   RMSE   Sq.   Avg.  Max.\n") %
				((method) ? "VMT" : "Volume") % FINISH;
	
	//---- read the adjustment factor ----

	factor = Get_Control_Double (ADJUSTMENT_FACTOR);

	//---- open the facility type labels ----

	if (Report_Flag (FACILITY_TYPE)) {
		key = Get_Control_String (FACILITY_TYPE_LABELS);

		if (!key.empty ()) {
			label_file.File_Type ("Facility Type Label File");
			Print (1);

			label_file.Open (Project_Filename (key));

			while (label_file.Read ()) {
				record = label_file.Record_String ();
				if (record.empty ()) continue;

				record.Split (key);
				i = key.Integer ();

				map_stat = facility_type.insert (Str_Map_Data (i, record));

				if (!map_stat.second) {
					Error ("Duplicate Facility Type Label");
				}
			}
			label_file.Close ();
		}
	}

	//---- open the area type labels ----

	if (Report_Flag (AREA_TYPE)) {
		key = Get_Control_String (AREA_TYPE_LABELS);

		if (!key.empty ()) {
			label_file.File_Type ("Area Type Label File");
			Print (1);

			label_file.Open (Project_Filename (key));

			while (label_file.Read ()) {
				record = label_file.Record_String ();
				if (record.empty ()) continue;

				record.Split (key);
				i = key.Integer ();

				map_stat = area_type.insert (Str_Map_Data (i, record));

				if (!map_stat.second) {
					Error ("Duplicate Area Type Label");
				}
			}
			label_file.Close ();
		}
	}

	//---- write the report names ----

	List_Reports ();

	//---- read the zone equiv ----

	if (Zone_Equiv_Flag ()) {
		zone_equiv.Read (Report_Flag (ZONE_EQUIV));
	}

	//---- process support data ----

	if (Link_Equiv_Flag ()) {
		link_equiv.Read (Report_Flag (LINK_EQUIV));
	}

	//---- read the line equiv ----

	if (line_flag) {
		line_equiv.Read (Report_Flag (LINE_EQUIV));
	}

	//---- read the stop equiv ----

	if (stop_flag) {
		stop_equiv.Read (Report_Flag (STOP_EQUIV));
	}
	return;

	//---- error message ----

field_error:
	Error (String ("The %s File has insufficient data for %d Time Increments") % key % num);

control_error:
	Error (String ("Missing Control Key = %s") % Current_Key ());
} 
Пример #7
0
SubareaPlans::SubareaPlans (void) : Demand_Service ()
{
	Program ("SubareaPlans");
	Version ("4.0.33");
	Title ("Subarea Plan and Vehicle Files");

	Network_File required_network [] = {
		NODE, LINK, ACTIVITY_LOCATION, PARKING, PROCESS_LINK, END_NETWORK
	};
	Network_File optional_network [] = {
		DIRECTORY, LANE_CONNECTIVITY, NEW_DIRECTORY, 
		NEW_ACTIVITY_LOCATION, NEW_PARKING, NEW_PROCESS_LINK, 
		TRANSIT_STOP, TRANSIT_ROUTE, TRANSIT_SCHEDULE, TRANSIT_DRIVER,
		NEW_TRANSIT_STOP, NEW_TRANSIT_ROUTE, NEW_TRANSIT_SCHEDULE, NEW_TRANSIT_DRIVER,
		END_NETWORK
	};
	Demand_File required_demand [] = {
		VEHICLE, NEW_VEHICLE, END_DEMAND
	};
	Demand_File optional_demand [] = {
		LINK_DELAY, NEW_BOUNDARY_SPEED, END_DEMAND
	};

	char *keys [] = {
		PLAN_FILE,
		PLAN_FORMAT,
		NODE_LIST_PATHS,
		SUBAREA_BOUNDARY_POLYGON,
		EXTERNAL_OFFSET_LENGTH,
		NEW_PLAN_FILE,
		NEW_PLAN_FORMAT,
		NEW_HOUSEHOLD_LIST,
		RETIME_EARLY_ARRIVALS,
		ZONE_EQUIVALENCE_FILE,
		TIME_PERIOD_EQUIVALENCE,
		SELECT_TIME_PERIODS,
		NULL
	};
	char *reports [] = {
		"TRIP_SUMMARY_REPORT",
		"PRINT_ZONE_EQUIVALENCIES",
		"TIME_PERIOD_EQUIVALENCE",
		NULL
	};

	Required_Network_Files (required_network);
	Optional_Network_Files (optional_network);
	Required_Demand_Files (required_demand);
	Optional_Demand_Files (optional_demand);

	Key_List (keys);
	Report_List (reports);
	Enable_Partitions (true);

	AB_Key_Flag  (true);

	trips = NULL;

	type_flag = true;
	transit_flag = output_flag = range_flag = false;
	delay_flag = location_flag = parking_flag = access_flag = extend_flag = early_flag = false;
	trip_flag = zone_flag = time_flag = turn_flag = hhlist_flag = boundary_flag = false;
	nlink = nshort = nlocation = nparking = naccess = num_adjust = total_adjust = 0;
	max_location = max_parking = max_access = max_vehicle = max_zone = 0;
	num_in_in = num_out_in = num_in_out = num_out_out = 0;
	leg_in_in = leg_out_in = leg_in_out = leg_out_out = 0;

	max_stop = max_route = 0;
	new_stop = new_route = 0;
	nstop = nroute = nschedule = ndriver = 0;
	current_traveler = current_trip = current_leg = boarding_stop = last_location = last_time = 0;

	external_offset = Round (15);		//---- 15 meters ----

	boundary.Data_Size (sizeof (Boundary));

	Compress_Vehicles (false);
}
Пример #8
0
void NetMerge::Program_Control (void)
{
	String key, merge_dir;

	//---- open network and demand files ----

	Data_Service::Program_Control ();

	Print (2, String ("%s Control Keys:") % Program ());
	Print (1);

	//---- merge directory ----

	merge_dir = Get_Control_String (MERGE_DIRECTORY);

	if (!merge_dir.empty ()) {
		Print_Filename (1, "Merge Directory", merge_dir);
		Fix_Directory (merge_dir);
	}

	//---- open merge node file ----

	key = Get_Control_String (MERGE_NODE_FILE);

	if (!key.empty ()) {
		node_file.File_Type ("Merge Node File");
		node_file.Open (merge_dir + key);
	}

	//---- open merge link file ----

	key = Get_Control_String (MERGE_LINK_FILE);

	if (!key.empty ()) {
		link_file.File_Type ("Merge Link File");
		link_file.Open (merge_dir + key);
	}

	//---- open merge shape file ----

	key = Get_Control_String (MERGE_SHAPE_FILE);

	if (!key.empty ()) {
		shape_file.File_Type ("Merge Shape File");
		shape_file.Open (merge_dir + key);
		shape_flag = true;
	}

	//---- open merge pocket file ----

	key = Get_Control_String (MERGE_POCKET_FILE);

	if (!key.empty ()) {
		pocket_file.File_Type ("Merge Pocket File");
		pocket_file.Open (merge_dir + key);
		pocket_flag = true;
	}

	//---- open merge lane use file ----

	key = Get_Control_String (MERGE_LANE_USE_FILE);

	if (!key.empty ()) {
		lane_use_file.File_Type ("Merge Lane Use File");
		lane_use_file.Open (merge_dir + key);
		lane_use_flag = true;
	}

	//---- open merge location file ----

	key = Get_Control_String (MERGE_LOCATION_FILE);

	if (!key.empty ()) {
		location_file.File_Type ("Merge Location File");
		location_file.Open (merge_dir + key);
		location_flag = true;
	}

	//---- open merge connection file ----

	key = Get_Control_String (MERGE_CONNECTION_FILE);

	if (!key.empty ()) {
		connect_file.File_Type ("Merge Connection File");
		connect_file.Open (merge_dir + key);
		connect_flag = true;
	}
	//---- open merge parking file ----

	key = Get_Control_String (MERGE_PARKING_FILE);

	if (!key.empty ()) {
		parking_file.File_Type ("Merge Parking File");
		parking_file.Open (merge_dir + key);
		parking_flag = true;
	}

	//---- open merge access file ----

	key = Get_Control_String (MERGE_ACCESS_FILE);

	if (!key.empty ()) {
		access_file.File_Type ("Merge Access File");
		access_file.Open (merge_dir + key);
		access_flag = true;
	}

	//---- open merge stop file ----

	key = Get_Control_String (MERGE_STOP_FILE);

	if (!key.empty ()) {
		stop_file.File_Type ("Merge Stop File");
		stop_file.Open (merge_dir + key);
		stop_flag = true;
	}

	//---- open merge sign file ----

	key = Get_Control_String (MERGE_SIGN_FILE);

	if (!key.empty ()) {
		sign_file.File_Type ("Merge Sign File");
		sign_file.Open (merge_dir + key);
		sign_flag = true;
	}

	//---- open merge signal file ----

	key = Get_Control_String (MERGE_SIGNAL_FILE);

	if (!key.empty ()) {
		signal_file.File_Type ("Merge Signal File");
		signal_file.Open (merge_dir + key);
		signal_flag = true;
	}

	//---- open merge timing file ----

	key = Get_Control_String (MERGE_TIMING_PLAN_FILE);

	if (!key.empty ()) {
		timing_file.File_Type ("Merge Timing Plan File");
		timing_file.Open (merge_dir + key);
		timing_flag = true;
	}

	//---- open merge phasing file ----

	key = Get_Control_String (MERGE_PHASING_PLAN_FILE);

	if (!key.empty ()) {
		phasing_file.File_Type ("Merge Phasing Plan File");
		phasing_file.Open (merge_dir + key);
		phasing_flag = true;
	}

	//---- open merge detector file ----

	key = Get_Control_String (MERGE_DETECTOR_FILE);

	if (!key.empty ()) {
		detector_file.File_Type ("Merge Detector File");
		detector_file.Open (merge_dir + key);
		detector_flag = true;
	}

	//---- open merge zone file ----

	key = Get_Control_String (MERGE_ZONE_FILE);

	if (!key.empty ()) {
		zone_file.File_Type ("Merge Zone File");
		zone_file.Open (merge_dir + key);
		zone_flag = true;
	}

	//---- open merge performance file ----

	key = Get_Control_String (MERGE_PERFORMANCE_FILE);

	if (!key.empty ()) {
		performance_file.File_Type ("Merge Performance File");
		performance_file.Open (merge_dir + key);
		performance_flag = true;
	}

	//---- open merge turn_delay file ----

	key = Get_Control_String (MERGE_TURN_DELAY_FILE);

	if (!key.empty ()) {
		turn_delay_file.File_Type ("Merge Turn Delay File");
		turn_delay_file.Open (merge_dir + key);
		turn_delay_flag = true;
	}

}