Skip to content

Commit

Permalink
Merge pull request #535 from emsec/feature/module_pin_pingroup_actions
Browse files Browse the repository at this point in the history
Feature/module pin pingroup actions
  • Loading branch information
joern274 authored Feb 29, 2024
2 parents 62b5f7c + 9b8bec4 commit 8a6afbb
Show file tree
Hide file tree
Showing 69 changed files with 3,039 additions and 1,430 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ All notable changes to this project will be documented in this file.
* boosted performance by using classes with faster memory access
* removed layouter code used prior to version 3.1.0 - thus removing the setting option to use that code
* added setting option to dump junction layout input data for experts to debug in case of layout errors
* module pins
* added qualifier for `pin_changed` core events telling receiver details about the recent modification
* added event scope and stacking classes so that `pin_changed` events can be collected and prioritized
* added specific GUI handler for every `pin_changed` event thus replacing the reload-entire-pingroup-tree policy
* added class `ActionPingroup` so that UNDO function works for all pin / pin group actions issued from GUI
* miscellaneous
* added INIT field declaration to FF-gate-types in example library
* added drag'n drop feature allowing to move several nodes in graph view at same time
Expand Down
2 changes: 1 addition & 1 deletion include/hal_core/netlist/event_system/event_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace hal
gates_remove_begin, ///< associated_data = number of gates to remove
gates_remove_end, ///< associated_data = number of removed gates
gate_removed, ///< associated_data = id of removed gate
pin_changed, ///< no associated_data
pin_changed, ///< associated_data = [4LSB: type of action] [28HSB: id of pin group or pin]
};
};

Expand Down
166 changes: 166 additions & 0 deletions include/hal_core/netlist/gate_library/enums/pin_event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// MIT License
//
// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once

#include "hal_core/utilities/enums.h"
#include "hal_core/defines.h"
#include <unordered_map>
#include <vector>

namespace hal
{
/**
* Spezifies the pin_changed event type
*
* The order of events in enum class defines the order in which events are handled.
*
*/
enum class PinEvent
{
unknown,
GroupCreate, /// new pin group created
GroupRename, /// pin group renamed
GroupTypeChange, /// changed PinType attribute of group (like data)
GroupDirChange, /// changed PinDirection attribute of group (like input)
GroupReorder, /// moved group to a new position within containing module
PinCreate, /// new pin created
PinAssignToGroup, /// pin assigned to new group
PinRename, /// pin renamed
PinTypeChange, /// changed PinType attribute of pin (like data)
PinDirChange, /// changed PinDirection attribute of pin (like input)
PinReorder, /// moved pin to a new position within containing group
PinDelete, /// pin deleted
GroupDelete /// group deleted
};

template<>
std::map<PinEvent, std::string> EnumStrings<PinEvent>::data;

class Module;

/**
* Wrapper class for core pin_changed events.
*
* Events can be send immediately or stacked and send at according to their priority.
*/
class PinChangedEvent
{
friend bool pin_event_order(const PinChangedEvent& a, const PinChangedEvent& b);
friend class PinChangedEventScope;

/**
* Subclass for event stack.
*/
class EventStack : public std::vector<PinChangedEvent>
{
public:
/**
* Scope count indicates the nesting depth of event-throwing subroutines.
* Only the top level (m_count=0) is allowed to send the events from stack.
*/
int m_count;

/**
* Construct empty stack
*/
EventStack() : m_count(0) {;}

/**
* Attempts to send events, typically at the end of a pin-changing subroutine.
* Events will only be send if m_count is zero.
*/
void send_events(Module* m);
};

static std::unordered_map<Module*,EventStack*> s_event_stack;

Module* m_module;
PinEvent m_event;
u32 m_id;

public:
/**
* PinChangedEvent class for single event
* @param m - The module comprising pins and pin groups
* @param pev - The pin event enum
* @param id - pin or pin group ID
*/
PinChangedEvent(Module* m, PinEvent pev, u32 id);

/**
* Returns the module for which pins or pin groups have been changed
* @return The module comprising pins and pin groups
*/
Module* get_module() const;

/**
* Return bitwise binary encoded PinEvent and ID
* 4LSB = The pin event enum as 4 bit int
* 28HSB = The ID as 28 bit int
* @return The bitcode according to scheme above
*/
u32 associated_data();

/**
* Attempts to send event.
* If this routine or any calling routine wants to collect events the event gets written on stack instead.
*/
void send();
};

/**
* By creating an instance of this class a new scope gets created thus collecting events.
*/
class PinChangedEventScope
{
Module* m_module;
public:

/**
* Constructor for scope instance incrementing scope count
* @param m The module comprising pins and pin groups
*/
PinChangedEventScope(Module* m);

/**
* Destructor for scope instance decrementing scope count
*/
~PinChangedEventScope();

/**
* Attempts to send all stacked events. Will do nothing if not issued from top-level scope.
*/
void send_events();
};

/**
* Function used by sort algorithm to organize events according to their priority.
* @param a - Pin changed event A
* @param b - Pin changed event B
* @return true if A should be handled before B, false otherwise.
*/
bool pin_event_order(const PinChangedEvent& a, const PinChangedEvent& b);
}
3 changes: 2 additions & 1 deletion include/hal_core/netlist/gate_library/enums/pin_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ namespace hal

template<>
std::map<PinType, std::string> EnumStrings<PinType>::data;
} // namespace hal

} // namespace hal
6 changes: 3 additions & 3 deletions include/hal_core/netlist/gate_library/gate_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ namespace hal
* Delete the given pin group.
*
* @param[in] pin_group - The pin group to be deleted.
* @returns Ok on success, an error message otherwise.
* @returns true on success, false otherwise.
*/
Result<std::monostate> delete_pin_group(PinGroup<GatePin>* pin_group);
bool delete_pin_group(PinGroup<GatePin>* pin_group);

/**
* Assign a pin to a pin group.
Expand Down Expand Up @@ -469,6 +469,6 @@ namespace hal
GateType& operator=(const GateType&) = delete;

Result<PinGroup<GatePin>*> create_pin_group_internal(const u32 id, const std::string& name, PinDirection direction, PinType type, bool ascending, u32 start_index);
Result<std::monostate> delete_pin_group_internal(PinGroup<GatePin>* pin_group);
bool delete_pin_group_internal(PinGroup<GatePin>* pin_group);
};
} // namespace hal
35 changes: 21 additions & 14 deletions include/hal_core/netlist/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "hal_core/netlist/event_system/event_handler.h"
#include "hal_core/netlist/gate_library/enums/pin_direction.h"
#include "hal_core/netlist/gate_library/enums/pin_type.h"
#include "hal_core/netlist/gate_library/enums/pin_event.h"
#include "hal_core/netlist/gate_library/gate_library.h"
#include "hal_core/netlist/pins/module_pin.h"
#include "hal_core/netlist/pins/pin_group.h"
Expand Down Expand Up @@ -526,19 +527,19 @@ namespace hal
* Delete the given pin group.
*
* @param[in] pin_group - The pin group to be deleted.
* @returns Ok on success, an error message otherwise.
* @returns true on success, false otherwise.
*/
Result<std::monostate> delete_pin_group(PinGroup<ModulePin>* pin_group);
bool delete_pin_group(PinGroup<ModulePin>* pin_group);

/**
* Move a pin group to another index within the module.
* The indices of some other pin groups will be incremented or decremented to make room for the moved pin group to be inserted at the desired position.
*
* @param[in] pin_group - The pin group to be moved.
* @param[in] new_index - The index to which the pin group is moved.
* @returns Ok on success, an error message otherwise.
* @returns true on success, false message otherwise.
*/
Result<std::monostate> move_pin_group(PinGroup<ModulePin>* pin_group, u32 new_index);
bool move_pin_group(PinGroup<ModulePin>* pin_group, u32 new_index);

/**
* Set the name of the given pin group.
Expand Down Expand Up @@ -574,9 +575,9 @@ namespace hal
* @param[in] pin_group - The new pin group.
* @param[in] pin - The pin to be added.
* @param[in] delete_empty_groups - Set `true` to delete groups that are empty after the pin has been assigned to the new group, `false` to keep empty groups. Defaults to `true`.
* @returns Ok on success, an error message otherwise.
* @returns `true` on success, `false` otherwise.
*/
Result<std::monostate> assign_pin_to_group(PinGroup<ModulePin>* pin_group, ModulePin* pin, bool delete_empty_groups = true);
bool assign_pin_to_group(PinGroup<ModulePin>* pin_group, ModulePin* pin, bool delete_empty_groups = true);

/**
* Move a pin to another index within the given pin group.
Expand All @@ -585,9 +586,9 @@ namespace hal
* @param[in] pin_group - The pin group.
* @param[in] pin - The pin to be moved.
* @param[in] new_index - The index to which the pin is moved.
* @returns Ok on success, an error message otherwise.
* @returns `true` on success, `false` otherwise.
*/
Result<std::monostate> move_pin_within_group(PinGroup<ModulePin>* pin_group, ModulePin* pin, u32 new_index);
bool move_pin_within_group(PinGroup<ModulePin>* pin_group, ModulePin* pin, u32 new_index);

/**
* Remove a pin from a pin group.
Expand All @@ -596,9 +597,9 @@ namespace hal
* @param[in] pin_group - The old pin group.
* @param[in] pin - The pin to be removed.
* @param[in] delete_empty_groups - Set `true` to delete the group of it is empty after the pin has been removed, `false` to keep the empty group. Defaults to `true`.
* @returns Ok on success, an error message otherwise.
* @returns `true` on success, `false` otherwise.
*/
Result<std::monostate> remove_pin_from_group(PinGroup<ModulePin>* pin_group, ModulePin* pin, bool delete_empty_groups = true);
bool remove_pin_from_group(PinGroup<ModulePin>* pin_group, ModulePin* pin, bool delete_empty_groups = true);

/*
* ################################################################
Expand Down Expand Up @@ -680,6 +681,12 @@ namespace hal
*/
std::vector<Gate*> get_gates(const std::function<bool(Gate*)>& filter, bool recursive = false) const;

/**
* Get the event handler connected to module
* @return The event handler;
*/
EventHandler* get_event_handler() const;

private:
friend class NetlistInternalManager;
Module(NetlistInternalManager* internal_manager, EventHandler* event_handler, u32 id, Module* parent, const std::string& name);
Expand Down Expand Up @@ -741,11 +748,11 @@ namespace hal

NetConnectivity check_net_endpoints(const Net* net) const;
Result<std::monostate> check_net(Net* net, bool recursive = false);
Result<ModulePin*> assign_pin_net(const u32 pin_id, Net* net, PinDirection direction, const std::string& name = "", PinType type = PinType::none);
Result<std::monostate> remove_pin_net(Net* net);
bool assign_pin_net(const u32 pin_id, Net* net, PinDirection direction);
bool remove_pin_net(Net* net);
Result<ModulePin*> create_pin_internal(const u32 id, const std::string& name, Net* net, PinDirection direction, PinType type, bool force_name);
Result<std::monostate> delete_pin_internal(ModulePin* pin);
bool delete_pin_internal(ModulePin* pin);
Result<PinGroup<ModulePin>*> create_pin_group_internal(const u32 id, const std::string& name, PinDirection direction, PinType type, bool ascending, u32 start_index, bool force_name);
Result<std::monostate> delete_pin_group_internal(PinGroup<ModulePin>* pin_group);
bool delete_pin_group_internal(PinGroup<ModulePin>* pin_group);
};
} // namespace hal
2 changes: 1 addition & 1 deletion include/hal_core/netlist/pins/base_pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@ namespace hal
{
}
};
} // namespace hal
} // namespace hal
Loading

0 comments on commit 8a6afbb

Please sign in to comment.